Skip to content

feat(codex): follow codex CLI continuation & compaction to avoid ~95% redundant session history traffic - #206

Open
chris7iu wants to merge 2 commits into
raine:mainfrom
chris7iu:feat/codex-unbounded-continuation-compaction
Open

chris7iu wants to merge 2 commits into
raine:mainfrom
chris7iu:feat/codex-unbounded-continuation-compaction

Conversation

@chris7iu

@chris7iu chris7iu commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follows the official codex CLI's stateful WebSocket previous_response_id delta continuation and chained /responses/compact encrypted_content consolidation to eliminate the ~95% redundant session history re-upload in upstream traffic:

  • Synthetic subagent continuation key when x-claude-code-agent-id is absent (src/providers/codex/continuation.rs, src/providers/codex/mod.rs, tests/codex_agent_continuation.rs): When Claude Code spawns subagents that share x-claude-code-session-id without sending x-claude-code-agent-id, resolve_continuation_owner derives a deterministic synthetic owner key (ConversationIdentity::Agent(session_id, "synthetic,<sha256>")) from prompt_signature + the leading developer envelope (AdditionalTools and leading developer instructions in Responses Lite) + the first role == "user" message in body.input. This prevents concurrent subagents from colliding with the main thread or each other, avoiding PromptChanged/NonPrefix continuation evictions and full-history re-uploads.
  • Unbounded WebSocket continuation transcripts (src/providers/codex/continuation.rs): Removes MAX_OWNER_TRANSCRIPT_BYTES (2 MB) and MAX_TOTAL_TRANSCRIPT_BYTES (20 MB) while keeping MAX_STATES and TTL_MS bounding. Long reasoning-heavy sessions with high-entropy reasoning.encrypted_content blobs no longer abort previous_response_id delta continuation after ~15–25 turns and fall back to re-uploading the full multi-megabyte transcript on every turn.
  • Unbounded post-compaction state & multi-compaction chaining (src/providers/codex/compaction.rs, src/providers/codex/mod.rs):
    • Removes MAX_STATE_BYTES (4 MB) and MAX_TOTAL_STATE_BYTES (20 MB) and extends STATE_TTL_MS to 24 hours so compacted sessions never drop their consolidated Compaction { encrypted_content } item.
    • Applies apply_compaction_replay before begin_compaction / request_compaction on subsequent compaction boundaries so consecutive compactions (both automatic and manual /compact) consolidate the prior Compaction { encrypted_content } item alongside new turns via /responses/compact, matching official codex CLI behavior without any arbitrary reasoning retention cap $K$.
  • Hook-tolerant compaction detection (src/providers/codex/translate/request.rs, src/providers/codex/compaction.rs): Ignores trailing system / developer messages injected by Claude Code UserPromptSubmit hooks when detecting compaction boundary requests (is_compact_messages_request) and when stripping the compaction instruction (without_compaction_instruction).
  • Coexistence of requestCompression and previousResponseId (src/config.rs): Keeps CodexTransport::Auto when both codex.requestCompression and codex.previousResponseId are enabled so normal turns use WebSocket previous_response_id delta continuation (~2–20 KB/turn) while HTTP requests (/responses/compact and HTTP fallbacks) use gzip request body compression.

Test Plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test --lib config::tests::codex_request_compression
  • cargo test --lib providers::codex::continuation::tests
  • cargo test --lib providers::codex::compaction::tests
  • cargo test --lib providers::codex::translate::request::tests::compact
  • cargo test --test codex_agent_continuation
  • cargo test --test smoke_cutover smoke_codex_http_server_compaction

@chris7iu chris7iu changed the title feat(codex): remove continuation/compaction byte caps and chain encrypted_content compaction feat(codex): follow codex CLI continuation & compaction to avoid ~95% redundant session history traffic Nov 11, 2026

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