Repository navigation
fix(pty): stop color-scheme 997 replies from painting cooked prompts - #13309
Conversation
Live xterm query replies (CSI ?997 color-scheme DSR, OSC) were written straight to the PTY master. On POSIX, a cooked slave with ECHO on copies them back as visible junk — the `997;1n` paint at npx confirm prompts. Route cooked-echo-risk replies through the existing startup ingress delivery so they wait for quiet and suppress their own echo, matching startup color-reply handling. CPR/DA stay on the immediate path. Closes #13137
Dual mode-2031 answerers enqueue two CSI ?997;1n writes; the input queue could coalesce them into one payload that failed the whole-string classifier and fell through to a raw PTY write under ECHO. Keep cooked-echo-risk replies atomic in the queue, extract multi-reply payloads on host write, and dedupe identical in-flight replies in delivery so stdin is not doubled either.
After a quiet write, CSI color-scheme replies have no echo projection, so a late second answerer could still double-write stdin. Keep reply identity in expectedEchoes briefly even with empty projections, and pin that with a regression test.
📝 WalkthroughWalkthroughThe change adds cooked-echo-safe terminal query reply classification and extraction for private-mode DSR and OSC replies. PTY write paths route handled replies through startup ingress instead of direct writes. Startup reply delivery tracks projections, suppresses duplicate replies, bounds pending state, and limits echo probes. PTY input coalescing excludes cooked-echo-risk replies. Tests cover extraction, routing, echo suppression, deferred delivery, deduplication, and session terminal control. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b8a7be12-db60-4af1-a968-ed6747763093
📒 Files selected for processing (10)
src/main/daemon/session.tssrc/main/providers/local-pty-provider.tssrc/relay/pty-handler.tssrc/renderer/src/components/terminal-pane/pty-input-write-queue.test.tssrc/renderer/src/components/terminal-pane/pty-input-write-queue.tssrc/shared/pty-startup-ingress-live-query-reply.test.tssrc/shared/pty-startup-ingress.tssrc/shared/pty-startup-reply-delivery.tssrc/shared/terminal-query-reply.test.tssrc/shared/terminal-query-reply.ts
Keep repeated protocol replies intact while routing each through cooked-echo containment. Cover daemon startup gates, cap live reply state and probe subprocess starts, and force a hard reply deadline when stty stalls.\n\nCo-authored-by: bbingz <[email protected]>
…ape-sequence-leaks-as-literal-text-d
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: eef79d74-2100-48df-9f5b-231c4757467a
📒 Files selected for processing (14)
src/main/daemon/session-terminal-control.test.tssrc/main/daemon/session.test.tssrc/main/daemon/session.tssrc/main/providers/local-pty-provider.tssrc/relay/pty-handler.tssrc/renderer/src/components/terminal-pane/pty-input-write-queue.test.tssrc/renderer/src/components/terminal-pane/pty-input-write-queue.tssrc/shared/pty-slave-line-discipline-echo.test.tssrc/shared/pty-slave-line-discipline-echo.tssrc/shared/pty-startup-ingress-live-query-reply.test.tssrc/shared/pty-startup-ingress.test.tssrc/shared/pty-startup-ingress.tssrc/shared/pty-startup-reply-delivery.tssrc/shared/terminal-query-reply.ts
🚧 Files skipped from review as they are similar to previous changes (7)
- src/shared/pty-startup-ingress.ts
- src/relay/pty-handler.ts
- src/main/providers/local-pty-provider.ts
- src/renderer/src/components/terminal-pane/pty-input-write-queue.ts
- src/shared/terminal-query-reply.ts
- src/main/daemon/session.ts
- src/renderer/src/components/terminal-pane/pty-input-write-queue.test.ts
| private claimEchoProbeStart(): boolean { | ||
| const now = Date.now() | ||
| if ( | ||
| this.echoProbeWindowStartedAt === null || | ||
| now < this.echoProbeWindowStartedAt || | ||
| now - this.echoProbeWindowStartedAt >= 1_000 | ||
| ) { | ||
| this.echoProbeWindowStartedAt = now | ||
| this.echoProbeStartsInWindow = 0 | ||
| } | ||
| if (this.echoProbeStartsInWindow >= ECHO_PROBE_MAX_STARTS_PER_SECOND) { | ||
| return false | ||
| } | ||
| this.echoProbeStartsInWindow += 1 | ||
| return true | ||
| } |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
Use a sliding probe-start window.
This fixed window can admit ten probe starts immediately before reset and ten immediately after reset. That permits 20 starts in a trailing one-second interval.
Store recent start timestamps. Remove timestamps older than one second before checking the limit. Add a boundary regression test.
…15559) A background-colour probe writes `OSC 11 ;? ST` then `CSI 6n` and reads exactly one response, using the CPR as its sentinel: a non-OSC first response means "unsupported" and it stops draining. #13309 routed live cooked-echo-risk replies through the ECHO-probe deferral while CPR kept the immediate path, so the CPR overtook the colour reply, the prober gave up, and the stray `ESC ]` was left in the tty for the next program — `gh auth login` died on it with an escape-sequence error. Queue a reply that needs no echo containment behind ones that do, FIFO, and only while something is actually deferred, so latency-critical replies stay immediate on every other path. Windows is unaffected: only posix-pty defers, so the queue is always empty there. Also: an in-flight echo probe is already the write continuation, so re-arming the timer for a queued reply would fork a second stty and throw away the first verdict; and teardown now hands queued uncontained writes to the pty best-effort instead of dropping bytes the caller was told were sent. Known scope limit, pinned by tests and tracked for follow-up: the guarantee is FIFO among recognised query replies, not over every byte — a reply coalesced with a keystroke, and ordinary typed input, still bypass the queue. Both were unordered before this change too.
…tablyai#15559) A background-colour probe writes `OSC 11 ;? ST` then `CSI 6n` and reads exactly one response, using the CPR as its sentinel: a non-OSC first response means "unsupported" and it stops draining. stablyai#13309 routed live cooked-echo-risk replies through the ECHO-probe deferral while CPR kept the immediate path, so the CPR overtook the colour reply, the prober gave up, and the stray `ESC ]` was left in the tty for the next program — `gh auth login` died on it with an escape-sequence error. Queue a reply that needs no echo containment behind ones that do, FIFO, and only while something is actually deferred, so latency-critical replies stay immediate on every other path. Windows is unaffected: only posix-pty defers, so the queue is always empty there. Also: an in-flight echo probe is already the write continuation, so re-arming the timer for a queued reply would fork a second stty and throw away the first verdict; and teardown now hands queued uncontained writes to the pty best-effort instead of dropping bytes the caller was told were sent. Known scope limit, pinned by tests and tracked for follow-up: the guarantee is FIFO among recognised query replies, not over every byte — a reply coalesced with a keystroke, and ordinary typed input, still bypass the queue. Both were unordered before this change too.
…tablyai#15559) A background-colour probe writes `OSC 11 ;? ST` then `CSI 6n` and reads exactly one response, using the CPR as its sentinel: a non-OSC first response means "unsupported" and it stops draining. stablyai#13309 routed live cooked-echo-risk replies through the ECHO-probe deferral while CPR kept the immediate path, so the CPR overtook the colour reply, the prober gave up, and the stray `ESC ]` was left in the tty for the next program — `gh auth login` died on it with an escape-sequence error. Queue a reply that needs no echo containment behind ones that do, FIFO, and only while something is actually deferred, so latency-critical replies stay immediate on every other path. Windows is unaffected: only posix-pty defers, so the queue is always empty there. Also: an in-flight echo probe is already the write continuation, so re-arming the timer for a queued reply would fork a second stty and throw away the first verdict; and teardown now hands queued uncontained writes to the pty best-effort instead of dropping bytes the caller was told were sent. Known scope limit, pinned by tests and tracked for follow-up: the guarantee is FIFO among recognised query replies, not over every byte — a reply coalesced with a keystroke, and ordinary typed input, still bypass the queue. Both were unordered before this change too.
…tablyai#13309) Route cooked-echo-risk terminal replies through bounded echo-safe delivery across local, daemon, and SSH relay PTYs. Preserve repeated valid replies, bypass the daemon startup input gate, and keep ordinary input plus latency-critical replies on their existing paths. Closes stablyai#13137 Co-authored-by: bbingz <[email protected]>
…tablyai#15559) A background-colour probe writes `OSC 11 ;? ST` then `CSI 6n` and reads exactly one response, using the CPR as its sentinel: a non-OSC first response means "unsupported" and it stops draining. stablyai#13309 routed live cooked-echo-risk replies through the ECHO-probe deferral while CPR kept the immediate path, so the CPR overtook the colour reply, the prober gave up, and the stray `ESC ]` was left in the tty for the next program — `gh auth login` died on it with an escape-sequence error. Queue a reply that needs no echo containment behind ones that do, FIFO, and only while something is actually deferred, so latency-critical replies stay immediate on every other path. Windows is unaffected: only posix-pty defers, so the queue is always empty there. Also: an in-flight echo probe is already the write continuation, so re-arming the timer for a queued reply would fork a second stty and throw away the first verdict; and teardown now hands queued uncontained writes to the pty best-effort instead of dropping bytes the caller was told were sent. Known scope limit, pinned by tests and tracked for follow-up: the guarantee is FIFO among recognised query replies, not over every byte — a reply coalesced with a keystroke, and ordinary typed input, still bypass the queue. Both were unordered before this change too.
Summary
Fixes #13137: terminal-generated mode-2031 color-scheme replies (
CSI ?997;1n/CSI ?997;2n) could be echoed as literal text into cooked prompts such asnpx skills updateconfirmations.This combines the core echo-safe routing approach from #13160 with multi-reply extraction, queue atomicity, daemon startup-gate coverage, and bounded live-session resources. Credit to @bbingz for the original parallel fix and analysis.
Closes #13137
Behavior
sttyprobes, caps probe starts at 10/second per PTY, and hard-falls back within 200 ms if a probe stalls.Reliability contract
997;1n) #13137; PTY master writes under POSIX ECHO painted997;1n, including coalesced/repeated replies and daemon pre-ready writes.997byte containment is pinned at the relay/provider and shared-delivery layers rather than by invoking the externalnpx skills updatecommand.Validation
pnpm run lintpnpm run typecheckORCA_CROSS_VERSION_BASELINE_REF=v1.4.176 pnpm test— 4,523 files passed; 48,471 tests passed; 97 skippedpnpm run build:relay— Linux, macOS, Windows, and WSL artifacts builtORCA_E2E_SSH_DOCKER=1 pnpm run test:e2e:ssh-docker-terminal-parking— 2 tests passed against a fresh Debian/OpenSSH containergit diff --checkReadiness review
No P0, P1, or P2 findings. Reviewed functional failure paths, startup ordering, concurrency, teardown, casts/crash/retry/growth, security and supply chain, performance/resources, mobile/backward compatibility, macOS/Linux/Windows/WSL behavior, SSH/folder-workspace behavior, and remote-wire compatibility.
No visual change.