Commit Graph
1 Commits
Author SHA1 Message Date
yetone 3e812ebde4 gateway: a provider that refuses a tool_result holding only tool_reference blocks gets them said as text too (#2124)
OpenDesign's Anthropic-compatible endpoint answers 422 "messages[4]:
missing field `content`" when a ToolSearch result carries only
tool_reference blocks, so every Claude Code turn after a deferred tool
loaded failed there.

The fix is a learned shape, scoped to the provider that refuses it, like
the deferred-tools one: refuseShapes marks shapeRefsOnly when a 400/422
says "missing field `content`" and the request held such a result, and
withoutRefusedShapes then puts a text block ("Tool X is loaded and can be
called now.") before the references in each refs-only tool_result,
keeping the references. Every Anthropic upstream route goes through
forward/forwardOnce, so /v1/messages, count_tokens and a group's member
all get it; a provider that takes the references unchanged never sees the
text. Requests translated to another API already rendered a reference as
text in stringOrText; it now uses the same sentence (toolLoadedText).

Run:
- TestRefsOnlyToolResultRefusedGetsText (fake vendor answering the
  reporter's 422 bytes, body from the reporter's repro.json): first ask
  refused, retried with the text; group member and count_tokens get it at
  once afterwards; a provider that takes them sees bare references.
- TestRefsSaidLeavesOtherResults: other results unchanged, two refs.
- Break checks: with the mark off, and with the mend off, the test fails
  with "status 422 ... missing field `content`".
- go test -tags nogui ./internal/gateway/ -count=1: ok (1069s, loaded
  machine; a first run with the default 10m timeout timed out under load).
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.

Not tried: the real OpenDesign endpoint (no key); the fake follows the
reporter's own curl evidence.
2026-10-14 16:42:47 +08:00