Repository navigation
Conversation
|
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:
📝 WalkthroughWalkthroughThe runtime now scopes active coordinator-run attribution to the worktree associated with the current terminal handle. It resolves worktree metadata from live PTY records or stored handle metadata, rejects unknown or cross-runtime handles, and uses the scoped run for parent, coordinator, and orchestration fields. Tests cover cross-worktree attribution and coordinator race authority. The reliability gate adds creator and Run-generation fencing and indexed retained-Run performance coverage. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)
27168-27201: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winWorktree-scoping fix looks correct; consider using
runtimeWorktreeIdsEqualfor the comparison.The gating logic itself is sound:
scopedActiveRunis only used whengetWorktreeIdForTerminalHandle(handle)andgetWorktreeIdForTerminalHandle(activeRun.coordinator_handle)resolve to the same worktree, and it safely falls back to no attribution when either side is unresolvable. However, this compares two worktree-id strings with strict===, while the rest of the file consistently normalizes such comparisons throughruntimeWorktreeIdsEqual(e.g. inrecordPtyWorktree,getSummaryForRuntimeWorktreeId) to tolerate path-representation differences across sources (PTY-derived vs handle-record-derived ids). If the two handles' worktree ids ever differ only in representation, this would silently drop a legitimate attribution instead of scoping it correctly.♻️ Suggested fix
- const scopedActiveRun = - activeRun && - handleWorktreeId && - this.getWorktreeIdForTerminalHandle(activeRun.coordinator_handle) === handleWorktreeId - ? activeRun - : undefined + const scopedActiveRun = + activeRun && + handleWorktreeId && + runtimeWorktreeIdsEqual( + this.getWorktreeIdForTerminalHandle(activeRun.coordinator_handle) ?? '', + handleWorktreeId + ) + ? activeRun + : undefined
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d68f99de-8719-44d5-a1f0-e12b194d214e
📥 Commits
Reviewing files that changed from the base of the PR and between 0404f27 and ea7b730f5553301eb310e1df55a341b4c592aa7e.
📒 Files selected for processing (2)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.ts
Greptile SummaryThis PR fixes a cross-worktree misattribution bug where an agent from one session's orchestration flow would incorrectly appear nested under a different session's card in the Projects sidebar. The root cause was
Confidence Score: 5/5Safe to merge — the change is a narrow, well-scoped fix that only tightens the fallback attribution logic without touching the primary The new Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/runtime/orca-runtime.ts | Adds getWorktreeIdForTerminalHandle() and scopedActiveRun guard; logic is correct, null-safe, and consistent with the existing getPaneKeyForTerminalHandle pattern. |
| src/main/runtime/orca-runtime.test.ts | Adds a focused regression test for the cross-worktree misattribution scenario; test setup and assertion are correct and directly target the fixed code path. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[getAgentStatusOrchestrationContextForHandle] --> B{dispatch found?}
B -- No --> Z[return undefined]
B -- Yes --> C{dispatch completed?}
C -- Yes --> D[activeRun = undefined]
C -- No --> E[activeRun = db.getActiveCoordinatorRun]
D --> F[handleWorktreeId = getWorktreeIdForTerminalHandle]
E --> F
F --> G[coordinatorWorktreeId = getWorktreeIdForTerminalHandle coordinator]
G --> H{handleWorktreeId AND coordinatorWorktreeId AND same worktree?}
H -- Yes --> I[scopedActiveRun = activeRun]
H -- No --> J[scopedActiveRun = undefined]
I --> K{task.created_by_terminal_handle?}
J --> K
K -- Present --> L[parentTerminalHandle = task.created_by_terminal_handle]
K -- Absent --> M{scopedActiveRun.coordinator_handle != handle?}
M -- Yes --> N[parentTerminalHandle = scopedActiveRun.coordinator_handle]
M -- No --> O[parentTerminalHandle = undefined]
L --> P[Return orchestration context]
N --> P
O --> P
Reviews (2): Last reviewed commit: "refactor(orchestration): drop redundant ..." | Re-trigger Greptile
502a714 to
94cb0d6
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
config/reliability-gates.jsonc (1)
6460-6476: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd evidence for the newly declared creator-authority command and assertions.
This change adds a new command and test file (
orchestration-creator-authority-performance.test.ts), a newassertionRefsblock for it, and two new assertions in the existingorca-runtime.test.tsblock ("retained renderer output remains readable through the recovered terminal" and "a creator pane and process reminted into Run B cannot parent its retained Run A worker"). Updateinvariant,oracle, andperformanceBudgettext to match.No entry in
evidenceRunsruns the new command or re-runsorca-runtime.test.tsto demonstrate these new assertions pass.redGreenEvidenceandknownGapsalso do not mention this addition.Every other command in this gate (and across the file) has a matching dated
evidenceRunsentry with a pass/fail result and summary. Without one here, the gate documents claimed coverage ("indexed retained-Run lookup scaling", "creator pane/process/Run-generation fencing") that has no recorded execution proof in this file.Add an
evidenceRunsentry for theorchestration-creator-authority-performance.test.tscommand, and extendredGreenEvidenceto cover the reminted creator-pane/process fencing assertion, consistent with how this file documents every other coverage claim.Also applies to: 6489-6495, 6507-6508, 6626-6626
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b03ff3d1-7cee-4a6f-81df-169fc5deb659
📥 Commits
Reviewing files that changed from the base of the PR and between bb30d7e36b82d4ee615791c782c9f2960016f3fd and 94cb0d68a40887be2af3734a96258ed9e0bbb806.
📒 Files selected for processing (1)
config/reliability-gates.jsonc
PR #11203 terminal dispositionDispositionApproved and left open. The validated candidate was pushed to the existing contributor branch; no Exact topology
Base-advance gateFetching The terminal head adds only two CI corrections after the verified candidate: Final status is clean except for the intentionally untracked workspace evidence directory. The Push leases
Security and workflow auditThe candidate changes no workflows, local actions, scripts, package manifests, lockfiles, file Fork workflow runs Validation and CI
Review state and remaining gapsThe sole review thread was already resolved and remains genuinely satisfied; there are zero Next action: repository maintainer owns the normal merge decision; this review owner must not merge. |
OrcaWin
left a comment
There was a problem hiding this comment.
Reviewed and validated at d2d765181f6305287b4b4743abf1d74ea33b78d4. Base gate, security/workflow audit, exact-lease push, proportional local validation, and terminal CI are green; no unresolved threads remain.
d2d7651 to
0921a84
Compare
0921a84 to
20b256a
Compare
… worktree getAgentStatusOrchestrationContextForHandle fell back to the app-wide getActiveCoordinatorRun() (an unscoped "most recently started" query over coordinator_runs) whenever a task lacked created_by_terminal_handle. With two orchestration sessions running in different worktrees at once, this attributed one worktree's dispatch to another worktree's coordinator, making agents from one session render nested under an unrelated session in the sidebar. Only trust the active run when its coordinator terminal lives in the same worktree as the handle being resolved. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…or scope Compare with the file's existing runtimeWorktreeIdsEqual instead of === so PTY-derived vs handle-record-derived worktree ids that differ only in path representation (e.g. across SSH/Windows) still match, instead of silently dropping a legitimate parent attribution. Addresses CodeRabbit review feedback on stablyai#11203. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
TerminalHandleRecord.worktreeId is typed string, so the `?? null` guard in getWorktreeIdForTerminalHandle could never activate. Addresses Greptile review feedback on stablyai#11203. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
20b256a to
daa4a1d
Compare
…h guard #11203 taught pane lookup to recover a reminted tab id by leaf id, so the old fixture (new tab id, live leaf id) resolved and bumped the snapshot a second time once this branch merged with main. Co-authored-by: Orca <help@stably.ai>
…s on a paired headless server (#12223) * fix(native-chat): show Claude's AskUserQuestion card when the agent runs on a paired headless host Three gaps kept the question card off the desktop when the agent ran on a remote `orca serve` host: - The `session.tabs` projection reduced HTTP agent-hook rows to identity only, hard-coding `state: 'done'` and an empty prompt, so `toolName` and the full `interactivePrompt` never left the host. It now publishes the newest fresh hook row's status fields, bounded by the same staleness window `agentType` uses, excluding `providerSessionOnly` resume rows, and yielding to live title evidence unless a question is actually pending. - Nothing republished `session.tabs` when only a hook row changed, and the re-emit carried an unchanged `snapshotVersion` that clients drop on their monotonic gate. Material hook transitions and pane/SSH status clears now bump the version and schedule a coalesced emit. - The desktop card resolved only from live status. It now falls back to the pending ask in the transcript, matching mobile, so a relay gap can no longer leave the composer mounted over a pane parked on a selector. Closes #11761 Co-authored-by: Orca <help@stably.ai> * fix(native-chat): date the hook-row recency guard against a real clock `resolveHookLiveAgentRow` compared a hook `receivedAt` (epoch ms) against title stamps that are title-observation sequence numbers, so the guard could never fire — any fresh hook row overrode live title-derived state, and a manual rename (the one epoch writer) inverted it. Stamp the live OSC title path with wall-clock ms and compare against that alone. The regression test fabricated epoch-valued title stamps production never writes; it now drives the title through `onPtyData`, and a new case pins the opposite direction (hook row newer than the title wins). Co-authored-by: Orca <help@stably.ai> * fix(native-chat): stop an orphaned tool call from pinning a dead question card extractPendingAsk pairs tool results to calls by a global FIFO (tool_use_id is dropped at decode time), so one call that never gets a result desyncs the queue for the rest of the transcript and strands an answered ask as pending. Real transcripts also hold asks the user escaped and typed past. On desktop that card replaces the composer, so the pane became unsendable. Drop in-flight calls at a turn boundary — a user turn or the decoders' interrupt row — since the turn that owned them is over. Claude's tool-result turns decode as role 'tool', so normal FIFO resolution is untouched. Co-authored-by: Orca <help@stably.ai> * refactor(native-chat): trim the headless AskUserQuestion projection Reuse rather than restate: the invalidator now takes the shared `AgentHookEventPayload` instead of a locally redeclared row shape, and the hook live row is a `Pick<>` of the retained OSC snapshot so one projection branch consumes either carrier. Fold the immediate/coalesced session-tabs emit into one method (also drops a redundant re-emit on the provider-session push). Drop card tests that re-route shared-parser assertions through React. Isolate pane-status-clear subscribers and prove the no-republish case by version arithmetic instead of a timed silence. Co-authored-by: Orca <help@stably.ai> * test(native-chat): pin the AskUserQuestion card render under real Electron Why: the 13 parser unit tests pin extraction, but nothing proved a card actually renders where an inert tool call used to. This spec reproduces the paired-headless topology from the client side — live status carrying agent identity and state 'working' but no interactivePrompt/toolName, with the pending ask present only in the transcript — and fails on main. Refs #11761 Co-authored-by: Orca <help@stably.ai> * test(native-chat): drop the unused testInfo parameter Why: oxlint no-unused-vars fails the lint gate on an unused test parameter. Co-authored-by: Orca <help@stably.ai> * test(native-chat): drop leftover proof scaffolding from the ask-card spec The env-var screenshot label and the fixed 2s settle only existed to make the pre-fix capture comparable; the card assertion already waits. Co-authored-by: Orca <help@stably.ai> * test(runtime): use a truly unresolvable pane key in the hook republish guard #11203 taught pane lookup to recover a reminted tab id by leaf id, so the old fixture (new tab id, live leaf id) resolved and bumped the snapshot a second time once this branch merged with main. Co-authored-by: Orca <help@stably.ai> * fix(runtime): refuse a hydrated unconfirmed hook row as live pane status #12346 landed on main after this branch was cut: a nonterminal row restored from last-status.json is stamped `restoredUnconfirmed` because its transition may have fired while no receiver was up, and every freshness gate treats it as never-fresh. The new headless `live` projection here only checked `receivedAt`, so a restart inside the 30-minute window would republish the hydrated row — resurrecting the AskUserQuestion card with no agent left to answer it. `agentType` still reads those rows: they prove identity, just not liveness. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai> Co-authored-by: Neil <nwparker@users.noreply.github.com>
…1203) Use durable Task-to-Run ownership and current pane, process-incarnation, and Run-generation authority for sidebar agent lineage. Add schema migrations, bounded lookup indexes, fail-closed renderer cleanup, and runtime/RPC regression coverage. Co-authored-by: Jaeyoung22 <89302528+Jaeyoung22@users.noreply.github.com>
…s on a paired headless server (stablyai#12223) * fix(native-chat): show Claude's AskUserQuestion card when the agent runs on a paired headless host Three gaps kept the question card off the desktop when the agent ran on a remote `orca serve` host: - The `session.tabs` projection reduced HTTP agent-hook rows to identity only, hard-coding `state: 'done'` and an empty prompt, so `toolName` and the full `interactivePrompt` never left the host. It now publishes the newest fresh hook row's status fields, bounded by the same staleness window `agentType` uses, excluding `providerSessionOnly` resume rows, and yielding to live title evidence unless a question is actually pending. - Nothing republished `session.tabs` when only a hook row changed, and the re-emit carried an unchanged `snapshotVersion` that clients drop on their monotonic gate. Material hook transitions and pane/SSH status clears now bump the version and schedule a coalesced emit. - The desktop card resolved only from live status. It now falls back to the pending ask in the transcript, matching mobile, so a relay gap can no longer leave the composer mounted over a pane parked on a selector. Closes stablyai#11761 Co-authored-by: Orca <help@stably.ai> * fix(native-chat): date the hook-row recency guard against a real clock `resolveHookLiveAgentRow` compared a hook `receivedAt` (epoch ms) against title stamps that are title-observation sequence numbers, so the guard could never fire — any fresh hook row overrode live title-derived state, and a manual rename (the one epoch writer) inverted it. Stamp the live OSC title path with wall-clock ms and compare against that alone. The regression test fabricated epoch-valued title stamps production never writes; it now drives the title through `onPtyData`, and a new case pins the opposite direction (hook row newer than the title wins). Co-authored-by: Orca <help@stably.ai> * fix(native-chat): stop an orphaned tool call from pinning a dead question card extractPendingAsk pairs tool results to calls by a global FIFO (tool_use_id is dropped at decode time), so one call that never gets a result desyncs the queue for the rest of the transcript and strands an answered ask as pending. Real transcripts also hold asks the user escaped and typed past. On desktop that card replaces the composer, so the pane became unsendable. Drop in-flight calls at a turn boundary — a user turn or the decoders' interrupt row — since the turn that owned them is over. Claude's tool-result turns decode as role 'tool', so normal FIFO resolution is untouched. Co-authored-by: Orca <help@stably.ai> * refactor(native-chat): trim the headless AskUserQuestion projection Reuse rather than restate: the invalidator now takes the shared `AgentHookEventPayload` instead of a locally redeclared row shape, and the hook live row is a `Pick<>` of the retained OSC snapshot so one projection branch consumes either carrier. Fold the immediate/coalesced session-tabs emit into one method (also drops a redundant re-emit on the provider-session push). Drop card tests that re-route shared-parser assertions through React. Isolate pane-status-clear subscribers and prove the no-republish case by version arithmetic instead of a timed silence. Co-authored-by: Orca <help@stably.ai> * test(native-chat): pin the AskUserQuestion card render under real Electron Why: the 13 parser unit tests pin extraction, but nothing proved a card actually renders where an inert tool call used to. This spec reproduces the paired-headless topology from the client side — live status carrying agent identity and state 'working' but no interactivePrompt/toolName, with the pending ask present only in the transcript — and fails on main. Refs stablyai#11761 Co-authored-by: Orca <help@stably.ai> * test(native-chat): drop the unused testInfo parameter Why: oxlint no-unused-vars fails the lint gate on an unused test parameter. Co-authored-by: Orca <help@stably.ai> * test(native-chat): drop leftover proof scaffolding from the ask-card spec The env-var screenshot label and the fixed 2s settle only existed to make the pre-fix capture comparable; the card assertion already waits. Co-authored-by: Orca <help@stably.ai> * test(runtime): use a truly unresolvable pane key in the hook republish guard stablyai#11203 taught pane lookup to recover a reminted tab id by leaf id, so the old fixture (new tab id, live leaf id) resolved and bumped the snapshot a second time once this branch merged with main. Co-authored-by: Orca <help@stably.ai> * fix(runtime): refuse a hydrated unconfirmed hook row as live pane status stablyai#12346 landed on main after this branch was cut: a nonterminal row restored from last-status.json is stamped `restoredUnconfirmed` because its transition may have fired while no receiver was up, and every freshness gate treats it as never-fresh. The new headless `live` projection here only checked `receivedAt`, so a restart inside the 30-minute window would republish the hydrated row — resurrecting the AskUserQuestion card with no agent left to answer it. `agentType` still reads those rows: they prove identity, just not liveness. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai> Co-authored-by: Neil <nwparker@users.noreply.github.com>
Summary
Orchestration...agent row under "Status check" that actually belonged to the separate "deadcode-cleanup" session.getAgentStatusOrchestrationContextForHandle(src/main/runtime/orca-runtime.ts) falls back todb.getActiveCoordinatorRun()whenever a dispatched task'screated_by_terminal_handleis unset. That query is unscoped —SELECT * FROM coordinator_runs WHERE status = 'running' ORDER BY created_at DESC LIMIT 1— so it returns the single most-recently-started coordinator run app-wide, regardless of which worktree it belongs to.getWorktreeIdForTerminalHandle()(mirrors the existinggetPaneKeyForTerminalHandlepattern) and only use the globally-active coordinator run as a fallback parent when its coordinator terminal lives in the same worktree as the handle being resolved.task.created_by_terminal_handle, which is already correctly session-scoped when present, is untouched and still takes priority.Scope, honestly
created_by_terminal_handleis populated on essentially every task created through the current bundled CLI (it resolves a sender or throws — seeresolveCoordinatorTerminalHandleinsrc/cli/handlers/orchestration.ts), so the main realistic path to hitting the unscoped fallback today is task rows from before thecreated_by_terminal_handlecolumn existed (added via a bareALTER TABLE ... ADD COLUMNwith no backfill) — i.e. users who've been running Orca across schema versions, not "any time two orchestrations run concurrently."getActiveCoordinatorRun()itself (src/main/runtime/orchestration/db.ts) is still an unscoped "globally most recent running" query. Two coordinators running concurrently in the same worktree can still pick the wrong one of each other — that's the pre-existing, broader problem tracked in [Bug]: Multiple orchestrators in a single workspace kill each other #4389 ("Multiple orchestrators in a single workspace kill each other") and out of scope here.parentPaneKey/coordinatorHandlefrom this context are read only by sidebar/dashboard grouping and naming (agent-row-lineage-model.ts,worktree-agent-orchestration-index.ts,build-dashboard-snapshot.ts,use-agent-row-conversation-name.ts) — no dispatch, message-routing, or hibernation logic depends on it.Net: a small, safe, regression-tested UI-correctness fix for a bug that's confirmed to happen in practice, not a full fix for cross-session orchestration attribution.
Repro
The "Status check" session shows an
Orchestration...agent row nested under it, even though that agent actually belongs to the separatedeadcode-cleanupsession (visible right below it):Test plan
does not attribute a dispatch to an active coordinator run from a different worktree) — confirmed it fails without the fix and passes with it.npx vitest run src/main/runtime/orca-runtime.test.ts— 1012/1013 passing (1 pre-existing skip), after merging up to currentmain.pnpm typecheckandoxlintclean on touched files.getActiveCoordinatorRun()(worker-escalation routing, worktree-lineage capture) with the same unscoped-singleton risk — left out of this PR since they're separable and not introduced/worsened here.No visual/UI change beyond agents now nesting under the correct session card in the sidebar.
Cross-platform / SSH / remote: this is a main-process orchestration-state fix with no OS-specific or transport-specific code paths; behavior is identical on macOS/Linux/Windows and local/SSH/remote worktrees.
🤖 Generated with Claude Code