Repository navigation
Fix Windows ConPTY OSC color reply leaks at the PTY owner - #9651
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change classifies PTY ownership as native ConPTY, Windows WSL, or POSIX and passes that classification through local, daemon, and relay startup-ingress paths. Startup-ingress contracts and span handling are centralized, while native ConPTY queries receive backend-specific suppression and lifecycle behavior. Terminal view colors can now be forwarded through runtime and remote terminal creation. Daemon and startup-ingress protocol versions are updated, with routing support for closing startup query authority. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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: 1
🧹 Nitpick comments (4)
src/relay/pty-handler.ts (1)
1333-1336: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valuePreserve WSL backend classification during relay revival.
reviveEntryresolves the PTY backend using the default shell and omitswslDistro. BecauseSerializedPtyEntrydoes not currently capture the originalshellPathorwslDistro, revived WSL sessions over the relay on Windows will lose their WSL context and misclassify aswindows-conpty.If preserving the correct backend classification across relay restarts is intended, consider updating
serializeto capturewslDistroandshellPathso they can be restored here.src/shared/pty-startup-ingress-contract.ts (1)
31-41: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winSafeguard sequence numbers against negative or out-of-bounds slice indices.
If this generic utility is ever called with negative or out-of-bounds
startorendarguments (which are perfectly valid forString.prototype.slice), the raw sequence boundary calculations will be corrupted because they blindly add the index arguments rather than compute the actual slice distance.Compute the normalized
startindex and use the resulting sliced data length to calculaterawEndSeqso the interval always equals the payload length.♻️ Proposed refactor
export function slicePtyIngressSourceSpan( span: PtyIngressSourceSpan, start: number, - end = span.data.length + end?: number ): PtyIngressSourceSpan { + const normalizedStart = start < 0 ? Math.max(0, span.data.length + start) : Math.min(span.data.length, start) + const slicedData = span.data.slice(start, end) return { - data: span.data.slice(start, end), - rawStartSeq: span.rawStartSeq + start, - rawEndSeq: span.rawStartSeq + end + data: slicedData, + rawStartSeq: span.rawStartSeq + normalizedStart, + rawEndSeq: span.rawStartSeq + normalizedStart + slicedData.length } }src/main/runtime/orca-runtime.ts (1)
1282-1282: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse
TerminalOscColorQueryReplyColorsfor the spawn contract.This redeclares the shared reply-color shape inline even though the same public type is already imported and used at Line 1082. Use the shared type here to prevent the launch and spawn contracts from drifting independently.
Proposed change
- terminalColorQueryReplies?: { foreground?: string; background?: string } + terminalColorQueryReplies?: TerminalOscColorQueryReplyColorssrc/main/runtime/rpc/methods/terminal.ts (1)
918-923: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider using
z.strictObject()for explicit object parsing.If you want to reject unknown keys in the color query replies,
z.strictObject()provides stricter validation. Based on learnings, Zod 4 introducesz.strictObject()andz.looseObject()for clearer object parsing modes.♻️ Proposed refactor
- terminalColorQueryReplies: z - .object({ - foreground: z.string().max(128).optional(), - background: z.string().max(128).optional() - }) - .optional(), + terminalColorQueryReplies: z + .strictObject({ + foreground: z.string().max(128).optional(), + background: z.string().max(128).optional() + }) + .optional(),
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b53448b1-d7c5-4d8f-9211-2cebb3aa3fef
📒 Files selected for processing (29)
docs/reference/plans/2026-07-19-windows-conpty-startup-query-and-focus-authority.mdsrc/main/daemon/daemon-foreground-confirmation-protocol.test.tssrc/main/daemon/daemon-protocol-version.tssrc/main/daemon/daemon-pty-adapter.test.tssrc/main/daemon/daemon-server.test.tssrc/main/daemon/daemon-server.tssrc/main/daemon/session.test.tssrc/main/daemon/session.tssrc/main/daemon/terminal-host-pty-owner-backend.test.tssrc/main/daemon/terminal-host.tssrc/main/ipc/pty.tssrc/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/providers/ssh-pty-provider.test.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/terminal.tssrc/main/runtime/runtime-rpc.test.tssrc/main/runtime/terminal-view-attribute-store.tssrc/relay/pty-handler.test.tssrc/relay/pty-handler.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/shared/pty-owner-backend.test.tssrc/shared/pty-owner-backend.tssrc/shared/pty-startup-ingress-contract.tssrc/shared/pty-startup-ingress-intent.tssrc/shared/pty-startup-ingress.test.tssrc/shared/pty-startup-ingress.ts
| private releaseAllPending(): void { | ||
| const pending = this.echoPending ?? this.queryPending | ||
| this.echoPending = null | ||
| this.queryPending = null | ||
| if (pending) { | ||
| this.emit(pending, false) | ||
| this.releaseEchoPending() | ||
| this.releaseQueryPending() | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect release/teardown paths and any test coverage for partial-query-at-teardown on ConPTY.
fd -t f 'pty-startup-ingress' src/shared
rg -nP -C4 'releaseAllPending|releaseQueryPending|case .teardown' src/shared/pty-startup-ingress.ts
rg -nP -C3 'drainAndClose' src/shared/pty-startup-ingress.test.tsRepository: stablyai/orca
Length of output: 4148
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== relevant source ==\n'
sed -n '1,240p' src/shared/pty-startup-ingress.ts
printf '\n== teardown/release area ==\n'
sed -n '240,340p' src/shared/pty-startup-ingress.ts
printf '\n== tests around ConPTY/query teardown ==\n'
sed -n '1,360p' src/shared/pty-startup-ingress.test.ts | sed -n '1,360p' | rg -n -C4 'windows-conpty|closeQueryAuthority|drainAndClose|queryPending|teardown|expire|snapshot|close-query|partial|split'Repository: stablyai/orca
Length of output: 18245
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== teardown-related tests ==\n'
sed -n '170,280p' src/shared/pty-startup-ingress.test.ts
printf '\n== relevant helper semantics ==\n'
sed -n '1,220p' src/shared/terminal-osc-color-reply.tsRepository: stablyai/orca
Length of output: 10373
Keep ConPTY queryPending private on teardown. releaseAllPending() still flushes a buffered split OSC query raw on drainAndClose(), unlike the other ConPTY barriers; gate releaseQueryPending() here too unless that flush-at-close behavior is intentional.
Summary
windows-conpty,windows-wsl, orposix-pty) instead of inferring ownership from renderer, cwd, or connection heuristics.This supersedes the design direction in #6975. That PR suppresses in downstream renderer handlers and treats remote runtimes as safe; the paired-Windows reproduction shows the PTY owner, not the viewer/connection kind, must decide.
Reproduction
A deterministic Session-level regression models the complete byte flow without sleeps:
OSC 10;?.remote-visible-rendererproducer sees the query and writes a synthetic color reply as PTY input.]10;rgb:...\\body reaches the client and authoritative snapshot.The shared byte-level harness also splits OSC queries at every byte and covers authority-close, deadline expiry, snapshot, malformed input, and re-entrant provider callbacks.
On real Windows, native
node-ptyloaded asWindowsTerminal. Codex CLI 0.144.6 did not naturally emit OSC 10/11 in the available configuration, but complete ESC-framed replies were consumed while injecting the exact ESC-stripped bodies reproduced the literal composer text from the field report.Screenshots
No intended visual change beyond preventing terminal protocol text from appearing in the composer.
Testing
pnpm lint—oxlintpasses; the combined command remains blocked by the unrelated pre-existing switch-exhaustiveness error inskill-freshness-group.tsx.pnpm typecheckpnpm test— targeted terminal/PTY suites were run instead; full relay/runtime baselines are noted below.pnpm buildPassed before and after the final review changes:
/tmpnormalization baselinemainoxlint,oxfmt --check,git diff --check, reliability-gate manifest, and max-lines ratchetKnown unrelated baseline: the full relay file has 80 passing tests and 15 Windows assertions that expect POSIX
kill(signal)arguments even though Windows node-pty callskill()argumentlessly.AI Review Report
The requested internal-review skill was unavailable, so four manual adversarial review/fix rounds were run against the branch diff. Review rejected both renderer ownership heuristics and a proposed input-reply filter, then checked:
Review found and fixed a split-query race across close/expiry/snapshot barriers, removed a redundant renderer-selected echo-projection wire field, and added the missing daemon server route for startup authority closure.
Cross-platform audit: native Windows ConPTY alone gets the suppression contract. Windows WSL, Windows-hosted POSIX/WSL shells, Linux/macOS PTYs, POSIX SSH, and paired non-Windows runtimes retain existing behavior. No keyboard shortcut, label, path, or UI-platform logic changed.
Security Audit
Notes
Tradeoffs: