Commit Graph
3 Commits
Author SHA1 Message Date
yetone 353464f161 gateway: a translated Anthropic or Responses reply that said nothing and counted no token is asked again, then fails, not completed (#2086, tensornull)
tensornull's Codex turn on an Anthropic-compatible proxy (baseAPI
anthropic, claude-opus-5-5) ended as response.completed after 21s with
no output: the route had status 200, no usage, no served model, no
ttft. Codex took it as its turn's end (last_agent_message null) and
didn't ask again. No usage and no served model mean the proxy never sent
a message_start Claude would have (it counts the prompt and names the
model), yet the stream said it ended (message_stop or a stop_reason), so
320af9858's replyEnds read it as whole and errEndedShort didn't apply.

Now a reply from an Anthropic or Responses upstream (repliesCounted) that
said nothing (no text, call, search or image) and counted no token at all
(uncounted) is the empty reply #667 already handles for Gemini: asked
again in place, then failed with "an empty reply (the model answered
nothing; try again)", which Codex retries. Same in streamTranslated and
the unstreamed translate path, for Responses, Messages and Chat clients.
Claude's own empty end_turn (after a tool's result) counts its prompt and
still completes, as does a Responses reply with usage and no output.

Not changed: a reply passed through in its own protocol (Codex asking a
Responses provider, Claude Code an Anthropic one) isn't read for this;
the passthrough has no empty-reply rule at all, Gemini's included.

Verified:
- New stream_uncounted_test.go. TestUncountedEmptyReplyFails (message_stop
  only; pings then message_stop; message_start with no usage then a
  stop_reason; zero usage), TestUncountedResponsesReplyFails and
  TestUncountedEmptyReplyFailsEveryClient (Chat streamed, Responses and
  Chat unstreamed) all FAIL on the old code ("ended response.completed
  \"completed\", want response.failed", "status 200, want the empty
  reply's failure") and pass with the change. TestCountedEmptyReplyStillCompletes
  and the #1933 tests (TestWellFormedStreamsStillComplete, TestMalformed*)
  pass.
- The full go test -tags nogui ./internal/gateway run failed only
  TestCodexHeadersReachKeyedRelay and TestStandaloneNativeAccounts, whose
  fake Codex backends answered response.completed with output [] and no
  usage, which the real backend never sends; their fakes now count
  tokens, and both pass. Run in a sandbox HOME with pinned
  caches; gofmt -l; go vet ./internal/gateway for darwin,
  GOOS=linux -tags nogui and GOOS=windows; GOOS=linux go build -tags
  nogui and GOOS=windows go build.
- Not tried: the reporter's proxy or its real bytes (the report has none);
  the fixtures are the shapes its route record allows. Not run: the full
  go test ./... (only internal/gateway changed).
2026-10-14 13:26:18 +08:00
mslxl a0c00370f9 feat: recognize acp-extension-codex as codex (#1256)
* feat: recognize acp-extension-codex as codex

* test: cover acp-extension-codex client recognition
2026-10-13 09:38:25 +08:00
yetone 79a7ba8864 gateway: Codex's own headers go on to a keyed provider, as Claude Code's do (#179) (lx_78654 on Discord: "This account only allows Codex official clients") — magpie sent Codex's requests as magpie/<version> with none of Codex's headers, so a provider that serves only Codex's clients (by User-Agent or originator, a version and an x-codex- header) refused them. A request from Codex (User-Agent or originator starting codex: codex_cli_rs, codex_exec, codex_vscode, Codex Desktop) to a key+URL provider over Responses or Chat, relayed or rebuilt, now carries its User-Agent, originator, session-id, thread-id and the x-codex- headers codexHeader passes; the provider's own key is the one sent, never magpie's, nor Codex's attestation; other agents go as magpie/<version>, and a provider's own User-Agent is still set when it signs. Headers as codex-cli 0.159.2 sent them to a fake upstream in a sandbox HOME. TestCodexHeadersReachKeyedRelay fails without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. 2026-09-30 17:37:30 +08:00