Files
magpie/internal
ggbdpqandfactory-droid[bot] e21b1dbc16 gateway: a broken tool exchange a Chat or Zed client left is mended for a Messages upstream, as the Chat and Responses paths mend theirs
What changed: buildAnthropic (every request built for a Messages
upstream: a Chat or Responses client's conversation translated, Zed's
bridge) now runs its messages through pairToolBlocks, as buildChat's
pairToolMessages (#554) and the relayed Responses path's pairToolItems
(#1341) mend theirs. Anthropic refuses a tool_use the next message's
tool_results don't answer ("`tool_use` ids were found without
`tool_result` blocks immediately after") and a tool_result naming a call
it never saw ("unexpected `tool_use_id` found in `tool_result` blocks");
an interrupted turn leaves the first behind, a client that dropped a
call the second. A call left unanswered gets the synthetic result the
other paths make; an answer to no call becomes a text block keeping
what it said. A well-formed exchange is built exactly as it was (ids in
their places, results in the order the client sent, text after them).

TestZedToolResultSaysIsError's fixture carried a result for a call the
request never made; it asserted the orphan went through as a
tool_result, which the cloud refuses. It now goes out as the text it
said, and the test says so.

Run:
- /tmp/sbx.sh test -tags nogui -count=1 -run 'TestMessages' ./internal/gateway/
  with the pairing call taken out: 6 FAIL (trace "user assistant(A)",
  and the end-to-end one 400 "unexpected `tool_use_id` found in
  `tool_result` blocks"); with it back in, all pass
- /tmp/sbx.sh test -tags nogui -count=1 ./internal/gateway/ — ok
- gofmt -l (nothing), go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... (the trayimage_darwin.go -Wenum-conversion
  warning as on main), go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-10-13 06:43:00 +08:00
..
…
…