Remote compaction preserves assistant messages and leaves next turn at ~234k input tokens

Resolved 💬 4 comments Opened Mar 11, 2026 by wakamex Closed Jun 29, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of Codex CLI is running?

codex-cli 0.112.0 source build from 2bc3e52a91bb88a0e067a95f8f8559f8711d30e6

What subscription do you have?

pro

Which model were you using?

gpt-5.4 started on xhigh switched to medium

What platform is your computer?

Linux 6.17.9-300.fc43.x86_64 x86_64 unknown

What terminal emulator and version are you using (if applicable)?

wezterm 20260205_190134_4bf8878b

What issue are you seeing?

Remote compaction is not materially shrinking context for a long-lived thread. In my case, the next turn after compaction still had about 234k input tokens, so compaction was happening repeatedly without creating meaningful headroom.

What steps can reproduce the bug?

Uploaded thread: 019cd2c3-4681-72b1-96bd-3527fa94df9d

I have a local sanitized testcase and compaction breakdown if more detail is needed, but I’m not attaching the full rollout publicly unless requested.

What is the expected behavior?

Compaction should significantly reduce prompt size and create enough headroom for continued work. It should not leave the next turn still near the context window ceiling.

Additional information

Local analysis of the compacted replacement history for this thread showed:

  • 1384 retained items total
  • 815 retained user messages, contributing about 41k serialized tokens
  • 567 retained assistant messages, contributing about 191k serialized tokens
  • 1 retained compaction item, contributing about 2.4k serialized tokens
  • total replacement history estimated at about 235k tokens
  • next turn after compaction had input_tokens ~= 234254

This seems to be happening on the OpenAI remote-compaction path rather than the local 20k-user-message compaction path.

Possibly relevant code: https://github.com/openai/codex/blob/main/codex-rs/core/src/compact_remote.rs#L187

View original on GitHub ↗

4 Comments

github-actions[bot] contributor · 5 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #14120
  • #13909
  • #13279
  • #13946

Powered by Codex Action

wakamex · 5 months ago

Those other issues have similar symptoms, but they don't point to assistant message retention as the root cause. Happy to provide more details if it helps.

Xynonners · 5 months ago

Yes, this likely is the cause of the repeating old messages in a long lived thread bug too.

etraut-openai contributor · 1 month ago

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 /feedback and open a new bug report.