Follow-up to ggbdpq's f16c1f7cd (#1678) after its review. Its four
sites now read wordsOf(body); three more deciders whose word lists hold
Chinese still matched the raw body, and one of its sites had no test:
- overflowed: an escaped 上下文长度超过限制 400 wasn't read as the
conversation too long. It is called from retryable (now decoded) and
from the candidate loop on the held error, so it decodes itself.
- shapeRefused: its negations (the quota and unserved words) missed
escaped Chinese, so a decision group's raw postDecide body that also
said 额度已用完 counted as a shape refusal and rested nobody.
- tooLongUnsaid: an escaped 该模型不支持 400 past the window was told
to the agent as a prompt too long, as its quota and unserved checks
read the raw body.
- forwardTranslated's alwaysThinks site had no test: breaking it left
every test green. TestTranslatedThinkingOffRefused now carries the
escaped #699 refusal.
Run (worktree on origin/main ebd7f4313 + f16c1f7cd + df4ea0ff6, sandbox
HOME, pinned caches): new TestEscapedWordsReadByEveryDecider passes
with and without escaping; each of overflowed, shapeRefused,
tooLongUnsaid and #1678's modelRetired put back to the raw body makes it
FAIL naming that decider ("上下文长度超过限制 not overflowed", "a shape
refusal that says the quota is spent rests nobody", "...told as too
long: prompt is too long ... (Fake answered 400: 该模型不支持当前令牌计划)",
"a retirement that says the quota is spent rests the model alone").
On main both sites now ask refusesThinkingOff (anthropic.go), which
reads alwaysThinks decoded since the rebase of f16c1f7cd; putting it
back to Match(b) makes TestTranslatedThinkingOffRefused/4 (and
#1678's passthrough test) FAIL with 400 "Fake: 该模型始终支持思
考,不可关闭". gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./... and
GOOS=windows go vet ./... exit 0. go test -tags nogui -count=1 ./...
(sandbox HOME): every package ok but internal/agent and internal/gateway,
which hit go test's default 10m bound at load average ~24 from other
sessions (the stacks show TestWSLMoreAgentsPick and
TestThinkingStreamsThroughGroup running for 2m and 2s, no hang); both
rerun alone with -timeout 40m: ok (gateway 669s, agent 600s).
What changed: #1669 taught failure(), resetsWritten and the per-model
rest's other-models check to read a JSON error whose encoder escapes
what isn't ASCII (Python's json.dumps does by default), but the other
word-list deciders still matched the raw body:
- modelRefused and modelRetired (fallback.go): an escaped 模型不支持
refusal rests the whole key or account (a cooldown, longer on
repeats) instead of the model alone (#1235's class), and the escaped
quota words of their negation are missed the same way. The candidate
loop's restAfterMarked feeds them the vendor's body as it arrived,
and the decision group's decideFailed the raw postDecide body; a
chat's rewritten error carries the decoded message, which is why the
chat path was spared.
- retryable (fallback.go): an escaped 额度已用完 on a 400 reads as not
retryable, so a decision group returns the error instead of asking
its next decision model.
- alwaysThinks (gateway.go, both 400 learn-again sites): a vendor's
escaped 思考不可关闭 refusal is not asked again with thinking left to
the model (#699's class), so the agent sees the 400 every turn.
All three now match on wordsOf(body), as failure() already does.
Run:
- New TestAnthropicPassthroughAlwaysThinksInEscapedChinese sends the
escaped refusal through /v1/messages: on the old code 400 after 1
call (the re-ask not taken), with the change 200 after 2.
- New TestEscapedWordsReadByTheOtherDeciders: modelRefused(403, escaped
模型不支持) and retryable(400, escaped 额度已用完) are false on the
old code, true with it; the same refusals unescaped stay true.
- Both fail with the fix stashed, pass restored. go test -tags nogui
-count=1 ./internal/gateway: ok. The named tests and the guards they
touch (TestAnthropicPassthroughAlwaysThinksInChinese,
TestModelNotInPlanRestsTheModelNotTheKey, TestFailureReadsEscapedWords,
TestResetsWritten, TestWrittenResetRestsUntilThen) also -race -count=5:
ok. go test -tags nogui -count=1 ./... under a temp HOME: ok.
gofmt -l internal/ empty. go vet ./..., GOOS=linux go vet -tags nogui
./..., GOOS=windows go vet ./...: clean but the trayimage_darwin.go
cgo -Wenum-conversion warning, as on main. Builds: darwin, linux
(-tags nogui), windows.
Rebased by yetone onto main, where both learn-again sites ask
refusesThinkingOff (anthropic.go, #1465): the decoding moved there.
Co-authored-by: yetone <yetoneful@gmail.com>
SenseNova answers a Token Plan key asked for deepseek-v4.1-flash with
403 "model is not available in the current token plan" while the same
key serves deepseek-v4-flash. That refusal was a plain failure: it
rested the whole key, its backoff counted per key and doubling up to
10 minutes, so an agent that kept asking for the model left every key
of the provider resting for every model (Sun1090: both keys "失败 · 9
分钟后恢复").
A 400/403/404/422 whose body says the model isn't served
(unservedWords), with no quota, credit, rate-limit or channel words,
now rests only that key's or account's model (modelRefused, keyed by
restID, which is now restKey/model for every candidate), its backoff
counted by the model and cleared when the model answers. The key's
other models stay first in order, and its row shows no rest.
TestModelNotInPlanRestsTheModelNotTheKey (two keys, four requests for
the refused model, SenseNova's error shape) fails without the change:
"key One rests for a model its plan lacks: {Why:other Status:403 ...
By:backoff Failures:3}" and "deepseek-v4.1-flash doesn't rest". With
it: go test -tags nogui ./... under a temp HOME passes; -race -count=5
over TestModelNotInPlan|TestSeveralKeys|TestFallback|TestRouting|
TestPool|TestGroup passes; go vet (darwin, GOOS=linux, GOOS=windows,
nogui) passes. Not tried against a real SenseNova key: the body's
"code" field in the fixture is a guess; the message is the reporter's.
macOS checks a newly written executable before its first exec: 0.27s
alone, 2-5s while other new programs start (a go test ./... starting its
test binaries). The same file again takes 0.009s, and the pass is kept
across a rename and an in-place rewrite. 108852b4 worked round this for one
test with /bin/sh -c; the class was every test that writes a `#!/bin/sh`
fake and times its answer.
testenv.Program(t, path, script) replaces os.WriteFile(path, script, 0o755)
for fakes. On macOS it renames a file that has run once from a pool to path
and writes the script into it in place; at the test's cleanup the file goes
back to the pool (only a path the test created; a stand-in it wrote over
stays). Fakes still end with their tests: nothing about how they are
started or waited on changed. Run (and gateway's TestMain) remove the pool
at the end. TestMain's PATH stand-ins are run once in the background
(testenv.StandIns). Other systems write the file as before.
Converted every `#!/bin/sh` fake written by tests under internal/ (agent,
gateway, gui, library, plugin, proc, provider, update). Windows, binary
and node/bun fakes are unchanged.
Under the same load (3 loops each starting 8 freshly written scripts at a
time), 4 rounds each, before (108852b4 / origin/main) vs after:
- provider TestSavedButSignedOutClaudeServed: 4/4 fail (8.01s) -> 4/4 pass
- provider TestClaudeSignInOverStaleCredentials: 4/4 fail (5.00s) -> 4/4 pass
- provider TestDevinSignedInOnlyInMagpie: 3/4 fail ("CLI's own []") -> 4/4 pass
- gateway TestClaudeRunEndsWhenTheClientLeaves: 4/4 fail -> 4/4 pass
(and 3/3 fail -> 3/3 pass at a third of that load)
- gateway TestClientGoneRecordedAsCanceled: 4/4 fail -> 4/4 pass
- gui TestProvidersAnswerWhileListsComeIn ("cursor found false" at 3.03s):
4/4 fail -> 4/4 pass. The same class, not bfe8bcaf's test order.
- proc TestUserPath (login shell's PATH never came, 7.01s): 4/4 fail ->
4/4 pass
Unloaded, every touched package passes; no pool directory or process is
left after a run.