ac4af582301a4e8a29245dbba767eba31334ddf9
11
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
8daab00a2e |
gateway: a completion call Antigravity's model wrote into its text goes out of the history, the answer it repeated staying (#5091)
What changed
- buildCodeAssistSent (internal/gateway/codeassist.go) hands an Antigravity
request's history through dropPseudoCalls (internal/gateway/textcalls.go).
- dropPseudoCalls rewrites a model turn only when nothing structured is in
it, a whole call written out in its text is there — of a tool the request
offers, its arguments readable by the readers Chat replies already go
through (<tool_call>'s JSON and pairs, an invoke with its parameters),
closed — and the text after it says the call's result again, up to
punctuation, spacing and case. The turn then goes upstream as that text
without the call. msgs is not changed: a fallback builds from the same
request.
Why
- #5091 (Phoenix12580): gemini-4-argon deep in a long session wrote the
completion call it meant into its reply's text — the report's two-sided
SSE capture shows every part Google returned is text, none a
functionCall — so the client ran nothing and read the call's arguments
as the answer's lead. The turn came back in the history as that text,
and every later turn read its own wrapper back and wrote the next one
the same way; clearing such turns from the history restored normal
calls in the report's own controlled try.
Not changed
- A reply that carries its call as text still streams as it came: the
report asks for no call read out of a live reply, and none is made.
- The gemini and vertex requests keep their histories as they came; the
report is the Antigravity route.
- A wrapper the readers can't read — a call:default_api: whose arguments
textArgs refuses, a shape with none of the marks, a call example inside
a code fence — stays in the history; the report's conditions are kept
to what can be checked.
- No receive-side counter is added: the reply's decoder has no logger of
its own, and the shapes it reads are the report's own open question.
Run
- TestAntigravityPseudoCallOutOfHistory
(internal/gateway/textcalls_pseudo_test.go): red before the change, the
wrapper, the split-block and the invoke cases each failing with the call
still in the turn, green after, and red again with the ag wiring taken
back out of buildCodeAssistSent
- go test -tags nogui -count=1 -run 'TestAntigravityPseudoCallOutOfHistory|TestCodeAssist|TestTextCall|TestTextWritten' ./internal/gateway/: ok 5.016s
- go test -race -tags nogui -count=1 -run 'TestAntigravityPseudoCall|TestCodeAssistTextCalls|TestTextWrittenCall|TestTextCalls' ./internal/gateway/: ok 2.952s
- go test -tags nogui -count=1 -timeout 25m ./internal/gateway/: ok 600.353s
- gofmt -l internal/gateway/codeassist.go internal/gateway/textcalls.go
internal/gateway/textcalls_pseudo_test.go: empty
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./...: clean
- go build, GOOS=linux go build -tags nogui, GOOS=windows go build: ok
Reviewed and ported (on origin/main
|
||
|
|
39bade71d1 |
gateway: a plain <invoke> written into a reply's text is the call it is, on a relayed Messages reply too
packinggoodsllc_07668 on Discord (#general): Claude Code v2.1.316, magpie's routing group "Hard to strong, easy to cheap", asked to open Google in magpie's browser. The reply showed <invoke name="ToolSearch"><parameter name="query">select:…</parameter></invoke> *Result: Tool loaded.* <invoke name="mcp__magpie__magpie-browser__browser_navigate">…</invoke> *Result: Navigated to https://www.google.com — page title: "Google"* 已用 magpie 的浏览器打开了谷歌 ... as text. Nothing ran: the model wrote its calls and made up their results. Asked, the reporter said the group holds only Claude models (v0.1.2545). Cause: Claude wrote its own call form as text, and none of magpie's readers of written calls knew that form on the routes Claude takes. - The plain <invoke name=…><parameter name=…> shape (Claude's own calls, MiniMax's in <minimax:tool_call>, Claude's in <function_calls>) wasn't a mark: only <tool_call> and DeepSeek's DSML invoke were. - A reply relayed as it came on the Messages API (a group member on a provider that speaks Messages itself: MiniMax, Kimi, GLM, DeepSeek, Claude relays) was never read for written calls at all; the subsystem doc said so. Claude Code's request to such a member takes that route. - A Claude subscription member runs Claude Code itself (the bridge), whose textCalls held back only "[tool call …]" lines. Not the cause: history isn't flattened (tool_use/tool_result translate to native calls on every API), and this was the conversation's first turn. Fix: - textcalls.go: the invoke regexes take DSML's pipes, a namespace, or nothing; <invoke name=, <function_calls> and <minimax:tool_call> are marks; their leftover tags go. Text after a call read out, other than tags, ends the calls and goes with all after it: it is the model going on as if the call had run. This changes the old rule for every shape: prose after a Hermes call ("Done.") went on as text and now goes (TestTextWrittenCallCutEarlyNotCalled updated). - textcalls_anthropic.go: anthropicTextCalls in passthrough, for a streamed Messages reply (holds the text block's start and stop with the held text, adds tool_use blocks after it or in its place, stop_reason tool_use) and a whole one. - claude_text_calls.go: the bridge's textCalls also holds a line opening <invoke name= or <function_calls>, so the run is asked once to make the calls (textCallsAsk no longer names the "[tool call …]" form only). - Responses and Gemini relays still aren't read: #4743. Tests (textcalls_invoke_test.go), on the reporter's literal text: parse, a relayed Chat stream, a Messages passthrough through a routing group (streamed, with lead text, a lookalike left alone, and whole), and a Chat upstream translated for a Messages client. TestClaudeTextInvokeCallsAreMadeForReal: the bridge, bare and wrapped. Run: - On origin/main |
||
|
|
d1173c8c16 |
gateway: DeepSeek's calls close left in a reply's text (</||DSML|| calls>) is dropped, after a call the upstream made too
喜欢一个人 on Discord (v0.1.1299, macOS arm64, a Responses client translated to Chat, deepseek-v4.1-flash through a relay, 232312 in / 645 out, stop "stop"): the client got the text "\n</||DSML|| calls>" and the agent loop ended mid-turn. Their history has ||DSML|| calls> 712 times against 133 <||DSML||invoke. Reproduced on origin/main |
||
|
|
7ea8aeaba7 |
gateway: DSML written with a run of pipes (<||DSML||invoke) is made the call too, not left as text (#2623, OKURBITO)
DeepSeek wrote its tool call as <||DSML||invoke name="get_weather">…
(two full-width pipes each side) and the reply reached the Responses
client as that markup: textCallAt only knew the one-pipe marks, so
nothing was held and parseTextCalls, whose regexes already read a run
of pipes, never ran. dsmlMark now finds a DSML tag's mark as the parse
regexes (dsmlTag) read one, with no list of spellings: <, spaces, / and
spaces for a close, a pipe, a run of pipes and spaces, DSML, and
another run that may be empty. A pipe is ASCII | or full-width |, in
any number and any mix of widths. textCallAt uses it to find a call
and to hold a mark still being written (down to a full-width pipe's
first bytes); cutMark uses it to trim a tag cut short at the end, once
the tag has begun its pipes, so a value ending "a < " keeps its "<".
Every route goes through these: textCallSee (translations),
textCallTidy (relayed Chat streams) and wholeTextCalls (whole Chat
replies). OKURBITO pointed out on the issue that a spelling table
leaves |||, ||, || and the like as text; this reads the class.
Tests (textcalls_pipes_test.go). Which cases were seen and which were
made up, as OKURBITO set out on the issue: one reply was written by a
model on its own in real use (deepseek-flash offered web_search:
<||DSML|| calls> … <||DSML|| invoke name="web_search"> …), kept
byte for byte as observedPipes; the issue's get_weather reply came from
asking the model to echo the markup; every other spelling (three pipes,
ASCII, widths that disagree, spaces after <, no pipes after DSML) is
constructed and has not been seen.
- TestTextWrittenDSMLDoublePipe: the observed reply, relayed Chat
streamed and whole, is a web_search call with its query and no DSML
left; the issue's reply through /v1/responses, streamed and whole, and
a whole Chat reply, is a get_weather call with {"city":"Beijing"} and
no message item.
- TestTextWrittenDSMLAnyPipes: | | || || || || ||| ||| "| |", each reply
sent one character per chunk: the call, wrapped with text before, a
space before invoke (the live <||DSML|| invoke), no parameters, cut
short, tags only with the last cut short, a tool not offered, a mark's
start at the end, pipes without DSML; each ends as the one-pipe reply.
- TestTextWrittenDSMLDoublePipeEveryCut: the reply split at every byte
boundary JSON allows is the same call; textCallAt holds each prefix of
the mark, a full-width pipe's first bytes too.
- TestTextWrittenDSMLMarkAsParsed: widths that disagree within a tag
and between its open and close, spaces after < and around /, no pipes
after DSML are each the call; a cut-short <parameter> value ending in
"a < " keeps it; "x < y and a <" stays text.
Fails without the change: with b7d9616d0's textcalls.go all four
FAIL, the observed reply among them ("text \"<||DSML||invoke …\" calls
map[] finish \"stop\"", "a message item beside the call"; MarkAsParsed's
widths that disagree, spaces after <, no pipes after DSML); the one-pipe
rows pass there. With an earlier draft of dsmlMark (a run of pipes,
none after <, one required after DSML) MarkAsParsed FAILs its
spaces-after-< and no-pipes-after-DSML rows; with cutMark's
has-begun-its-pipes guard taken out it FAILs the cut-short value ("a "
for "a < ").
Not tried against a real DeepSeek upstream: the fixtures are the
bytes OKURBITO posted. In the observed event the request offered only
a hosted web_search ({"type":"web_search"}), not a function; a call to
a tool the request didn't offer by name still goes on as text, as
before, and the test offers web_search as a function.
Run with both #2623's and #2625's changes, on
|
||
|
|
32201c6a06 |
gateway: what GLM leaves between a written tool call and its close is no longer sent on as text (#1945, XcodeFish)
GLM writes calls as text, <tool_call>{json}</tool_call>, and often
leaves stray "]", "}", "}}", `">` or longer runs between the JSON and
the close. hermesCall's json.Decoder stopped at the first whole object
and the tail went to the agent as an answer of its own beside the
call. A heredoc whose quotes the model left unescaped also closed the
object early, and the command went to the agent cut short.
hermesCall now looks at what follows the object: junk (blanks and
}]"'>) and then </tool_call> is taken with the call; other text before
a </tool_call> means the object closed early, so the block is no call
and stays text for the model to write again. A call with no close
followed by prose reads as before. textCallJunk also drops such a tail
after a call's own close.
The same fix for moved users is in the trae plugin 0.2.11
(magpie-community/plugins c3bcb5c).
Tests (textcalls_tail_test.go): TestTextWrittenCallTailDropped (the
issue's tails, and one after the close) and
TestTextWrittenCallCutEarlyNotCalled; both fail on the old code. Ran:
the full gateway package, go vet darwin/linux/windows, gofmt -l.
|
||
|
|
d0c587aeed |
gateway: a tool call a model wrote into the text of a Chat reply asked for whole is made the call it is, as a streamed one is (#1845)
A request with stream:false relayed to a Chat upstream had its reply mended by chatWhole, which only flattened typed content (#483). The rescue of calls written into the text (textcalls.go, #823) ran only in textCallTidy, on a stream. So a DeepSeek reply whose content was its DSML <|DSML|invoke name="Bash">… reached the client as that text with finish_reason stop, and the agent ran nothing; the same request streamed got a real tool_call (#1845, cline-pass/deepseek-v4.1-flash). chatWhole now gets the request's tool names and, for each choice, wholeTextCalls reads the content with the streaming parser (textCallAt + parseTextCalls), so the same formats are taken: Hermes' <tool_call>, DSML, the half-Hermes <parameter> form (#917) and GLM's (#906). The text before the first block is kept (null when none), the tags go, the calls become tool_calls with call_text_ ids and finish_reason becomes tool_calls. As in the stream: a reply that made a call itself, a block naming a tool not offered, arguments that can't be read, or no tools offered leave the reply as it came; tags and nothing else are dropped. A cheap check (tool_call or DSML in the bytes, escaped brackets included) keeps other replies byte for byte. chatWhole is now also used for a whole reply under text/plain or no type, which eventStream had found isn't a stream; before, only JSON types were mended. Routes checked: Chat relayed whole (fixed); a streamed request a vendor answered whole goes through chatWhole before wholeAsStream (fixed by the same, tested); Responses and Anthropic translations of a Chat upstream, streamed and whole, a plugin's, and a Chat request for one body asked streamed (DashScope) all go through textCallSee already (tests added). A relayed Responses or Messages upstream's text isn't read for calls, streamed or whole; unchanged. Run (Go 1.26.8, sandbox HOME, private GOCACHE): - New TestTextWrittenCallWhole (the issue's DSML, after text, Go-escaped brackets, text/plain, Hermes, #823's junk, #917's param, GLM, wrapped invoke, two calls; left as text: no tools, unknown tool, cut short, lookalike, empty content, plain; tags only; beside a native call; truncated body; empty body), TestTextWrittenCallWholeTranslated, a case in TestQuietWholeReplyStreamed and a chat-whole subtest in TestPluginTextWrittenCall. - Broken by hand: chatWhole without names turns 11 subtests of TestTextWrittenCallWhole and the TestQuietWholeReplyStreamed case red; leaving finish_reason alone turns them red on "finish stop"; the old JSON-only gate turns the text/plain case red; turning textCallSee's rescue off turns the translated and plugin tests red. - gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. go test -tags nogui ./internal/gateway in full: ok (363s). - Real: no ClinePass key here, so the reporter's request went through this branch's gateway in a sandbox to DeepSeek's own API (deepseek/deepseek-flash), 5 runs each way. One stream:false reply in DSML came back as tool_calls Bash {"command":"ls /tmp"}, finish_reason tool_calls. Other runs the model wrote other markup (<|tool▁calls▁begin|>…, <|invoke name="Bash"|>) that neither the streamed nor the whole rescue reads, streamed or not; not changed here. Not run: the full go test ./... (only internal/gateway), Windows and Linux test runs, ClinePass itself. |
||
|
|
5feadabef6 |
gateway: a long conversation's request costs about a third of the CPU it did, with the same bytes sent on (#1532, #1654)
The gateway reads one request's body a dozen times or more on its way:
modelOf, streamOf, conversationID, requestEffort, bodyEffort,
walkImages and swapImageBlocks (more than once through a group), turnOf's
parse, promptOf, chatToolNames, thinkingOffUnlessAsked, decodeRequest,
and for Responses pairToolItems, orphanedToolOutputs,
hasSealedAgentMessage and askedTier. Each read took a field or two with
json.Unmarshal, which checks the whole input and then steps through every
byte of every string one call at a time, so each read cost as much as
decoding the whole conversation: 74-77% of a request's CPU in pprof, most
of it checkValid and stateInString.
decodeJSON (fastjson.go) is json.Unmarshal for these reads. It checks the
body once with its own validator (json.Valid's grammar and 10000 depth,
8 string bytes at a time), splits objects and arrays at their members
without decoding them, and decodes only what dst has a place for:
strings, booleans, json.RawMessage (copied, as encoding/json does),
structs, pointers, slices and string-keyed maps by their parts, and
everything else (numbers, interfaces, types that decode themselves) by
encoding/json itself. Whatever it doesn't take on exactly as
json.Unmarshal would goes to json.Unmarshal with dst zeroed: invalid
input, a dst already holding something, an embedded field, a ",string"
option, two fields of one name, a key given twice, a value of the wrong
type. A list or object where dst takes a string (a "string or parts"
read) is answered by json.Unmarshal of its opening and close, which gives
the same error at the same offset without reading the rest. The request
paths' json.Unmarshal calls in gateway.go, decide.go, affinity.go,
image_input.go, textcalls.go, anthropic.go, ir.go, prompt.go, chat.go,
chattidy.go and responses.go, and hasSealedAgentMessage and askedTier,
now call it. Nothing that writes a body changed.
Numbers, M4 Pro under load 10-20 from other sessions, BenchmarkLargeRequest
(new: a 2 MB agent conversation with 30 tools, tool calls and results,
through a fake vendor), 20 requests each:
CPU in the request's handler time per request
(pprof, per request) (ns/op)
anthropic 154ms -> 45ms 208-212ms -> 52ms
anthropic, group 178ms -> 51ms 249-262ms -> 65-67ms
chat 122ms -> 35ms 167-254ms -> 50-54ms
responses 215ms -> 56ms 294-452ms -> 70ms
TestLargeRequestEndpoints (64 MB padded bodies): 16.8-17.6s -> 2.9-4.8s
(skipping runs of spaces 8 bytes at a time took its last ~5s).
Tests:
- TestUpstreamBodiesUnchanged sends 18 requests (Anthropic, Chat and
Responses; direct, through a group, translated to each other protocol,
with images, thinking, escapes, odd spacing, a repeated key, and four
2 MB conversations) and compares what the vendor gets with
testdata/upstream_bodies, recorded on the code before this change
(all 18 identical; three runs agreed). Breaking decodeJSON's \n
unescape by hand turns the three translated cases holding one red.
- TestDecodeJSONIsUnmarshal / FuzzDecodeJSON compare decodeJSON with
json.Unmarshal (dst DeepEqual, error nil-ness) for 19 types shaped like
the gateway's, and jsonValid with json.Valid, over seeds, every cut
and a changed byte at every place of each seed, and 2.5 minutes of
fuzzing (~1.75M inputs). Breaking the validator's control-byte check
by hand turns it red.
- go test -tags nogui -timeout 40m ./... on this commit rebased onto
origin/main
|
||
|
|
a532d1586c |
gateway: a tool call DeepSeek writes into its text as {"name":…} then <parameter name="k">v, its closes missing, is the call (#917, Moody-Sin)
DeepSeek through group/deepseek in Pi wrote <tool_call>{"name":"bash">
then <parameter name="command">cd … && node .review-tmp and stopped: half
Hermes' block, half its own template, with the closes (its own tokens,
which the API drops) gone. None of the text-call readers took it, so Pi got
it as text and the turn ended. paramCall reads the name as JSON closed with
}, > or nothing, then each <parameter name="k"> (or <parameter=k>) up to
its close, the next parameter, </tool_call> or the end; a JSON value is
taken as it. A tool not offered, or a name with nothing after it, stays text.
Tested for real: real DeepSeek (deepseek-flash, through a sandbox
gateway's group/deepseek), asked to echo the screenshot's text with a
bash tool offered, wrote exactly it; the live gateway (old code) handed it
on as that text with finish "stop", the new one as a bash call with
{"command":"cd /e/Project/synara && node .review-tmp"} and finish
"tool_calls". TestTextWrittenParamCallRelayed is new and fails without the
change. go vet, go build (GOOS=linux nogui, GOOS=windows) and go test
-tags nogui ./internal/gateway/ under a temp HOME pass.
|
||
|
|
307f413687 |
gateway: a tool call GLM writes into its text in its own format is made, and Codex's exec gets its code as a custom tool call (#906, nullburn)
GLM-5.3-Flash on a local vLLM, used from Codex Desktop through magpie's Responses endpoint, wrote its calls into its text as GLM's template does: <tool_call>exec<arg_key>input</arg_key><arg_value>…</arg_value></tool_call>. magpie held text from <tool_call> on but read only Hermes' JSON after it, so the block went to Codex as text and the turn ended. parseTextCalls now reads GLM's form when what follows <tool_call> is not JSON: the tool's name, then each <arg_key>/<arg_value> pair, a value that is JSON (number, object, list, boolean) taken as JSON, else the string it says. As before, every block must name a tool the request offered, else the whole reply stays the text it was. It works wherever the text is read for calls: Chat's relay, the translated Chat, Responses and Anthropic paths, streamed and whole, and a plugin's model; a Responses custom tool (Codex's exec) becomes a custom_tool_call carrying the input. Tested end to end in a sandbox HOME: a fake vLLM streaming GLM's markup split mid-tag, added as a provider, magpie serve on a spare port, and a Responses client offering exec as a custom tool and update_plan: streamed and whole, the reply came back as the text before the block and a custom_tool_call exec whose input is the code. TestGLMTextCallCustomTool (stream split mid-tag, streamed and whole), TestGLMTextCallFunctionTool (JSON values kept, two calls), TestGLMTextCallChatAndMessages and TestPluginGLMTextCall are new and fail without the change; TestGLMTextCallUnofferedLeftAsText (an unoffered tool stays text) passes with and without it. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (TestClientGoneRecordedAsCanceled fails now and then on main without this change too). |
||
|
|
c353f7bd3f | gateway: a reply that is only a <tool_call> and DeepSeek's closing tags says nothing, and a <tool_call> wrapping DeepSeek's own invoke is the call (Dazzle-sys, #823 again: Trae CN's DeepSeek V4.1 Flash in Pi showed <tool_call> </|DSML|parameter> </|DSML|invoke> </ as its reply) — the reply (17 tokens out, the 04:23:54 Trae CN row in the request log) was the Hermes opener with no JSON in it, then DeepSeek's closes, cut short. A <tool_call> was read only for a JSON object, so the held text went to the agent as it was, and the model read it back. A <tool_call> whose content starts with a tag, or is nothing, now has its opener dropped and what follows read as it is: a DSML invoke in it is the call; held text that is tags and nothing else (a tag cut short at its end, </, too) is dropped, and the reply ends as it did (stop) when no call was in it. Text that only looks like a tag (x </tool_call> y) goes on whole. trae 0.1.13 does the same in the plugin. TestTextWrittenTagsOnly fails on the old code with the screenshot's text; go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. | ||
|
|
bbc89f9e2b | gateway: a tool call a model wrote into its text is made the call it is, so the agent runs it and the session goes on (Dazzle-sys, #823: 报错导致会话直接中断,回复继续也是重复报错) — deep into a long session (~700k tokens in the screenshots) DeepSeek stopped calling tools and wrote them as text instead, Hermes' <tool_call>{"name":…,"arguments":…}</tool_call> or its own <|DSML|function_calls> blocks, sometimes with a raw newline in a command or stray DSML closing tags after it. pi got text, ran nothing and ended the turn; told 继续, the model copied its own text calls and it happened again. Now, when the request offered tools and the reply made no call itself, a reply whose text holds such blocks, each parseable and naming an offered tool, reaches the client as those tool calls (finish tool_calls / stop_reason tool_use), with the prose before them kept and the tags gone: on the Chat relay (textCallTidy, a line filter after the others, the marker held back across chunks) and on every translated path, streamed or not (textCallSee on the IR events). A block naming an unknown tool, one cut off, a reply with no tools offered or with a native call, and text that only looks like a tag stay as they were. With the owner's real WorkBuddy AI account in a sandbox on deepseek-v4.1-flash: native calls passed unchanged on Chat (relayed) and Messages (translated); asked to write <tool_call>{…bash…}</tool_call> as text, the client got a bash tool call {"command":"ls -la /tmp"} and finish tool_calls, twice. TestTextWrittenCallRelayed, TestTextWrittenCallWithJunkRelayed and TestTextWrittenDSMLCallTranslated (Anthropic, stream and not) fail on the old code; TestTextWrittenCallLeftAsText and TestTextWrittenCallBesideNative guard what is left alone. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. |