Skip to content

fix(codex): route oversized full-context Auto requests over gzipped HTTP and isolate ephemeral forks - #216

Open
chris7iu wants to merge 1 commit into
raine:mainfrom
chris7iu:fix/codex-auto-oversized-and-fork-isolation
Open

chris7iu wants to merge 1 commit into
raine:mainfrom
chris7iu:fix/codex-auto-oversized-and-fork-isolation

Conversation

@chris7iu

Copy link
Copy Markdown
Contributor

Summary

Fixes long-context Codex Auto transport stalls and retry loops observed on multi-megabyte (~350k+ token / ~11.5 MB) sessions:

  1. Pre-send gzipped HTTP routing for oversized full-context Auto requests (src/config.rs, src/providers/codex/client.rs):

    • Adds codex.autoWebSocketMaxBytes / CCP_CODEX_AUTO_WS_MAX_BYTES (default 4 MiB; 0 disables).
    • When Auto transport has requestCompression + HTTP fallback enabled and is sending a full-context request (previous_response_id == None, or pre-send WEBSOCKET_CONTINUATION_SOCKET_MISSING when pooled socket is absent/dead) whose serialized JSON exceeds autoWebSocketMaxBytes, bypasses WebSocket pre-send and dispatches directly over gzip-compressed HTTP.
    • Sessions with an active previous_response_id delta stay on WebSocket regardless of total conversation size, and should_fallback_to_http remains strictly pre-send (preserving the no-post-send-HTTP-replay invariant).
  2. Isolate Claude Code background/ephemeral forks (src/providers/codex/translate/request.rs, src/providers/codex/compaction.rs, src/providers/codex/mod.rs):

    • Identifies the 7 Claude Code ephemeral FE(...) forks (away_summary, prompt_suggestion, agent_summary, rename, side_question /btw inside <system-reminder>, extract_memories, auto_dream).
    • Maps main-thread forks to ConversationIdentity::Agent(session_id, fork_label) and uses non-mutating compaction::peek_compaction_replay (compaction_attempt = None) so aborted or mismatched background forks never clobber the main session's previous_response_id, pooled WebSocket, or CompactionState.
  3. Fix premature 502 bailout after in-socket full-context retry (src/providers/codex/mod.rs):

    • Narrows the full_context_retry_attempted short-circuit from is_continuation_retry_error to is_missing_previous_response_error, allowing transient WebSocket drops (websocket_missing_terminal, keepalive failures, start timeouts) after a full-context retry to use the normal retry budget while still failing fast on repeated missing-origin errors.
  4. Observability and downstream disconnect responsiveness (src/providers/codex/websocket.rs):

    • Includes Message::Close(CloseFrame) code and reason in missing_terminal_error while preserving the existing prefix and detail.
    • Races guard.send(Message::Text(...)) against tx.closed() in start_codex_websocket_events so downstream disconnects immediately drop the socket lock, evict the pool entry, and close the upstream WebSocket.

Verification

  • cargo fmt --all -- --check (passed)
  • cargo clippy --locked --offline --all-targets -- -D warnings (passed, 0 warnings)
  • cargo test --locked --offline (all 985 unit tests and all integration test targets including tests/codex_websocket_proxy.rs passed)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant