Repository navigation
Fix native Windows PTY startup query handling - #9500
Conversation
…only-sometimes-new-codex-session-pri # Conflicts: # docs/reference/terminal-model-view-contract.md # docs/reference/terminal-query-authority.md # src/main/daemon/session.test.ts # src/main/daemon/terminal-host.ts # src/main/providers/types.ts
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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)
📝 WalkthroughWalkthroughAdds a source-owned PTY startup ingress pipeline that intercepts startup OSC color queries, emits canonical replies, suppresses matching ConPTY projections, and preserves raw sequence accounting. The change wires ingress through local providers, daemon sessions, SSH relay handling, IPC, runtime batching, renderer delivery, snapshots, and teardown. It adds protocol-version gating, transformed 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/daemon/daemon-stream-data-batcher.ts (1)
247-282: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
sequenceChars/seqdrift when a queued entry is split.
sliceSequenceCharsfalls back toslice.lengthfor any non-transformed slice unless the whole entry fits, so a merged entry with real raw/clean divergence is reported as if it matched.- On partial drains,
entry.sequenceCharsis reduced, butentry.seqis reused unchanged for later flushes, so subsequent slices carry the wrong sequence value.
writeStreamDataEventshas the same chunk-length assumption and will need the same treatment once this path preserves divergence.
🧹 Nitpick comments (3)
src/main/daemon/daemon-protocol-version.ts (1)
5-7: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDerive
PREVIOUS_DAEMON_PROTOCOL_VERSIONSinstead of hand-listing it.Manually enumerating every prior version risks drifting out of sync the next time
PROTOCOL_VERSIONis bumped (forgetting to append the new "previous" entry).♻️ Proposed refactor
-export const PREVIOUS_DAEMON_PROTOCOL_VERSIONS = [ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 -] as const +export const PREVIOUS_DAEMON_PROTOCOL_VERSIONS = Array.from( + { length: PROTOCOL_VERSION - 1 }, + (_, i) => i + 1 +)src/main/ipc/pty.ts (1)
4142-4150: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a
// Why:comment for this design-driven constraint.As per coding guidelines, code driven by a design document or non-obvious constraint should have a brief comment explaining why the behavior is necessary. Since this conditionally applies cooked-echo suppression specifically for native Windows ConPTY as dictated by the startup-query design doc, please add a
// Why:comment here.💡 Proposed refactor
if (startupTerminalColorQueryReplyColors) { spawnOptions.startupIngress = { colors: startupTerminalColorQueryReplyColors, deadlineMs: 5_000, + // Why: Native Windows ConPTY echoes the raw query back to us; suppress it so + // it doesn't leak into the terminal (terminal-query-authority.md). ...(nativeWindowsConptySpawn ? { echoProjection: 'windows-conpty-esc-stripped' as const } : {}) } }Source: Coding guidelines
src/main/providers/local-pty-provider.ts (1)
122-128: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider reusing
PtyDataEventinstead of a duplicate inlineDataCallbackshape.
DataCallback's payload is structurally identical to the exportedPtyDataEventtype (from./pty-provider-events), whichdegraded-daemon-pty-provider.tsalready adopted in this same PR. ImportingPtyDataEventhere too would keep a single source of truth for this shape.♻️ Suggested consolidation
-type DataCallback = (payload: { - id: string - data: string - sequenceChars?: number - transformed?: boolean - seq?: number -}) => void +type DataCallback = (payload: PtyDataEvent) => void
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5c70562a-a217-496f-abe4-8584a953c3ae
📒 Files selected for processing (51)
docs/reference/plans/2026-07-19-windows-conpty-startup-query-and-focus-authority.mddocs/reference/terminal-model-view-contract.mddocs/reference/terminal-query-authority.mdsrc/main/daemon/daemon-protocol-version.tssrc/main/daemon/daemon-pty-adapter.test.tssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/daemon-pty-router.tssrc/main/daemon/daemon-server.tssrc/main/daemon/daemon-stream-data-batcher.test.tssrc/main/daemon/daemon-stream-data-batcher.tssrc/main/daemon/daemon-stream-data-entry.tssrc/main/daemon/daemon-stream-data-split.tssrc/main/daemon/daemon-stream-events.tssrc/main/daemon/daemon-stream-keep-tail-drop.tssrc/main/daemon/degraded-daemon-pty-provider.tssrc/main/daemon/session.test.tssrc/main/daemon/session.tssrc/main/daemon/terminal-host-create-contract.tssrc/main/daemon/terminal-host-options.tssrc/main/daemon/terminal-host.tssrc/main/daemon/terminal-modes.tssrc/main/daemon/terminal-snapshot.tssrc/main/daemon/types.tssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/ipc/ssh.test.tssrc/main/ipc/terminal-startup-color-query-replies.tssrc/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/providers/pty-provider-events.tssrc/main/providers/ssh-pty-provider.test.tssrc/main/providers/ssh-pty-provider.tssrc/main/providers/types.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/terminal.tssrc/main/ssh/ssh-relay-session-data-delivery.test.tssrc/main/ssh/ssh-relay-session-terminal-error.test.tssrc/main/ssh/ssh-relay-session.test.tssrc/main/ssh/ssh-relay-session.tssrc/preload/api-types.tssrc/preload/index.tssrc/relay/pty-handler.test.tssrc/relay/pty-handler.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-dispatcher.tssrc/renderer/src/runtime/remote-runtime-terminal-frame-drop-resync.test.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer.tssrc/shared/pty-startup-ingress-intent.tssrc/shared/pty-startup-ingress.test.tssrc/shared/pty-startup-ingress.tssrc/shared/terminal-stream-protocol.ts
| const rawLengthBefore = last.sequenceChars ?? last.data.length - data.length | ||
| const combinedRawLength = rawLengthBefore + (options.rawLength ?? data.length) | ||
| last.sequenceChars = combinedRawLength === last.data.length ? undefined : combinedRawLength | ||
| last.seq = options.seq |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
seq is dropped on merge instead of being carried forward, in both the daemon and relay batching paths. Both implementations correctly accumulate rawLength/sequenceChars across merged writes (old value + new contribution), but neither does the equivalent for seq — it's only set when the current call explicitly provides one, otherwise it's discarded (daemon: reset to undefined; relay: left undefined on a fresh pending object). This can silently erase a previously-tracked absolute raw-stream position the moment an untracked write gets folded into a tracked entry, degrading the client's resync-detection fidelity for the merged output.
src/main/daemon/daemon-stream-data-entry.ts#L26-L29: changelast.seq = options.seqto fall back to an extended prior value, e.g.last.seq = options.seq ?? (last.seq === undefined ? undefined : last.seq + data.length).src/relay/pty-handler.ts#L697-L719: in themeta.seq === undefinedbranch, fall back similarly:pending.seq = existing?.seq === undefined ? undefined : existing.seq + data.lengthinstead of leavingpending.sequnset.
📍 Affects 2 files
src/main/daemon/daemon-stream-data-entry.ts#L26-L29(this comment)src/relay/pty-handler.ts#L697-L719
| ...(rawLength !== data.length ? { rawLength } : {}), | ||
| ...(transformed ? { transformed: true } : {}), | ||
| ...(nextContainsBackgroundOutput ? { containsBackgroundOutput: true } : {}) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Mark non-linear chunks as transformed to prevent slicing corruption.
When a new chunk is created with a non-linear byte-to-sequence mapping (rawLength !== data.length) but transformed is falsy, it is saved without transformed: true.
During flushPendingData, this chunk is not considered indivisible (since pending.transformed is not true) and gets sliced. The first slice incorrectly inherits the full original rawLength, while the remaining slice loses its raw length tracking entirely, permanently corrupting the sequence space.
Mirror the merge path (line 2387) by explicitly marking chunks as transformed: true whenever sequence preservation is broken.
🐛 Proposed fix
- ...(rawLength !== data.length ? { rawLength } : {}),
- ...(transformed ? { transformed: true } : {}),
+ ...(!preservesSeq || transformed ? { rawLength, transformed: true as const } : {}),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ...(rawLength !== data.length ? { rawLength } : {}), | |
| ...(transformed ? { transformed: true } : {}), | |
| ...(nextContainsBackgroundOutput ? { containsBackgroundOutput: true } : {}) | |
| ...(!preservesSeq || transformed ? { rawLength, transformed: true as const } : {}), | |
| ...(nextContainsBackgroundOutput ? { containsBackgroundOutput: true } : {}) |
| ? { | ||
| seq: pending.startSeq + (pending.rawLength ?? nextData.length), | ||
| rawLength: pending.rawLength ?? nextData.length | ||
| } | ||
| : {}), | ||
| ...(pending.transformed ? { transformed: true } : {}), |
There was a problem hiding this comment.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Use makePtyDataPayload to preserve rawLength when startSeq is undefined.
This inline object construction incorrectly omits rawLength if typeof pending.startSeq !== 'number'. If a chunk has a broken sequence tracking (startSeq is undefined) but contains a valid rawLength !== data.length (e.g., from a transformed gap), the renderer will fall back to using data.length for its internal calculation.
This discrepancy forces the renderer to send incorrect processedChars in its ACKs back to main, leading to an accounting wedge in rendererInFlightTotalChars. Using makePtyDataPayload guarantees rawLength is included even when startSeq is missing.
🐛 Proposed fix
- sendPtyDataToRenderer(payload.id, {
- id: payload.id,
- data: nextData,
- ...(typeof pending.startSeq === 'number'
- ? {
- seq: pending.startSeq + (pending.rawLength ?? nextData.length),
- rawLength: pending.rawLength ?? nextData.length
- }
- : {}),
- ...(pending.transformed ? { transformed: true } : {}),
- ...(pending.containsBackgroundOutput === true ? { background: true } : {}),
- ...(pending.droppedOutput === true ? { droppedOutput: true } : {})
- })
+ const payloadToSend = makePtyDataPayload(
+ payload.id,
+ nextData,
+ pending.startSeq,
+ pending.containsBackgroundOutput,
+ pending.rawLength,
+ pending.transformed
+ )
+ if (pending.droppedOutput === true) {
+ payloadToSend.droppedOutput = true
+ }
+ sendPtyDataToRenderer(payload.id, payloadToSend)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ? { | |
| seq: pending.startSeq + (pending.rawLength ?? nextData.length), | |
| rawLength: pending.rawLength ?? nextData.length | |
| } | |
| : {}), | |
| ...(pending.transformed ? { transformed: true } : {}), | |
| const payloadToSend = makePtyDataPayload( | |
| payload.id, | |
| nextData, | |
| pending.startSeq, | |
| pending.containsBackgroundOutput, | |
| pending.rawLength, | |
| pending.transformed | |
| ) | |
| if (pending.droppedOutput === true) { | |
| payloadToSend.droppedOutput = true | |
| } | |
| sendPtyDataToRenderer(payload.id, payloadToSend) |
| onData({ id: 'ssh-pty-1', data: '', sequenceChars: 9, transformed: true }) | ||
|
|
||
| expect(runtime.onPtyData).toHaveBeenCalledWith('ssh-pty-1', '', expect.any(Number), 9, true) | ||
| expect(mockWindow.webContents.send).toHaveBeenCalledWith('pty:data', { | ||
| id: 'ssh-pty-1', | ||
| data: '', | ||
| sequenceChars: 9, | ||
| transformed: true, | ||
| seq: 17, | ||
| rawLength: 9 | ||
| }) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect the ssh-relay-session.ts onData handler to see how the outgoing
# 'pty:data' payload is constructed relative to sequenceChars/rawLength.
fd -e ts ssh-relay-session.ts --exclude '*.test.ts' | xargs -I{} ast-grep run --pattern 'onData($_, $BODY)' --lang typescript {}
rg -n -B3 -A15 "webContents\.send\('pty:data'" src/main/ssh/ssh-relay-session.tsRepository: stablyai/orca
Length of output: 851
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== relevant source =="
sed -n '1128,1160p' src/main/ssh/ssh-relay-session.ts
echo
echo "== payload shape / type references =="
rg -n "sequenceChars|rawLength|pty:data|onData\\(" src/main src/renderer -g '!**/*.map'
echo
echo "== ssh relay tests =="
rg -n "sequenceChars|rawLength|pty:data" src/main/ssh -g '*.test.ts'Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== ssh-relay-session.ts snippet =="
sed -n '1138,1154p' src/main/ssh/ssh-relay-session.ts
echo
echo "== all sequenceChars/rawLength references =="
rg -n "sequenceChars|rawLength" src/main -g '!**/*.map'Repository: stablyai/orca
Length of output: 21605
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== pty event types =="
sed -n '1,120p' src/main/providers/pty-provider-events.ts
echo
echo "== SSH relay tests that define expected payload shape =="
sed -n '130,220p' src/main/ssh/ssh-relay-session.test.ts
echo
echo "== SSH relay data delivery test =="
sed -n '80,120p' src/main/ssh/ssh-relay-session-data-delivery.test.ts
echo
echo "== renderer pty dispatcher event shape =="
sed -n '150,220p' src/renderer/src/components/terminal-pane/pty-dispatcher.tsRepository: stablyai/orca
Length of output: 7770
Drop sequenceChars from the pty:data payload expectation. The SSH relay should match the renderer-facing contract used elsewhere: seq + rawLength, without forwarding the internal sequenceChars field.
…only-sometimes-new-codex-session-pri # Conflicts: # src/main/daemon/daemon-server.ts # src/main/daemon/types.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/daemon/daemon-server.ts (1)
712-718: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a brief comment explaining the
connectionId: nullconstraint.As per coding guidelines, when code is driven by a design document or non-obvious constraint, add a brief one- or two-line comment explaining why the behavior is necessary. Since the daemon strictly handles local PTYs, explicitly passing
connectionId: nullguarantees the validation treats the spawn as local, but this contextual assumption isn't immediately obvious.Consider adding a standard
// Why:comment here.♻️ Proposed refactor
startupIngress: parsePtyStartupIngressIntent(p.startupIngress, { allowWindowsEchoProjection: isNativeWindowsLocalPtySpawn({ + // Why: Daemon PTYs are exclusively local; remote connections are managed by the main process or relay. connectionId: null, cwd: p.cwd, shellOverride: p.shellOverrideSource: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0b0258c3-b97a-4c54-8954-83bf3c1278b8
📒 Files selected for processing (4)
src/main/daemon/daemon-protocol-version.tssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/daemon-server.tssrc/main/daemon/types.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/daemon/daemon-protocol-version.ts
- src/main/daemon/daemon-pty-adapter.ts
- src/main/daemon/types.ts
…only-sometimes-new-codex-session-pri
Upstream (stablyai#9500) appends the agent launch command after the OSC-133 bootstrap inside PowerShell -EncodedCommand. Under ConstrainedLanguage (WDAC/AppLocker on managed Windows) the bootstrap's top-level return guards abort the whole script and swallow the launch, so a new Claude session opened pwsh but never ran claude. Scope the bootstrap in & { } so its returns stay local and the command runs.
* Fix native Windows PTY startup query handling * Fix daemon boot smoke protocol lookup * Fix Windows daemon repro protocol lookup
Fixes #9432
Summary
Design: Windows ConPTY startup query and focus authority
Validation
validation-screenshots/manifest records the evidence.open //./pipe/dockerDesktopLinuxEngine: The system cannot find the file specified.Automated relay and SSH coverage passed.git diff --check; focused matrix (1,146 passed, 15 skipped); broader matrix (1,188 passed, 15 skipped); focused relay startup (2 passed, 97 skipped); relay builds for Windows, Linux, macOS, and the WSL hook.skill-freshness-group.tsx:101, reproduced exactly on clean base.