Repository navigation
fix(orchestration): keep worker lineage across app restart (STA-6366) - #19121
Conversation
Terminal handles are minted per process, so after a restart the projected parent (coordinator or creator) named a handle no live row carried and every worker rendered as a top-level row. The projection now resolves the parent from the durable pane keys (runs.coordinator_pane_key, tasks.created_by_pane_key) whenever the stored handle is not one this process minted, re-resolves it to the live handle for that pane, and omits stale handles so they cannot mismatch a row. The creator-pane incarnation gate is untouched: it still decides mutation authority, and display lineage no longer depends on it. Dispatch lookup also passes the pane identity so a worker's own dispatch resolves once its handle is reminted.
…ge-restart # Conflicts: # src/main/runtime/runtime-agent-orchestration-projection.ts
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe runtime orchestration projection now accepts pane-key options and re-resolves parent, creator, and coordinator panes against live processes. Dispatch lookup can use pane identity after process restarts. New runtime tests cover persisted lineage, reminted handles, coordinator rebinding, and stale coordinator handles. Renderer tests cover pane-key-based row grouping. Two test assertions received formatting-only changes. Merge Risk: ⚪ Minimal · up to The restart-lineage changes preserve durable pane identity while avoiding stale process handles, with runtime and renderer coverage for the changed behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
ℹ️ No critical issues — the fix is sound and well-grounded. One coverage gap and a minor doc note below.
Reviewed changes
runtime-agent-orchestration-projection.ts— splits durable Run membership (creatorLineageInRun) from live mutation authority (currentCreatorHandle, the byte-identical incarnation gate), addsresolveLivePaneto remap a stored(handle, paneKey)pair to what this process can address, and omits stale handles instead of publishing them.- Dispatch lookup —
getForHandlenow takes an options object (paneKey,evidence,deferAttention) and threadspaneKeyintogetActiveDispatchForTerminalso a reminted worker still resolves its own dispatch viaassignee_pane_key. orca-runtime-prune-mobile-session-tab-group-layout.ts— forwardspaneKeyinto thegetForHandlecall.- Tests — a restart-shaped lineage spec (
lineage-and-scan-cache-part-07.spec.ts) plus rendereragent-row-lineage-modelguards; two formatting-only edits underconfig/scripts/.
The projection-side tests are genuinely red-before-fix: the old code published the stale coordinatorHandle as parentTerminalHandle/coordinatorHandle and never emitted parentPaneKey, so the exact toEqual assertions would have failed. The creatorLineageInRun vs coordinatorHandle asymmetry (a gone creator falls back to the coordinator, while a gone coordinator still publishes its durable pane key) is self-correcting on the next publish and matches the renderer's existing resolveAgentRowParentPaneKey fallback, so it produces no visible divergence.
ℹ️ The reminted-worker dispatch path from the summary has no test
The summary lists "a worker whose own handle was reminted had no context at all" as a second break, fixed by threading paneKey into getActiveDispatchForTerminal. But neither new test remints a worker handle — test one re-registers the daemon-retained handle (registerPreAllocatedHandleForPty('pty-worker', beforeHandles.worker)), and test two pre-allocates a handle that already matches the dispatch's assignee_handle. So the assignee_pane_key fallback branch in findActiveDispatchForAssignee is never exercised by the new coverage; the fix would still be green if that branch were removed.
Technical details
# Cover the reminted-worker dispatch lookup
## Affected sites
- `src/main/runtime/orca-runtime-tests/lineage-and-scan-cache-part-07.spec.ts:141` — the worker handle is re-registered, not reminted, so the dispatch is found by `assignee_handle`, never by pane key.
- `src/main/runtime/orchestration/db/dispatch-context/dispatch-lookup.ts:131` — `findActiveDispatchForAssignee`'s pane-key fallback is the branch being relied on but not covered.
## Required outcome
- A restart-shaped test that gives a worker a fresh handle (do not re-register the old one) and asserts the worker still resolves its dispatch and nests under the coordinator, proving the `assignee_pane_key` lookup path.
## Open questions for the human (optional)
- Is the "worker handle reminted" scenario actually reachable in production, or are all surviving workers daemon-retained (making the pane-key dispatch lookup defensive only)? If it is reachable, it needs this test.ℹ️ Nitpicks
resolveLivePane's doc comment says a pane-key-only result is "published even when no pane is live yet, so the row nests again as soon as that pane is restored." That is true for the coordinator path, but the creator path (parent = creator?.handle ? creator : …) discards a pane-key-only creator and falls back to the coordinator. A one-line caveat would keep the contract honest.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Ten commits, of which six are store/selector performance work that touches nothing here. Two conflicts, both in skill-guide expectations, and both taken from main: they assert the wording of a guide rewrite that main has now reverted (#19126), and this branch never authored them — the only commit on this side that touches those files is the previous merge, which carried main's own content at the time. Worth noting for the PR description rather than the code: main's #19121 makes worker lineage survive an app restart, which is the limitation this branch documents as deferred. Whether it closes that gap for a structured worker needs checking separately; the structured lane keeps no hold across a restart for its own reasons, so the two are not obviously the same fix.
…stablyai#19121) * fix(orchestration): keep worker lineage across app restart (STA-6366) Terminal handles are minted per process, so after a restart the projected parent (coordinator or creator) named a handle no live row carried and every worker rendered as a top-level row. The projection now resolves the parent from the durable pane keys (runs.coordinator_pane_key, tasks.created_by_pane_key) whenever the stored handle is not one this process minted, re-resolves it to the live handle for that pane, and omits stale handles so they cannot mismatch a row. The creator-pane incarnation gate is untouched: it still decides mutation authority, and display lineage no longer depends on it. Dispatch lookup also passes the pane identity so a worker's own dispatch resolves once its handle is reminted. * test(orchestration): compare lineage without the merged attention field

Summary
Fixes STA-6366: after an Orca restart, workers lost their parent in the sidebar and Agents tab.
Root cause. Terminal handles are minted per process and never persisted. The orchestration projection derived a worker's parent purely from handles: the creator path was refused by the process-incarnation gate (by design), and the fallback
runs.coordinator_handlewas the previous process's handle, so noparentPaneKeywas ever emitted and stale handles reached the renderer. The durable pane keys (runs.coordinator_pane_key,tasks.created_by_pane_key) were never consulted. A second break:buildByPaneKeylooked up the dispatch by handle only, so a worker whose own handle was reminted had no context at all.Fix.
runtime-agent-orchestration-projection.ts:resolveLivePane(storedHandle, storedPaneKey): keep the handle if this process can address it, otherwise re-resolve the pane key to the live handle, otherwise emit the durable pane key alone so the row nests again when the pane is restored.No proactive rebind on startup:
bindRunbumps the consumer generation and fences deliveries, which would silently invalidate every task'screated_by_run_generation. Authority is still re-established by the coordinator's first command, as today.Tests
orca-runtime-tests/lineage-and-scan-cache-part-07.spec.ts(new part file): restart-shaped test builds a Run with a coordinator-created worker and a worker-created nested task on runtime A, constructs runtime B over the same DB and persisted graph with only daemon-retained handles re-registered, and asserts the worker nests under the coordinator pane with the fresh handle and the nested worker under the worker pane. Second test asserts a stale coordinator handle is omitted while the durable pane key is still published. Both red before the fix.agent-row-lineage-model.test.ts: nests by parent pane key when handles are stale; keeps a child as a root when its parent pane key names no visible row.Merged main (#16904 added
attentionto the same projection);getForHandlenow takes an options object carryingpaneKey,evidence, anddeferAttention.Gates
tc:node,tc:web,check:code-quality:changed,check:react-doctor:changedgreen.orca-runtime.test.tsplus the orchestration, federation, RPC, and lineage suites: 2655 passed.Unverified
No live app-restart repro with a running coordinator and workers; the mechanism is confirmed by source and the restart-shaped unit test. Federated (
--on <server>) workers were reasoned about, not executed: on a worker host the remote dispatch has no localrunsrow, so no coordinator pane key exists and behavior is unchanged there.