gateway: Zed's test still checks is_error true on a real result, beside the mended orphan (#1558)
What changed: d1d45dd3 made TestZedToolResultSaysIsError's toolu_2 result an orphan turned to text, and its assertion went from [false true] to [false]: nothing checked any more that a result with is_error true goes to Zed's cloud with it (yetone/magpie-releases#9). The fixture's assistant now makes toolu_2's call, so both real results keep [false true], and a separate toolu_9 result with no call checks the orphan goes as its text. The pairing tests also check the synthetic result is is_error, and a new TestMessagesSecondAnswerDropped checks a call answered twice keeps only its first answer. docs/subsystems/gateway-routing.md gets a bullet for the Messages build's mending, beside the Gemini and Responses ones. Why: the patch's tests passed with is_error dropped from the synthetic result and with the second-answer rule removed. Run (sandbox HOME, private GOCACHE): - go test -tags nogui -run 'TestMessages|TestZed' ./internal/gateway/: ok - pairToolBlocks call removed: the six TestMessages tests and TestZedToolResultSaysIsError fail ("is_error: [false true false]", "what the lost result said is not kept"). - IsError dropped from the synthetic result: TestMessagesUnansweredCall GetsSyntheticResult fails. The duplicate's continue removed: TestMessagesSecondAnswerDropped fails ("user[A,A]"). Co-authored-by: ggbdpq <ggbdpq@gmail.com>
This commit is contained in:
@@ -75,6 +75,7 @@ served by a plugin are in [Provider and plugin ownership](provider-plugins.md).
|
||||
- Only an account is held at a usage cap (`capHeld`) or rested out of one model's pool (`pooled`); a key's windows order it and rest it, nothing more.
|
||||
- Codex offers its image tool (the `image_gen` namespace, #870) to every magpie provider. When a provider other than a ChatGPT sign-in or openai.com answers a bare 400, `attempt` asks it once more without the tool (`image_tool.go`). This happens both passed through and translated. If that works, the provider is marked unfit for the tool (`tool:image_gen`) and isn't offered it again. If it doesn't, the tool is restored and the 400 stands (#949).
|
||||
- A turn the agent stopped with its tool call still out is replayed by the client with the call and no result, and Google's APIs turn a history whose call turn goes unanswered away with 400, every later turn of the conversation with it. The Gemini build (`buildCodeAssistSent`, which serves a Google sign-in, Vertex AI and a custom provider's Gemini API alike) answers such a call with the synthetic result the chat build pairs an interrupted turn's call with (`pairToolMessages`, #1275), right after the calls (`pairFunctionTurns`, #1560): beside the answers the client sent there, or in a user turn of its own before what the user said, since a turn mixing a `functionResponse` with text is turned away too (#1533); a Claude model on Antigravity gets it in the one tool_result turn. A call with no id counts as answered by a response of its name.
|
||||
- A request built for a Messages upstream (`buildAnthropic`: a Chat, Responses or Gemini client translated, and Zed's bridge) has its tool exchanges mended after its messages are built (`pairToolBlocks`, #1558, ggbdpq), since Anthropic answers 400 for a `tool_use` the next message doesn't answer and for a `tool_result` naming no call of the message before it. A call left unanswered gets the synthetic interrupted result, `is_error` set, first in the user message after it or in one of its own; a result that answers no call goes as a text block with what it said (its images as they came); a second answer to one call is dropped. A well-formed exchange goes as it was built. An Anthropic client relayed to a Messages upstream isn't mended. [`anthropic_tool_pairing_test.go`](../../internal/gateway/anthropic_tool_pairing_test.go).
|
||||
- A Responses request bound for anything but a ChatGPT sign-in has its tool exchanges mended in `attempt`, before it is relayed or translated, plugins included ([`responses.go`](../../internal/gateway/responses.go)). An item inside a run of calls and results (after one of the run's results and before the last, or before any result when the model didn't write it) moves to the end of that run (`joinToolRuns`, #1752, Edward4226): Codex writes its `<image_resize_notice>` right after each result whose image it resized, so a batch of two calls had it between their results, and a strict upstream answered 400 (OpenCode Go/DeepSeek "No tool output found for tool call …", Volcengine's "must be followed by tool messages", #1822); a Chat translation answered the second call with a synthetic result. An item carrying a `call_id` never moves, the model's own reasoning and text between its calls stay, and a call opens a run only when a result after it answers it. A result with no call id becomes a user message after its run (`orphanedToolOutputs`), and a call nothing answers gets a synthetic result at the end of its run (`pairToolItems`, #1341). `TestRelayedCodexImageBatchKeepsItsResultsTogether`, `TestJoinToolRunsOnlyMovesWhatBreaksARun`.
|
||||
- Codex's model list from the backend path (`codexModels`) is the ChatGPT backend's for its sign-in and then magpie's (`provider.CodexListed`), its ETag and every reply's `X-Models-Etag` tagged with `provider.CodexListTag` so a change has Codex ask again. A Codex there only for account failover, not connected (`CodexOwnOnly`, `agent.CodexOwnOnly`; #1385), gets the backend's alone, tagged with `provider.CodexOwnListTag`; neither tag contains the other, so connecting or disconnecting has Codex fetch the list again. The user's picks on the codex provider (`provider.CodexNativePicked`) narrow the backend's listed models. They keep its hidden ones (`visibility: "hide"`), which no picker shows. One of those is `codex-auto-review`: when the list lacks it and no reviewer is set, Codex's auto-review runs on the conversation's model at low effort (#1460, `TestCodexModelListPicksKeepHidden`). The account's own models kept out of agents' lists for routing groups (`provider.CodexNativeUnlisted`) are dropped from it too, hidden ones kept: every one when the codex provider is "Only through routing groups" (`Provider.Unlisted`), and those a group that unlists its members names (`Group.Unlists`). A Codex there only for failover keeps them, as it is handed no groups; `spawnChoices` drops the same ones (#1602, `TestCodexModelListUnlistedForGroups`).
|
||||
- Reasoning state goes through magpie's translation as the vendor wrote it when the agent and the upstream speak the same API (#1445, XYenon): a non-streaming request to a stream-only account, web search on the agent's own API, a plugin, failover. The IR carries it sealed (`Part.Sealed`, `SealedBy`; events `KThinkStart`, `KSealed`, `KTextSig` in [`ir.go`](../../internal/gateway/ir.go)), so each thinking block or reasoning item stays apart, whole or streamed, and a seal is written only for its own API (`sealedBy`). Anthropic's `redacted_thinking` goes back raw (to DeepSeek as a thinking block, below), and a thinking block signed with no text keeps its signature (`aBlock` still writes `"thinking": ""`, #1447), on Claude's subscription too. A Responses reasoning item keeps its id, summary and `encrypted_content`, and goes back to a Responses upstream as it came when it has no reasoning text (`sealedReasoning`; text, another vendor's, is still left out for OpenAI, #1411). Gemini's `thoughtSignature` stays on the call it signed and on text; a later call of a signed step goes without one, and only an unsigned step or Claude on Antigravity gets `skip_thought_signature_validator`. Another API's agent gets the call's signature in its id, as on chat (#687), with its length in the mark (`__ts<n>__`), so an id a client shortened carries no signature and the call goes as unsigned (#1536); it gets no one else's seal. Carrying reasoning across APIs (an envelope) isn't done.
|
||||
|
||||
@@ -21,6 +21,7 @@ type aBlockProbe struct {
|
||||
ToolUseID string `json:"tool_use_id"`
|
||||
Text string `json:"text"`
|
||||
Content json.RawMessage `json:"content"`
|
||||
IsError bool `json:"is_error"`
|
||||
}
|
||||
|
||||
// aMessageProbe is one message of it.
|
||||
@@ -161,7 +162,7 @@ func TestMessagesUnansweredCallGetsSyntheticResult(t *testing.T) {
|
||||
if !anthropicValid(msgs) {
|
||||
t.Fatal("sequence fails Anthropic's tool exchange validation")
|
||||
}
|
||||
if got := msgs[2].Content[0]; got.Type != "tool_result" || got.ToolUseID != "A" || string(got.Content) != `"`+wantInterrupted+`"` {
|
||||
if got := msgs[2].Content[0]; got.Type != "tool_result" || got.ToolUseID != "A" || string(got.Content) != `"`+wantInterrupted+`"` || !got.IsError {
|
||||
t.Fatalf("the synthetic result is not what the other paths make: %+v %s", got, got.Content)
|
||||
}
|
||||
if got := msgs[2].Content[1]; got.Type != "text" || got.Text != "go on" {
|
||||
@@ -325,3 +326,20 @@ func TestMessagesUpstreamAnswersABrokenToolExchange(t *testing.T) {
|
||||
t.Fatalf("the orphan result reached the upstream as one: %s", f.got)
|
||||
}
|
||||
}
|
||||
|
||||
// A call answered twice keeps its first answer, and only that one goes
|
||||
// out: Anthropic takes one tool_result per tool_use.
|
||||
func TestMessagesSecondAnswerDropped(t *testing.T) {
|
||||
r := &Request{Messages: []Message{
|
||||
{Role: "user", Parts: []Part{{Kind: Text, Text: "run it"}}},
|
||||
{Role: "assistant", Parts: []Part{call("A")}},
|
||||
{Role: "user", Parts: []Part{result("A", "first"), result("A", "again")}},
|
||||
}}
|
||||
trace, msgs := messagesTrace(t, r)
|
||||
if want := "user assistant(A) user[A]"; trace != want {
|
||||
t.Fatalf("trace = %q, want %q", trace, want)
|
||||
}
|
||||
if got := string(msgs[2].Content[0].Content); got != `"first"` {
|
||||
t.Fatalf("the first answer didn't stand: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,8 +218,13 @@ func TestZedRequestShapes(t *testing.T) {
|
||||
func TestZedToolResultSaysIsError(t *testing.T) {
|
||||
req := &Request{Model: "m", MaxTokens: 10, Messages: []Message{
|
||||
{Role: "user", Parts: []Part{{Kind: Text, Text: "run echo hi"}}},
|
||||
{Role: "assistant", Parts: []Part{{Kind: ToolCall, ID: "toolu_1", Name: "bash", Args: json.RawMessage(`{"command":"echo hi","n":12345678901234567890}`)}}},
|
||||
{Role: "user", Parts: []Part{{Kind: ToolResult, CallID: "toolu_1", Text: "hi"}, {Kind: ToolResult, CallID: "toolu_2", Text: "no", IsError: true}}},
|
||||
{Role: "assistant", Parts: []Part{
|
||||
{Kind: ToolCall, ID: "toolu_1", Name: "bash", Args: json.RawMessage(`{"command":"echo hi","n":12345678901234567890}`)},
|
||||
{Kind: ToolCall, ID: "toolu_2", Name: "bash", Args: json.RawMessage(`{"command":"false"}`)},
|
||||
}},
|
||||
// toolu_9 answers no call the request has: it goes as the text it
|
||||
// said (pairToolBlocks), as the cloud refuses it as Anthropic does
|
||||
{Role: "user", Parts: []Part{{Kind: ToolResult, CallID: "toolu_1", Text: "hi"}, {Kind: ToolResult, CallID: "toolu_2", Text: "no", IsError: true}, {Kind: ToolResult, CallID: "toolu_9", Text: "late"}}},
|
||||
}}
|
||||
raw, _, err := zedRequest(req, "anthropic", "claude-sonnet-5-5")
|
||||
if err != nil {
|
||||
@@ -254,13 +259,10 @@ func TestZedToolResultSaysIsError(t *testing.T) {
|
||||
if !bytes.Contains(raw, []byte(`12345678901234567890`)) {
|
||||
t.Errorf("a tool input number changed: %s", raw)
|
||||
}
|
||||
// toolu_2's result answers no call in the request, so it goes out as
|
||||
// the text it said (pairToolBlocks), where the cloud refuses a result
|
||||
// with no call as Anthropic does; the one real result keeps is_error
|
||||
if len(errs) != 1 || errs[0] != false {
|
||||
if len(errs) != 2 || errs[0] != false || errs[1] != true {
|
||||
t.Errorf("is_error: %v in %s", errs, raw)
|
||||
}
|
||||
if !slices.Contains(texts, "no") {
|
||||
if !slices.Contains(texts, "late") {
|
||||
t.Errorf("what the lost result said is not kept: %v in %s", texts, raw)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user