codex icon indicating copy to clipboard operation
codex copied to clipboard

TUI: startup-only palette cache leaves input unreadable after system light/dark changes (0.154.0)

Open lightninglu10 opened this issue 2 months ago • 42 comments

What version of Codex CLI is running?

codex-cli 0.154.0. The startup-only cache is also present in upstream main at a592c38c16cdd7623dacc9168926ebccedfb67d3.

What subscription do you have?

Not relevant to this terminal-rendering issue.

Which model were you using?

Model-independent; observed in long-running Codex CLI sessions.

What platform is your computer?

macOS, Darwin 25.6.0, arm64.

What terminal emulator and version are you using?

CodePress Terminal, a Tauri/xterm.js host configured to follow the system light/dark appearance. The host updates its terminal palette and answers OSC 10/11 queries. Exact host release not recorded.

What issue are you seeing?

After the terminal changes between light and dark appearance while Codex is already running, the composer and previously rendered user-message blocks retain their old background colors. The terminal's default foreground updates, producing nearly white text on a pale background (or the inverse mismatch). Long-lived sessions become unreadable after an automatic macOS appearance change.

Refocusing and redrawing do not refresh the cached palette. Restarting/resuming refreshes the startup colors, but the next appearance change can break the session again.

This follows up my earlier report #37298, which described a failed refresh permanently poisoning the color cache in 0.146.0. The current implementation has a different failure mode: focus-driven refresh has been removed entirely, so no transient failure is required.

What steps can reproduce the bug?

  1. Configure a terminal to follow macOS system appearance and start Codex while the terminal is light.
  2. Send a message so both a user-message block and the composer are visible.
  3. Change macOS appearance to dark without restarting Codex, or leave the process running across the automatic appearance change.
  4. Refocus the terminal and type in the composer.
  5. Observe that the terminal's normal foreground/background have changed but the composer/message backgrounds retain the light-theme color. Repeat dark to light as well.

A terminal host can verify the distinction by recording OSC 10/11 requests: the current focus handler intentionally does not send a new pair on focus regain.

What is the expected behavior?

Codex should adapt its palette-dependent rendering when the terminal's colors change, without restarting the process, losing draft text, dropping/reordering keys or pasted input, or inserting terminal replies into the composer.

Root cause and relevant change

PR #35649, merged July 27, intentionally removed focus-time palette queries because they could block the input loop and discard keystrokes. That input-preservation fix is important, but it also leaves a long-lived TUI unable to adapt to system appearance changes.

Source at the inspected commit:

  • terminal_palette.rs: the process-global cache stores the startup foreground/background; attempted prevents re-querying through default_colors().
  • tui/event_stream.rs: FocusGained explicitly preserves the startup-cached palette and only returns the focus event.
  • style.rs: user messages get an explicit derived background without a paired explicit foreground. When the terminal's default foreground changes, the old explicit background remains.
  • terminal_probe.rs: the existing Unix color probe uses a direct reader. Its read_until helper explicitly does not replay unrelated input, so simply calling this again from the focus handler would reintroduce the reason for #35649.

Proposed approach

Please restore runtime palette refresh through the normal terminal input/event path rather than reinstating the old synchronous raw-input probe:

  1. Request OSC 10/11 asynchronously on focus regain as a compatibility fallback. Also support a terminal theme-change notification so a theme switch while the terminal stays focused can refresh the palette; #38575 tracks DECSET 2031 for that case.
  2. Parse replies through the existing input owner, preserving ordinary keys, bracketed paste, and fragmented/late replies. Coalesce repeated refresh triggers and keep only one bounded refresh outstanding; never wait on terminal replies in the UI input handler.
  3. Commit a complete valid foreground/background pair atomically. On timeout or malformed/partial replies, preserve the last known good palette and allow a later retry, avoiding #37298's poisoned-cache behavior.
  4. Invalidate palette-dependent render caches and repaint the composer and affected transcript content when colors actually change. Preserve an explicitly chosen syntax-highlighting theme.
  5. Preserve startup trust/confirmation protections and terminal ownership during external-editor handoff and suspend/resume; a refresh must not start a second competing stdin reader.

Suggested regression coverage: both light/dark directions in the same process; theme changes without a focus transition; repeated focus notifications; immediate, delayed, fragmented, missing and partial OSC replies; a failed refresh followed by a successful one; typing and bracketed paste during refresh; unchanged draft and input ordering; and recoloring existing visible user-message blocks, not only newly generated output.

Workaround

Launching a new process with FORCE_COLOR=1 codex selects Codex's basic-color fallback, which uses the default/reset color for the derived composer background. This is source-backed, not an interactive validation from this investigation, and sacrifices richer colors. Restarting normally only fixes colors until the next theme change. /theme controls syntax highlighting and does not invalidate this palette cache.

Related issues

  • #37298 — my earlier report: one failed requery permanently disabled future refreshes.
  • #14105 — composer readability after a live terminal theme switch.
  • #38575 — theme-change reporting without a focus transition.
  • #18942 — related focus/theme refresh discussion.
  • #35649 — intentional removal of focus queries to preserve input.

This report adds the 0.154.0 observation and the current startup-only-cache diagnosis, linking the earlier reports rather than treating this as an unrelated color preference. Per the current contribution policy, I am including the implementation constraints and regression cases here for the maintainers.

lightninglu10 avatar Sep 13 '26 04:09 lightninglu10

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

  • #43778

Powered by Codex Action

github-actions[bot] avatar Sep 13 '26 04:09 github-actions[bot]

Status: still reproduces on current main.

Evidence: the FocusGained handler in codex-rs/tui/src/tui/event_stream.rs still keeps the startup-cached palette by design, and the palette cache in terminal_palette.rs latches on first attempt, so a mid-session OS appearance switch still leaves stale composer and message backgrounds. Related: #45291 was closed as a duplicate of this issue, confirming this as the live tracker.

What is left: async palette refresh through the input path as proposed above, with atomic pair commit and repaint on change.

lightninglu10 avatar Sep 15 '26 07:09 lightninglu10

Confirmed on Codex CLI 0.155.0 on macOS arm64, September 18, using Herdr 0.9.0. A live light/dark switch updates the terminal surface but leaves the composer and some other TUI elements using the previous colors. With multiple long-running agent sessions, the workaround means interrupting, exiting, and resuming each session.

I also checked the installed CLI in a controlled pseudo-terminal, without submitting a model request:

  1. Answer the startup OSC 10/11 queries with foreground #eeeeee and background #111111.
  2. Let the TUI initialize and type an unsubmitted draft.
  3. Change the harness's color-query answers to foreground #111111 and background #ffffff, then send focus-lost/focus-gained (CSI O, CSI I).
  4. Compare with a fresh process started using those light colors.
Observation Dark startup, then light answers + refocus Fresh light startup
OSC 10/11 requests One pair at startup; no new pair after refocus One pair at startup
Explicit input background #2d2d2d, retained after refocus #f4f4f4
DECSET 2031 subscription Not emitted Not emitted

The harness used TERM=xterm-256color, COLORTERM=truecolor, FORCE_COLOR=3, with NO_COLOR removed. It kept the switched process alive for four seconds after the focus event. This verifies the stale palette and lack of re-query, not a fix or input-preservation behavior during a refresh.

Current upstream a633ebc1 still explicitly keeps the startup-cached palette in the focus handler. Herdr already has terminal-side support for Mode 2031 notifications, but Codex does not subscribe in the tested release.

The existing implementation references in #38575 look relevant: Codex fork PR and crossterm support PR. I have not tested those patches. Linking them here alongside the current-release reproduction, per the contribution policy, rather than opening another duplicate issue or external PR.

naveedjanmo avatar Sep 19 '26 01:09 naveedjanmo

Independent repro on macOS + Ghostty.

When macOS appearance switches from Light to Dark while Codex is already running, Ghostty updates to the dark theme, but the Codex composer/bottom panel remains light. Restarting/resuming Codex fixes the colors.

Environment:

  • macOS 15.7.9 (24G830)
  • Ghostty 1.3.1, build 15212, commit 332b2aefc
  • codex-cli 0.155.1

This affects long-running sessions in normal daily use, especially with automatic macOS appearance switching.

Happy to test a prerelease/nightly fix if useful.

pletinsky avatar Sep 20 '26 15:09 pletinsky

Independent confirmation on Codex CLI 0.155.1 with Herdr 0.9.1 on macOS 26.6.2.

During a dark-to-light appearance transition, already-running Codex sessions kept the dark composer/input background and stale palette-dependent colors, while the Herdr terminal surface switched to light. A new Codex session created in the same Herdr workspace immediately used the correct light palette.

Restarting or resuming the affected Codex processes is the only recovery I observed. This old-process/new-process comparison is consistent with the startup-only palette cache described in this issue.

rakhimovv avatar Sep 21 '26 08:09 rakhimovv

Same issue with gnome-terminal

mradalbert avatar Sep 28 '26 16:09 mradalbert

I reproduced this with Codex CLI 0.158.0 on macOS 26.6.2 (arm64), Ghostty 1.3.1, and tmux 3.7c. Following the contribution policy, I’m sharing a tested reference patch here: pbar1/codex:auto-theme, commit 3d33104c3b, based on upstream cd7d9e128c.

With Ghostty following system appearance, start Codex with -c 'tui.theme="ansi"', type an unsent draft, and switch macOS between light and dark. The running composer retains its previous shading while a fresh instance gets the correct colours. Selecting ANSI or Base16 does not avoid this: the composer still uses RGB shading derived from the cached terminal palette.

One additional cache surfaced during testing: an already-open theme picker retains keyboard-hint foregrounds captured at construction, even after its preview and selection shading refresh.

The patch preserves the normal shaded UI and explicit syntax-theme selection. It polls OSC 10/11 every second, pauses the crossterm reader for an exclusive probe, preserves queued input, and replays interleaved typing/paste. Only complete foreground/background pairs replace the cache; changed colours invalidate rendering caches and refresh picker hints. Missing replies retain the last good palette. A terminal that has previously answered keeps the normal retry interval, avoiding a roughly 31-second stale-colour delay encountered with a longer failure backoff.

Validation:

  • Repository regressions compare the complete composer buffer with a fresh composer for ANSI and all six Base16 variants, including exact input shading and draft preservation. A running-process pseudo-terminal test covers interleaved Unicode paste, missing replies, and successful recovery. The focused run passed 155 unit tests and two integration tests; five unit tests and one integration test are new.
  • Separate local scripts changed actual macOS appearance via AppleScript, keeping each patched process alive and comparing it with fresh installed instances. All 42 comparisons passed: seven themes × three appearances × composer/picker. These compare draft-cell styles and picker colour sets, not screenshots or full-screen equality. The driver scripts are outside the repository test suite.

This implementation is Unix-only polling, not DECSET 2031 support (#38575). The probe has a 100 ms read deadline, and input processing pauses during the handoff. It is not a fully asynchronous reply parser; that remains an architectural tradeoff. The replay and input-preservation tests specifically address the regression that motivated #35649. Full cross-platform CI has not been run.

pbar1 avatar Oct 04 '26 04:10 pbar1

I would love a fix for this. It's so ugly. At the moment I have to restart my Codex instances

Codex+ghosttty using system theme following sunset

Ugly: Image

Correct: Image

shepherdjerred avatar Oct 05 '26 04:10 shepherdjerred

Also a problem on Linux (GNOME) + Ghostty.

louwers avatar Oct 07 '26 08:10 louwers

Note this, might not be OS specific, as an app that can switch its theme voluntarily, like IntelliJ IDEA, visual studio code, or even terminal emulators

bric3 avatar Oct 12 '26 09:10 bric3

Confirming this is still present in Codex CLI 0.162.1, with an additional terminal/multiplexer reproduction and a check of where the appearance change reaches.

Environment:

  • macOS on Apple Silicon (Darwin 27.0.0 arm64).
  • iTerm2 3.7.1, with separate light/dark profile colors enabled.
  • tmux 3.7b, verified both with tmux -V and tmux display-message -p '#{version}' against the running server.
  • Codex syntax theme: cushman.

Reproduction: keep Codex sessions running inside tmux, then change macOS appearance. The terminal surface changes, but existing Codex sessions can retain a pale composer/input background against the dark terminal, with poor text contrast. Different concurrently running Codex sessions can show different background colors.

To check whether tmux was blocking the update, I switched the actual macOS appearance from dark to light and inspected all four attached clients:

tmux list-clients -F '#{client_theme}'

All four immediately reported light; after restoring dark appearance, all four reported dark. This validates the iTerm2 -> tmux theme-update path in this setup. It does not demonstrate that Codex subscribes to or consumes theme notifications.

Source inspection of the matching release still shows the startup-only behavior:

The practical impact is having to restart/resume long-running Codex sessions after system appearance changes. Please include iTerm2 + tmux in regression coverage for a runtime palette-refresh fix, while preserving drafts, typing and bracketed paste as discussed above. No local fix or reference patches were tested in this investigation.

GitZhangChi avatar Oct 13 '26 10:10 GitZhangChi

Sharing another tested reference implementation for this issue, from a Linux/NixOS setup using Ghostty with Omarchy theme changes and Herdr remote Codex sessions. The terminal/Herdr surface follows the new theme, but the running Codex composer retains its startup-derived background and loses contrast.

Reference implementation:

Reproduction: start Codex with a dark terminal palette, keep the process running, then switch the terminal to a light theme. The terminal's default colors change, while the composer retains its previous derived background. The inverse transition is also relevant. This concerns terminal-derived UI styles; /theme syntax highlighting is a separate setting.

The patch polls OSC 10/11 every two seconds on Unix terminals that answered the startup probe. It uses the pinned crossterm dependency's existing color-query APIs and shared parser, temporarily dropping the EventStream under the event broker lock. This preserves interleaved input without adding a separate raw /dev/tty reader or replay parser. A complete changed foreground/background pair updates the shared palette and requests a redraw. The UI can continue drawing during queries; queries serialize with editor/suspend handoffs and terminal restoration. Explicit syntax-theme selection is preserved.

Validation on Linux:

  • 13 event-stream tests, including light/dark changes, unchanged palettes, failed queries retaining the last good sample, paused handoffs, and drawing/input wakeup while a query is pending.
  • 5 palette tests and the existing real-PTY panic-recovery test.
  • 9 focus-palette integration tests, including a new real-PTY dark → light → dark test checking the rendered composer background while ordinary keys and bracketed paste arrive during queries. The unanswered-query/input-preservation and external-editor tests also pass.
  • Rustfmt and diff checks pass.

Limitations/tradeoffs: this is Unix polling, not DECSET 2031 support or a fully asynchronous reply path. Input delivery can wait for the query round trips; crossterm's timeout is two seconds per color. A query failure retains the last complete palette and stops further monitoring for that TUI, so this version does not implement recovery after a failed query. The tests validate the patch through a controlled PTY; it has not yet been deployed into the original Ghostty → Herdr session, and full cross-platform CI has not been run.

Posting this as implementation evidence under the existing report in accordance with the current contribution policy.

ryantm avatar Oct 13 '26 18:10 ryantm

Confirming this issue with another macOS report.

Environment checked on the reporting machine:

  • Codex CLI: 0.162.1
  • macOS: 27.0.1 (build 26A434)
  • tui.theme = "ansi"
  • Terminal/session environment: Herdr, used from a terminal on macOS (clarified by the user). Exact terminal application/version, Herdr version, and any multiplexer involvement were not verified.

User-observed behavior:

  1. Keep an existing Codex CLI session running while the macOS/Herdr terminal environment switches between light and dark appearance.
  2. The composer/input area becomes unreadable: the supplied screenshot shows black input text against a dark gray composer background.
  3. The user reports this happens repeatedly at appearance changes, and only a newly started session returns to normal. Concurrent sessions can show different composer backgrounds.

Impact: restarting interrupts ongoing work, so restarting/resuming is not an acceptable ongoing solution. Please refresh the composer foreground/background consistently in the existing process when terminal appearance changes, preserving the current conversation, draft input, and ongoing work.

Evidence boundary: the symptom and recovery behavior are reported by the user and supported by screenshots shared privately. I checked the installed CLI version and configuration, but did not independently reproduce the appearance transition or inspect the implementation. No local fix was applied. Screenshots are not attached here because they include unrelated session/status details.

paperw8 avatar Oct 13 '26 23:10 paperw8

Also observed with Codex CLI 0.162.1 in iTerm2 on macOS, configured to use different themes for system light and dark appearance.

Steps to reproduce:

  1. Configure iTerm2 to follow the system light/dark appearance with different terminal themes.
  2. Start an interactive Codex CLI session.
  3. Leave Codex running while the system appearance changes and iTerm2 switches to its light theme.
  4. Observe the Codex prompt area after the switch.

The terminal background updates, but the prompt retains its previous dark appearance. Codex only partially follows the new terminal theme.

Expected: the running session should automatically update the prompt and other palette-dependent UI when iTerm2 changes appearance, preserving the conversation and draft input. Exiting and resuming, or manually changing a theme, does not meet this requirement. Claude Code handles the automatic transition in the reporter's setup.

No tui.theme override is configured. The exact iTerm2 version and a screenshot were not collected. This is a user-reported observation; restarting was suggested but was not tested as part of this report.

samlevin avatar Oct 14 '26 19:10 samlevin

Been happening for me also for quite a while. Currently running

  • codex 0.162.1
  • cmux 0.65.0

Quit and resume resolves it but very annoying if it's working on something at the moment it changes.

ianawilson avatar Oct 16 '26 02:10 ianawilson

Confirming the same issue on Linux/NixOS with Ghostty and Herdr.

Environment verified on the reporting machine:

  • Running Codex CLI executable: 0.154.0 (checked the running process executable, not only the shell PATH).
  • Herdr: 0.9.3, running inside Ghostty.
  • Ghostty is configured with theme = light:Catppuccin Latte,dark:Catppuccin Mocha.
  • Herdr has automatic theme switching enabled with matching Catppuccin light/dark themes. The desktop appearance is managed by Noctalia.
  • No tui.theme override was found in the user's Codex configuration.

Reproduction reported by the user:

  1. Start Codex in a Herdr pane and leave the session running across an automatic light/dark appearance change.
  2. Ghostty, Herdr, and the surrounding terminal background switch appearance.
  3. Codex's composer and user-message backgrounds retain the previous appearance. Light → dark leaves pale text on pale boxes; dark → light leaves dark boxes in the light terminal.

A screenshot captured during the investigation directly confirms the dark terminal/Herdr surface with pale composer and user-message backgrounds. Both transition directions were reported by the user; we did not force an additional theme transition or restart the session during the investigation. The screenshot is omitted because it contains unrelated conversation and workspace details.

The matching rust-v0.154.0 source supports the startup-cache diagnosis:

  • terminal_palette.rs: Cache::get_or_init_with latches the queried colours using attempted.
  • style.rs: user_message_style() derives an explicit background from cached default_bg().
  • chat_composer.rs: the composer uses the same user_message_style().

Expected: existing sessions should refresh palette-dependent backgrounds when terminal appearance changes, preserving conversation, draft text, and keyboard/paste input. Please include Ghostty → Herdr on Linux in regression coverage. No local patch was applied.

munnik avatar Oct 16 '26 19:10 munnik

Confirming this on macOS with Codex CLI 0.164.0 and cmux 0.65.0 (108), commit dda24fbd2. The installed CLI version was checked against the latest stable release before reporting.

Reproduction observed today:

  1. Keep an interactive Codex session running with a dark terminal theme.
  2. Switch cmux to GitHub Light Default and reload its configuration.
  3. The surrounding terminal becomes white, but the Codex composer and user-message blocks retain dark backgrounds. Composer text becomes dark on dark and difficult to read.
  4. Exit and resume the same Codex conversation. The user confirmed that reopening restores the correct light appearance and readable input.

Expected: palette-dependent UI should refresh in the existing process when terminal colors change, preserving the conversation, draft input and ongoing work.

The retained startup palette in the matching 0.164.0 source is consistent with this symptom; this is not a claim of an independently tested upstream fix. cmux 0.65.2 has not been tested here. No source patch was applied, and temporary contrast-setting experiments were reverted. Screenshots are omitted because they contain unrelated private workspace and conversation details.

amine-kacem-tech avatar Oct 26 '26 09:10 amine-kacem-tech

Also reproducing with Codex CLI 0.164.0 inside herdr 0.9.5 on macOS. When macOS automatically switches from light to dark appearance, the terminal background and foreground update, but the composer and previously submitted user messages retain their light backgrounds. This leaves pale text on a pale background and makes them difficult to read.

grogancolin avatar Oct 27 '26 21:10 grogancolin

Additional data point from Linux

Environment: codex-cli 0.166.0 (CachyOS openai-codex 0.166.0-1.1 package), WezTerm 20260716-195552-76b606ec, CachyOS (Linux 7.3), panes served by WezTerm's unix-domain multiplexer. Light and dark schemes are switched with a key binding that calls window:set_config_overrides.

  1. WezTerm cannot trigger either proposed refresh path on an in-window theme switch

WezTerm does not implement DECSET 2031: DecPrivateModeCode has no 2031 entry, so it never sends CSI ? 997 ; 1 n / CSI ? 997 ; 2 n reports. A theme switch bound to a key also causes no focus transition. A fix that relies only on 2031 reports plus FocusGained (as proposed in #38575 and #54159) will therefore still leave the composer unreadable in WezTerm until the user moves focus to another pane and back.

  1. The reference implementation works on Linux

I cherry-picked rodchristiansen/codex@ec16e6a0d65ea9267dd268e5c7d677caff9bba8d (rodchristiansen/codex#1) onto rust-v0.166.0 (it applied cleanly) and built it with the crossterm change from rodchristiansen/crossterm#1. To stand in for the missing 2031 support, WezTerm was configured to send the report to the pane after switching scheme:

window:set_config_overrides(overrides)
local report = overrides.color_scheme and '\x1b[?997;1n' or '\x1b[?997;2n'
wezterm.time.call_after(0.3, function()
  for _, tab in ipairs(window:mux_window():tabs()) do
    for _, p in ipairs(tab:panes()) do
      window:perform_action(wezterm.action.SendString(report), p)
    end
  end
end)

(In practice I restrict this to panes running the patched build, since other programs would receive the bytes as input.)

With that in place, the composer and its background update live when switching from light to dark and back, with no restart.

So the refresh machinery is sound on Linux. What WezTerm users additionally need is a trigger that does not depend on 2031 or focus changes, for example a lightweight periodic OSC 10/11 re-query while the TUI is idle, or a manual refresh command or key binding.

bhcopeland avatar Oct 31 '26 09:10 bhcopeland

I can reproduce this consistently on Codex CLI 0.166.0 in Apple Terminal, in both directions (light to dark and dark to light).

Environment

  • Codex CLI: codex-cli 0.166.0, standalone installation
  • macOS: 26.6.2 (25G83), Apple Silicon / arm64
  • Terminal: Apple Terminal 2.15
  • TERM=xterm-256color, COLORTERM=truecolor
  • No explicit tui.theme override in my user configuration

Reproduction

  1. Start Codex CLI in Apple Terminal with the terminal following the macOS appearance.
  2. Send messages so that user-message blocks are visible in the transcript.
  3. Switch macOS from light to dark appearance while keeping Codex running.
  4. Observe the composer and existing user-message blocks.
  5. Repeat in the opposite direction.

Observed behavior

The terminal's main background and text change appearance, but the composer and existing user-message blocks retain incompatible background colors. In dark appearance, these areas have pale backgrounds with almost-white text; in light appearance, they have dark backgrounds with dark text. Diff highlighting also remains inconsistent with the new appearance.

Expected: the composer, user-message blocks, and diff colors update consistently and remain readable without restarting the session.

This confirms the visible behavior in Apple Terminal on 0.166.0. I have not independently investigated the underlying implementation or tested the workarounds described above.

Image Image

PietroLonginetti avatar Oct 31 '26 17:10 PietroLonginetti