Repository navigation
fix(terminal): one intentional-stop register, and per-run spawn and input facts - #22989
Conversation
…put facts Main now keeps one register of PTY stops it made on purpose, with an owner count and a kind: reversible (sleep, hibernation) or replaced (a restart handing the pane to a new process). It replaces four separate markers, and every exit path reads it, so a hibernated or restarted pane keeps its tab and binding through the exit instead of being retired and grafted back. Main also records two facts per process run, keyed by incarnation: whether the run was a fresh spawn (from the spawn-commit origin, which now counts a cold restore as a reattach) and when a client first sent it input a person produced. Renderer keystroke, paste, drop and quick-command writes carry a userInput flag; terminal.send, stream input and dispatched agent prompts are recorded by the runtime, excluding terminal query replies.
… keep its pane One process can reach the runtime's exit handler twice: main's synthetic exit when the kill reply overtakes the stream, then the provider's own exit, which certifies the death. Both must read the same stop, a later process on the same id must not, and the stop is forgotten when the duplicate-exit window closes.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 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:
📝 WalkthroughWalkthroughPTY writes now require an input kind: Priority: ⬇️ Low Merge Risk: 🔵 Low · up to Terminal input can be recorded as having started too early, or not recorded when a malformed IPC write is accepted. These provenance errors do not currently block terminal writes, but should be corrected before the run facts are used for tab behavior. The overlapping-stop exit flags have been fixed. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Centralizing intentional stops should make terminal recovery more consistent, but it changes which panes survive a process exit. The new input labels also cross several terminal entrypoints. No current security decision using the new run facts was identified; incomplete coverage and an unresolved exit-ordering case warrant review without establishing a vulnerability. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❓ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 71 files. (95 skipped: 95 over the file limit.) ✨ Finishing Touches 💡 2📝 Generate docstrings 💡
⚔️ Resolve merge conflicts 💡
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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ee134418-631c-4001-8989-479344f680bf
📒 Files selected for processing (62)
src/main/ipc/pty-daemon-ssh-lease-lifecycle.test.tssrc/main/ipc/pty-pane-restart-replace.test.tssrc/main/ipc/pty-ssh-undelivered-kill.test.tssrc/main/ipc/pty/delivery/exit.tssrc/main/ipc/pty/ipc/renderer-kill.tssrc/main/ipc/pty/ipc/spawn-commit-persist.tssrc/main/ipc/pty/ipc/write-input-user-input.test.tssrc/main/ipc/pty/ipc/write-input.tssrc/main/ipc/pty/register-handlers.tssrc/main/ipc/pty/runtime/controller-deps.tssrc/main/ipc/pty/runtime/controller.tssrc/main/ipc/pty/runtime/kill.tssrc/main/ipc/pty/runtime/spawn-commit-run-facts.test.tssrc/main/ipc/pty/runtime/spawn-commit.tssrc/main/ipc/pty/runtime/spawn-preflight-requested-shell.test.tssrc/main/ipc/pty/session.tssrc/main/persistence/loading-store/pty-binding-span.tssrc/main/runtime/orca-runtime-controller-knows-pty-is-live.tssrc/main/runtime/orca-runtime-on-pty-exit.tssrc/main/runtime/orca-runtime-refresh-floating-workspace-pty-liveness.tssrc/main/runtime/orca-runtime-runtime-id.tssrc/main/runtime/orca-runtime-sleep-resolved-worktree-terminals.tssrc/main/runtime/orca-runtime-stop-exact-terminals-for-worktree.tssrc/main/runtime/orca-runtime-write-terminal-agent-prompt.tssrc/main/runtime/rpc/methods/terminal/terminal-send-method.tssrc/main/runtime/rpc/terminal-send.test.tssrc/main/runtime/runtime-pty-controller-contract.tssrc/main/runtime/terminal-close-observed-exit-test-fixture.tssrc/main/runtime/terminal-intentional-stop-exit.test.tssrc/main/runtime/terminal-intentional-stops.test.tssrc/main/runtime/terminal-intentional-stops.tssrc/main/runtime/terminal-run-facts-input.test.tssrc/main/runtime/terminal-run-facts.test.tssrc/main/runtime/terminal-run-facts.tssrc/preload/api/pty-api.tssrc/preload/api/pty-bridge-session-control.tssrc/renderer/src/components/terminal-pane/deferred-split-pane-handoff.tssrc/renderer/src/components/terminal-pane/keyboard-handlers-ime-enter-keyup.test.tsxsrc/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.tssrc/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.tssrc/renderer/src/components/terminal-pane/pty-input-write-queue-contract.tssrc/renderer/src/components/terminal-pane/pty-input-write-queue.tssrc/renderer/src/components/terminal-pane/pty-preconnect-input-buffer.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport-user-input.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.test.tssrc/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.tssrc/renderer/src/components/terminal-pane/terminal-drop-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-internal-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-path-writer.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-path-writer.tssrc/renderer/src/components/terminal-pane/terminal-pane-menu-paste.tssrc/renderer/src/components/terminal-pane/terminal-pane-paste-execution.tssrc/renderer/src/components/terminal-pane/terminal-programmatic-text-paste.tssrc/renderer/src/components/terminal-pane/terminal-pty-paste-writer.test.tssrc/renderer/src/components/terminal-pane/terminal-pty-paste-writer.tssrc/renderer/src/components/terminal-pane/terminal-quick-command-dispatch.test.tssrc/renderer/src/components/terminal-pane/terminal-quick-command-dispatch.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-mobile-actions.tssrc/renderer/src/runtime/runtime-terminal-inspection.test.tssrc/renderer/src/runtime/runtime-terminal-inspection.ts
💤 Files with no reviewable changes (5)
- src/main/runtime/runtime-pty-controller-contract.ts
- src/main/ipc/pty/runtime/controller.ts
- src/main/ipc/pty/runtime/controller-deps.ts
- src/main/ipc/pty/session.ts
- src/main/ipc/pty/runtime/spawn-preflight-requested-shell.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| if (stop && joinsInFlightStop) { | ||
| stop.kind = kind | ||
| stop.incarnationId ??= incarnationId | ||
| stop.owners += 1 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '20,62p' src/main/ipc/pty/runtime/undelivered-ssh-kill.ts
sed -n '15,63p' src/renderer/src/components/terminal-pane/pty-exit-delivery.ts
sed -n '20,95p' src/main/runtime/terminal-intentional-stops.tsRepository: stablyai/orca
Length of output: 5954
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- spawn-run.ts ---'
sed -n '1,90p' src/main/ipc/pty/ipc/spawn-run.ts
printf '%s\n' '--- spawn-options.ts ---'
sed -n '160,215p' src/main/ipc/pty/ipc/spawn-options.ts
printf '%s\n' '--- orca-runtime-sleep-resolved-worktree-terminals.ts ---'
sed -n '1,40p' src/main/runtime/orca-runtime-sleep-resolved-worktree-terminals.ts
sed -n '130,180p' src/main/runtime/orca-runtime-sleep-resolved-worktree-terminals.ts
printf '%s\n' '--- kill.ts ---'
sed -n '1,100p' src/main/ipc/pty/runtime/kill.ts
printf '%s\n' '--- relevant usages ---'
rg -n -C 4 'isReversibleStopInFlight|claimExit|replacedByRestart|recordUndeliveredSshPtyKill|\.mark\(' src/main src/renderer/src/components/terminal-paneRepository: stablyai/orca
Length of output: 42219
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- replacement and stop mark sites ---'
rg -n -C 8 "intentionalPtyStops\.mark|stopReplacedPty|replacesPtyId|intentionalStop" src/main/runtime src/main/ipc/pty
printf '%s\n' '--- renderer-kill.ts ---'
sed -n '1,165p' src/main/ipc/pty/ipc/renderer-kill.ts
printf '%s\n' '--- undelivered SSH tests around reversible and replacement ---'
rg -n -C 8 "reversible|replaced|undelivered|keepHistory" src/main/ipc/pty-ssh-undelivered-kill.test.ts src/main/runtime/terminal-intentional-stop-exit.test.ts src/main/runtime/terminal-intentional-stops.test.ts 2>/dev/null
printf '%s\n' '--- exit delivery mapping ---'
sed -n '130,170p' src/main/ipc/pty/delivery/exit.tsRepository: stablyai/orca
Length of output: 41718
🏁 Script executed:
sed -n '1,115p' src/main/runtime/terminal-intentional-stops.tsRepository: stablyai/orca
Length of output: 3326
Give replacement precedence to the renderer, but track reversible ownership separately.
A replacement owner must make claimExit return 'replaced' so the renderer receives replacedByRestart. However, isReversibleStopInFlight must remain true while any reversible owner is active. kill.ts uses this result to suppress an undelivered SSH kill, and replaying a hibernation kill can terminate a pane that remains live.
Track reversible owners independently while keeping replaced precedence for exit classification.
Suggested fix
type IntentionalStop = {
kind: TerminalIntentionalStopKind
+ reversibleOwners: number
/** Null until known; the first exit that claims the stop pins it to that process. */
incarnationId: string | null
owners: number
stopped: boolean
expiryTimer?: ReturnType<typeof setTimeout>
@@
if (stop && joinsInFlightStop) {
- stop.kind = kind
+ if (kind === 'replaced') stop.kind = kind
+ if (kind === 'reversible') stop.reversibleOwners += 1
stop.incarnationId ??= incarnationId
stop.owners += 1
} else {
clearTimeout(stop?.expiryTimer)
- stop = { kind, incarnationId, owners: 1, stopped: false }
+ stop = {
+ kind,
+ reversibleOwners: kind === 'reversible' ? 1 : 0,
+ incarnationId,
+ owners: 1,
+ stopped: false
+ }
this.stopsByPtyId.set(ptyId, stop)
}
@@
}
settled = true
owned.stopped ||= stopped
+ if (kind === 'reversible') owned.reversibleOwners -= 1
owned.owners -= 1
@@
isReversibleStopInFlight(ptyId: string): boolean {
const stop = this.stopsByPtyId.get(ptyId)
- return stop?.kind === 'reversible' && stop.owners > 0
+ return stop !== undefined && stop.owners > 0 && stop.reversibleOwners > 0
}
}There was a problem hiding this comment.
ℹ️ No critical issues — a couple of robustness gaps in the new registers.
Reviewed changes
- One intentional-stop register.
TerminalIntentionalStopsreplacesmarkReplacedPtyStop/replacedPtyStopsById,reversibleStopOwnersByPtyId, andintentionalHandlelessPtyStops. Entries are keyed by PTY id, pinned to an incarnation, shared by owner count, survive read, and expire after the duplicate-exit window. All four stop writers and both exit readers (runtime + renderer delivery) now go through it. - Per-run facts.
TerminalRunFactsRegisterrecordsfreshSpawnand write-oncefirstUserInputAtper process.spawnCommitBindingOriginnow treats a cold restore as a reattach. Input provenance is tagged at the writer ({ userInput: true }throughpty:write/pty:writeAccepted, and a wrappedreserveWriteonsendTerminalunless the payload is a query reply). - Renderer/transport plumbing.
PtyInputOptionsthreads the tag through the write queue (no coalescing across the tag boundary), the preconnect buffer, paste/drop/quick-command paths, and captured input. - Tests. 21 new/updated test files covering hibernation, restart, runtime sleep, synthetic + late provider exits, incarnation reuse, expiry, fresh-spawn classification, and input provenance.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| } | ||
| } | ||
| const intentionalStop = | ||
| session.runtime?.intentionalPtyStops?.claimExit(payload.id, payload.incarnationId) ?? null |
There was a problem hiding this comment.
This read passes payload.incarnationId raw, while the runtime's read applies exitIncarnationId ?? pty?.incarnationId. claimExit only rejects a mismatch when both incarnations are non-null, so an exit that omits the incarnation can claim a stop pinned to a different process. Because the reversible/sleep/exact-stop markers now persist for the duplicate-exit window (they were deleted at stop completion in the base), a reused PTY id is exposed on those paths — and the renderer would keep the binding (preserveRendererBinding / replacedByRestart) for the wrong process.
Technical details
# Unknown incarnation weakens the deliberate-stop incarnation guard
## Affected sites
- `src/main/ipc/pty/delivery/exit.ts:156-157` — `claimExit(payload.id, payload.incarnationId)` has no `pty?.incarnationId` fallback, unlike `runtime/orca-runtime-on-pty-exit.ts:118-119`.
- `src/main/runtime/terminal-intentional-stops.ts:81-83` — mismatch is only rejected when both sides are truthy; a null mark or a falsy exit matches any process on the id.
- `src/main/ipc/pty/provider/bind-listeners.ts:109-112` — the renderer payload omits `incarnationId` whenever the provider exit had none, so `payload.incarnationId` can be `undefined` at the read above even though the runtime record knows the incarnation.
## Required outcome
- The register's stated invariant ("a later process that reuses the id never matches", `terminal-intentional-stops.ts:6-7`) should hold when either side's incarnation is unknown, or the code/intent should document that it deliberately cannot.
- At minimum, the renderer read should use the same incarnation fallback as the runtime read so both readers agree on which process an exit describes (they must agree — both are read for one exit).
## Suggested approach (optional)
- Pass `exitIncarnationId ?? this.ptysById.get(payload.id)?.incarnationId` into the delivery read, or thread the already-resolved incarnation into `finalizePtyExitForRenderer`.
- Optionally gate the mark's join and `claimExit`'s match on a non-null incarnation when the entry is pinned, so an unknown exit cannot claim a pinned stop.
## Open questions for the human
- Is a committed spawn result with no `incarnationId` (legacy daemon / older SSH relay) a state this register is expected to handle, or is it out of scope for the intentional-stop path?A sleep and a restart that stop the same process now each keep their label: the exit carries both renderer flags, and a runtime kill during the sleep still records its SSH stop as reversible. A later stop of an already-stopped process joins its entry, so a failed repeat cannot erase the stop that landed. The cold-restore rule moves into the run facts, so the binding span keeps labelling a cold restore as a spawn.
Drives a real xterm through the pane's input handling: a macOS input-source substitution, an iPadOS Hangul syllable, and a composition the route delivers after a pane switch each reach onData flagged as user input, which is what tags the write main records.
… are not input - A landed stop that no exit pinned to an incarnation now ends when a new process commits on the same id, so that process's exit is not read as the stop. Both spawn-commit funnels report through one runtime method. - A spawn commit with no incarnation starts its run facts clean, since it cannot be told from a new process. - Stream input that is only focus reports no longer counts as user input; the desktop renderer already excludes them through xterm's own signal. - The IME provenance test uses typed fakes: the pane input and composition route installers now take only the fields they read.
There was a problem hiding this comment.
ℹ️ No new issues in the delta — one documentation note below.
Reviewed changes
- Kept every overlapping stop kind on one exit.
TerminalIntentionalStopsnow storesownersByKind: Map<kind, {inFlight, stopped}>, andclaimExitreturns every kind still on the entry, so a sleep and a restart that stop the same process both label the exit (preserveRendererBindingandreplacedByRestart). - A later stop joins an already-stopped process. A settled entry is joined only by its own known incarnation (
joins), andowners.stopped ||= stoppedmeans a failed repeat cannot erase a stop that landed. - Cold-restore classification moved into the run facts.
spawnCommitBindingOriginreverts to returning'spawn'for a cold restore that omitsisReattach(keeping the binding span's historical label);recordSpawnCommitmaps that to'cold-restore', sofreshSpawnis still false for cold restores. - IME/Hangul provenance tests. New
terminal-ime-user-input-provenance.test.tsexercises macOS input-source substitution, iPadOS Hangul syllable commits, and a composition delivered after a pane switch, asserting each reachesonDatawithwasUserInput: true.
All three incremental tests are red for the right reason: the overlapping-stop test fails under the old last-kind-wins model, the SSH-join test fails the same way, and the IME tests rely on xterm's real onUserInput signal. The two prior threads (the renderer-side incarnation fallback in exit.ts and the both-null incarnation early-return in terminal-run-facts.ts) are unchanged by these commits and stay open.
ℹ️ Nitpicks
- The PR description is stale on the cold restore: its "Fresh spawn" bullet still says "
spawnCommitBindingOriginnow also counts a cold restore as a reattach". Commit0cd6e607fdmoved that rule intoTerminalRunFactsRegister.recordSpawnCommit, sospawnCommitBindingOriginnow returns'spawn'for a cold restore that omitsisReattach(a cold restore that setsisReattachwas already'reattach'). Worth updating the body so reviewers get the current mechanism.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 220311f9-98d6-4fac-9da4-b4d8013eab02
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
src/main/ipc/pty-ssh-undelivered-kill.test.tssrc/main/ipc/pty/delivery/exit.tssrc/main/persistence/loading-store/pty-binding-span.tssrc/main/runtime/orca-runtime-on-pty-exit.tssrc/main/runtime/terminal-intentional-stop-exit.test.tssrc/main/runtime/terminal-intentional-stops.test.tssrc/main/runtime/terminal-intentional-stops.tssrc/main/runtime/terminal-run-facts.tssrc/renderer/src/components/terminal-pane/terminal-ime-user-input-provenance.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| const intentionalStops = | ||
| session.runtime?.intentionalPtyStops?.claimExit(payload.id, payload.incarnationId) ?? [] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '130,180p' src/main/ipc/pty/delivery/exit.ts
sed -n '95,145p' src/main/runtime/orca-runtime-on-pty-exit.ts
sed -n '85,145p' src/main/ipc/pty/provider/bind-listeners.ts
rg -n 'finalizePtyExitForRenderer|ptyIncarnationById|onPtyExit\(' src/main/ipc/pty src/main/runtime/orca-runtime-on-pty-exit.tsRepository: stablyai/orca
Length of output: 12602
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- exit.ts imports and flow ---'
sed -n '1,190p' src/main/ipc/pty/delivery/exit.ts
printf '%s\n' '--- runtime onPtyExit ---'
sed -n '1,180p' src/main/runtime/orca-runtime-on-pty-exit.ts
printf '%s\n' '--- intentional stop definitions/usages ---'
rg -n -C 5 'intentionalPtyStops|claimExit|markPtyStopRequested|class .*PtyStop|interface .*PtyStop' src/main
printf '%s\n' '--- ownership state and cleanup ---'
cat -n src/main/ipc/pty/provider/ownership-state.ts
cat -n src/main/ipc/pty/provider/state-cleanup.ts
printf '%s\n' '--- provider listener and renderer-exit entrypoints ---'
sed -n '1,145p' src/main/ipc/pty/provider/bind-listeners.ts
sed -n '1,110p' src/main/ipc/pty/delivery/ssh-intake.ts
printf '%s\n' '--- diff for reviewed file and nearby bindings ---'
git diff --unified=30 600adba9f03a4afd850e910e9065434471290d5f fbe1a1a1d1d5dcf8f3a28d7f18711916a713f865 -- src/main/ipc/pty/delivery/exit.ts src/main/ipc/pty/provider/bind-listeners.ts src/main/runtime/orca-runtime-on-pty-exit.ts src/main/ipc/pty/delivery/ssh-intake.tsRepository: stablyai/orca
Length of output: 42094
🏁 Script executed:
set -e
sed -n '1,190p' src/main/ipc/pty/delivery/exit.ts
sed -n '1,180p' src/main/runtime/orca-runtime-on-pty-exit.ts
rg -n -C 5 'intentionalPtyStops|claimExit|markPtyStopRequested|isCurrentPtyExit|clearProviderPtyState' src/main
cat -n src/main/ipc/pty/provider/ownership-state.ts
cat -n src/main/ipc/pty/provider/state-cleanup.ts
sed -n '1,145p' src/main/ipc/pty/provider/bind-listeners.ts
sed -n '1,110p' src/main/ipc/pty/delivery/ssh-intake.ts
git diff --unified=20 600adba9f03a4afd850e910e9065434471290d5f fbe1a1a1d1d5dcf8f3a28d7f18711916a713f865 -- src/main/ipc/pty/delivery/exit.ts src/main/ipc/pty/provider/bind-listeners.ts src/main/runtime/orca-runtime-on-pty-exit.ts src/main/ipc/pty/delivery/ssh-intake.tsRepository: stablyai/orca
Length of output: 42868
🏁 Script executed:
set -e
printf '%s\n' '--- claimExit implementation and register ---'
rg -n -C 12 'claimExit|class Intentional|intentionalPtyStops|incarnationId.*null' src/main src/shared
printf '%s\n' '--- provider cleanup implementation ---'
cat -n src/main/ipc/pty/provider/state-cleanup.ts | sed -n '1,130p'
printf '%s\n' '--- ownership implementation ---'
cat -n src/main/ipc/pty/provider/ownership-state.tsRepository: stablyai/orca
Length of output: 41684
Resolve the incarnation before provider cleanup.
For a non-local provider exit without incarnationId, clearProviderPtyState deletes ptyIncarnationById before renderer finalization. The runtime still resolves pty?.incarnationId, but renderer finalization passes undefined to claimExit. A retained stop from an earlier incarnation can therefore set preserveRendererBinding or replacedByRestart.
Read ptyIncarnationById before cleanup and pass the resolved value to both runtime handling and renderer delivery. Preserve undefined when the exit cannot be identified.
Suggested fix
-import { isCurrentPtyExit, ptyOwnership } from './ownership-state'
+import { isCurrentPtyExit, ptyIncarnationById, ptyOwnership } from './ownership-state'
...
if (!isCurrentPtyExit(payload)) {
return
}
const syntheticExit = session.consumeSyntheticKillExit(payload.id, payload.incarnationId)
+ const exitIncarnationId =
+ payload.incarnationId ?? ptyIncarnationById.get(payload.id)
if (!isLocalProvider) {
clearProviderPtyState(payload.id)
ptyOwnership.delete(payload.id)
...
- session.runtime?.onPtyExit(payload.id, payload.code, payload.incarnationId, {
+ session.runtime?.onPtyExit(payload.id, payload.code, exitIncarnationId, {
...
id: payload.id,
code: payload.code,
- ...(payload.incarnationId ? { incarnationId: payload.incarnationId } : {})
+ ...(exitIncarnationId ? { incarnationId: exitIncarnationId } : {})
})The dashboard popout's terminal preview writes to the PTY through its own runtime path, which recorded no input, so a pane typed into only from the preview read as untyped. It now records before the write, after the mobile-driver check. One classifier, shared with terminal.send, decides which provenance-free bytes nobody typed: a whole terminal reply or only focus reports, which also covers the focus-in a desktop renderer sends when it reattaches a remote pane.
…t adds happy-dom serves navigator.userAgent from the prototype, so the test found no own descriptor to restore and left the iPad user agent in place. The pane-switch case then ran as a Mac pane only because it followed the Hangul case. Deleting the own-property stub restores the default platform for every case.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 856cf7b2-5d0f-4d16-93aa-9ef7d189f473
📒 Files selected for processing (14)
src/main/ipc/pty/ipc/spawn-commit-persist.tssrc/main/ipc/pty/runtime/spawn-commit-run-facts.test.tssrc/main/ipc/pty/runtime/spawn-commit.tssrc/main/runtime/orca-runtime-attach-remote-terminal-source-range-consumer.tssrc/main/runtime/orca-runtime-controller-knows-pty-is-live.tssrc/main/runtime/orca-runtime-runtime-id.tssrc/main/runtime/terminal-intentional-stops.test.tssrc/main/runtime/terminal-intentional-stops.tssrc/main/runtime/terminal-run-facts-input.test.tssrc/main/runtime/terminal-run-facts.test.tssrc/main/runtime/terminal-run-facts.tssrc/renderer/src/components/terminal-pane/terminal-ime-composition-route.tssrc/renderer/src/components/terminal-pane/terminal-ime-user-input-provenance.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-pane-input.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
| export function isUntypedTerminalInput(payload: string): boolean { | ||
| return isTerminalQueryReply(payload) || TERMINAL_FOCUS_REPORTS_ONLY_RE.test(payload) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Exclude coalesced query replies from user-input facts.
If a client sends two query replies in one payload, isTerminalQueryReply(payload) rejects the payload because it recognizes only one complete reply. The focus-report regex also rejects it. The runtime then records firstUserInputAt even though no person sent input. Use the existing extractOnlyTerminalQueryReplies helper for reply-only payloads, and test two consecutive replies. (raw.githubusercontent.com)
There was a problem hiding this comment.
✅ No new issues found in the delta — the both-null incarnation gap is closed, and the new stop-retirement and input-provenance changes hold up.
Reviewed changes
- Added
TerminalIntentionalStops.noteSpawnCommit: a spawn commit on an id retires a landed stop that no exit ever pinned and has no in-flight owners, so a reused id cannot inherit it. The runtime's newnoteTerminalSpawnCommitdrives both spawn funnels, recording run facts and retiring the stop together. - Extended the no-provenance classifier to focus reports (
CSI I/CSI O) throughisUntypedTerminalInput, so a paired client's automatic focus replies no longer count as a run's first user input onsendTerminalor the dashboard preview. - Recorded the pop-out dashboard preview's raw keystrokes (
writeTerminalPreviewInput) as a run's first user input, before the write that could end the process. - Fixed
TerminalRunFactsRegister.recordSpawnCommitto start a clean run when a commit omits the incarnation, closing the both-null collapse; added a test for it. - Narrowed the IME composition route and pane-input parameter types to the fields they read, dropping the test's type assertions.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…oint reads it A run's first input was recorded by opposite defaults: the renderer's pty:write recorded nothing unless a writer opted in, terminal.send recorded everything that was not a reply, and main's own controller writes recorded nothing. Each unclassified producer silently took its transport's default, so the worktree-create draft counted from the renderer and not from main, and mailbox pointers never counted. Every host write entry point now takes a required kind: driving, launch or query-reply. That covers the runtime controller's write and settled write, the terminal writer, sendTerminal, sendTerminalAgentPrompt, pty:write and pty:writeAccepted, the renderer transport and the runtime input helpers. The fact is recorded once, just before the provider write, in the controller funnel and the pty:write funnel: only driving bytes count, and a payload that is only a reply or focus reports never does. The per-producer records are gone. Launch writes (create-time drafts and follow-ups, the agent launch prompt, restored and cold-restore startup commands, the SSH background launch) do not count. Mailbox pointers, dispatch, plugins and agent-team sends do. The runtime mixins are unchecked by the compiler, and the pane session is an any bag, so two source scans fail on any write there that leaves out its kind.
…ks every write's kind The pane-connection session is an `any` bag, so a transport write there that left out its input kind compiled, and only a text scan over the renderer caught it. Declaring `transport: PtyTransport` on the session puts those writes under the compiler, so the scan is gone. One hidden-delivery guard now narrows a null PTY id itself instead of relying on an untyped predicate. The main-process scan over `@ts-nocheck` runtime files missed five files whose directive sits on the second line, below a lint directive, and missed a write through a local alias of the PTY controller. It now finds both.
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ec02d267-edee-40a3-a857-e2622c949794
📒 Files selected for processing (145)
src/main/ipc/pty/ipc/write-input-chunk-yield.test.tssrc/main/ipc/pty/ipc/write-input-user-input.test.tssrc/main/ipc/pty/ipc/write-input.tssrc/main/ipc/pty/runtime/controller.tssrc/main/ipc/pty/runtime/operations.tssrc/main/ipc/pty/runtime/spawn-commit-run-facts.test.tssrc/main/plugins/plugin-host-methods.test.tssrc/main/plugins/plugin-host-service-bindings.tssrc/main/runtime/agent-prompt-line-settle.test.tssrc/main/runtime/agent-prompt-receipt-correlation.test.tssrc/main/runtime/agent-prompt-submission-runtime-hook-and-generation.test.tssrc/main/runtime/agent-prompt-submission-runtime.test.tssrc/main/runtime/agent-prompt-submission-windows-submit-delay.test.tssrc/main/runtime/claude-agent-teams-tmux-dispatcher.tssrc/main/runtime/claude-agent-teams-types.tssrc/main/runtime/orca-runtime-attach-remote-terminal-source-range-consumer.tssrc/main/runtime/orca-runtime-controller-knows-pty-is-live.tssrc/main/runtime/orca-runtime-create-pty-headless-terminal-state.tssrc/main/runtime/orca-runtime-deliver-pending-messages.tssrc/main/runtime/orca-runtime-get-worktree-terminal-provisioning-host.tssrc/main/runtime/orca-runtime-resolve-authoritative-terminal-wait-permission.tssrc/main/runtime/orca-runtime-resolve-terminal-split-source-authority.tssrc/main/runtime/orca-runtime-restore-live-paired-renderer-session-owned-mobile-terminals.tssrc/main/runtime/orca-runtime-runtime-id.tssrc/main/runtime/orca-runtime-terminal-handle-incarnation.test.tssrc/main/runtime/orca-runtime-tests/agent-status-and-waits-part-03.spec.tssrc/main/runtime/orca-runtime-tests/agent-status-and-waits.spec.tssrc/main/runtime/orca-runtime-tests/mobile-session-tabs-part-13.spec.tssrc/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-07.spec.tssrc/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-08.spec.tssrc/main/runtime/orca-runtime-tests/terminal-handles-and-agent-status.spec.tssrc/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery-part-02.spec.tssrc/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery-part-07.spec.tssrc/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-03.spec.tssrc/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-04.spec.tssrc/main/runtime/orca-runtime-write-terminal-agent-prompt.tssrc/main/runtime/orchestration/coordinator-runtime-contract.tssrc/main/runtime/orchestration/mailbox-pointer-pty-write.tssrc/main/runtime/orchestration/preamble.tssrc/main/runtime/rpc/methods/agent-launch-terminal-prompt.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-release-mobile-report.test.tssrc/main/runtime/rpc/methods/orchestration/worker/worker-start-prompt-contract.test.tssrc/main/runtime/rpc/methods/terminal/terminal-input-delivery.tssrc/main/runtime/rpc/methods/terminal/terminal-send-method.tssrc/main/runtime/rpc/terminal-agent-prompt-send.test.tssrc/main/runtime/rpc/terminal-multiplex-ack-output-budget.test.tssrc/main/runtime/rpc/terminal-multiplex-ack-overflow-recovery.test.tssrc/main/runtime/rpc/terminal-multiplex-desktop-resize-routing.test.tssrc/main/runtime/rpc/terminal-multiplex-input-write-rejection.test.tssrc/main/runtime/rpc/terminal-multiplex-output-pause-and-viewport.test.tssrc/main/runtime/rpc/terminal-output-batching.test.tssrc/main/runtime/rpc/terminal-send.test.tssrc/main/runtime/runtime-pty-controller-contract.tssrc/main/runtime/runtime-terminal-contracts.tssrc/main/runtime/runtime-terminal-writer.tssrc/main/runtime/runtime-worktree-startup-readiness.tssrc/main/runtime/terminal-input-kind-unchecked-call-sites.test.tssrc/main/runtime/terminal-intentional-stop-exit.test.tssrc/main/runtime/terminal-interactive-wait-visibility.test.tssrc/main/runtime/terminal-query-responder.test.tssrc/main/runtime/terminal-run-facts-input.test.tssrc/main/runtime/terminal-run-facts.test.tssrc/main/runtime/terminal-run-facts.tssrc/main/runtime/terminal-send-stale-leaf-liveness.test.tssrc/preload/api/pty-api.tssrc/preload/api/pty-bridge-session-control.tssrc/renderer/src/components/native-chat/claude-model-switch-confirmation.tssrc/renderer/src/components/native-chat/native-chat-runtime-image-send.tssrc/renderer/src/components/native-chat/native-chat-runtime-send.test.tssrc/renderer/src/components/native-chat/native-chat-runtime-send.tssrc/renderer/src/components/native-chat/use-native-chat-composer-interrupt.tssrc/renderer/src/components/native-chat/use-native-chat-interactive-send.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-interactive-send.tssrc/renderer/src/components/terminal-pane/deferred-split-pane-handoff.test.tssrc/renderer/src/components/terminal-pane/keyboard-handlers-ime-enter-keyup.test.tsxsrc/renderer/src/components/terminal-pane/pty-connection-foreground-write-path.test.tssrc/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.tssrc/renderer/src/components/terminal-pane/pty-connection-hibernation-wake.test.tssrc/renderer/src/components/terminal-pane/pty-connection-hook-completion-bell-arbitration.test.tssrc/renderer/src/components/terminal-pane/pty-connection-hook-completion-side-effects.test.tssrc/renderer/src/components/terminal-pane/pty-connection-interrupt-inference.test.tssrc/renderer/src/components/terminal-pane/pty-connection-reattach-mode-reset.test.tssrc/renderer/src/components/terminal-pane/pty-connection-replay-payload-handling.test.tssrc/renderer/src/components/terminal-pane/pty-connection-setup-split-spawn.test.tssrc/renderer/src/components/terminal-pane/pty-connection-ssh-startup-draft-delivery.test.tssrc/renderer/src/components/terminal-pane/pty-connection-startup-command-delivery.test.tssrc/renderer/src/components/terminal-pane/pty-connection-terminal-input-gating.test.tssrc/renderer/src/components/terminal-pane/pty-connection-typed-agent-identity.test.tssrc/renderer/src/components/terminal-pane/pty-connection-windows-keyboard-reset.test.tssrc/renderer/src/components/terminal-pane/pty-connection/deferred-cold-restore-and-snapshot.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-serializer-settle.tssrc/renderer/src/components/terminal-pane/pty-connection/pty-input-forward.tssrc/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.tssrc/renderer/src/components/terminal-pane/pty-input-write-queue-contract.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/pty-preconnect-input-buffer.test.tssrc/renderer/src/components/terminal-pane/pty-preconnect-input-buffer.tssrc/renderer/src/components/terminal-pane/pty-transport-input-kind-call-sites.test.tssrc/renderer/src/components/terminal-pane/pty-transport-input-write.test.tssrc/renderer/src/components/terminal-pane/pty-transport-reattach-admission.test.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport-user-input.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/renderer/src/components/terminal-pane/remote-runtime-error-surface-dismissal.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-query-reply-immediate.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-host-session-launch.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-host-surface-replacement.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-input-coalescing.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-input-fallback.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-stale-handle-recovery.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-sticky-replacement-policy.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-stream-reconnect.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.test.tssrc/renderer/src/components/terminal-pane/terminal-captured-input-dispatch.tssrc/renderer/src/components/terminal-pane/terminal-drop-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-internal-handler.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-path-writer.test.tssrc/renderer/src/components/terminal-pane/terminal-drop-path-writer.tssrc/renderer/src/components/terminal-pane/terminal-ios-hangul-preedit-coexistence.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-menu-paste.tssrc/renderer/src/components/terminal-pane/terminal-pane-paste-execution.tssrc/renderer/src/components/terminal-pane/terminal-paste-operation-order.test.tssrc/renderer/src/components/terminal-pane/terminal-programmatic-text-paste.tssrc/renderer/src/components/terminal-pane/terminal-pty-paste-writer.test.tssrc/renderer/src/components/terminal-pane/terminal-pty-paste-writer.tssrc/renderer/src/components/terminal-pane/terminal-quick-command-dispatch.test.tssrc/renderer/src/components/terminal-pane/terminal-quick-command-dispatch.tssrc/renderer/src/components/terminal-pane/terminal-startup-command-paste.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-mobile-actions.tssrc/renderer/src/lib/agent-draft-paste-content.tssrc/renderer/src/lib/agent-followup-delivery.test.tssrc/renderer/src/lib/agent-followup-delivery.tssrc/renderer/src/lib/agent-paste-draft-submit-retry.test.tssrc/renderer/src/lib/agent-paste-draft.test.tssrc/renderer/src/lib/agent-paste-draft.tssrc/renderer/src/lib/launch-agent-background-session-remote.test.tssrc/renderer/src/lib/launch-agent-background-session.tssrc/renderer/src/lib/new-workspace.test.tssrc/renderer/src/lib/startup-draft-input-kind.test.tssrc/renderer/src/runtime/runtime-terminal-inspection.test.tssrc/renderer/src/runtime/runtime-terminal-inspection.tssrc/shared/source-scan/call-argument-scan.tssrc/shared/terminal-input-kind.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| } | ||
|
|
||
| export type PtyWritePayload = { id: string; data: string } | ||
| export type PtyWritePayload = { id: string; data: string; inputKind: TerminalInputKind } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n 'isPtyWritePayload|writePtyInputAccepted|writePtyInput\b|recordInput\(' src/main/ipc/pty/ipc/write-input.ts src/main/ipc/pty/register-handlers.ts src/main/runtime/terminal-run-facts.ts
sed -n '20,80p;145,210p' src/main/ipc/pty/ipc/write-input.ts
sed -n '55,78p' src/main/runtime/terminal-run-facts.tsRepository: stablyai/orca
Length of output: 6342
🏁 Script executed:
set -eu
printf '%s\n' '--- write-input imports, predicate, and handlers ---'
sed -n '1,45p;112,190p' src/main/ipc/pty/ipc/write-input.ts
printf '%s\n' '--- IPC registrations and validation references ---'
rg -n -C 5 'createPtyWriteInput|isPtyWritePayload|writePtyInputAccepted|writePtyInput' src/main/ipc/pty
printf '%s\n' '--- TerminalInputKind declarations and consumers ---'
rg -n -C 4 'TerminalInputKind|inputKind' src/main | head -240Repository: stablyai/orca
Length of output: 40286
🏁 Script executed:
set -eu
printf '%s\n' '--- TerminalInputKind declaration ---'
sed -n '1,160p' src/shared/terminal-input-kind.ts
printf '%s\n' '--- all direct inputKind validators and payload construction ---'
rg -n -C 3 'inputKind\s*===|inputKind\s*!==|TerminalInputKind|pty:write|pty:writeAccepted' src/shared src/renderer src/main | head -320Repository: stablyai/orca
Length of output: 29779
Validate inputKind at the renderer IPC boundary.
isPtyWritePayload accepts missing and invalid inputKind values. Both IPC handlers can pass these values to recordInput. recordInput treats them as non-driving and returns, while the PTY write continues. This can omit the first-user-input provenance record.
Add a runtime check for the three allowed TerminalInputKind values.
Suggested fix
+ const isTerminalInputKind = (value: unknown): value is TerminalInputKind =>
+ value === 'driving' || value === 'launch' || value === 'query-reply'
+
const isPtyWritePayload = (value: unknown): value is PtyWritePayload =>
typeof value === 'object' &&
value !== null &&
typeof (value as { id?: unknown }).id === 'string' &&
(value as { id: string }).id.length > 0 &&
- typeof (value as { data?: unknown }).data === 'string'
+ typeof (value as { data?: unknown }).data === 'string' &&
+ isTerminalInputKind((value as { inputKind?: unknown }).inputKind)| // Why no kind: terminal.send has no launch kind, and its query-reply kind is for mobile | ||
| // clients, so the host classifies a desktop's bytes itself. |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline src/main/runtime/rpc/methods/terminal/terminal-send-method.ts --match 'terminal|send' || true
ast-grep outline src/main/runtime/terminal-run-facts.ts --match 'input|record' || true
rg -n -C 5 'inputKind|query-reply|launch|driving|terminal\.send|record.*Input' \
src/main/runtime/rpc/methods/terminal/terminal-send-method.ts \
src/main/runtime/terminal-run-facts.ts \
src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts \
src/renderer/src/runtime/runtime-terminal-inspection.tsRepository: stablyai/orca
Length of output: 42166
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- input-kind definitions and usages ---'
rg -n -C 4 'export type TerminalInputKind|type TerminalInputKind|inputKind:|sendInput\(|sendRuntimePtyInputVerified|sendRuntimePtyInput\(' \
src/shared src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts \
src/renderer/src/runtime/runtime-terminal-inspection.ts \
src/main/runtime/rpc/methods/terminal/terminal-send-method.ts \
src/main/runtime/terminal-run-facts.ts
printf '%s\n' '--- transport write and startup sections ---'
sed -n '1360,1490p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
sed -n '2540,2645p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
printf '%s\n' '--- host send handler and run facts ---'
sed -n '20,270p' src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
sed -n '1,125p' src/main/runtime/terminal-run-facts.ts
printf '%s\n' '--- runtime inspection write path ---'
sed -n '210,330p' src/renderer/src/runtime/runtime-terminal-inspection.tsRepository: stablyai/orca
Length of output: 36109
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- all transport sendInput declarations and calls ---'
rg -n -C 6 'sendInput(?:Immediate|Accepted)?\b|sendRuntimePtyInput(?:Verified)?\b|inputKind\s*===\s*['\"'\"']launch['\"'\"']|inputKind\s*:\s*['\"'\"']launch['\"'\"']' \
src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts \
src/renderer/src/runtime src/renderer/src/components \
src/shared src/main/runtime
printf '%s\n' '--- launch references near transport write flow ---'
rg -n -C 10 'launch|startup|draft|sendInput' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts | tail -n 260
printf '%s\n' '--- transport type/factory and callback declarations ---'
sed -n '1,220p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tsRepository: stablyai/orca
Length of output: 45666
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- launch input call sites ---'
rg -n -C 8 "inputKind\s*:\s*['\"]launch['\"]|,\s*['\"]launch['\"]\s*\)|sendRuntimePtyInputVerified|sendRuntimePtyInput\(" \
src/renderer/src --glob '*.ts' --glob '*.tsx'
printf '%s\n' '--- remote transport factory option types and startup send references ---'
rg -n -C 8 "startupCommandDelivery|launchDraft|resolvedLaunchDraft|createRemoteRuntimePtyTransport|PtyTransportOptions" \
src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts \
src/renderer/src/components/terminal-pane/pty-transport-types.ts \
src/renderer/src --glob '*.ts' --glob '*.tsx' | head -n 500Repository: stablyai/orca
Length of output: 42320
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- launch caller ---'
fd -i 'agent-followup-delivery.ts' 'launch-agent-background-session.ts' src
for f in $(fd -i 'agent-followup-delivery.ts' 'launch-agent-background-session.ts' src); do
echo "--- $f ---"
rg -n -C 12 'sendRuntimePtyInputVerified|window\.api\.pty\.write|launch' "$f"
done
printf '%s\n' '--- host runtime write and fact-record binding ---'
rg -n -C 8 'recordInput\(|runFacts|TerminalRunFactsRegister|inputKind' \
src/main/runtime --glob '*.ts' | head -n 500Repository: stablyai/orca
Length of output: 41429
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -C 10 'resolvedLaunchDraft|TerminalSend|inputKind' \
src/shared/rpc-contract/terminal-unary-params.ts \
src/main/runtime/rpc/methods/terminal/terminal-send-method.ts \
src/main/runtime src/renderer/src/runtime/runtime-terminal-inspection.ts \
--glob '*.ts' | head -n 700Repository: stablyai/orca
Length of output: 42323
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -C 10 'firstUserInputAt' src/main --glob '*.ts' | head -n 300Repository: stablyai/orca
Length of output: 25828
Preserve 'launch' for remote terminal writes.
The remote terminal.send path drops 'launch' and the host classifies the write as 'driving'. This can set firstUserInputAt for startup text. Extend the remote contract to preserve 'launch'; keep ordinary desktop input as 'driving'.
Suggested fix
--- a/src/shared/rpc-contract/terminal-unary-params.ts
+++ b/src/shared/rpc-contract/terminal-unary-params.ts
@@
- inputKind: z.enum(['query-reply']).optional(),
+ inputKind: z.enum(['launch', 'query-reply']).optional(),--- a/src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
+++ b/src/main/runtime/rpc/methods/terminal/terminal-send-method.ts
@@
- inputKind: params.inputKind === 'query-reply' ? 'query-reply' : 'driving',
+ inputKind: params.inputKind ?? 'driving',--- a/src/renderer/src/runtime/runtime-terminal-inspection.ts
+++ b/src/renderer/src/runtime/runtime-terminal-inspection.ts
@@
- { terminal, text: data, client: DESKTOP_RUNTIME_CLIENT },
+ {
+ terminal,
+ text: data,
+ client: DESKTOP_RUNTIME_CLIENT,
+ ...(inputKind === 'launch' ? { inputKind } : {})
+ },
@@
- { terminal, text: data, client: DESKTOP_RUNTIME_CLIENT },
+ {
+ terminal,
+ text: data,
+ client: DESKTOP_RUNTIME_CLIENT,
+ ...(inputKind === 'launch' ? { inputKind } : {})
+ },There was a problem hiding this comment.
ℹ️ No new issues in the delta — the
TerminalInputKindrefactor holds up. One informational note below about paired-host writes, for the follow-up.
Reviewed changes
- Replaced the
userInputflag with a typed kind. A sharedTerminalInputKind('driving' | 'launch' | 'query-reply') now names the kind at every host write entry point — thepty:write/pty:writeAcceptedpreload and IPC boundary,PtyTransport.sendInput, the runtime controllerwrite/writeWithSettlement,RuntimeTerminalWriter,sendTerminal,sendTerminalAgentPrompt, and the plugin/tmux/worker delegates. - One record point.
TerminalRunFactsRegister.recordInputis called from both write funnels (ipc/pty/runtime/operations.tsandipc/pty/ipc/write-input.ts) and owns both the kind check and the payload check (whole query reply, or only focus reports).withUserInputTag,recordUserInput, and thePtyInputOptionstag were deleted. - Launch writes no longer count as user input. Worktree startup drafts, startup follow-ups, and the agent launch prompt now write
'launch'; a dispatched agent prompt writes'driving'; query replies write'query-reply'. The write queue refuses to coalesce across kinds, and the preconnect buffer and deferred-split handoff preserve the kind across a remount. - Tests. New
findCallsMissingArgumentscanner plus ratchets that fail if any@ts-nocheck/any-bag write site omits its kind, and focused tests for the single record point, the startup-draft kind on both renderer routes, and the preconnect kind handoff. The renderer connection suites that assert'query-reply'are pinning the unclassified branch (the harness never emits xterm'sonUserInput); the realdrivingpath is exercised bypty-transport-user-input.test.tsand the IME provenance suite, so that split is intentional, not a gap.
ℹ️ Paired-host terminal writes cannot mark launch input
A desktop client driving a terminal on a paired remote runtime crosses terminal.send, whose schema carries only inputKind: 'query-reply'. The remote transport drops the kind, so the host labels the write 'driving' and classifies it by bytes. A create-time draft or startup command delivered to a paired-host pane therefore still sets firstUserInputAt, even though the local and SSH-provider paths now mark the same bytes 'launch'. The added comments in runtime-terminal-inspection.ts and remote-runtime-pty-transport.ts acknowledge the classification-by-bytes rule, but not this consequence for the run-facts consumer.
Mergeable as-is — no current reader uses the facts yet. Worth deciding before the tab-membership follow-up ships, since a pane that only received Orca's own startup writes would otherwise look user-driven on a paired host.
Technical details
# Paired-host writes lose the launch kind
## Affected sites
- `src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts:2583` — `sendInput(data: string)` takes no kind and ignores the one passed by callers.
- `src/renderer/src/runtime/runtime-terminal-inspection.ts:242-244` — `sendRuntimePtyInputWithinLimit`/`sendRuntimePtyInputVerified` send `terminal.send` without `inputKind` when the target is an environment.
- `src/shared/rpc-contract/terminal-unary-params.ts:118` — `inputKind: z.enum(['query-reply']).optional()`, so the wire has no `launch`.
- `src/main/runtime/rpc/methods/terminal/terminal-send-method.ts:239` — host maps anything but `query-reply` to `'driving'`.
- `src/main/runtime/terminal-run-facts.ts:65-73` — `recordInput` then records by payload, so a non-reply launch byte is counted.
## Required outcome
- Decide whether a paired-host startup/draft write should be distinguishable from a person's input by the run-facts consumer. Either extend the wire (capability-negotiated) or have the consumer tolerate it.
## Open questions for the human
- Is the paired-host case expected to keep tab-membership parity with the local/SSH-provider paths, or is classifying by bytes acceptable for that transport?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues in the new commit.
Reviewed changes
- Renderer kind enforcement moved to the compiler.
ConnectPanePtySession.transportis now typedPtyTransport(the bag keeps its[key: string]: any), sosession.transport.sendInput(...)requires a kind at compile time;pty-transport-input-kind-call-sites.test.tswas deleted as redundant. - Main-process scan widened. The receiver regex accepts a local
controller/Controlleralias, the@ts-nocheckfilter matches on any line (picking uporca-runtime-sync-window-graph.ts, which opens with a lint directive), and a planted case covers aconst controller = this.ptyController; controller.write(...)site.
No production behavior change; the @ts-nocheck ratchet and the compiler now split the coverage cleanly, and the previously skipped directive-on-line-2 files are scanned.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…-run-facts # Conflicts: # src/main/ipc/pty/ipc/spawn-commit-persist.ts # src/main/ipc/pty/runtime/controller-deps.ts # src/main/runtime/orca-runtime-on-pty-exit.ts
…ing save succeeds The runtime spawn funnel reported the commit before its host-session binding save, so a spawn discarded for a failed save still recorded run facts and cleared a landed stop. Report it after the save, and separately on the adopted return, which makes no save. Also align tests and fixtures with main: the removed stop-owner map, required write input kinds, SQLite-backed stores and async binding saves.
The merge moved the renderer funnel's spawn-commit report into the publish step, after the binding save, but no test covered it: deleting the call or moving it back before the save left every suite green. Cover both: a committed spawn records its run facts and supersedes an unpinned landed stop, and a spawn discarded for a failed binding save records nothing and leaves the stop.
There was a problem hiding this comment.
✅ No new issues found — the runtime spawn funnel now reports its commit only after the binding save succeeds, with a test that fails under the prior ordering.
Reviewed changes
- Report the runtime spawn commit after its binding save.
commitRuntimePtySpawnno longer callsnoteTerminalSpawnCommitbefore the host-session binding write, so a spawn discarded for a failed save can no longer record run facts or retire a landed intentional stop. The adopted branch keeps its own call because it returns without a save. - Cover the discarded spawn.
spawn-commit-run-facts.test.tsadds a case whose binding save rejects, asserting the run is not fresh and the'reversible'stop still claims the exit — red under the prior ordering. - Merge alignment with
main. The merge with#22612(SQLite profile state) resolved thespawn-commit-persist.tssplit by placing the IPC funnel's report inpublishPtyIpcSpawnCommit(after the save), and re-aligned the affected tests and fixtures with the removed stop-owner map, the required write input kinds, and async binding saves.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…tion succeeds The runtime funnel reported each commit before registering the process, so a spawn that exited during start still recorded run facts and could end a landed stop, while the renderer funnel reports only after registration. Report after registration on both the ordinary and the adopted branch, so only a committed, registered run has facts and an unknown run keeps reading as not fresh.
There was a problem hiding this comment.
✅ No new issues found — the runtime spawn funnel's commit report now lands after registration, with tests that fail under the prior ordering.
Reviewed changes
- Report the runtime spawn commit after registration.
commitRuntimePtySpawnnow callsnoteTerminalSpawnCommitonly onceregisterPersistedPtySpawnhas resolved, on the ordinary branch (spawn-commit.ts:197) and on the adopted branch (spawn-commit.ts:96, previously before registration). A spawn rejected for exiting during start no longer records run facts or retires a landed intentional stop, matching the renderer funnel. Every successful path still reports exactly once, sinceregisterPersistedPtySpawneither resolves or throws. - Pin the rejected-start case.
spawn-commit-run-facts.test.tsadds a case parametrized over the new-process and adoption shapes, asserting the run is not fresh and the'reversible'stop still claims the exit — red under the prior ordering. - Broaden the landed-stop supersede test. The existing "a committed spawn supersedes a landed stop" case now runs over both spawn shapes.
The one open prior thread (exit.ts:157, the claimExit incarnation mismatch) is untouched by these commits and remains open; approval is withheld on that basis.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Review statusReady for review. Head What review changed
Live QA (a separate macOS machine, isolated profiles, identical starting state for each arm)
Known, pre-existing, fixed separately
Checks
Scope note: the diff is large (about 170 files) because the required input kind is threaded through every PTY writer and its test expectations. Production code is about +400 net lines; the rest is tests. |
…-run-facts # Conflicts: # src/main/ipc/pty-ssh-undelivered-kill.test.ts # src/main/runtime/runtime-pty-controller-contract.ts
… the intentional-stop registry
There was a problem hiding this comment.
✅ No new issues found — the merged explicit-close hook now reads reversibility from the intentional-stop register, with tests that pin both the destructive and reversible cases.
Reviewed changes
- Rebased the merged explicit-close hook onto the new register. The merge of
main(#22929, every explicit terminal close commits through one main transaction) addedPtyRuntimeController.recordUnconfirmedStop, whose first cut readdeps.reversibleStopOwnersByPtyId— a map this PR deletes. Commite664c0267brewires it toruntime?.intentionalPtyStops?.isReversibleStopInFlight(ptyId) ?? false, matching the existing read inipc/pty/runtime/kill.ts:33. The check is equivalent to main'sreversibleStopOwnersByPtyId.has: both are true only while a reversible owner is in flight, andruntimeis always defined when the controller is installed (runtime?.setPtyControllerguards it), so the?? falsedefault is unreachable in production. - Covered both outcomes.
pty-ssh-undelivered-kill.test.tsrecords an explicit close's unconfirmed SSH stop and reportsfalse(no replay order) for a local PTY and for one with a reversible stop in flight; the reversible case fails if that hook ever treats the stop as destructible.
The one open prior thread (exit.ts:157, the claimExit incarnation-mismatch guard) is untouched by these commits and remains open; approval is withheld on that basis.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…-run-facts # Conflicts: # src/main/runtime/orca-runtime-runtime-id.ts
There was a problem hiding this comment.
✅ No new issues found — the merge of
origin/mainresolves its one conflict correctly and leaves the branch's mechanism untouched.
Reviewed changes
- Merged
origin/maininto the branch (commit65e6d78ade). The branch's own mechanism files are byte-identical to the last reviewed heade664c0267b; the merge's only conflict wasorca-runtime-runtime-id.ts. - Kept both sides of that conflict. Main's new
tuiIdleEvidenceSourceobject (from its tui-idle refactor, also read by the neworca-runtime-resolve-exit-waiters.ts) is preserved and spread intoterminalIdlePollsandterminalWait, alongside the branch'sintentionalPtyStops,terminalRunFacts,noteTerminalSpawnCommit, and theterminalWriterinput kind. Main'sintentionalHandlelessPtyStopsstays deleted; a repo-wide grep finds none of the marker names this PR removed.
The one open prior thread (exit.ts:157, the claimExit incarnation-mismatch guard) is untouched by the merge; approval is withheld on that basis.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Sometimes Orca stops a terminal's process on purpose: when you put a worktree to sleep, when a finished agent pane is hibernated, or when Codex restarts after an account switch. The tab is meant to stay, so the process can be woken up or replaced.
On main, the code that reacts to a process ending could not tell those stops apart from a process dying on its own. So when you put a worktree to sleep, Orca deleted its terminal tab from the saved session. After a restart the tab was gone, and waking the worktree opened a brand-new terminal with the old output lost.
This PR keeps one list of stops Orca made on purpose, and every place that reacts to a process ending reads it. A slept tab now survives a restart and wakes with its output.
It also has Orca record two facts about each run of a terminal's process: whether the process was freshly started for its pane, and when input first drove it. The next PR in this series uses them to decide what happens to a tab when its process exits (see "Why the run facts ship first" below).
What Changed
Before (what the user saw): sleep a worktree, quit Orca, reopen it: the terminal tab is gone and the pane is blank. Waking the worktree creates a new tab with a new shell and none of the old output. Hibernating a finished agent pane and a Codex account restart went through the same exit handling, and also removed the pane from the saved session and from what paired devices (phone, web) see.
After: the saved tab, its link to its terminal process, and the identity of that process run all survive the sleep. After a restart Orca restores the same tab and terminal with its output, and the shell works.
Terms used below:
Mechanism 1: one list of intentional stops (
src/main/runtime/terminal-intentional-stops.ts)reversible(sleep, hibernation; the binding is how the pane wakes) andreplaced(a restart hands the pane to a new process). Owners are counted per kind, so if a sleep and a restart stop the same process, its exit carries both labels. A stop that fails removes only its own kind.markReplacedPtyStop/replacedPtyStopsById,markReversibleStops/reversibleStopOwnersByPtyId(session, controller and controller contract), and the runtime'sintentionalHandlelessPtyStops.Mechanism 2: per-run facts (
src/main/runtime/terminal-run-facts.ts, kept in memory per process run, pruned with the runtime's record of the terminal)TerminalInputKind(src/shared/terminal-input-kind.ts):driving: input that drives the run: keystrokes (including IME and Hangul composition, which xterm reports as user input), paste, drop, quick commands, captured keys, native chat sends,terminal.sendand streamed input from any client, typing in the dashboard preview, orchestration dispatch, mailbox pointers, plugins and agent teams;launch: bytes Orca writes to start the run: startup and restored commands, the command a restore re-runs, the SSH background launch command, a worktree-create draft and follow-up, and theagent launchprompt;query-reply: the terminal's automatic answers to the running program (xterm's replies and focus reports, capability replies, headless replies, the focus-in replayed on reattach).drivinginput at one place, which both write paths (desktop and runtime) call just before the write reaches the process. It is recorded before the write because input such asexitcan end the process before the write returns. A payload that is only a terminal reply or only focus reports never counts, whatever its label.@ts-nocheck) are covered by a source-scan test that fails on any terminal write there without a kind. The one unavoidable default is input arriving over the network from a client that sends no kind: it counts, unless the payload is only a reply or focus reports.Why
Why one list. Four separate "stopped on purpose" markers each answered the same question for one caller, and the exit handler asked only one of them. That is why sleep, hibernation and the Codex restart all lost the tab. With one list that every exit path reads, a new kind of stop cannot be forgotten by a reader.
Why a required input kind. An optional "user input" flag had opposite defaults on different write paths, so any writer nobody classified silently took whichever default its path had. Review found three such misses in a row: focus reports from paired devices, typing in the dashboard preview, and a create-time draft tagged on one path but not on its twin in main. A required kind turns an unclassified writer into a compile error instead of a silent default. Where a default cannot be avoided it counts the input, which errs toward today's behaviour (the tab closes on exit) rather than wrongly keeping a tab someone typed into.
Why the run facts ship first, before anything reads them. The next PR in this series has main decide, at the moment a process exits, whether its tab stays or closes. It keeps a tab whose process was freshly started and never received input, and closes the rest. That rule is only as good as its facts, and they have to be recorded by every writer from the moment each process starts; a reader added later cannot recover them for runs already in progress. Threading the input kind through every writer is most of this diff. Landing the facts now, where they change no behaviour of their own, keeps the next PR's actual behaviour change small enough to review on its own. Until then a mislabelled write has no effect, because nothing reads the facts.
Why entries are not deleted when an exit reads them. "Delete on first read" breaks even a single hibernation, because the exit handler and the desktop window both read that exit. It also misreads the process's own late exit after the one Orca reported itself. Tests prove both.
Why launch bytes do not count as input. A prompt passed at launch is the start command, the same fact as a prompt passed on the command line, which never counts. The next PR's rule asks whether anything drove the run after it started.
Why the facts are per process run and kept in memory. A terminal's id can outlive its process (restart, wake, reattach). The next PR needs facts about the process that exited, not about the id, and nothing about a run is useful after the app restarts.
Differences from the common pattern
Linked Issue
No tracking issue. This is the run-facts step of the terminal tab membership series; it is independent of #22929 and targets main.
Visual Proof
Live on a separate macOS machine, isolated profiles, identical starting state. Open a terminal,
echoa marker, Sleep the worktree from the sidebar menu, quit Orca, relaunch, click the worktree.Testing
New tests (each proved red by deleting its core line, then restored):
terminal.send, stream input, dispatch, mailbox pointers and preview typing are recorded before the write; a launched run stays untyped until a driving write; a create-time draft and follow-up leave the run untyped, and the renderer and main routes for the same draft agree; wire replies, reply-only and focus-report-only payloads are not recorded; a reply mixed with a keystroke is.@ts-nocheckruntime file.Suites: typecheck (node, web and CLI), full-repo oxlint, the changed-code quality gate and React Doctor are clean. The main runtime, PTY IPC, plugin, cross-version wire and renderer terminal-pane suites pass; the only failures seen were timeouts under machine load in files this PR does not touch, which pass when run alone. CI is green.
AI Disclosure
Implemented with Claude (Opus) coding agents under Brennan's direction. Reviewed through seven independent AI review loops plus an architecture challenge, with live Electron QA of main against this PR on a separate machine.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
inputKind: 'query-reply'was already on theterminal.sendwire, and input from an older client goes through the same reply check.drivingwrite only until the run's first input is recorded. The reply check stops running once it is recorded.Author X handle: @BrennanKB5
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)