Repository navigation
feat(codex): follow codex CLI continuation & compaction to avoid ~95% redundant session history traffic - #206
Open
chris7iu wants to merge 2 commits into
Conversation
…pted_content compaction
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follows the official
codexCLI's stateful WebSocketprevious_response_iddelta continuation and chained/responses/compactencrypted_contentconsolidation to eliminate the ~95% redundant session history re-upload in upstream traffic:x-claude-code-agent-idis absent (src/providers/codex/continuation.rs,src/providers/codex/mod.rs,tests/codex_agent_continuation.rs): When Claude Code spawns subagents that sharex-claude-code-session-idwithout sendingx-claude-code-agent-id,resolve_continuation_ownerderives a deterministic synthetic owner key (ConversationIdentity::Agent(session_id, "synthetic,<sha256>")) fromprompt_signature+ the leading developer envelope (AdditionalToolsand leadingdeveloperinstructions in Responses Lite) + the firstrole == "user"message inbody.input. This prevents concurrent subagents from colliding with the main thread or each other, avoidingPromptChanged/NonPrefixcontinuation evictions and full-history re-uploads.src/providers/codex/continuation.rs): RemovesMAX_OWNER_TRANSCRIPT_BYTES(2 MB) andMAX_TOTAL_TRANSCRIPT_BYTES(20 MB) while keepingMAX_STATESandTTL_MSbounding. Long reasoning-heavy sessions with high-entropyreasoning.encrypted_contentblobs no longer abortprevious_response_iddelta continuation after ~15–25 turns and fall back to re-uploading the full multi-megabyte transcript on every turn.src/providers/codex/compaction.rs,src/providers/codex/mod.rs):MAX_STATE_BYTES(4 MB) andMAX_TOTAL_STATE_BYTES(20 MB) and extendsSTATE_TTL_MSto 24 hours so compacted sessions never drop their consolidatedCompaction { encrypted_content }item.apply_compaction_replaybeforebegin_compaction/request_compactionon subsequent compaction boundaries so consecutive compactions (both automatic and manual/compact) consolidate the priorCompaction { encrypted_content }item alongside new turns via/responses/compact, matching officialcodexCLI behavior without any arbitrary reasoning retention capsrc/providers/codex/translate/request.rs,src/providers/codex/compaction.rs): Ignores trailingsystem/developermessages injected by Claude CodeUserPromptSubmithooks when detecting compaction boundary requests (is_compact_messages_request) and when stripping the compaction instruction (without_compaction_instruction).requestCompressionandpreviousResponseId(src/config.rs): KeepsCodexTransport::Autowhen bothcodex.requestCompressionandcodex.previousResponseIdare enabled so normal turns use WebSocketprevious_response_iddelta continuation (~2–20 KB/turn) while HTTP requests (/responses/compactand HTTP fallbacks) use gzip request body compression.Test Plan
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test --lib config::tests::codex_request_compressioncargo test --lib providers::codex::continuation::testscargo test --lib providers::codex::compaction::testscargo test --lib providers::codex::translate::request::tests::compactcargo test --test codex_agent_continuationcargo test --test smoke_cutover smoke_codex_http_server_compaction