Files
magpie/internal
ggbdpq 8ea2d48fb2 fix(gateway): salt a relayed Messages reply's tool_use id the client has seen again (#4910)
Claude Code keeps every tool_use id of a session in one Set and drops a
block whose id it has already seen; a turn whose only block is dropped
becomes "[Tool use interrupted]", and the agent loops on calls that did
run (#4910). An upstream that speaks Messages itself and is relayed as it
came may number its calls' ids by their place in the reply (LiteLLM's
bridge: fc_0 on every turn), so the id one turn went out under comes again
on the next, and every later call of the session is dropped.

A relayed reply's tool_use id the client already holds — an assistant
block of the request the reply answers, or one the reply itself said
before — now goes out under the mark, the upstream's own id and a fresh
salt, which nothing the client holds names; an id the client has seen no
more goes as it came, so an upstream whose ids are its own is relayed
byte for byte. The answer comes back under the salted id and goes to the
upstream as the id it gave, on the call and on the result answering it,
so a strict upstream keeps its own pairing and its prompt cache.

A reply translated from another wire needed nothing: the model's own
call ids pass through there, one fresh a reply.

Run: TestMessagesRelayedToolUseIDsUniqueAcrossTurns fails on the old
code with the one fc_0 on both turns and passes with the change;
TestMessagesRelayedToolUseIDsUniqueInATurn,
TestMessagesRelayedOwnToolUseIDsUntouched,
TestMessagesTranslatedToolUseIDsUniqueAcrossTurns green.

Review, changed from ggbdpq's patch: anthropicInID gives a salted id
back unchanged. Without that, a salted id that a later turn sends to
an upstream of another wire (a group that moved on) was decoded into
the upstream's id plus the salt's NUL byte, and went out with the
NUL. TestSaltedToolUseIDTranslatedAsHeld (added in review) checks it,
and that anthropicOutID's ids still round-trip.

Broken by hand at the reviewed head: the salting turned off in
gateway.go, the three relayed-uniqueness tests red (the translated
and own-id tests stay green, as they should); the anthropicInID guard
removed, TestSaltedToolUseIDTranslatedAsHeld red. Restored, green.

Run at the pushed tree (this stack of nine on origin/main 3c2dceb34),
on mote (macOS arm64, Go 1.26.8):
- go test -count=1 -timeout 45m ./internal/catalog/...
  ./internal/plugin/... ./internal/davsync/... ./internal/gateway/...:
  catalog, plugin and davsync ok; gateway red on one test only,
  TestCodexPoolSaysTheClientsVersion, the open #4807 (another test's
  Codex identity reaches it in a full package run). It passes run
  alone at this tree, 3 of 3.
- go vet ./... (darwin); GOOS=linux and GOOS=windows go vet -tags
  nogui ./...: ok. gofmt -l on every tracked .go file: clean.
- The hand breaks above ran on this stack before its rebase onto
  3c2dceb34. That commit changed member.go only, nothing these tests
  reach.
Not tried: the GUI suite, since no GUI file changed. Windows and Linux
test runs (the Claude bridge tests use a shell fake and skip on
Windows). No real vendor, Claude Code or network was used; every
case runs against fakes.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-03 07:43:18 +08:00
..
…
…
…
…
…
…
…