Repository navigation
fix(terminal): the terminal's owner answers colour queries for the terminal's whole life - #23925
Conversation
…le life Codex and Claude's `theme: auto` ask the terminal for its foreground and background colours (OSC 10/11) and pick their colours from the reply. Orca answered in the process that owns the PTY only for agent launches and only for 5 s; after that the query was handed to whichever viewer was attached. On Windows ConPTY the owner kept swallowing the query but stopped answering it, so a Codex started from an older shell tab lost its message shading (#22332). On a headless `orca serve` host no viewer existed yet, so a Codex started before anyone attached got no reply at all (#22500). The owner (in-process provider, terminal daemon, SSH relay) now answers every OSC 10/11 query for the PTY's whole life and strips it, so no downstream view ever sees one to answer twice. It answers from, in order: the host-wide viewer theme pushed to that process, the creating viewer's colours sent at spawn (now for every PTY, not only agents), and Orca's default dark theme. The desktop pushes its renderer theme to every owner on change and on (re)connect: a daemon request gated on protocol v38, and an SSH relay notification that older relays ignore. The answer-once rule, the 5 s colour window and the colour-authority handoff are removed; Kitty keyboard queries keep their startup window. Viewer-side answerers (renderer xterm, main's hidden-pane model responder, the mobile webview) stay as the fallback for older owners, which still hand queries off; they are never reached for a new owner.
…ainted with Review follow-ups to the lifetime PTY-owner colour answerer. - The theme catalog moves to src/shared so the renderer and the PTY owners read one source; the owner's last-resort default is derived from it rather than copied. - Main seeds every owner from the host's saved theme settings (light or dark, custom themes, colour overrides) at startup, so a headless host and a desktop pane that queries before the renderer's first push are not told dark to a light-theme user. The renderer's push replaces it. - Colours an app sets with OSC 10/11, and clears with OSC 110/111, are tracked per terminal and reported back, as a viewer paints them; a theme change drops them, as a viewer's theme apply does. - A terminal a paired client created with its own colours answers with those, not the host's theme (`colorSource: 'remote-viewer'` on the spawn intent), so a light client on a dark host is told light. - After the 5 s startup window a reply's echo is watched for 512 bytes instead of 256 KB, and a torn query candidate is released after 500 ms rather than held indefinitely.
…e lookup The 512-byte post-startup echo watch now applies only to replies the PTY owner produced itself. A viewer's reply relayed through answerLiveQueryReply keeps the 256 KB watch, because a cooked-mode app can keep printing after it queries and the echo then trails that output. The renderer's getTerminalTheme now calls the shared lookupTerminalTheme, so the custom-vs-built-in theme lookup exists once.
Two indexOf searches per OSC went quadratic on long runs of ST-terminated hyperlinks, and the tracker now sees every chunk of every terminal.
…acted last A paired client's colours reached the host only as frozen spawn colours on terminal.create, tagged remote-viewer. UI-started agent sessions on a headless host answered OSC 10/11 with the host's saved theme, and a client's theme flip never reached panes it had created. The host now holds one viewer colour value that every PTY owner answers with. The desktop renderer's push, a window focus on the host, the new terminal.setViewerColors RPC, and terminal.create colours from older clients all set it; equal values do not re-notify daemons or relays. The remote-viewer tag (colorSource / terminalColorQuerySource / spawnFromRemoteViewer) is gone; it never shipped in a release.
… change and focus The renderer publisher now hands each published fg/bg to subscribers. A new remote-runtime-terminal-color-push module calls terminal.setViewerColors on every host this client is connected to when it connects (or the host restarts), when the colours change, and when the window gains focus. A host that answers method_not_found or forbidden is not asked again until it reconnects. The app shell also republishes terminal view attributes on settings and system theme changes, so a theme change reaches main and paired hosts with no terminal pane open.
…own theme Round 1 kept one host-wide viewer colour value set by whichever viewer acted last, so a paired client's push (reconnect after sleep, a dusk theme flip) took over the host desktop's own panes until its window regained focus. The value is now derived: this host's renderer colours when a local window has pushed, otherwise the last paired client's push (terminal.setViewerColors or terminal.create colours), otherwise the saved theme. Only a headless host takes a client's theme. The window-focus reassert and the identical-re-push takeover are gone; owners are notified only when the derived value changes.
…y window closes The PTY owner answers OSC 10/11 for the terminal's whole life, and it tried every ESC as a query start: a 240 KB SGR-heavy read cost about 2 ms and 256 KB of bare ESC about 15 ms, long after startup. Once the Kitty query window closes only an OSC colour query can match, so the scan jumps between ESC ] starts, plus a trailing lone ESC so a query torn right after its ESC still resolves on the next read. Output and replies are unchanged.
Review status: ready (head 71bcf3b)The problem: Codex and Claude Code ask the terminal for its colours when they start and shade their messages and prompt from the answer. Orca answered only during a 5-second startup window or from a window showing the tab. So on Windows a Codex started in a shell open more than 5 seconds lost the grey band on your own messages (#22332), and on a headless What changes for you: every terminal now answers colour queries for its whole life, with the colours it is painted in. On Windows, late Codex launches keep their message shading. On a headless host, Codex started from a paired desktop gets that desktop's theme. A desktop host always answers with its own window's theme, so a paired laptop can't change the colours on the machine you're sitting at. Fixed during review (pushed):
Deferred (not blocking):
Before merging: open PR #23908 also bumps the daemon protocol to v38. Whichever lands second must move to v39. Verified:
Not verified: SSH relay and WSL live runs; the phone app; a non-daemon Windows terminal (every normal pane was daemon-backed on that build). With the "system" theme under automation on Windows, one run showed a light pane answering dark. The code reads both from the same source, so this is most likely the test harness emulating light on one page, but it wasn't reproduced on a real OS switch. |
|
| if (isFreshConnection) { | ||
| this.resyncBackgroundedSessions() | ||
| // Why: a replacement daemon starts with no colours, and a disconnected push was dropped. | ||
| this.syncColorQueryReplyColors() | ||
| } |
There was a problem hiding this comment.
Theme update lost on reconnect
If the daemon socket drops while the theme changes, notify drops the colour update. Reconnecting to the same daemon keeps the existing event listener, so this isFreshConnection check skips the resend. Existing panes then answer later OSC 10/11 queries with the old theme until another colour change is published.
| resolve(base: TerminalOscColorQueryReplyColors): TerminalOscColorQueryReplyColors { | ||
| if (this.overridesBase !== null && this.overridesBase !== baseKey(base)) { | ||
| this.overrides = {} | ||
| this.overridesBase = null | ||
| } | ||
| return { ...base, ...this.overrides } |
There was a problem hiding this comment.
Stale app-set colour survives theme
If a theme apply changes another property, such as cursor appearance, but leaves foreground and background unchanged, xterm rebuilds its palette and clears colours set by the program. This tracker compares only the two base colours, so it retains the old override. Later OSC queries report a colour the pane no longer paints.
| private answerColorQuery(slots: readonly TerminalOscColorQuerySlot[]): boolean { | ||
| const replies = this.colorQueries.replies(slots) | ||
| return ( | ||
| replies.length > 0 && | ||
| replies.findIndex((reply) => !this.delivery.answer(reply, 'owner')) !== 0 | ||
| ) |
There was a problem hiding this comment.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- One owner answers OSC 10/11 for the terminal's whole life —
PtyStartupIngressnow scans onlyESC ]starts once the Kitty window closes, answers every colour query from a sharedPtyOwnerColorQueryReplies(app-set overrides → host theme), and strips it so no downstream view answers twice. The oldansweredSlots/queryOpenhandoff is removed; a torn candidate is held 500 ms then released. - Shared theme source — the terminal theme catalog and selection rules move to
src/shared/terminal-themes*+terminal-theme-selection.ts, so app, main, daemon and relay resolve colours from one place;ORCA_DEFAULT_COLOR_QUERY_REPLY_COLORSis the last-resort pair. - Viewer-colour precedence —
terminal-view-attribute-storeresolvesown-window attrs ?? paired client ?? seeded settings; a paired push only overrides on a host with no window. - Push plumbing — main
publishColorQueryReplyColorsfans out to local/daemon/relay owners with dedupe, and the renderer (remote-runtime-terminal-color-push+use-terminal-viewer-color-publication) pushes to paired hosts on connect, theme change and focus. - Protocol — daemon
PROTOCOL_VERSION38, new gatedsetColorQueryReplyColorsrequest, newpty.setColorQueryReplyColorsrelay notification, newterminal.setViewerColorsRPC appended to the manifest, compatibility contracts bumped.
Scope of review: full diff plus three focused passes (ingress exactly-once, viewer-colour plumbing, mixed-version wire compatibility).
ℹ️ Rollout sequencing for the two v38 bumps
This PR and open PR #23908 both raise PROTOCOL_VERSION to 38. Whichever lands second must move to v39, otherwise a daemon built with the other capability set is labelled v38, passes supportsColorQueryReplyColors(38), and silently ignores the new notification — losing host-colour answering without any error. The PR body already flags this; calling it out so it is handled at merge time rather than after.
Technical details
# Daemon protocol version collision on merge
## Affected sites
- `src/main/daemon/daemon-protocol-version.ts` — `PROTOCOL_VERSION = 38`, `COLOR_QUERY_REPLY_COLORS_DAEMON_PROTOCOL_VERSION = 38`.
- `src/shared/local-build-compatibility-contract.{ts,json}` — `daemonProtocolVersion: 38`.
## Required outcome
- The two capabilities must carry distinct daemon protocol versions so `supportsColorQueryReplyColors` cannot return true for a daemon that lacks the `setColorQueryReplyColors` handler.
## Open questions for the human
- Which of #23908 / #23925 lands second, and is the version bump in the message or a follow-up commit?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (80)
💤 Files with no reviewable changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughPTY owners now answer OSC 10/11 color queries throughout a PTY’s lifetime. Replies use validated host colors, startup colors, or dark-theme defaults, with application-set overrides tracked across output. Viewer colors are selected and published through IPC, daemon and relay providers, and paired-runtime RPC. The daemon protocol advances to version 38. Startup-window handling remains for Kitty queries. Fixed issue severity: <fixed_issue_severity>Medium</fixed_issue_severity> Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The change supports lifetime color replies and headless theme updates without an established merge-blocking issue. It is mergeable subject to normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The inspected changes restrict replies to validated colors and retain existing remote-access checks. No introduced security regression was established. Risk remains low rather than minimal because complete remote-path isolation and mixed-version behavior were not fully verified. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❓ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 36.96% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 46 functions across 50 files. (20 skipped: 1 unsupported, 19 over the file limit.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |

ELI5
Programs like Codex and Claude Code ask the terminal "what are your colours?" when they start, and pick their own colours from the answer. Orca only answered in some situations (a few seconds after a tab opened, or once a window was showing the tab), so late or background launches got no answer and drew their messages and prompt without the right background. Now whatever owns the terminal always answers, for the terminal's whole life, with the colours the pane is really painted with.
What Changed
What this fixes:
orca servehost, a Codex started from a paired desktop's Orca UI, before any window shows the tab, gets no prompt background or the wrong theme.Scope: colour replies (OSC 10/11) in every terminal on macOS, Linux and Windows: local, terminal daemon, SSH relay, and headless hosts with paired desktop clients. Nothing about how panes are painted changes; only what programs are told when they ask.
Before: the host answered colour queries during a 5-second startup window, then handed them to whichever window was showing the tab. On Windows (ConPTY), late queries were swallowed with no reply. A tab nobody was showing got no reply at all.
After: the process that owns the terminal (the local provider, the terminal daemon, or the SSH relay) answers every colour query for the terminal's whole life, and removes it from the output so no window answers it a second time. It answers with, in order:
The theme also reaches the host when you change theme or the OS switches light/dark with no terminal pane open. The terminal theme catalog moved into shared code, so the app, main process, daemon and relay resolve themes from one source.
Mechanism notes:
terminal.setViewerColors. An older host answers "unknown method" and the client stops asking that connection. An older client never calls it; the colours it already sends when creating a terminal are used instead.Why
Known limits:
Linked Issue
Fixes #22332
Fixes #22500
Visual Proof
Tested live on the PR head against its base, each as a background dev build with its own profile.
Windows (#22332), Codex started in a terminal open more than 15 seconds. Before: your own message row has no shading. After: it has the grey band.
The same late terminal asked directly for its colours. Before: no reply at all. After: one reply per query, matching the painted theme.
Headless host + light-theme desktop client (#22500), Codex started from the Orca UI in a background tab. Before: the composer has no background. After: it has the light shaded band.
A late colour query on the headless host answers with the light client's colours. A desktop host keeps answering with its own dark theme after a light client connects.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
26 test files covering this change pass (1,604 tests), including real fish, bash and zsh PTY tests and the full runtime suite, on the branch merged with current
main.New tests cover: late queries, a headless host before any window attaches, one reply per query, app-set colour overrides and resets, the host window winning over a paired client, a headless host taking a paired client's colours, the paired-client push (connect, change, focus, older host), the echo watch for relayed replies, split fragments, the daemon protocol gate, and the relay push including a resend on reconnect.
A differential fuzz (500,000 randomized chunk splits) shows the faster query scan emits byte-identical output to the previous scan.
Typecheck clean (node, web, cli); oxlint, oxfmt and the changed-code quality gate clean.
Live: Windows 11 (terminal daemon + ConPTY, real Codex 0.159.0) and macOS (headless
orca servehost paired to a light-theme desktop client, real Codex 0.158.0), each PR head vs its base. Not run live: SSH relay, WSL, the phone app, and a non-daemon ConPTY terminal (every normal pane on that build was daemon-backed).AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
ESC ]starts once the first few seconds are over. Measured per 240 KB chunk of coloured output: about 0.5 ms (plain text about 0.01 ms).Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)