Files
magpie/internal
yetone 627fd1a3b7 claude: a turn Claude Code ends with no answer is a 502 saying why, not a 200 with content null
steven_4422 (Discord) sent 18 PNG frames as image_url parts to
claude/claude-sonnet-5-5 in a Chat request, not streamed, and got 200
with {"message":{"content":null},"finish_reason":"stop"} and zero
usage; 17 were answered. Whatever ended Claude Code's turn, the bridge
took an end with nothing said as the answer:

- a run that exits with a request waiting and nothing begun (the
  interactive helper at its deadline, or failing to send the message,
  exits 1 with the reason on stderr) closed the segment empty;
- a turn whose result came with no message, or only a <synthetic> one
  of Claude Code's own words, left the segment open to be closed empty
  by the exit or the run's timeout;
- relay finished a reply whose events ended with neither a KStop nor a
  KError: the collector's empty result went as a 200, a stream ended
  as a finished reply.

Now readOutput ends such a turn with a 502 carrying Claude Code's own
words, else its result's, else "said nothing of why"; the exit
goroutine emits "Claude Code ended before it answered" with its exit
and stderr; relay turns an unended reply into a 502 (whole) or an
error event (stream) in every protocol. A 5xx lets another account
take over, as other bridge failures do.

Claude Code itself (2.1.316, read from its binary and run on mote
against a fake Messages API) has no image-count limit: it passed 18,
24 and 40 images through, by -p and by the interactive helper, and
turns the API's refusal of an image into an is_error result, already
a 4xx/5xx here. So 18+ images are passed through, and what refused or
dropped the reporter's turn is upstream of magpie; the client now gets
its reason instead of an empty answer.

Run (mote, at this head, rebased on 0f8c3d867):
- go test -tags nogui -race -count=1 -timeout 45m ./internal/gateway/
  ./internal/claudetui/: ok (gateway 1607s,
  claudetui 131s), no races.
- GOOS=linux and GOOS=windows go vet of both packages: ok; gofmt -l clean.
- Full suite: not run at push.

Broken by hand: with claude_subscription.go at its parent and the new
tests kept, all 36 TestClaudeSilentTurnFails cases and all 4
TestRelayUnendedReplyFails cases are red: the exit variant, not
streamed, gives the reporter's body byte for byte (200, content null,
zero usage); streamed, a 502 with no reason; the result and synthetic
variants hang until the test's 20s deadline.

Not tried: a real Claude account at 18+ images (no credentials on
mote, and the Keychain is off-limits), so the upstream reason for the
reporter's turn is unknown; the interactive mode through the gateway
against real Claude Code (the helper alone was run with 18 and 40
images against a fake API).

Reported-by: steven_4422 (Discord)
2026-11-08 17:05:09 +08:00
..
…
…
…
…
…
…