Codex CLI TUI remains sluggish after compaction because visible transcript replay is not compact-aware

Resolved 💬 4 comments Opened Jun 5, 2026 by lzt11319 Closed Jun 6, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

Codex CLI TUI remains sluggish after compaction because visible transcript replay is not compact-aware

Summary

In long Codex CLI sessions, terminal interaction can remain sluggish after /compact or automatic compaction. My offline diagnosis suggests that model-history compaction succeeds, but the TUI keeps a separate visible transcript history and can continue to render/reflow pre-compaction UI cells.

In other words, compaction reduces model prompt pressure, but it does not necessarily reduce terminal rendering pressure.

Environment diagnosed

  • Codex target: rust-v0.136.0
  • Commit: 7ca611348db9446711ed16ed81c84095e3721cee
  • Diagnosis type: offline/mock/source-level evidence plus synthetic fixture measurements
  • Real OpenAI API calls: none
  • Real auth/config reads: none
  • Source edits during diagnosis: none

I can re-run or adapt the diagnosis on a newer commit if maintainers prefer a current-main reproduction target.

Evidence summary

The diagnosis intentionally separated model-history pressure from TUI transcript rendering pressure:

| ID | Result | Interpretation |
| --- | --- | --- |
| H1 | confirmed / high | After successful compaction, model history is replaced; the old raw transcript does not keep linearly entering the model prompt. |
| H2 | inconclusive / medium | replacement_history avoids replaying the old prefix, but suffix growth still has proportional effects; real resume-to-prompt needs deeper instrumentation. |
| H3 | confirmed / medium | TUI transcript_cells are separate from model history and are not cleared by compaction; resize/reflow can still process UI history. |
| H4 | inconclusive / low | Terminal scrollback/profile was not A/B tested; it may amplify rendering work but was not proven as an independent root cause. |
| H5 | confirmed / medium | History insert / pre-wrap paths can produce bursts proportional to historical lines and wrapped rows. |
| H6 | rejected / medium | Synthetic large-draft keypress path did not exceed the visible-lag threshold in the offline proxy. |
| H7 | rejected / medium | Local resize/input/history rendering paths do not require model API/network calls. |

The relevant repo-relative evidence bundle is published in a companion proof-of-concept repository:

Expected behavior

After successful compaction, Codex CLI should not keep paying visible rendering/reflow cost for the full pre-compaction transcript by default. It should preserve enough recent context for continuity while bounding old transcript rendering work.

Actual behavior suggested by diagnosis

Compaction reduces model-context pressure, but visible UI transcript history is independent. Long pre-compaction UI history can remain in TUI data structures and still affect resize/reflow/history insertion behavior.

Proposed upstream direction

Make TUI transcript replay compact-aware:

  1. On successful compaction, define a compact boundary in the visible transcript.
  2. Preserve all post-compaction content.
  3. Preserve the final pre-compaction turn in lightweight form: user message + assistant final answer; heavy tool output/logs/diffs from that turn are folded.
  4. Fold older pre-compaction UI history into a single marker/summary cell.
  5. Keep persistent rollout/session audit data intact; this is about visible rendering, not deleting records.
  6. Add a config fallback for users who prefer legacy full-history rendering.

Possible config shape:

[tui]
compact_aware_rendering = true

Set to false to retain legacy full visible-history rendering.

Suggested tests

  • Unit test that compaction creates a compact boundary and TUI replay starts from the compact-aware visible window.
  • Resume test that pre-compaction folded history does not expand back into visible transcript by default.
  • Resize/reflow test that bounded visible history is used after compaction.
  • Config test that compact_aware_rendering = false restores legacy full-rendering behavior.
  • Regression test that model-history compaction remains independent from UI transcript folding.

Companion proof-of-concept / workaround

A companion repo is available at https://github.com/lzt11319/codex-afterglow. It packages a compact-aware TUI patch and binary-first installer as an unofficial user workaround/proof-of-concept.

Published release: https://github.com/lzt11319/codex-afterglow/releases/tag/afterglow-v0.1.0-alpha.0

This is not an official OpenAI project and is not intended as a substitute for an upstream fix. I am happy to open a smaller upstream PR if this direction is acceptable.

View original on GitHub ↗

4 Comments

lzt11319 · 2 months ago

I prepared an upstream-friendly 3-commit patch series here, but GitHub says pull requests are limited to repository collaborators:
https://github.com/openai/codex/compare/main...lzt11319:afterglow/compact-aware-tui-rendering-main
Could a maintainer advise the preferred way to submit this, or open/enable a PR from this branch?

etraut-openai contributor · 2 months ago

The TUI transcript displays the full history of the conversation. This is by design.

When you say "sluggish", what is your metric? The TUI renders only new contents in the terminal, not the entire contents of the transcript. The exception to this rule is when you resize the terminal, when some portion of the transcript needs to be re-rendered.

lzt11319 · 2 months ago

One practical case where this hurts:

Sometimes Codex CLI has terminal rendering glitches where newly appended output is missing some lines. I usually resize the terminal to force a redraw.

But in long sessions, resizing becomes slow even after /compact, because the visible transcript is still large. So /compact helps model context, but not the TUI rendering cost.

A useful feature could be “Compact & New”: compact the current session, then start a clean new session with the same repo/config/settings and the compacted summary injected.

This would let users continue the task without manually migrating context or carrying over the old terminal rendering cost.

mehulparmariitr · 1 month ago

Related current umbrella investigation: https://github.com/openai/codex/issues/24527. It preserves transcript resize/reflow as a possible long-session amplifier but found that the largest ordinary typing stalls were instead inside synchronous terminal-size lookup, with reflow approximately zero. This cross-reference distinguishes the confirmed compaction/transcript path here from other causes that remain after compaction.