Skip to content

fix(orchestration): keep worker lineage across app restart (STA-6366) - #19121

Merged
Jinwoo-H merged 3 commits into
mainfrom
sta-6366-worker-lineage-restart
Sep 6, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
sta-6366-worker-lineage-restart

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​262 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​260
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​56

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_handle was the previous process's handle, so no parentPaneKey was 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: buildByPaneKey looked 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:

  • Display lineage is split from mutation authority. The incarnation gate is byte-identical and still decides whether the creator handle is the authoritative parent handle; display uses durable Run membership.
  • New 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.
  • Stale handles are omitted, never published. A creator whose pane is gone falls back to the coordinator.
  • The coordinator-is-self guard compares by pane key as well as handle.
  • Dispatch lookup passes the pane key through so a reminted worker still resolves its own dispatch.

No proactive rebind on startup: bindRun bumps the consumer generation and fences deliveries, which would silently invalidate every task's created_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 attention to the same projection); getForHandle now takes an options object carrying paneKey, evidence, and deferAttention.

Gates

tc:node, tc:web, check:code-quality:changed, check:react-doctor:changed green. orca-runtime.test.ts plus 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 local runs row, so no coordinator pane key exists and behavior is unchanged there.

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
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 0e331ba5-7f0b-4705-af19-35c2a4989752

📥 Commits

Reviewing files that changed from the base of the PR and between 6fcd829 and 49ba710.

📒 Files selected for processing (7)
  • config/scripts/generate-bundled-skill-guides.test.mjs
  • config/scripts/orca-cli-skill-guidance.test.mjs
  • src/main/runtime/orca-runtime-prune-mobile-session-tab-group-layout.ts
  • src/main/runtime/orca-runtime-tests/lineage-and-scan-cache-part-07.spec.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/runtime-agent-orchestration-projection.ts
  • src/renderer/src/components/dashboard/agent-row-lineage-model.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The 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 49ba7

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the orchestration fix and its purpose: preserving worker lineage across an app restart.
Description check ✅ Passed The description is detailed and covers the problem, root cause, implementation, linked issue, tests, validation results, and known limitations. It does not reproduce every template heading or provide …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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), adds resolveLivePane to remap a stored (handle, paneKey) pair to what this process can address, and omits stale handles instead of publishing them.
  • Dispatch lookup — getForHandle now takes an options object (paneKey, evidence, deferAttention) and threads paneKey into getActiveDispatchForTerminal so a reminted worker still resolves its own dispatch via assignee_pane_key.
  • orca-runtime-prune-mobile-session-tab-group-layout.ts — forwards paneKey into the getForHandle call.
  • Tests — a restart-shaped lineage spec (lineage-and-scan-cache-part-07.spec.ts) plus renderer agent-row-lineage-model guards; two formatting-only edits under config/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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 59fe826 into main Sep 6, 2026
29 checks passed
brennanb2025 pushed a commit that referenced this pull request Sep 6, 2026
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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant