Files
magpie/docs
yetoneandggbdpq 82ff889338 gateway: a Chat tool call naming no function is dropped, not sent for the client to refuse (#1475)
AricRedemption on #1475: a long Qoder turn ended with an upstream tool
call whose function.name was no string, and the AI SDK refused the
whole reply ("Expected 'function.name' to be a string"), not retryable
and with the call already in the history, so every "continue" died
there while the gateway logged status=200 done=true. The parsers for
calls a model writes into its text already refuse a nameless one, but
calls an upstream made itself went out as they came.

A call whose function names nothing in a JSON string (absent, null,
another kind) is dropped on every path a relayed Chat reply leaves by:
a stream (chatTidy.nameless, its later fragments with it, and the id
mend no longer gives the dropped fragments an id back), a whole reply
(wholeNameless in chatWhole) and a whole reply given as the stream the
agent asked for (chatWholeEvents). A finish of tool_calls with no call
left ends stop. An empty string name goes as it came. Translated routes
are unchanged: their names are Go strings by construction.

Changed from gua2100's patch (hunt61-a-1475-unnamed-call, d851d922f):
- chatWholeEvents turned the finish to stop whenever any call was
  dropped, so a named call beside a nameless one went out with finish
  stop and the client ended its turn without running it; it now does so
  only when no call is left. The calls it keeps are numbered 0.. with no
  gap where a dropped one stood, and a call with no function object is
  dropped there too, as wholeNameless already did.
- chatWhole turned any whole reply ending tool_calls with no named call
  into stop, a reply that came with no tool_calls at all included; it
  now does so only when wholeNameless dropped a call.
New tests for both: TestNamelessCallBesideAGoodOneWholeAsStream,
TestToolCallsFinishWithNoCallsStaysWhole.

Run at this head (451c7e929 on 576b5dcbc), on mote:
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway: ok
  (528s). The first try at e53ba61f4 was red only on
  TestClaudeCallerEnvironmentInAMessageIsTheLastGiven, red 2 of 20 on
  origin/main too; fixed at its cause in 576b5dcbc, under this commit.
- go test -tags nogui -count=1 -run '^(TestNameless|TestNameAbsent|
  TestToolCallsFinishWithNoCallsStaysWhole|TestChatCallsEndToolCalls|
  TestEmptyCallID|TestStreamedCallGivenAnID|TestTextWritten|TestDSML|
  TestQuietWholeReplyStreamed|TestPluginTextWrittenCall|TestChatTidy|
  TestGeminiCompat|TestWhole|TestRelayed)' ./internal/gateway: ok.
- go vet -tags nogui ./internal/gateway on darwin, GOOS=linux and
  GOOS=windows: clean (at the review tree). gofmt -l: clean.
- Not run: go test ./... across every package.

Red on main: with chattidy.go, whole_stream.go and chat_call_ids.go
from origin/main, 7 of the 8 new tests fail, e.g.
TestNamelessCallStreamDropped "calls map[], finish \"tool_calls\"" and
TestNamelessCallBesideAGoodOneWholeAsStream "[{Index:0 ID:call_bad
...} {Index:1 ID:call_up ...}]" (TestToolCallsFinishWithNoCallsStaysWhole
guards unchanged behaviour and passes there).
Broken by hand:
- the patch's own chattidy.go and whole_stream.go:
  TestNamelessCallBesideAGoodOneWholeAsStream fails with
  "[{Index:1 ID:call_up ...}], finish \"stop\"" and
  TestToolCallsFinishWithNoCallsStaysWhole with finish "stop".
- the `calls = nil` clearing removed: TestNamelessCallWithoutAnIDStaysDropped
  "the call dropped for naming no function came back with an id".
- wholeNameless not called in chatWhole: TestNamelessCallWholeDropped
  "calls [{call_up ...}], finish \"tool_calls\"".

Not tried: a real Qoder subscription or the reporter's exact reply (the
report says replays came back well formed; fixtures are synthetic with
the shape the client's error names), a real AI SDK client. Not covered:
a relayed stream that keeps a named call beside a dropped one keeps the
upstream's index numbers, so a gap is left where the dropped call stood;
Responses and Anthropic relays (responsesWholeEvents,
anthropicWholeEvents, passthrough) forwarding a nameless function_call
or tool_use, which has no report.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-31 09:33:09 +08:00
..