TUI resize reflow emits full clear outside synchronized output, causing blank flash
What version of Codex CLI is running?
codex-cli 0.135.0
Also reproduced earlier with 0.134.0.
What subscription do you have?
Not subscription-specific.
Which model were you using?
Not model-specific, this is TUI resize/rendering behavior.
What platform is your computer?
macOS 26.6.0 arm64 / Apple Silicon.
What terminal emulator and version are you using (if applicable)?
Reproduced in multiple terminal frontends, including:
- Ghostty 1.3.1 (
TERM=xterm-ghostty) - iTerm2
The same underlying byte ordering is visible in raw terminal-output captures, so this does not appear specific to one terminal frontend.
What issue are you seeing?
During terminal resize reflow, Codex emits a full terminal clear outside the synchronized output transaction that contains the repaint. Terminals that honor synchronized output can briefly present the cleared screen before the repaint arrives, producing a visible blank flash during resize.
The relevant bad ordering is:
ESC[?2026l
ESC[r ESC[0m ESC[H ESC[2J ESC[3J ESC[H
ESC[?2026h ...replay/repaint...
That is:
sync end -> full clear -> next sync start/repaint
The bug is not tied to one terminal. The reproducible condition is a long Codex TUI session plus a terminal height resize that triggers resize reflow.
What steps can reproduce the bug?
Manual visual repro:
- Open Codex in a normal terminal.
- Resume a long session with enough visible/replayable content.
- Resize the terminal window shorter/taller a few times.
- Affected builds briefly flash a blank cleared screen during resize.
Byte-level proof:
Capture Codex's terminal output while performing the resize, then inspect the ordering of synchronized-output markers and the resize-replay full clear:
- synchronized output start:
ESC[?2026h - synchronized output end:
ESC[?2026l - resize-replay full clear:
ESC[r ESC[0m ESC[H ESC[2J ESC[3J ESC[H
The affected ordering is:
ESC[?2026l
ESC[r ESC[0m ESC[H ESC[2J ESC[3J ESC[H
ESC[?2026h ...
The exact terminal size is not important. The important condition is a long TUI session plus a height resize that causes resize reflow.
What is the expected behavior?
Resize replay should present clear + replay/repaint as one synchronized output transaction:
sync start -> full clear -> replay/repaint -> sync end
Terminals that honor synchronized output can then avoid publishing the intermediate cleared state.
Additional information
Related but not duplicate:
- #21978 tracks stale terminal size / constrained rendering after resize in Ghostty and is still open. It does not identify the synchronized-output atomicity failure or provide raw byte ordering.
- #18575 introduced terminal resize reflow and fixed older stale wrapping / scrollback issues. The current bug appears to be an atomicity gap in that resize-reflow path, not evidence that the reflow feature is absent.
Root-cause hypothesis from source inspection:
codex-rs/tui/src/app/resize_reflow.rs clears immediately in clear_terminal_for_resize_replay():
fn clear_terminal_for_resize_replay(&mut self, tui: &mut tui::Tui) -> Result<()> {
if tui.is_alt_screen_active() {
tui.terminal.clear_visible_screen()?;
} else {
tui.terminal.clear_scrollback_and_visible_screen_ansi()?;
}
let mut area = tui.terminal.viewport_area;
if area.y > 0 {
area.y = 0;
tui.terminal.set_viewport_area(area);
}
Ok(())
}
Then draw_with_resize_reflow() later wraps viewport/history/render in stdout().sync_update(...). That means the clear can leave the process before synchronized output is enabled for the replay/repaint.
Codex doctor report
codex doctor --json was run under a real pty and reported overallStatus: ok. Full output is omitted here because it contains local paths and environment details that are not needed for this rendering bug.
Relevant fields:
{
"overallStatus": "ok",
"codexVersion": "0.135.0",
"runtime.provenance": {
"platform": "macos-aarch64",
"version": "0.135.0"
},
"terminal.env": {
"status": "ok",
"TERM": "xterm-256color",
"stdin/stdout/stderr": "terminal"
},
"updates.status": {
"latest version": "0.135.0",
"latest version status": "current version is not older"
}
}
Hi, I'd like to investigate and work on this issue. I'll try reproducing it and validate whether moving the resize replay clear operation into the synchronized output transaction resolves the blank flash.
I investigated this issue and implemented a candidate fix.
The approach defers terminal clearing until the synchronized update/render path executes, preventing the blank cleared frame from being emitted before replay/repaint.
Implementation: furqan-debug/codex branch: fix/issue-25622-resize-reflow-race-condition commit: c66e8cf
Unfortunately it appears external PR creation is currently restricted, so I'm sharing the implementation details here in case it's useful.
Confirmed independently on stock Codex 0.154.0 / Linux aarch64 / stock Foot 1.27.0. This adds a current-release Linux reproduction to the original macOS report and supports the deferred-clear analysis already described above.
Reproduction and scope
I resumed a synthetic 12-turn transcript in --no-alt-screen mode, waited until history replay was settled, then resized the terminal once per operation. Each operation was separated by about 700 ms; the session was idle, with no streaming or model request.
- Official
rust-v0.154.0release,codex-aarch64-unknown-linux-musl; downloaded archive SHA-256 matched the digest in the GitHub release metadata. - Unmodified system Foot package
1.27.0-1,TERM=foot. - Private headless Wayland test, Hyprland 0.56.1, desktop animations disabled and no compositor plugins loaded.
- Captured Codex's PTY output before forwarding it to Foot, preserving byte order across read boundaries.
All five operations below produced both ESC[2J and ESC[3J with synchronized output off:
| Operation | Terminal size, columns × rows | Unsynchronized full clears |
|---|---|---|
| Width shrink | 96×29 → 72×29 | 2J, 3J |
| Height shrink | 72×29 → 72×21 | 2J, 3J |
| Width expansion | 72×21 → 96×21 | 2J, 3J |
| Height expansion | 96×21 → 96×29 | 2J, 3J |
| Height shrink again | 96×29 → 96×21 | 2J, 3J |
For the first operation, relative to the proxy observing the resize:
1.164 ms ESC[?2026h early redraw begins
1.324 ms ESC[?2026l early redraw ends
78.742 ms ESC[2J clear while sync is OFF
78.742 ms ESC[3J clear while sync is OFF
78.952 ms ESC[?2026h transcript replay/redraw begins
79.431 ms ESC[?2026l replay/redraw ends
The contiguous byte sequence around that clear was:
ESC[?2026l ESC[r ESC[0m ESC[H ESC[2J ESC[3J ESC[H ESC[?2026h
These are PTY receive timestamps, not screen presentation times or a measured blank-flash duration. In particular, the roughly 75 ms wait before replay is separate from the short unsynchronized clear interval. A recording shows an intermediate wrapped layout followed by the completed transcript reflow; it does not establish that a blank frame is presented on every resize.
Current source and suggested fix boundary
I also inspected main at 6f39a47bb3b04de4c804187bfbf55edc56939aab:
clear_terminal_for_resize_replaystill clears immediately and resets the viewport position.reflow_transcript_nowcalls that clear before queueing the rebuilt history.draw_with_resize_reflowopens the synchronized transaction later.
main was source-inspected; the runtime reproduction above is the released 0.154.0 binary.
The narrow fix would defer the clear and associated viewport reset until the transaction that consumes the queued replay and redraws the composer. A separate synchronized transaction containing only the clear would still expose an empty state between transactions.
This atomicity fix can be evaluated independently of the existing 75 ms resize debounce. Changing that debounce is a separate responsiveness/performance decision; it should not be needed to correct the clear/repaint ordering.
Useful regression coverage would capture actual terminal output and require every resize-replay full clear to occur inside the same synchronized transaction as replay and composer repaint. Width/height resize and repeated resizes should also preserve the final viewport/composer position. Checking only the final screen can miss the intermediate state.
Capturing the ordering on another Linux terminal
Resume a disposable session with several wrapped paragraphs, wait for it to settle, resize it shorter and narrower, then exit. With util-linux script, for example:
script -q -f -O resize-output.bin -c 'codex --no-alt-screen resume SESSION_ID'
This small scanner prints the synchronization state at each full clear. Inspect clears associated with the resize, rather than treating startup/shutdown clears as resize failures. The capture contains conversation text; only the scanner's offsets/control-sequence output is needed here.
import pathlib
import re
data = pathlib.Path("resize-output.bin").read_bytes()
sync = False
for match in re.finditer(rb"\x1b\[[?0-9;]*[A-Za-z]", data):
code = match.group()
if code == b"\x1b[?2026h":
sync = True
elif code == b"\x1b[?2026l":
sync = False
elif code in (b"\x1b[2J", b"\x1b[3J"):
print(match.start(), repr(code), "synchronized:", sync)
(response from codex)
Thanks for the detailed traces. I confirmed on CLI 0.171.0 that inline mode (--no-alt-screen) still clears the screen before the synchronized repaint during resize. The default full-screen mode skips that clear.
Since this no longer affects the default mode, we’re closing this as not planned. If you use --no-alt-screen, switching back to full-screen mode should avoid the flash.
Related case: in a fixed-size xterm.js host on Windows (ConPTY, Codex CLI 0.172.0, --no-alt-screen), after a Markdown table rendered, the transcript visibly replayed for 3-4 seconds. The clear (ESC[2J ESC[3J) came first, then the repaint of the transcript (about 200 lines) inside one synchronized-output block, and that block took longer to arrive than xterm.js's 1-second synchronized-output timeout.
Host-side workaround: when a PTY chunk contains ESC[3J, buffer from there (from ESC[2J if it is in the same chunk) until the ESC[?2026l that closes the next synchronized block, then pass it to xterm.js in a single write(). A 300 ms idle timeout (while no synchronized block has started) and a 15 s overall cap release the buffer. That eliminated the visible replay in our test. Limitation: an ESC[3J split across two PTY reads is not detected.
https://github.com/aru-labs/lossless-memory