timonwong (#2599): after the user stops a reply while the model is still
thinking, the agent keeps a turn with no text and no calls and sends it
again on every later turn. Translated (buildChat) or relayed, it reached
the Chat upstream as {"role":"assistant","content":""} (reasoning_content
alone, on DeepSeek), and DeepSeek and Kimi turned every request of the
conversation away: "Invalid assistant message: content or tool_calls must
be set".
One rule, withoutSilentAssistants (chat.go), runs on both Chat routes:
buildChat before pairToolMessages (Claude Code, Codex and Gemini clients,
and the plugins fed by buildChat), and silentAssistantsOut in passthrough
next to developerAsSystem (a Chat client's own body). An assistant
message with no content or only blank text parts, and no tool_calls or
function_call, is left out; the user messages it stood between join into
one (texts with a blank line, else their parts in order), so no two user
messages stand in a row. A prefill (prefix, partial, a Resume), a legacy
function_call, a refusal and an audio reply stay. A relayed body without
such a turn goes byte for byte. TestChatThinkingOnlyAssistantKeptOutside-
Exchange pinned the old pass-through; it now expects the joined message.
Built on ggbdpq's patch (cb438ebb on their fork) and its fake upstream,
written again because the review found it missed shapes the issue names:
- after a tool result it kept the empty turn ("a strict template wants the
reply behind its tool message"), so the interruption mid tool loop still
sent content "" and still got the 400. tool then user is what any agent
sends when the user writes after a tool result; it is now left out.
- the relay dropped an assistant with a legacy function_call or a refusal
and empty content, and a client's own prefix/partial prefill;
kept blank text-part arrays (still refused); joined only string users;
re-marshalled with HTML escaping.
- its Resume check compared a joinSplitCalls turn index with
len(r.Messages)-1.
Verified (sandbox HOME, pinned caches, go1.26.8 darwin/arm64, base
origin/main 72d6103e2):
- The fake upstream refuses with the issue's literal 400 body any
assistant without content or tool_calls, plus DeepSeek's #1462/#1822
reasoning rule. On main's product code 18 subtests of the new tests go
red with that 400 (Claude Code: thinking, redacted, empty text,
thinking+empty text, [], "", after a tool result; Codex: lone reasoning,
empty output_text, no content; Gemini thought-only; relay: "", null, no
content, blank parts, after a tool result; relay keeps-what-speaks), and
TestChatThinkingOnlyAssistantLeftOutOutsideExchange. With ggbdpq's
product files instead, after-a-tool-result (both routes), blank parts
and TestChatRelaySilentAssistantsOnly are red. With this change all
pass; TestChatResumeEmptyPrefillKept is a guard, green before and after.
- gofmt -l: clean. go vet -tags nogui ./... for darwin, linux, windows:
ok. Full suite with both this and the #2575 test change in the tree,
set -o pipefail; go test -tags nogui -timeout 45m ./... : 66 packages
ok, none failed (internal/gateway 825s, internal/provider 266s).
- Rebased onto origin/main ec6454395 (claude_subscription, ir.go):
gofmt clean, vet darwin/linux/windows on internal/gateway and
internal/settings ok; go test -tags nogui -timeout 45m
./internal/gateway ./internal/settings: ok (gateway 668s).
- Not tried against real DeepSeek or Kimi (the fake answers with the
issue's bytes). Gemini and Responses upstreams are not changed; the
Messages build already drops an empty turn and merges same-role
neighbours (anthropicBody's push).
Co-authored-by: ggbdpq <67929842+ggbdpq@users.noreply.github.com>