Commit Graph
6 Commits
Author SHA1 Message Date
yetone 9bb1efdde3 gateway: a reply names the model the agent asked for when it went out under another name (issennknight)
issennknight on Discord (#general): an agent asked for deepseek-v4.1-flash,
which goes out as deepseek-v4.1-flash-1017 (settings' ModelIDs). The vendor's
reply said -1017, magpie passed it back, and the agent warned that the model
didn't match.

Before, only MemberModel (#822) or X-Magpie-Response-Model: member rewrote a
reply's model, and only to the group member's id. Now the default is
nameAsked. When magpie sent the request under another name than the agent
asked for (a model's own id, a routing group, a provider/model id), the
reply names the asked model. That covers Chat and Anthropic `model`,
Responses `response.model` (created, in_progress, completed), Anthropic
`message.model` (message_start) and Gemini `modelVersion`, streamed and
whole, translated paths and plugins included: it all goes through serve's
one memberWriter. A vendor that sent back the wire name as asked keeps its
own name, a dated -20261017 too. Usage rows, recent calls and the Routing
page still record served = the vendor's name: the writer sits outside
captureResponseWriter. Claude Code, Claude Desktop and Codex get the asked
name (or the vendor's), never the member's id, as before.

Streams are rewritten one complete line at a time (memberLines). A run
with no "model" in it is written through as the same slice. Only a JSON
reply that has a target at decide time is held whole, which is what
MemberModel already did.

A JSON body that doesn't parse (a reply cut short) goes on as it came.
A request to a remote magpie now sends X-Magpie-Response-Model: vendor
(passOnCaller). That magpie names the vendor's model, as before, so this
one still records what served the call (TestRemoteMagpieGroupNotSwapped
went red without it).

Existing tests that held a native reply byte for byte now expect only
its model renamed to the asked id (namedAs in member_test.go):
passthrough_severed, stream_accounting, refusal, refusal_thinking,
thinking_signature and vertex. The archive keeps the reply as the
vendor sent it, under the vendor's name (archive_test).

Also dropped: the openai-model header code. serve never relays that header,
so the test for it could not pass.

Run (mote, at this head rebased on origin/main 15066f84f):
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok
  except internal/gui: TestSettingsSaveKeepsWhatItDoesNotSend (#4514,
  SearchAll from b09349d17) and TestColdTurnsTaken (#4510). Both are filed,
  and neither touches this change. Three other sessions' suites ran on
  mote at the same time.
  The first full run (base 80bcef18f) had internal/gateway red in 10
  tests: the byte-for-byte tests above, the remote-magpie served test and
  the truncated JSON body. Each one was fixed as described.
- Rebased on 544b91ca8 (no gateway files changed in between): go build ./...,
  go vet, then go test ./internal/gateway ./internal/settings
  ./internal/provider: all ok.
- go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean (cgo warnings only); gofmt -l clean.
- go test -race -count=3 on the member and served tests: ok (122s).
- the 10 formerly red tests with TestReplyNames, TestGeminiReplyNames,
  TestMemberLine, TestMemberWriter and Masked, after the rebase: ok.

Red on the old code (the new tests over a git archive of the base):
- TestReplyNamesAskedModel: 36 subtests fail (own id, group and provider
  id, x 6 protocol paths, x streamed or not), e.g. `the reply names
  "deepseek-v4.1-flash-1017", want "deepseek-v4.1-flash"`.
- TestGeminiReplyNamesAskedModel: both subtests fail (modelVersion -1017).

Broken by hand: dropping `|| m.wire == m.asked` from target() fails
"as asked, dated" in 12 subtests.

Real use: Codex 0.165.0 (codex exec --json) under a sandbox HOME and
CODEX_HOME on mote. A fake Responses vendor always answered
deepseek-v4.1-flash-1017, and a tee between Codex and `magpie serve` logged
what Codex got. providers.json had d with deepseek-v4.1-flash and group
fast; settings.json had modelIDs d/deepseek-v4.1-flash ->
deepseek-v4.1-flash-1017.
- old build: the vendor was asked for -1017; Codex got "model":
  "deepseek-v4.1-flash-1017" in response.created, in_progress and completed,
  both for -m deepseek-v4.1-flash and for -m group/fast.
- new build: the vendor was still asked for -1017; Codex got
  "deepseek-v4.1-flash" and "group/fast"; the usage rows still say served
  deepseek-v4.1-flash-1017. Codex answered "pong" both times. Codex 0.165
  itself shows no warning for a body model either way (its "model
  rerouted" reads the openai-model header), so the agent behind the
  report's warning was not the one run.

Not tried: the reporter's own agent (not named) and Claude Code; the
Responses WebSocket path (responses_ws.go's own frames); a compressed
reply, which still goes through as it is; Antigravity's effort-variant
wire, where the wire differs from the asked name on purpose.
2026-11-01 04:51:17 +08:00
yetone 5c1ccec4a1 provider: WorkBuddy plugin min 0.2.6, an empty tool_calls is no call (plugins #540)
itspig (plugins #540, 2026-10-31) ran v0.1.2283 with workbuddy 0.2.5 on
the live account in a [workbuddy, volcengine] group: the refusal
"\nSorry, I can't respond to this question.\n" still reached the client
and the workbuddy try was done/200 with firstText 3208, volcengine never
asked.

The cause was in the plugin. copilot.tencent.com puts "tool_calls": []
on every delta (f2c7536d7), and the plugin's unsaid let a reply through
at the first delta with a truthy tool_calls, which [] is in JS. The gate
opened at the reasoning chunk, so the line went on as text and the
gateway, seeing text, rightly took the try as answered. 0.2.5's fixture
came from itspig's paste, read off magpie after chatTidy had dropped the
empty list. workbuddy 0.2.6 (plugins d0d0716) counts only a list with a
call in it.

- The workbuddy mover's min is 0.2.6 (npm view --prefer-online: 0.2.6).
- TestDeepSeekRefusalAfterThinkingFailsOver gets "workbuddy's wire":
  what 0.2.6 hands on from that framing (tool_calls [], finish_reason ""
  until the last, empty reasoning_content and refusal) is refused and b
  answers. The gateway's hold and firstText don't count a delta with
  only role, refusal "" or an empty list as text.

Run on mote, at this tree before the rebase onto origin/main and again
after it (see below):
- go test ./internal/gateway -run
  'TestDeepSeekRefusalAfterThinkingFailsOver|TestWorkBuddy540EndToEnd'
  -count=1: ok.
- go test ./internal/provider -run 'Mover|Moved|Workbuddy|WorkBuddy': ok.
- gofmt -l clean.
- End to end (TestWorkBuddy540EndToEnd, kept out of this commit, since it
  needs the plugin's source beside it): the real workbuddy plugin loaded
  by magpie's plugin host behind a fetch shim to a fake
  copilot.tencent.com, signed in with an API key, in a group
  [workbuddy-plugin/deepseek-v4.1-flash, b/m] under the test's sandbox
  HOME, asked as a streamed chat, a one-body chat, Messages (Claude Code's
  ask) and Responses (Codex's ask), for itspig's paste and for the wire
  framing.

Broken by hand: the same end-to-end test with 0.2.5 (b5cc782) loaded is
red on the wire framing for chat, Messages and Responses (b never asked,
"Sorry" in the reply) and green on the paste, which is what itspig saw.

Not tried: a live WorkBuddy account; the trigger prompt was not run; the
full ./... suite.
2026-10-31 08:44:46 +08:00
yetone f1d5bedba6 provider: WorkBuddy plugin min 0.2.5, the filter's line with its newlines (plugins #540)
itspig (plugins #540, 2026-10-30) found v0.1.2278 with workbuddy 0.2.4
still passed WorkBuddy's content_filter refusal to the agent: the real
chunk's content is "\nSorry, I can't respond to this question.\n", and
0.2.4 trimmed only the leading newline, so the line went on as an answer
and the group's next member was never asked. workbuddy 0.2.5 (plugins
b5cc782) trims both sides.

- The workbuddy mover's min is 0.2.5 (npm view --prefer-online: 0.2.5).
- TestDeepSeekRefusalAfterThinkingFailsOver gets a subtest with what
  0.2.5 hands on from itspig's literal chunks (empty content and refusal
  on the reasoning chunk, extra_fields/function_call null, role on the
  content_filter chunk): the try fails as refused and b answers.

Run on mote at this tree: go test ./internal/gateway -run
TestDeepSeekRefusalAfterThinkingFailsOver -count=1 ok (3 subtests);
go test ./internal/provider -run 'Mover|Moved|Workbuddy|WorkBuddy' ok;
gofmt -l clean.

Broken by hand: the new subtest fed 0.2.4's output (the line with its
newlines left in the content_filter chunk) goes red.

Not tried: a live WorkBuddy account; the full ./... suite.
2026-10-31 07:20:40 +08:00
yetone c8f199695c gateway: DeepSeek's reasoning is held for a refusal after it; WorkBuddy plugin min 0.2.4 (plugins #540)
itspig (plugins #540): deepseek-v4.1-flash on WorkBuddy, through
group/tiered, reasoned ~5s, said "Sorry, I can't respond to this
question.", and ended finish_reason content_filter with 0 output tokens
under a 200. The try was recorded done/200, none of the 15 members behind
it was asked, and DeepSeek Harness failed "The model refused to complete
the request".

Two halves:
- workbuddy 0.2.4 (plugins 4883f94) takes the filter's canned line out of
  a streamed chat that ends content_filter with nothing else said.
- refusesAfterThinking now holds DeepSeek's reasoning too (as Claude's,
  GPT's and Gemini's), only while another candidate could answer: with it
  let through as it came, a refusal after it could never go to the next
  member. DeepSeek's own API documents finish_reason content_filter. The
  cost: in a group with a member behind it, DeepSeek's thinking reaches
  the agent once its text begins (kept alive meanwhile), as Claude's does;
  on the last candidate it streams as before. GLM, Kimi and others are
  unchanged.
- The workbuddy mover's min is 0.2.4 (npm view --prefer-online: 0.2.4).

Run on mote at this tree: go test ./internal/gateway -run
'TestDeepSeekRefusalAfterThinkingFailsOver|TestThinkingHeldFor|
TestRefusalAfterThinkingFailsOver|TestThinkingStreams' ok; go test
./internal/provider ok; gofmt -l clean. The full ./... suite was started at
this tree minus the one-line min and is still running; its result goes on
plugins #540 (owner rule: tag without waiting).

Broken by hand: without the deepseek prefix, TestDeepSeekRefusalAfterThinkingFailsOver/refused
goes red (DeepSeek's reasoning reached the agent, b never asked) and
TestThinkingHeldFor red for the three DeepSeek ids; /answered stays green.

Not tried: a real WorkBuddy refusal (no prompt reproduces it on demand);
the upstream's literal chunking isn't in the issue, so the fixture is
built from its fields (reasoning, content_filter, 0 tokens).
2026-10-31 06:05:29 +08:00
yetone 2fc277de9f gateway: GLM's thinking streams again through a group (悠悠哥 on Discord: ZCode's thinking shows only at the end, all at once) — since a8f0baaa (#248) a stream that had only reasoned was held, up to 4 minutes, until its text or a call began, for a refusal after the reasoning to go to the next account; so GLM on a ZCode account (or any key with retries left, or any group member before the last) showed Claude Code its thinking only once the text came, in one burst. Only Claude's, OpenAI's and Gemini's safety filters end a reply that has only reasoned with a refusal, so reasoning is now held only for those models (claude-*, gpt-*/o-series/codex, gemini-*); anybody else's (GLM, DeepSeek, Kimi, MiniMax…) goes through as it comes, as before #248. Requests, headers and prompts are unchanged. TestThinkingStreamsThroughGroup (a fake vendor streaming three thoughts 200ms apart, on Anthropic's API and on Chat with reasoning_content, read by a real HTTP client through a group) and TestThinkingHeldFor fail without the change; TestRefusalAfterThinkingFailsOver now names Claude and GPT models and still passes. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. 2026-10-01 16:20:10 +08:00
yetone a8f0baaaa0 gateway: a refusal after only thinking goes to the next account (#248, Koohoko: safeguards stopped the response above) — Opus 5.5 at xhigh thought 10–25s and then ended with stop_reason refusal, and magpie had counted the first thinking delta as the reply having started, so the stream was already Claude Code's and the refusal passed through instead of the next account being asked. Reasoning (Anthropic thinking, Responses reasoning and summaries, Chat reasoning_content, Gemini thought parts) is now held with the reply, up to 4 minutes, and let through with it as soon as text or a call comes. A ChatGPT bio_policy translated for Claude Code or a Chat agent kept only its message, read as any failure, and set the account aside; the refusal's code now survives translation. TestRefusalAfterThinkingFailsOver and TestThinkingHeldLonger fail without the change. 2026-10-01 03:57:45 +08:00