Remote compact can create huge compacted records and make session unrecoverable
Summary
A long-running Codex CLI session became unusable because remote compaction persisted very large compacted records. Future resume/compact attempts exceeded the model context window even though normal user/assistant messages were not the main source of size.
Environment
- Package:
@openai/codex - Codex CLI version:
0.133.0 - Install path:
/opt/homebrew/lib/node_modules/@openai/codex - Repository metadata:
github.com/openai/codex, directorycodex-cli - Platform: macOS
- Model shown in CLI:
gpt-5.5, reasoning high, summaries auto - Session cwd:
/Volumes/T7/3333_Deveploment/12_MonetizingYourKnowledge
Error messages
Your input exceeds the context window of this model. Please adjust your input and try again.
Later, after trying to resume:
Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying.
What I found
The session JSONL had grown to 892 MB. Size by record type showed that compacted records dominated the file:
783.6 MB 62 compacted//
38.9 MB 4591 turn_context//
19.0 MB 707 response_item/message/user
18.3 MB 5412 response_item/function_call_output/
11.3 MB 3648 response_item/reasoning/
9.3 MB 13437 event_msg/token_count/
Largest lines were all compacted records:
19.3 MB line=42045 compacted//
19.3 MB line=41903 compacted//
19.3 MB line=42190 compacted//
18.9 MB line=41358 compacted//
18.9 MB line=41590 compacted//
Removing compacted, tool outputs, token counts, reasoning records, and binary image/attachment metadata made the session usable again. A recent-context slimmed file was about 22 KB and could show the recent history again.
Expected behavior
Compaction should produce a bounded summary and should never make a session unrecoverable.
Actual behavior
Repeated/remote compaction produced or retained huge compacted records. These records appear to be recursively included or otherwise unbounded, eventually making resume/compact impossible.
Suggested fixes
- Enforce a hard byte/token limit on each
compactedrecord. - Avoid including previous
compactedpayloads in future compact input. - If remote compact fails, do not persist partial or oversized compact data.
- Add a repair/prune command, e.g.
codex debug prune-session <id> --drop compacted,function_call_output,token_count,reasoning. - Ensure resume can fall back to recent user/assistant/event messages when compacted state is corrupt.
6 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
+1
had to perform lobotomy and strip everything i could
Thanks. I reviewed the linked issues.
I agree this is related to #23257, #23589, #24014, #24002, and #24100, but I do not think #24191 is a full duplicate.
The main difference in this report is that the session became unrecoverable because persisted
compactedrecords themselves grew without a safe bound. In my affected CLI session, the rollout JSONL was 892 MB andcompactedrecords accounted for about 783 MB. This was not only an image-base64 issue; the recovery also required removing stalecompacted, tool outputs, token_count, reasoning records, and attachment/media metadata.So I think #24191 should either stay open as the broader persisted-session corruption / repair issue, or be explicitly linked to the canonical issue that will cover:
#23257 is very close for the image/base64 part, but #24191 covers the broader CLI/session recovery failure mode.
Solution: Codex #24191 — Remote Compact Creates Huge Unrecoverable Records
Issue Summary
GitHub: openai/codex #24191
Title: Remote compact can create huge compacted records and make session unrecoverable
Labels: bug, CLI, context, session
Competition: Low (2 comments)
Quote: $2,000-$3,000
Root Cause Analysis
Primary Root Cause: Remote Compaction Lacks Size Bounds
The remote compaction process generates a compacted session record that can exceed the model's context window. Unlike local compaction (which has built-in size limits), remote compaction has no size guard, allowing it to produce records that are too large for future resume/compact operations.
Failure Chain
Root Cause Details
Proposed Fix
Fix 1: Compaction Output Size Limit
File:
codex-rs/core/src/session/compaction.rsFix 2: Recursive Compaction Guard
Thanks
Thanks for reporting this problem. Until recently, Codex used a separate endpoint and server-side logic for compaction. We recently switched to a more robust approach where the compaction logic is moved locally using the same endpoint as normal turns. This eliminates "remote compaction" errors and increases the stability and reliability of compaction operations. If you see further problems with compaction, please use
/feedbackand open a new bug report.