Skip to content

fix(terminal): contain plain-shell startup color replies - #16123

Closed
brennanb2025 wants to merge 3 commits into
mainfrom
brennanb2025/sta-4145-osc-color-echo
Closed

brennanb2025 wants to merge 3 commits into
mainfrom
brennanb2025/sta-4145-osc-color-echo

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​148 $\color{#cf222e}{\Huge{\mathbf{−}}}$​103 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​150 $\color{#cf222e}{\Huge{\mathbf{−}}}$​46 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104

ELI5

Fancy shell prompts (Oh My Posh, starship, powerlevel10k) start by asking the terminal "what colours
are you using?" The terminal is supposed to answer privately, out of sight. In plain (non-agent)
Orca terminals nobody answered properly, so the raw reply leaked onto your screen — every new
terminal opened with junk sitting next to your prompt:

❭ 10;rgb:ffff/ffff/ffff11;rgb:2828/2c2c/3434

Orca already knew how to intercept that question and answer it quietly, but only did so for agent
panes. Now plain panes get the same treatment, and the leftover echo the shell's own line editor
produces is swallowed too.

User-facing before / after

Before After
Open a plain terminal on macOS or Linux with a prompt theme that asks about colours Garbled colour codes printed next to your prompt, on every single new terminal Clean prompt; Orca answers the question out of sight
The same text appearing in scrollback and in restored sessions The junk was persisted, so it came back when the session was restored Contained before anything is stored or drawn
Agent panes (Codex, Claude, opencode…) Already clean Unchanged
Prompt themes that don't ask about colours Already clean Unchanged

When it bites

macOS and Linux users whose shell prompt theme asks the terminal for its colour scheme at startup —
Oh My Posh, starship and powerlevel10k all do. It showed up at the very first prompt of every plain
terminal, which is the first thing you see.

Summary

  • arm startup OSC 10/11 handling for plain panes from their validated, pane-local xterm colors
  • keep an armed POSIX execution host authoritative across the renderer-visible handoff until both startup slots or the deadline close it
  • contain both independent PTY and zsh/readline reply echoes before persistence and renderer fanout

Supersedes #14307

  1. Uses the existing per-pane color payload instead of an app-global terminal-view fallback.
  2. Fixes the premature renderer visibility handoff and the independent PTY-plus-line-editor echo lifecycle, not only the plain-pane arming gate.
  3. Adds execution-host regressions for POSIX ordering, zsh ZLE byte shapes, WSL ownership boundaries, and post-startup authority closure.

Verification

  • Pre-fix acceptance failures captured for plain-pane arming, renderer-visible POSIX ownership, and zsh reply echo containment.
  • Neutering the final source-group retirement reproduced the visible 10;rgb / 11;rgb failure; restoring it passed.
  • pnpm vitest run --config config/vitest.config.ts src/shared/pty-startup-ingress.test.ts src/main/daemon/session.test.ts src/main/ipc/pty-dispatcher-handshake-osc-answers.test.ts — 106 passed.
  • pnpm typecheck — passed.
  • Changed-code quality and React Doctor checks — 0 findings.
  • macOS Electron startup fixture — clean FIXTURE% prompt with no color reply text.
  • Linux openclaw focused POSIX ingress and daemon suites — 97 passed.
  • Full pnpm test completed with 13 unrelated failures: 12 deterministic failures persisted with the touched startup policy restored to origin/main, and one performance budget test measured 185 ms against a 150 ms threshold.

Visual proof

Clean startup prompt with no OSC color reply text

Fixes #14306

STA-4145

@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 325ebf94-4a04-4d6f-a4a3-445f3ee4689f

📥 Commits

Reviewing files that changed from the base of the PR and between 94e7586 and f7d3ef3.

📒 Files selected for processing (9)
  • src/main/daemon/session-mock-subprocess.ts
  • src/main/daemon/session.test.ts
  • src/main/ipc/pty-dispatcher-handshake-osc-answers.test.ts
  • src/main/ipc/terminal-startup-color-query-replies.ts
  • src/shared/pty-startup-ingress.test.ts
  • src/shared/pty-startup-ingress.ts
  • src/shared/pty-startup-reply-delivery.ts
  • src/shared/pty-startup-reply-echo-shapes.test.ts
  • src/shared/pty-startup-reply-echo-shapes.ts
💤 Files with no reviewable changes (1)
  • src/main/ipc/terminal-startup-color-query-replies.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/shared/pty-startup-reply-echo-shapes.ts
  • src/shared/pty-startup-ingress.ts
  • src/shared/pty-startup-reply-delivery.ts
  • src/main/ipc/pty-dispatcher-handshake-osc-answers.test.ts
  • src/shared/pty-startup-ingress.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change removes agent-based gating from startup OSC color reply normalization. It adds PTY and line-editor sources to echo projections, supports zsh line-editor variants, and tracks projections until all matches are consumed. It preserves armed POSIX query authority during close-query. Tests cover plain-shell replies, POSIX and WSL visibility, zsh echo suppression, and renderer handoff behavior.

Merge Risk: 🔵 Low · up to f7d3e

Plain terminal panes can now answer startup color queries using validated, pane-local data within a bounded handoff window. The change is mergeable with owner awareness because the PTY creation path does not clearly document or validate which callers are trusted to request this behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The changes address startup color reply handling, POSIX authority retention, and PTY or line-editor echo suppression for issue #14306. However, the provided file summary does not show the required pan… Add or provide evidence for the pane-local terminal color fallback in both local and daemon spawn paths. Add regression coverage that confirms plain panes arm startup ingress through both paths. [#14306]
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The production changes and regression tests remain focused on plain-shell startup color replies, POSIX startup authority, echo containment, and related test support. No unrelated code changes are evid…
Title check ✅ Passed The title clearly and concisely describes the main change: containing startup color replies in plain terminal shells.
Description check ✅ Passed The description is detailed and covers the problem, user impact, implementation, linked issue, visual proof, and verification results. It does not reproduce every template heading or checklist item, b…
Full details: Linked Issues check

Explanation

The changes address startup color reply handling, POSIX authority retention, and PTY or line-editor echo suppression for issue #14306. However, the provided file summary does not show the required pane-local color fallback in both local and daemon spawn paths.

Full details: Out of Scope Changes check

Explanation

The production changes and regression tests remain focused on plain-shell startup color replies, POSIX startup authority, echo containment, and related test support. No unrelated code changes are evident.

Full details: Description check

Explanation

The description is detailed and covers the problem, user impact, implementation, linked issue, visual proof, and verification results. It does not reproduce every template heading or checklist item, but the required information is mostly present.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor

Heads-up: this PR and #16542 are rewriting the same function

Flagging before either merges, because whichever lands second will silently undo the other.

Both change replyEchoProjections in src/shared/pty-startup-reply-echo-shapes.ts:

  • This PR adds a source: 'pty' | 'line-editor' discriminator to EchoProjection, threads it through PtyStartupReplyEchoMatch, adds two zsh ZLE shapes, and adds a preferLongestAtSameOffset argument to locateEcho.
  • fix(pty): match the echo shapes a real tty actually produces #16542 corrects the two existing shapes: the kernel needle now caret-encodes every control rather than only ESC, and the readline needle is also produced for private DSR replies rather than OSC only.

The two are complementary in intent and conflicting in text. Specifically:

Suggested order: land this one first (it is a narrow correction to two existing shapes, plus tests), then rebase #16123 on top. #16123's restructuring absorbs a corrected pair cleanly; the reverse means re-deriving the corrections inside a changed shape of the function.

One thing worth carrying across either way: #16123's zsh shapes are BEL-initial, same as the readline needle here. This PR adds a minimum-length floor and requires a non-empty DSR parameter list, because answerLiveQueryReply takes client-supplied bytes on the relay path and the containment grammar admits CSI ? n — which would otherwise arm a two-byte BEL n needle. Worth applying the same floor to the ZLE shapes if the OSC payload can be short.

Context for why this matters more than usual here: 61c65151129 (never landed) diagnosed a case where a needle outliving its budget silently deleted spans of ordinary output. Needle breadth wasn't the cause there, but it is the same blast radius.

Full detail in #16542.

@nwparker

Copy link
Copy Markdown
Contributor

#16542 has merged — this will need a rebase, and there's one thing worth carrying across

Sorry for the collision. #16542 (d1a11b32992) touched the same function, replyEchoProjections. It merged first because it was a narrow correction to two existing shapes; your restructuring absorbs a corrected pair more cleanly than the reverse would have.

What changed under you

Both shapes this branch preserves were wrong against a real tty:

  • The kernel needle was reply.replaceAll('\x1b', '^['). ECHOCTL carets every control, so a BEL-terminated OSC reply echoes ^G and the old needle kept a literal BEL — a string no tty produces. Now caret-encodes all controls, exempting TAB/LF/CR (the kernel passes those through) and mapping DEL to ^?.
  • The readline needle was gated on reply.includes('\x1b]'). Readline mangles CSI replies too (ESC [ ? becomes BEL), so a private DSR echo was never matched at a readline prompt. That was the reachable bug: a latched mode-2031 push painting 997;1n on a bash prompt.

Both were captured from a live pty rather than read off the spec, and there's now a pty-reply-echo-shapes.node-pty.test.ts in the shell-contracts lane that writes to a real bash master and feeds back what it echoes.

The bit worth carrying across

Your two ZLE shapes are BEL-initial, same as the readline needle. #16542 added a minimum-length floor plus a non-empty-parameter requirement on the DSR grammar, because the containment grammar admits CSI ? n and answerLiveQueryReply takes client-supplied bytes on the relay path — without the floor a peer could arm a two-byte BEL n needle and delete the first bell-then-n in ordinary output.

If oscPayload can ever be short, \x07${oscPayload}\x07 has the same exposure. 61c65151129 (never landed) is the precedent: a needle that outlived its budget silently deleted spans of ordinary output. Worth applying the same floor.

Also relevant to your source discriminator

I tried to verify the ConPTY branch on a real Windows host — node-pty with useConpty, against cmd.exe, both at a prompt and under a set /p cooked read, for BEL-OSC, ST-OSC and private DSR. All six echoed zero bytes. So the ConPTY leak in #9651 probably wasn't line-discipline echo at all, and the ESC-stripped needle there is still unverified — I left it alone and downgraded its comment rather than guessing, since #9500 Decision 3 forbids generalising the ESC-strip without evidence. If your source: 'pty' | 'line-editor' split is heading somewhere that makes that distinction explicit, that's probably the right place for it.

Your zsh work covers a gap #16542 explicitly left open, so this is a rebase request, not a suggestion to drop anything. Happy to do the rebase myself if that's easier.

# Conflicts:
#	src/shared/pty-startup-reply-echo-shapes.ts
session.test.ts crossed the 800-line cap once this branch's startup-authority
case merged with main's additions. Split rather than raise the limit.
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded: a merged PR already covers this change. #23925 (59ef748): the PTY owner answers OSC 10/11 for every PTY (not only agents) for its whole life and strips the query, which removes the plain-shell reply leak this PR

(Stale-PR cleanup 2026-10-20, approved by Brennan. Reopen if something here is still missing on main.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OSC 10/11 color query reply echoes as visible text in non-agent panes on POSIX (macOS + Linux)

2 participants