Repository navigation
Conversation
Greptile SummaryThe PR prevents settled-but-unreleased orchestration workers from automatically resuming their provider sessions and carries that fence through recovery, persistence, renderer state recapture, and retirement.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/main/runtime/orca-runtime.ts | Applies settled-worker fences before recovery and retires persisted and renderer fences when dispatch ownership ends. |
| src/main/runtime/orchestration/db/worker-dispatch/worker-terminal-recovery.ts | Keeps settled workers with owned, unreleased terminal resources in the recovery query. |
| src/main/runtime/orchestration/orchestration-legacy-worker-terminal-recovery.ts | Distinguishes settled blocked panes from live terminal-recovery candidates. |
| src/main/runtime/rpc/methods/orchestration.ts | Triggers resume-fence reconciliation immediately after lifecycle messages settle a worker. |
| src/renderer/src/hooks/ipc-events/agent-status-listeners.ts | Applies fence updates only to sleeping records matching both pane and worktree identity. |
| src/renderer/src/store/slices/agent-status.ts | Preserves the automatic-resume fence when the same provider session record is recaptured. |
| src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts | Clears exact provider-session recovery duplicates when an authoritative agent exit is observed. |
| tests/e2e/completed-worker-retirement-resume.spec.ts | Aligns the checkpoint with the settled done state and waits for terminal startup restoration before activation assertions. |
Sequence Diagram
sequenceDiagram
participant W as Worker
participant O as Orchestration DB
participant R as Main Runtime
participant UI as Renderer Store
participant P as Provider Session
W->>O: Report worker_done
O->>O: Commit settled dispatch
R->>O: Plan terminal recovery
O-->>R: Settled, owned terminal row
R->>UI: fenced(paneKey, worktreeId)
UI->>UI: Preserve automatic-resume block
UI--xP: Suppress cold auto-resume
R->>O: Observe release, retain, or retirement
O-->>R: Terminal row no longer active
R->>UI: unfenced(paneKey, worktreeId)
UI->>UI: Retire automatic-resume block
Reviews (6): Last reviewed commit: "test(orchestration): port settled-worker..." | Re-trigger Greptile
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between a0efa6abc8e3eff720aba810423e342c074b5b16 and 3728d6c. 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change adds settled-worker terminal recovery rows and tracks whether blocked panes are settled. Runtime lifecycle reconciliation now prepares recovery and emits Merge Risk: 🔵 Low · up to This change prevents settled workers from automatically resuming and strengthens recovery identity checks, but the fence can be published before its state is durably stored and an early event may be missed during UI hydration. A restart or hydration race could therefore allow an affected settled session to resume unexpectedly; the PR is mergeable with explicit owner awareness and follow-up on durable fence ordering and reconciliation. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description clearly explains the change, rationale, scope, trade-offs, performance impact, and validation results. However, it omits the required Linked Issue, Visual Proof or an explicit N/A explanation, Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. Resolution Add a linked issue after ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4cbb5134-5474-49a9-a53e-d5b0240f40ba
📥 Commits
Reviewing files that changed from the base of the PR and between ba5f334 and 2912a5334deda09f5db70e82ebdf5180f1afeb57.
📒 Files selected for processing (18)
src/main/runtime/orca-runtime.tssrc/main/runtime/orchestration/db/worker-dispatch/worker-terminal-recovery.tssrc/main/runtime/orchestration/orchestration-legacy-worker-terminal-recovery.test.tssrc/main/runtime/orchestration/orchestration-legacy-worker-terminal-recovery.tssrc/main/runtime/orchestration/orchestration-settled-worker-resume-fence-db.test.tssrc/main/runtime/rpc/methods/orchestration-settlement-resume-fence.test.tssrc/main/runtime/rpc/methods/orchestration.tssrc/main/runtime/rpc/orchestration-legacy-lifecycle.tssrc/main/window/runtime-window-lifecycle.tssrc/preload/api/agent-status-api.tssrc/preload/index.tssrc/renderer/src/hooks/ipc-events/agent-status-listeners.tssrc/renderer/src/hooks/legacy-worker-terminal-recovery-event.test.tssrc/renderer/src/hooks/legacy-worker-terminal-recovery-event.tssrc/renderer/src/store/slices/agent-status.tssrc/shared/agent-status-types.tssrc/shared/worktree/id.tstests/e2e/completed-worker-retirement-resume.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one coverage observation and two nits.
Reviewed changes
- Settlement-triggered fence —
orchestration.sendandorchestration.checknow callfenceSettledWorkerPanes→prepareLegacyWorkerTerminalRecovery()when aworker_donereconciles tocompleted/failed, and the legacy lifecycle path does the same onsettled. - Settled-but-unreleased recovery rows —
listLegacyWorkerTerminalRecoveryRowskeepsWORKER_SETTLED_STATESdispatches whose terminal resource is stillownedand notreleased/retained, sorelease_unknownresources stay recoverable. - Settled panes fenced, never adopted —
planLegacyWorkerTerminalRecoverytags blocked panes withsettledand skips settled rows as adoption candidates. - Renderer fence lift — new
fenced/unfencedresolutions carry aworktreeId; the listener verifies identity before applyingset-automatic-resume-block, andsleepingRecordFromEntrynow carries the block across re-derivation. - E2E checkpoint —
completed-worker-retirement-resume.spec.tsexpects the settleddonestate.
ℹ️ Immediate fence does not cover stop/abandon settlement, and is dropped if no sleeping record exists yet
The fence is stamped by prepareLegacyWorkerTerminalRecovery() and only lands on a pane that already has a sleeping record (both the fenced notifier listener and the workspace-session write are gated on an existing record). orchestration.workerStop (settleWorkerStop → stopped) and orchestration.workerAbandon (abandonWorkerDispatch → abandoned) settle into WORKER_SETTLED_STATES but never invoke the fence trigger, so those panes stay unfenced until the next recovery pass (startup, relay-ready, or a later worker_done). This is a bounded window rather than a regression — the backstop recovery pass eventually fences — but it means a stopped worker's pane can still auto-resume during the release window, which is exactly the race this PR otherwise closes. Worth confirming whether stop/abandon are intended to be covered, or documenting that they rely on the backstop.
Technical details
# Settled stop/abandon paths do not fence at settlement
## Affected sites
- src/main/runtime/rpc/methods/orchestration-worker-stop.ts:163 — `settleWorkerStop` settles to `stopped`; no `prepareLegacyWorkerTerminalRecovery()` call.
- src/main/runtime/rpc/methods/orchestration-worker-control.ts:265 — `abandonWorkerDispatch` settles to `abandoned`; no fence trigger.
- src/main/runtime/rpc/methods/orchestration.ts:129 — `fenceSettledWorkerPanes` is only wired into `worker_done` send/check reconciliation.
## Required outcome
- Either fence stopped/abandoned workers at settlement, or confirm the next-recovery-pass backstop is the intended coverage for those states.
## Open questions for the human
- Is a stopped/abandoned worker's pane expected to be non-resumable during the release window? If so, these two settle paths need the same trigger.ℹ️ Nitpicks
worktreeIdsEqual(src/shared/worktree/id.ts:47) is byte-for-byte identical to the existingruntimeWorktreeIdsEqual(src/main/runtime/orca-runtime.ts:43161); the PR migrates only one call site and leaves the duplicate. Consider delegating one to the other.- The comment at
src/renderer/src/store/terminals/terminal-pane-hibernation.ts:66still reads "sleepingRecordFromEntry does not copy the flag", which this PR makes inaccurate (it now copies viacarryOverAutomaticResumeBlock). The mitigation it justifies is still valid, but the stated premise is stale.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
42ba022 to
c8bdcd2
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts (1)
39-39: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd a same-session cross-worktree regression test.
clearSleepingRecordProviderDuplicatesalready requires matchingworktreeId. The existing sibling test uses a different provider session, so add a sibling in another worktree with the same provider session and assert that only the exited worktree is cleared.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0b946e29-b2fb-48fc-9553-543eeecd9403
📥 Commits
Reviewing files that changed from the base of the PR and between 2912a5334deda09f5db70e82ebdf5180f1afeb57 and 42ba02244f2c1ea44f32a6bfbde1e685f1c847c3.
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pty-connection-main-side-effect-authority.test.tssrc/renderer/src/components/terminal-pane/pty-connection/agent-idle-working-handlers.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
a0efa6a to
3728d6c
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Renderer-side resume retirement on agent exit —
agent-idle-working-handlers.tsnow clears the pane's sleeping record (and any legacy provider-session duplicate aliases) inonAgentExitedbefore notifying the exit handler, so a settled worker whose shell title confirms exit cannot have its dead session resurrected by a later workspace open. - Test parametrization — the new retirement coverage in
pty-connection-main-side-effect-authority.test.tswas widened from a singleclaudecase toit.each(['claude', 'codex']), asserting exact-record clearing, sibling isolation, and clear-before-exit-callback ordering for both agents.
The retirement path reuses the existing getSleepingRecordForPane / clearSleepingRecordProviderDuplicates helpers and is gated on a confirmed exit (the main-process agent-exited fact or the idle→shell title transition, which replay/reattach paths already suppress). The focused suite passes (2 tests, claude + codex).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- E2E restoration-readiness wait — added
waitForTerminalStartupRestorationReadyand awaited it after reload, so the pre-activation snapshot cannot race terminal startup restoration. - Gated-empty reseed consistency — the
gateWorktreeAgentActivationemptybranch now passesreseedEmptiedWorkspace: opts?.providesInitialSurface !== true, matching the ungated and folder-workspace paths so an explicitly activated empty workspace reseeds a terminal while surface-providing callers stay opted out.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
b7ec691 to
844a16c
Compare
|
Heads up @Jinwoo-H — a pre-release readiness review found this PR and #17374's sibling #17430 implement the same STA-4577 settled-worker resume fence. We're keeping this one and closing #17430, because your production code is a verified strict superset: across the 18 shared files, What I changed here (tests and comments only — no production logic touched): #17430 had ~370 lines of coverage this branch had none of —
Sanity-checked the tests actually bite: inverting
One latent issue I found, unrelated to the port: Remaining before merge (from the review, all pre-existing on both PRs): |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Ported settle-fence coverage from #17430 —
orca-runtime.test.tsgained three tests covering thefencedstamp, theunfencedlift, and the fail-closed unreadable-plan path; a newagent-status-settled-worker-resume-fence.test.tsstore suite asserts the fence survives turn completion, periodic capture, and launch-config re-registration while not leaking onto a different provider session. - Cold-restore guard test —
pty-connection-cold-restore-resume-command.test.tsnow asserts a settled worker whose dispatch fenced automatic resume is never cold-restored. - Strengthened existing assertions — the DB and settlement tests now pin exact
release_state/dispatchstate transitions and assert the settled-but-unreleased rows stay recoverable;useIpcEvents-agent-status-ssh-authority.test.tspins the worktree-identity guard onfenced/unfencedevents. - Forward-compat coverage —
legacy-worker-terminal-recovery-event.test.tsgained a test asserting an unknown resolution kind resolves toignorerather than detaching a surface. - Documentation only on production paths — added
Why/JSDoc notes to the fence stamping, lifting, and recovery-query code plusworktreeIdsEqual; no production behavior changed in this delta.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Summary
release_unknownterminal resources in recovery planning, with exact pane/worktree identity checks.donestate.Validation
pnpm tcpnpm run check:code-quality:changedThe focused E2E build progressed past the stale recovery expectation and reached workspace activation, but timed out in the generic
waitForActiveTerminalManagerhelper before the final assertions. No lifecycle assertion failed.Scope
This is a product fix with accompanying unit/integration/E2E coverage; it is not test-only.
ELI5
When a worker says it is done, its terminal can still be hanging around for a moment. Orca used to see that old sleeping record and start it again during cleanup. The runtime now puts a do-not-auto-resume fence on the exact pane and worktree as soon as settlement is committed, carries it through restart and recovery, and lifts it only after the terminal row is no longer active.
Performance Measurement
No speed-up is claimed or measured; this is a lifecycle-race correctness fix. Recovery remains one SQL query. Added work is bounded to one settled-state check per returned recovery row, one blocked-pane set build, and one pass over each host's sleeping-session map. For S sleeping records and R retired fences, the extra scan is O(S) with O(R) copies/notifier events; R=0 causes no session writes. No wall-clock benchmark was run.
User-Facing Trade-offs
Completed workers intentionally do not auto-resume while their terminal is still owned or unreleased; a user may need explicit release/retain or a manual restart. Other worker launch and recovery behavior is unchanged.