Repository navigation
Conversation
📝 WalkthroughWalkthroughThe change adds synchronous PTY ECHO-state detection and uses it for immediate or deferred terminal query reply delivery. Query replies are parsed, classified, kept atomic, ordered, and bounded across local, relay, and remote-runtime paths. PTY session wiring and native node-pty support are updated. Integration tests cover cooked-mode delivery and child-stdin isolation. CI now gates expensive checks by code-path classification. 🚥 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: 8
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
config/patches/[email protected] (1)
41-50: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUse an MSYS-safe
cmd.exeinvocation.Line 41 and Line 50 still use
cmd /c. Git Bash can rewrite/c, so the WinPTY batch commands can fail during a Windows source build. Use the project-safe form that preserves the command switch in both locations.As per coding guidelines: “Never launch a
.cmdrunner with barecmd.exe /cfrom a Git Bash pane because MSYS rewrites/c.”Source: Coding guidelines
🧹 Nitpick comments (3)
tests/e2e/pty-input-write-queue-ssh.spec.ts (2)
57-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the cast so the unsupported-architecture guard stays type-safe.
Line 58 casts the
uname -moutput tokeyof typeof FISH_ASSETS. The indexed access at line 59 is then typed as a defined release, so the guard at line 60 is dead code to the type checker while it is still required at runtime. Any future refactor can delete it without a type error.♻️ Proposed fix
- const arch = execDockerSshRelayTargetCommand(target, 'uname -m') as keyof typeof FISH_ASSETS - const release = FISH_ASSETS[arch] + const arch = execDockerSshRelayTargetCommand(target, 'uname -m').trim() + const release: (typeof FISH_ASSETS)[keyof typeof FISH_ASSETS] | undefined = Object.hasOwn( + FISH_ASSETS, + arch + ) + ? FISH_ASSETS[arch as keyof typeof FISH_ASSETS] + : undefined if (!release) { throw new Error(`No pinned fish binary for Docker architecture ${arch}`) }
174-181: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winWrite the screenshot into the Playwright output dir.
Lines 174-176 write into
process.cwd()/validation-screenshots/sta-3948. That path pollutes the repository working tree and collides between parallel workers.testInfo.outputPathgives a per-test directory that Playwright creates and cleans.♻️ Proposed fix
- const screenshotDir = path.join(process.cwd(), 'validation-screenshots', 'sta-3948') - const screenshotPath = path.join(screenshotDir, 'linux-ssh-fish-child-stdin-pass.png') - mkdirSync(screenshotDir, { recursive: true }) + const screenshotPath = testInfo.outputPath('linux-ssh-fish-child-stdin-pass.png') await orcaPage.screenshot({ path: screenshotPath, fullPage: true })
mkdirSyncand thenode:fsimport can then be dropped if nothing else uses them.src/shared/node-pty-echo-state-requirement.ts (1)
1-12: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReduce the new TypeScript comments.
Keep only concise, non-obvious rationale.
src/shared/node-pty-echo-state-requirement.ts#L1-L12: Replace the overview block with one short contract comment.src/shared/node-pty-echo-state-requirement.ts#L52-L58: Reduce the CI rationale to one line.src/shared/pty-slave-line-discipline-echo.ts#L94-L104: Reduce the kernel and fallback explanation to one line.src/main/daemon/session-same-turn-query-reply-wiring.test.ts#L1-L13: Remove the multi-paragraph test overview.src/main/daemon/session-same-turn-query-reply-wiring.test.ts#L78-L79: Keep one short assertion rationale.src/main/daemon/session-same-turn-query-reply-wiring.test.ts#L123-L125: Keep one short flush-gate rationale.As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e9a213a6-58c2-4a76-9048-eb29b2fccd2c
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (43)
.github/CONTRIBUTING.md.github/workflows/adhoc-mac-build.yml.github/workflows/daily-mac-build.yml.github/workflows/hourly-mac-build.yml.github/workflows/pr.yml.github/workflows/pullfrog.ymlconfig/patches/[email protected]config/patches/[email protected]config/reliability-gates.jsoncconfig/scripts/pr-workflow-parallelism.test.mjspackage.jsonsrc/main/daemon/pty-subprocess.test.tssrc/main/daemon/pty-subprocess.tssrc/main/daemon/session-same-turn-query-reply-wiring.test.tssrc/main/daemon/session-subprocess-handle.tssrc/main/daemon/session.tssrc/main/providers/local-pty-provider-io-events.test.tssrc/main/providers/local-pty-provider.tssrc/relay/pty-handler-same-turn-query-reply-wiring.test.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/renderer/src/components/terminal-pane/remote-runtime-pty-batching.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-batching.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-query-reply-immediate.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-input-coalescing.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/shared/fish-query-reply-child-stdin.node-pty.test.tssrc/shared/node-pty-echo-state-requirement.test.tssrc/shared/node-pty-echo-state-requirement.tssrc/shared/pty-cooked-querier-reply-delivery.node-pty.test.tssrc/shared/pty-slave-line-discipline-echo.test.tssrc/shared/pty-slave-line-discipline-echo.tssrc/shared/pty-startup-ingress-contract.tssrc/shared/pty-startup-ingress-live-query-reply.test.tssrc/shared/pty-startup-ingress.tssrc/shared/pty-startup-reply-delivery.test.tssrc/shared/pty-startup-reply-delivery.tssrc/shared/pty-startup-reply-echo-shapes.tssrc/shared/terminal-query-reply-delivery.tssrc/shared/terminal-query-reply.test.tssrc/shared/terminal-query-reply.tstests/e2e/pty-input-write-queue-ssh.spec.ts
💤 Files with no reviewable changes (4)
- .github/workflows/hourly-mac-build.yml
- .github/workflows/daily-mac-build.yml
- .github/workflows/adhoc-mac-build.yml
- .github/CONTRIBUTING.md
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| "runner": "local", | ||
| "platform": "macos", | ||
| "command": "ORCA_E2E_SSH_DOCKER=1 pnpm exec playwright test tests/e2e/pty-input-write-queue-ssh.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1", | ||
| "result": "passed", | ||
| "durationSeconds": 36.9, | ||
| "summary": "Run with SKIP_BUILD=1 against the existing e2e bundle. Both Docker OpenSSH Electron tests passed: the live OSC query returned its RGB reply, and an upstream-node-pty Linux ARM64 relay without echoState kept OSC/DA1 bytes out of the next fish 4.8.1 child's stdin." | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Evidence command does not match its own summary.
The evidenceRun dated 2026-08-14 for pty-input-write-queue-ssh.spec.ts has this "command":
ORCA_E2E_SSH_DOCKER=1 pnpm exec playwright test tests/e2e/pty-input-write-queue-ssh.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1
Its "summary" states "Run with SKIP_BUILD=1 against the existing e2e bundle." The recorded command omits SKIP_BUILD=1. Add SKIP_BUILD=1 to the command string so the logged command reproduces what was actually run.
📝 Proposed fix
- "command": "ORCA_E2E_SSH_DOCKER=1 pnpm exec playwright test tests/e2e/pty-input-write-queue-ssh.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1",
+ "command": "ORCA_E2E_SSH_DOCKER=1 SKIP_BUILD=1 pnpm exec playwright test tests/e2e/pty-input-write-queue-ssh.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1",📝 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.
| "runner": "local", | |
| "platform": "macos", | |
| "command": "ORCA_E2E_SSH_DOCKER=1 pnpm exec playwright test tests/e2e/pty-input-write-queue-ssh.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1", | |
| "result": "passed", | |
| "durationSeconds": 36.9, | |
| "summary": "Run with SKIP_BUILD=1 against the existing e2e bundle. Both Docker OpenSSH Electron tests passed: the live OSC query returned its RGB reply, and an upstream-node-pty Linux ARM64 relay without echoState kept OSC/DA1 bytes out of the next fish 4.8.1 child's stdin." | |
| } | |
| "runner": "local", | |
| "platform": "macos", | |
| "command": "ORCA_E2E_SSH_DOCKER=1 SKIP_BUILD=1 pnpm exec playwright test tests/e2e/pty-input-write-queue-ssh.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1", | |
| "result": "passed", | |
| "durationSeconds": 36.9, | |
| "summary": "Run with SKIP_BUILD=1 against the existing e2e bundle. Both Docker OpenSSH Electron tests passed: the live OSC query returned its RGB reply, and an upstream-node-pty Linux ARM64 relay without echoState kept OSC/DA1 bytes out of the next fish 4.8.1 child's stdin." | |
| } |
| "evidence": "Ten consecutive local unit-gate runs passed 1,380 tests in 29.57 seconds total with no fixed timing sleeps. The exact Docker SSH OSC oracle passed three consecutive runs before extraction and then passed both registered full-spec runs. The upstream-node-pty fish handoff oracle passed three local runs, including the final post-rebase run. CI and the normal soak window are not yet available." | ||
| }, |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
flakeHistory claims are not backed by any logged evidenceRun.
flakeHistory.evidence states: "Ten consecutive local unit-gate runs passed 1,380 tests in 29.57 seconds total with no fixed timing sleeps." The evidenceRuns array for this gate logs only a single unit-gate run (2026-08-09, 138 tests, 2.35s) plus three Electron/Docker runs. No entry shows 10 runs or 1,380 total tests. Since this manifest exists specifically to provide an auditable evidence trail for reliability claims, add the missing evidenceRuns entries (or entries summarizing the 10-run soak) that back this claim, or correct the flakeHistory text to match what is actually logged.
| describe('same-turn query reply wiring', () => { | ||
| const OSC11_REPLY = '\x1b]11;rgb:1e1e/1e1e/1e1e\x07' | ||
|
|
||
| it('hands the pty’s sync ECHO probe to the startup ingress', async () => { | ||
| const write = vi.fn() | ||
| const readEchoState = vi.fn(() => 0) | ||
| spawnMock.mockReturnValueOnce({ ...mockProc, write, readEchoState }) | ||
| const { id } = await provider.spawn({ cols: 80, rows: 24 }) | ||
|
|
||
| provider.write(id, OSC11_REPLY) | ||
|
|
||
| // Both matter: the probe must be CONSULTED, and a `quiet` verdict must reach the | ||
| // pty in this turn rather than behind the deferral timer. | ||
| expect(readEchoState).toHaveBeenCalled() | ||
| expect(write).toHaveBeenCalledWith(OSC11_REPLY) | ||
| }) | ||
|
|
||
| it('still defers the reply when the pty reports the slave would echo', async () => { | ||
| const write = vi.fn() | ||
| spawnMock.mockReturnValueOnce({ ...mockProc, write, readEchoState: () => 1 }) | ||
| const { id } = await provider.spawn({ cols: 80, rows: 24 }) | ||
|
|
||
| provider.write(id, OSC11_REPLY) | ||
|
|
||
| expect(write).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('does not let DA1 overtake a held OSC reply', async () => { | ||
| const da1 = '\x1b[?1;2c' | ||
| const write = vi.fn() | ||
| spawnMock.mockReturnValueOnce({ ...mockProc, write, readEchoState: () => 1 }) | ||
| const { id } = await provider.spawn({ cols: 80, rows: 24 }) | ||
|
|
||
| provider.write(id, OSC11_REPLY) | ||
| provider.write(id, da1) | ||
|
|
||
| expect(write).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Sync ECHO probe wiring tests depend on a POSIX platform. createPtySlaveEchoSyncProbe returns undefined when process.platform === 'win32', so readEchoState is never consulted and no same-turn write happens on Windows. Both new wiring suites assert the opposite.
src/main/providers/local-pty-provider-io-events.test.ts#L355-L393: add a POSIX gate such asitOnPosixHost, matchingpty-subprocess.test.ts.src/relay/pty-handler-same-turn-query-reply-wiring.test.ts#L69-L102: confirmbeginPtyHandlerTestforces a POSIXprocess.platform; if it does not, add the same gate.
📍 Affects 2 files
src/main/providers/local-pty-provider-io-events.test.ts#L355-L393(this comment)src/relay/pty-handler-same-turn-query-reply-wiring.test.ts#L69-L102
Source: Coding guidelines
| it('applies the same bound to DA1 replies kept atomic for ordering', async () => { | ||
| const { writes, pendingYields, queue } = createParkedQueue() | ||
| const replies = Array.from({ length: 10_000 }, (_, index) => `\x1b[?${index};2c`) | ||
|
|
||
| for (const reply of replies) { | ||
| expect(queue.enqueueQueryReply('pty-1', reply)).toBe(true) | ||
| } | ||
| expect(queue.enqueue('pty-1', 'k')).toBe(true) | ||
|
|
||
| await Promise.resolve() | ||
| for (let turn = 0; turn < PTY_INPUT_WRITE_QUEUE_MAX_PENDING_REPLIES; turn += 1) { | ||
| await releaseNextWrite(writes, pendingYields) | ||
| } | ||
| await queue.waitForDrain() | ||
|
|
||
| expect(writes.map((write) => write.data)).toEqual([ | ||
| replies[0], | ||
| ...replies.slice(-PTY_INPUT_WRITE_QUEUE_MAX_PENDING_REPLIES), | ||
| 'k' | ||
| ]) | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Release the final parked write before waiting for drain.
Line 264 waits while drain() is parked after it writes the 64th retained reply. The queued k write still needs one release. The test will time out.
Proposed fix
for (let turn = 0; turn < PTY_INPUT_WRITE_QUEUE_MAX_PENDING_REPLIES; turn += 1) {
await releaseNextWrite(writes, pendingYields)
}
+ await releaseNextWrite(writes, pendingYields)
await queue.waitForDrain()📝 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.
| it('applies the same bound to DA1 replies kept atomic for ordering', async () => { | |
| const { writes, pendingYields, queue } = createParkedQueue() | |
| const replies = Array.from({ length: 10_000 }, (_, index) => `\x1b[?${index};2c`) | |
| for (const reply of replies) { | |
| expect(queue.enqueueQueryReply('pty-1', reply)).toBe(true) | |
| } | |
| expect(queue.enqueue('pty-1', 'k')).toBe(true) | |
| await Promise.resolve() | |
| for (let turn = 0; turn < PTY_INPUT_WRITE_QUEUE_MAX_PENDING_REPLIES; turn += 1) { | |
| await releaseNextWrite(writes, pendingYields) | |
| } | |
| await queue.waitForDrain() | |
| expect(writes.map((write) => write.data)).toEqual([ | |
| replies[0], | |
| ...replies.slice(-PTY_INPUT_WRITE_QUEUE_MAX_PENDING_REPLIES), | |
| 'k' | |
| ]) | |
| }) | |
| it('applies the same bound to DA1 replies kept atomic for ordering', async () => { | |
| const { writes, pendingYields, queue } = createParkedQueue() | |
| const replies = Array.from({ length: 10_000 }, (_, index) => `\x1b[?${index};2c`) | |
| for (const reply of replies) { | |
| expect(queue.enqueueQueryReply('pty-1', reply)).toBe(true) | |
| } | |
| expect(queue.enqueue('pty-1', 'k')).toBe(true) | |
| await Promise.resolve() | |
| for (let turn = 0; turn < PTY_INPUT_WRITE_QUEUE_MAX_PENDING_REPLIES; turn += 1) { | |
| await releaseNextWrite(writes, pendingYields) | |
| } | |
| await releaseNextWrite(writes, pendingYields) | |
| await queue.waitForDrain() | |
| expect(writes.map((write) => write.data)).toEqual([ | |
| replies[0], | |
| ...replies.slice(-PTY_INPUT_WRITE_QUEUE_MAX_PENDING_REPLIES), | |
| 'k' | |
| ]) | |
| }) |
| const term = nodePty.spawn(process.execPath, [querierScript, String(rawDelayMs)], { | ||
| name: 'xterm-256color', | ||
| cols: 120, | ||
| rows: 30, | ||
| cwd: workDir, | ||
| env: { PATH: process.env.PATH ?? '/usr/bin:/bin', TERM: 'xterm-256color' } | ||
| }) | ||
|
|
||
| const echoProbe = createPtySlaveEchoProbe(readPtySlavePath(term)) | ||
| const echoSyncProbe = createPtySlaveEchoSyncProbe(term) | ||
| // Vacuity guard: a DEFINED probe proves nothing — the JS patch alone yields one | ||
| // that answers 'unknown' forever. The `verdictsAtQuery` assertion below is the | ||
| // real check; this one names the cause when the native binding is a prebuild. | ||
| expect( | ||
| echoSyncProbe?.(), | ||
| `the sync probe gave no definite verdict, so #13892's same-turn reply is off. ${NODE_PTY_SOURCE_BUILD_HINT}` | ||
| ).toMatch(/^(quiet|echoing)$/) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
The probe vacuity assertion runs outside the try/finally that kills the pty. Both suites spawn a live pty, then assert the sync probe returned a definite verdict before entering the block that owns term.kill(). On a prebuilt node-pty the probe answers unknown, the assertion throws, and the spawned process and pty fd stay open for the Vitest worker.
src/shared/pty-cooked-querier-reply-delivery.node-pty.test.ts#L96-L112: move theechoSyncProbe?.()assertion into thetryblock that starts at line 140.src/shared/fish-query-reply-child-stdin.node-pty.test.ts#L130-L156: move theechoSyncProbe?.()assertion into thetryblock that starts at line 217.
📍 Affects 2 files
src/shared/pty-cooked-querier-reply-delivery.node-pty.test.ts#L96-L112(this comment)src/shared/fish-query-reply-child-stdin.node-pty.test.ts#L130-L156
| let accepted = false | ||
| for (const reply of replies) { | ||
| const handled = needsCookedEchoSafeQueryReply(reply) | ||
| ? delivery.answer(reply) | ||
| : delivery.answerInOrder(reply) | ||
| accepted = handled || accepted | ||
| } | ||
| return accepted |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Return value can report full ownership after partial delivery.
The doc comment states the return value is true only when delivery owns the WHOLE payload. The loop uses handled || accepted, so one accepted reply makes the result true even when a later reply is rejected. The caller then drops the rejected bytes instead of writing them on its own path. answer and answerInOrder both return false when the delivery is closed or an immediate write throws, so a mixed payload can lose its tail.
Track every reply instead, and let the caller keep the payload when any reply is rejected.
♻️ Proposed change to keep the contract all-or-nothing
- let accepted = false
- for (const reply of replies) {
- const handled = needsCookedEchoSafeQueryReply(reply)
- ? delivery.answer(reply)
- : delivery.answerInOrder(reply)
- accepted = handled || accepted
- }
- return accepted
+ let allAccepted = true
+ for (const reply of replies) {
+ const handled = needsCookedEchoSafeQueryReply(reply)
+ ? delivery.answer(reply)
+ : delivery.answerInOrder(reply)
+ allAccepted = handled && allAccepted
+ }
+ return allAcceptedNote that a mixed result still leaves the accepted replies queued, so the caller must not re-send them. If that is intended, then document the OR semantics instead.
| const relayExports = execDockerSshRelayTargetCommand( | ||
| target, | ||
| 'module=$(find /root/.orca-remote -type d -path \'*/node_modules/node-pty\' | head -n 1); node -e "const p=require(process.argv[1]); console.log(Object.keys(p.native || {}).join(\',\'))" "$module"' | ||
| ) | ||
| testInfo.annotations.push({ type: 'relay-node-pty-exports', description: relayExports }) | ||
| expect(relayExports).not.toContain('echoState') |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check how the relay bundles node-pty and whether the patch reaches it.
set -euo pipefail
fd -H -t f 'package.json' -d 3 --exec sh -c 'grep -l "node-pty" "$1" || true' _ {} \;
rg -n --glob '!**/node_modules/**' 'orca-remote|relay.*node-pty|node-pty.*relay' -C3 config src | head -80
rg -n 'echoState' --glob '!**/node_modules/**' -C2 | head -60Repository: stablyai/orca
Length of output: 9573
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- test context ---'
sed -n '110,175p' tests/e2e/pty-input-write-queue-ssh.spec.ts
printf '%s\n' '--- helper definition and call sites ---'
rg -n -C8 'function execDockerSshRelayTargetCommand|const execDockerSshRelayTargetCommand|execDockerSshRelayTargetCommand' tests config src
printf '%s\n' '--- relay package and patch wiring ---'
rg -n -C5 'node-pty|echoState|node_modules/node-pty|relay-assets' package.json pnpm-lock.yaml config tests src --glob '!**/node_modules/**' | head -240Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- command execution behavior ---'
sed -n '1,55p' tests/e2e/helpers/docker-ssh-relay-target.ts
rg -n -C4 'node-pty|echoState|upstream-node-pty|relay-node-pty-exports' \
tests/e2e/pty-input-write-queue-ssh.spec.ts \
config/reliability-gates.jsonc \
config/relay-assets \
package.json
printf '%s\n' '--- empty module behavior ---'
node - <<'JS'
const { spawnSync } = require('node:child_process')
const result = spawnSync(process.execPath, [
'-e',
'require(process.argv[1])',
''
], { encoding: 'utf8' })
console.log(JSON.stringify({
status: result.status,
stdout: result.stdout,
stderr: result.stderr.split('\n').slice(0, 2).join('\n')
}, null, 2))
JSRepository: stablyai/orca
Length of output: 27517
Add an explicit empty-module failure.
If find returns no path, fail with a named error before require; otherwise the helper reports only a raw docker exec failure. Keep the echoState assertion because the relay intentionally uses upstream node-pty, while the later child-stdin assertion covers fallback behavior.
Root-cause follow-up to #15559, which stopped a CPR overtaking a deferred colour reply but left the deferral itself in place. Orca answers terminal queries by writing to the PTY master, which a line discipline in ECHO copies straight back out as junk on a cooked prompt (#12112). The guard was to withhold the write until an `stty` subprocess proved ECHO clear — and forking is what forced the decision to be async. Any deferral, however short, lets a reply written later in the same turn overtake this one, so the async probe was the bug's root cause. Read the bit synchronously instead. Linux and the BSDs redirect a master's mode ioctls to the slave, so a `tcgetattr` on the master fd node-pty already owns answers for the slave with no fork: measured 0.26us against 2403us for the subprocess. With a verdict available inline, a querying program that already cleared ECHO — every raw-mode prober, including the colour probe behind the `gh auth login` report — is answered in its own turn and can never be reordered. The deferral stays for the genuinely cooked case, and the ordering guarantee stays underneath it: hosts whose node-pty predates this patch get no sync probe and fall back to the deferred path, which mixed client/host versions make a live production path. Reply routing is all-or-nothing: a payload needing neither containment nor ordering stays on the host's own path, so a CPR answered during shell startup cannot pass the daemon's post-ready flush gate and splice into the buffered startup command. Native side is fail-safe: a kernel that did not redirect would answer from the master's own termios, whose ECHO defaults set, so the degraded verdict is "echoing" — never a false "quiet". The JS half ships in the pnpm patch while the binding needs a source build, so ORCA_REQUIRE_NODE_PTY_ECHO_STATE=1 makes CI fail rather than silently skip when it is handed an upstream prebuild. Co-authored-by: Brennan <[email protected]>
ee68656 to
bc319ab
Compare
Three defects found in external review of the reply-ordering work. node-pty delivers onData inside the master write, so a query can be answered while the queue is mid-flush. `flushPendingWrites` spliced the array off before writing, so that reply saw an empty queue, took the same-turn path, and landed ahead of entries the loop had not written yet — reproduced as 01, 99, 02, 03. It now shifts one entry at a time so a re-entrant reply queues behind the rest, bounded by the length at entry so a re-entrant push cannot spin the loop. An overflow flush can re-enter as far as teardown. `answer` did not re-check `closed` afterwards, so it queued behind a closed delivery, returned true, and the reply was never written and never reported. The payload router's ownership comment overstated its guarantee. The `any` semantics are deliberate — returning false after a constituent was already written would have the caller re-write the whole payload and duplicate it into the child's stdin — so the residual mixed-failure drop is now documented rather than implied away.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/pty-startup-reply-delivery.ts (1)
327-333: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the added comments.
Keep only the non-obvious invariant in each comment.
src/shared/pty-startup-reply-delivery.ts#L327-L333: State that bounded shifting preserves FIFO order during synchronous reentry.src/shared/pty-startup-reply-delivery.ts#L149-L151: State that flushing can synchronously close delivery and requires a closed-state check.src/shared/pty-startup-ingress-live-query-reply.test.ts#L469-L471: State that the test protects FIFO order during flush reentry.As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5cfc7923-0901-4b82-af67-a8da3a832805
📒 Files selected for processing (3)
src/shared/pty-startup-ingress-live-query-reply.test.tssrc/shared/pty-startup-reply-delivery.tssrc/shared/terminal-query-reply-delivery.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/shared/terminal-query-reply-delivery.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
|
Closing in favour of #15578, which takes the opposite approach and lands instead. This PR made the ECHO probe fast (native #15578 deletes the withholding scheduler outright — pending-write queue, async probe, poll budget, rate limit, deadline flush, and the The one thing withholding covered, the verbatim echo of a Everything of value here survives in #15578 — the all-or-nothing reply routing that keeps a CPR behind the daemon's post-ready flush gate, the renderer change that stops query replies being concatenated with keystrokes during a viewport claim, and the real-PTY fish test. The |
Root-cause follow-up to #15559.
Supersedes #14609 (STA-3948, @brennanb2025). This is that branch rebased onto main and reconciled with #15559, which landed in the meantime, plus fixes for three defects found in review. #14609 is closed in favour of this PR; the original commit is preserved with its
Co-authored-bytrailer.What this actually fixes (corrected)
#15559 is what makes reply ordering correct, not this PR. Its cross-call FIFO holds a CPR behind a still-deferred colour reply, and that holds regardless of how long the deferral lasts — verified by running the ordering scenario with the sync probe absent (an unpatched host), where
OSC → CPRis still preserved.What this PR removes is the deferral itself, and with it two things the FIFO cannot address:
So: a latency and robustness fix that deletes the mechanism which produced the ordering bug, not the ordering fix itself.
Why the deferral existed
Orca answers terminal queries by writing to the PTY master, which a line discipline in ECHO copies straight back out as junk on a cooked prompt (#12112). The guard was to withhold the write until an
sttysubprocess proved ECHO clear — and forking is what forced the decision to be asynchronous.That async hop is the bug. Any deferral, however short, lets a reply written later in the same turn overtake the held one. #15559 stopped a CPR jumping the queue, but left the deferral — and the latency and fork cost — in place.
The root-cause fix
Read the bit synchronously. Linux and the BSDs redirect a master's mode ioctls to the slave, so
tcgetattron the master fd node-pty already owns answers for the slave with no fork:sttysubprocess (before)tcgetattron master (after)With a verdict available inline, a program that already cleared ECHO — every raw-mode prober, including the colour probe behind the
gh auth loginreport — is answered in its own turn and can never be reordered.The deferral stays for the genuinely cooked case, and #15559's ordering guarantee stays underneath it: hosts whose node-pty predates this patch get no sync probe and fall back to the deferred path, which mixed client/host versions make a live production path.
Fail-safe by construction
Every non-ideal outcome degrades toward the old behaviour, never toward a false "quiet":
tcgetattrfails →-1→unknown→ deferred path.echoing→ deferred path.Verification
-1.tcgetattrneeds only GLIBC_2.2.5, far below the 2.31 floor, so no new glibc surface.pnpm install --frozen-lockfile --ignore-scriptsfrom a cold store (0 reused / 1280 downloaded) applies the patch, and a from-source rebuild exportsechoState.stty -echo/stty echoin real time.\x1b]11;rgb:...in the next program's stdin; post-fix stdin is clean.Guards against silent inertness
The JS half of the patch ships in the pnpm patch while the native half needs a source build, so
readEchoStateexists the momentnode_modulesis patched even when the loaded binding is an upstream prebuild withoutechoState— a test that only checked "does the probe exist" would pass with the fix switched off.ORCA_REQUIRE_NODE_PTY_ECHO_STATE=1makes CI fail rather than skip. A live-PTY test additionally asserts the probe really observes a quiet slave, so a kernel that does not redirect fails loudly instead of leaving the fast path inert.Review-driven changes to the rebased branch
Adversarial review found three defects, all fixed here with regression tests that fail without their fix:
answerInOrdertook ownership even with nothing to order behind, soSession.writereturned before reaching the post-ready flush gate. A CPR answered during shell startup landed ahead of the buffered startup command and the shell ran the spliced remainder —4;1Recho ...— so the agent never launched. A payload needing neither containment nor ordering now stays on the host's own path.ERR_PNPM_INVALID_PATCH; the lockfile hash was regenerated. The rebase had also droppedlint-stagedfrompatchedDependencies— restored.quietassertion was missing.Known scope limit (unchanged)
Ordering is FIFO among recognised query replies, not over every byte. A reply coalesced with a keystroke and ordinary typed input still bypass the queue. The renderer change narrows this — query replies buffered during a viewport claim are no longer concatenated with keystrokes — but the host-side gap remains, pinned by known-limitation tests.