Codex compaction retains hundreds of historical user messages, leaving ~187K active context after compaction
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 125k
- Forks
- 19.4k
- PR merge metrics
- PR metrics pending
Description
What version of the Codex App are you using (From “About Codex” dialog)?
26.901.31953
What subscription do you have?
ChatGPT Plus
What platform is your computer?
Windows
What issue are you seeing?
In very long-running Codex Goals, context compaction does not significantly reduce the active working set.
Using the default Codex configuration, I observed a compaction event that retained 192 historical user messages alongside the generated compaction checkpoint.
The checkpoint itself was only ~41.9K serialized characters, while the retained user messages occupied ~1.95M characters.
Immediately after compaction, the next model request still contained 187,306 input tokens.
Prompt caching was working correctly (~99.84% cached), so this does not appear to be a cache issue. The problem is that a large amount of historical user content remains pinned in the active context after compaction.
codex-context-compaction-retention-report.md
What steps can reproduce the bug?
- Use the default Codex configuration.
- Start or continue a very large, long-running Codex Goal.
- Allow the Goal to accumulate many messages and go through automatic context compactions.
- Inspect a recent "compacted" event in the local rollout JSONL.
- Inspect replacement_history and count retained messages.
- Inspect the first token_count event after compaction.
In my case:
- Compaction window: 420
- Replacement-history items: 194
- Retained user messages: 192
- Retained user-message size: ~1,948,886 serialized characters
- Compaction checkpoint size: ~41,922 characters
The next request after compaction contained:
- Input tokens: 187,306
- Cached input: 187,008
- Uncached input: 298
- Output: 31
I can reproduce the behavior when a Codex Goal becomes sufficiently large.
What is the expected behavior?
Compaction should preserve the full conversation in local/searchable history while substantially reducing the active context sent to the model.
Older completed or superseded messages should be summarized or represented through retrievable references instead of keeping hundreds of historical user messages active after compaction.
The goal is not to reduce Codex's maximum context capacity, but to make compaction actually produce a smaller working set.
Additional information
This occurred with the default Codex configuration. I am not using a custom compact_prompt or experimental_compact_prompt_file.
Codex App version: 26.901.31953
Platform: Windows x64
Subscription: ChatGPT Plus
The issue becomes reproducible in sufficiently large/long-running Goals.
25 retained messages accounted for approximately 98.7% of the retained user-message data, suggesting that a relatively small number of very large historical messages or attachments dominate the post-compaction working set.
I also have a redacted JSONL excerpt containing only the relevant compaction metadata and the immediately following token_count event, with prompts, paths, credentials, and account identifiers removed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with codex-context-compaction-retention-report.md and the local rollout JSONL, inspecting the compacted event, replacement_history, and first following token_count event. Compare retained historical messages with the compaction checkpoint; done means compaction substantially reduces the active model context while preserving full local/searchable history.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- ai
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100