mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-07 15:57:53 +08:00
Codex captures x-codex-turn-state from /responses SSE, /responses/compact JSON and the WS handshake (codex-api sse/responses.rs, endpoint/compact.rs), then echoes it back on later requests of the same turn. The HTTP path dropped it because the header is not in the generic response allowlist, while the WS path already relayed it — an inconsistency that broke the protocol chain. Relay it explicitly at every commit point instead of widening the global allowlist (which would leak it into Anthropic/Gemini responses): - streaming, non-streaming and SSE-to-JSON handlers relay it, clearing any value left over by a previous failover attempt when upstream sends none - under the first-output guard the header is only staged; provenance is recorded when applyAttemptResponseHeaders actually writes it, because a first-output timeout discards the staged headers and the client never receives that blob - record (api key + client session) -> minting account, TTL-bounded with an opportunistic sweep, and strip echoes known to come from another account before they go upstream. Stripping only: injection is the Claude bridge's job. Same-account or unknown provenance passes through unchanged.