Commit Graph
1 Commits
Author SHA1 Message Date
yetone 8edb9dbb75 gateway: a compaction a model answers with a tool call is asked again as text
Lucy on Discord (v0.1.1676, Codex, group/auto-deepseek-v4-1-flash):
"compaction: group/auto-deepseek-v4-1-flash failed to summarise this
conversation 3 times in a row (last: the model wrote no summary (it
answered with reasoning, function_call exec_command))", so Codex could
not compact at all with that group.

Cause: the summary request offers no tools (tools [], f81913994), but its
history is Codex's exchange of exec_command calls, and a DeepSeek model
deep in it goes on with that exchange: it thinks, then calls exec_command
again. Nothing on magpie's side stops a call coming back: on a Messages
upstream the history's tools are declared as stubs (Anthropic requires
them, tool_choice none), an OpenAI-compatible server can read calls out
of the model's text with no tools offered, and magpie passes a call to an
undeclared tool through. codexCompact took that reply as "no summary"
and failed, three times, then held the conversation for 5 minutes.

Fix (codexCompact, every route that compacts: Lite and not, a group or a
single model, Chat, Responses and Messages upstreams): a summary reply
that called a tool (calledTool) is asked once more with the conversation
as text (plainCompact, as for a relay's 404): no exchange of calls to go
on with, no stubs, nothing found by tool_search. If that also writes no
summary, magpie compacts locally (localSummary, saying why), so Codex
goes on instead of failing. Codex's compaction prompt is unchanged.
Replies of reasoning alone or nothing fail as before.

Run on mote, the full suite at ea53eb126 + this change:
- gofmt -l: clean
- go vet ./internal/gateway: darwin, GOOS=linux, GOOS=windows (-tags nogui): clean
- set -o pipefail; go test -tags nogui -timeout 45m ./...: 76 packages ok, no FAIL
  (gateway 707s, agent 426s, provider 187s)
- new tests: TestCodexCompactToolCallAsksAgainAsText (Chat, Responses,
  Anthropic x group/auto-ds and ds/deepseek-flash; upstreams streaming
  DeepSeek-shaped reasoning + exec_command calls while the history holds
  calls) and TestCodexCompactToolCallEveryTimeCompactsLocally
- broken by hand: with codex_backend.go at origin/main both tests are red
  in all 9 cases with the reporter's message, "compaction: the model
  wrote no summary (it answered with reasoning, function_call
  exec_command)"; green with the fix
- real DeepSeek (deepseek-flash, the owner's key): Chat with no tools and
  Messages with the stub and tool_choice none/auto all summarised a short
  exec_command history (3 of 3 each), as did the text form plainCompact
  sends

Rebased onto a57ec0168 (Cursor plugin min only): go build ./... and
the gateway and provider compaction tests ok again at the pushed head.

Not tried: Lucy's own conversation and group members (the long history
that makes DeepSeek call a tool did not reproduce on a short one), and
a real Codex end to end through a sandbox gateway.
2026-10-28 15:14:31 +08:00