Files
magpie/docs
yetoneandwaynesguan 0a5dc40abc gateway: a group's trusted Claude, GPT and Gemini thinking streams as it comes, a refusal or error after it going to the next member (#4166)
A try whose model's vendor may refuse after its reasoning (#248) had its
reasoning held while another candidate could answer, whatever the member
had answered lately. Through a routing group Claude Code saw a Claude
member's thinking only with its text, all at once, and never its
"thinking with <effort> effort". waynesguan measured it on one WorkBuddy
account: `workbuddy claude-opus-5.5` alone, first thinking at 3.66s;
through the group, all 67 thinking deltas with the text at 17.25s.

Ported from waynesguan's 71aacaa (on f8987ce61): the trust #4512 gave
DeepSeek now covers Claude, GPT and Gemini, but only where a refusal
after the reasoning can be handed to the next candidate in the same
stream (handsOver, refusalHandover). Once a member's thinking has gone
on to an answer thoughtCleanMost (3) times running, its reasoning goes
as it comes; a refusal after it, nothing yet said, goes to the next
member, whose reply follows as the same one; the refusal takes the trust
back. Where no handover is possible (no stream, a Gemini-protocol agent,
a compaction wanted whole, refusals asked again enough, the last
candidate) it is held as before. holdsThinking is decided after hw.over.

Added in review: the port alone lost failover for errors. passOver
handed over only a refusal; a retryable error after shown reasoning
(Anthropic's mid-stream overloaded_error) counted as the answer begun and
reached the agent, the next member never asked, where the held stream
had failed over. passOver now hands a retryable error over too
(handOver(status, msg, refused=false)): the try fails with its status
and words, as a held one did, and the next member's stream follows. A
non-retryable error (a request at fault) still reaches the agent. This
also applies to GLM's and trusted DeepSeek's shown reasoning, which had
the same gap.

Tests:
- TestTrustedThinkingFailsOverOnEveryPath: claude (Anthropic upstream),
  gpt and gemini (Chat upstream) members x refused / overloaded /
  invalid x /v1/messages, /v1/chat/completions, /v1/responses, 27
  cases; spliced stream checked per protocol (one message_start, block
  indexes, sequence numbers, one [DONE]).
- TestClaudeThinkingStreamsOnceTrusted, TestClaudeTrustedThinkingStreamsThroughGroup
  (waynesguan's), TestClaudeTrustedThinkingErrorFailsOver.

Broken by hand:
- main's fallback.go + gateway.go: the 18 refused/overloaded cases,
  TestClaudeThinkingStreamsOnceTrusted ("a trusted Claude member's
  reasoning is still held") and ...ThroughGroup ("first thought only
  1.541µs before the text") FAIL.
- port without the error handover: the 9 overloaded cases and
  TestClaudeTrustedThinkingErrorFailsOver FAIL (the agent got
  "Overloaded", b asked 0 times).

Run (mote, via mote-run): go test ./internal/gateway/ at 741f7a8f2
(877s) ok but TestClosedBeforeSentEveryTimeSaysWhy (bare EOF, Codex
closed-unsent path, already #5031, not touched here); after rebase on
e7b0c398e: -run 'Thinking|Refusal|Handover|ObjectRoot|DeepSeek' ok;
gofmt -l clean; go vet ./internal/gateway/, GOOS=linux go vet -tags
nogui ./..., GOOS=windows go vet ./... ok. Full suite runs after push;
its reds are filed separately.

Not tried: a real refusal or overloaded_error after thinking from a real
account (can't be triggered at will); Claude Code against a real group
with this build; Windows/WSL runs (vet only).

Co-authored-by: waynesguan <wenwenguan@tencent.com>
2026-11-04 18:37:43 +08:00
..