Claude Code 2.1.316 doesn't end a turn at a refusal. It asks the same
model again, then its fallback model (claude-opus-4-8 for Opus 5.5),
whose answer ends the turn with result success. The bridge ended the
reply at the first stop_reason refusal, so the client got "Partial "
plus a refusal, and the gateway's hw.refused moved to another account
or handed the refusal back. That is the "model error" the reporter saw.
readOutput now holds a refusal from Claude Code's own model and goes on
with the next message as one reply. Not held: a client tool call, or a
schema reply. The refusal's stop_details are held too. The refusal is
told only if it stands: at a result with no API status (Claude Code's
model_refusal_no_fallback, -p or TUI) or at the end of output. Then
hw.refused and b01766d13 see it as before. A result with a status after
a refusal is that error, not a refusal. The continuing message's model
goes on the KUsage as Model and Served. The try records the fallback
model, and a reply told whole names it. A stream's message_start can't
change it. Prompts and system text sent upstream are unchanged.
Real behaviour: Claude Code 2.1.316 on mote, in a sandbox HOME and
CLAUDE_CONFIG_DIR, against a fake Anthropic upstream that refuses
claude-opus-5-5 (or every model). The -p and TUI stream-json lines were
captured and trimmed into the fixtures in
claude_refusal_fallback_test.go.
Run (mote-run, worktree at base 4a4a82cd4):
- gofmt -l internal/gateway: no output.
- go vet -tags nogui ./internal/gateway on darwin, GOOS=linux and
GOOS=windows: clean.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway: ok
(813s).
- The new tests plus TestClaudeSubscriptionRefusal*,
TestClaudeSubscriptionBigRefusal*, TestClaudeCutStream* and
TestClaudeRefusalMovesToNextKey: ok.
Broken by hand:
- On the unmodified claude_subscription.go (stashed), FallbackAnswers
(print, tui) are red with reply "Partial " stop "refusal", and
RetryFails is red. NoFallback passes, so that behaviour is unchanged.
- Dropping the Served on the continuing usage turns the served
assertions red.
- Dropping the collector's KUsage Model turns the non-stream try's
Served red (claude-opus-5-5).
- Making the standing-refusal case `case standing:` (no status check)
turns RetryFails red.
Not tried:
- A real Claude account (none on mote). The fallback was a fake
upstream's refusal.
- The full go test ./... suite.
- Words a retracted try streamed before its refusal stay in a stream.
Claude Code shows them too.
- A refusal after the client's own tool call keeps the old behaviour
(the reply ends there).
- The overload/529 fallback needs --fallback-model, which the bridge
doesn't pass (nor does Claude Code by default). That path is
unchanged.