Skip to content

fix(orchestration): preserve active workers across updates - #11271

Merged
OrcaWin merged 11 commits into
mainfrom
orchestration-contract-compatibility
Jul 29, 2026
Merged

OrcaWin merged 11 commits into
mainfrom
orchestration-contract-compatibility

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • adopt durable pre-update Tasks, Dispatches, messages, gates, and questions into an ordinary current Run while preserving the live process, PTY, assignment, and filesystem work
  • keep exact legacy send, check, ask, reply, and completion prompts working through a narrowly attested per-Dispatch adapter; unprovable history is clearly read-only with no reply or acknowledgment affordance
  • recover the exact retained PTY into its existing background tab and block provider resume or fresh spawn, preventing missing tabs and duplicate codex resume workers on workspace re-entry
  • preserve execution-host authority across local, SSH, WSL, remote runtime, and packaged Windows paths, including legacy decision_gate delivery

Deliberate scope

This does not revive the retired scheduler, block updates, permanently fence PTY geometry or SIGWINCH, or claim exhaustive updater/topology coverage. Normal terminal resize behavior resumes after intentional viewing. The migration guarantees safe, non-destructive, agent-recoverable continuity rather than perfect preservation of every transient state.

Design and invariants are documented in docs/reference/plans/2026-07-28-orchestration-seamless-update-migration.md.

Verification

  • pnpm typecheck
  • pnpm lint
  • pnpm test: 3,799 files and 40,149 tests passed
  • pnpm exec electron-vite build --mode e2e
  • 5 focused Electron E2Es passed: legacy adoption, current-worker restart, missing-terminal no-replacement, workspace re-entry stability, and hidden Codex background restoration
  • git diff --check

Screenshots

Not applicable; this is runtime migration and terminal lifecycle behavior.

AI review report

Prior CodeRabbit, Greptile, and internal review findings were triaged by impact. Valid authority, host-routing, question-delivery, duplicate-worker, and tab-recovery findings were fixed. Permanent geometry fencing and exhaustive topology guarantees were intentionally removed from scope.

Security audit

Legacy mutations require attested principal and Dispatch authority. Ambiguous or unprovable callers degrade to read-only inspection; no fallback executes a mutation locally.

Notes

No update blocking and no dual scheduler.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change adds legacy orchestration adoption and compatibility routing across storage, RPC, CLI, runtime authority verification, terminal recovery, renderer state, SSH, WSL, and Windows update flows. It introduces durable delivery and receipt contracts, authority evidence and redaction, legacy lifecycle handlers, restart reconciliation, resume fencing, recovery notifications, expanded reliability gates, and E2E coverage. The Windows updater now validates distinct installer artifacts and uses stricter process and file-lock checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise and matches the main change: preserving active workers across updates.
Description check ✅ Passed The description is mostly complete and covers the required sections, though it uses a Verification section instead of the template's Testing section.
✨ 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.

Comment thread src/main/runtime/orchestration/db.ts Resolved
Comment thread src/main/runtime/orchestration/db.ts Resolved
@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR implements a seamless update migration for the Orca orchestration system, atomically adopting pre-update legacy Tasks, Dispatches, messages, and questions into a new current Run under adoptedRunId while preserving live worker assignments. A narrowly-scoped per-Dispatch legacy compatibility adapter allows exact legacy CLI prompts to continue working through the update boundary; surviving PTYs are recovered into a background tab with auto-resume fencing to prevent duplicate codex resume spawns.

  • DB schema v19 migration: adds delivery_contract to messages, contract_version/launch_token_hash to dispatch_contexts, and five new tables all within the existing BEGIN IMMEDIATE migration transaction.
  • Legacy compatibility layer: new RPC-layer files dispatch orchestration.send/check/ask/reply through principal-scoped, idempotent operation receipts, with attestCompatibilityAuthority requiring exactly one non-revoked hydrated commitment before granting authority.
  • Terminal recovery: reconcileLegacyWorkerTerminals serialises PTY adoption through a promise queue, with SSH-relay-ready triggering a second session-tab publication after reconciliation.

Confidence Score: 5/5

Safe to merge. The migration is fully transactional, the authority model is consistently enforced before every state write, and the previously flagged issues have both been corrected in this diff.

The v18 to v19 schema migration runs inside the existing BEGIN IMMEDIATE boundary; adoptLegacyRunIfNeeded creates the adopted run before migrating foreign-key rows and validates cross-run consistency before committing. The attestCompatibilityAuthority revocation lifecycle is wired in all the necessary eviction paths. The terminal recovery queue serialises concurrent calls correctly, and PTY adoption is gated on strict identity matching with ambiguous dispatches deferred rather than silently dropped.

Files Needing Attention: No files require special attention. The heaviest logic is in db.ts and orca-runtime.ts; both have accompanying test files covering the new paths.

Important Files Changed

Filename Overview
src/main/runtime/orchestration/db.ts Core schema v18 to v19 migration: adds delivery_contract/contract_version columns, five new tables, and the adoptLegacyRunIfNeeded atomic data-migration logic. Previously flagged LIKE-wildcard and .all() existence-check issues are both corrected in this diff.
src/main/runtime/orca-runtime.ts Adds reconcileLegacyWorkerTerminals promise-queue, prepareLegacyWorkerTerminalRecovery fence logic, verifyOrchestrationCompatibilityCaller authority verification, and notifySshRelayReady double-publication for post-reconcile tab visibility.
src/main/runtime/rpc/orchestration-legacy-authority.ts New file: LegacyCompatibilityAuthority resolves worker/coordinator candidates from the adopted run and guards all mutation paths behind verifyAttestedLegacyCandidate.
src/main/agent-hooks/server.ts Adds hydratedAuthorityCommitments/currentAuthorityObservations tracking and attestCompatibilityAuthority, with revocation tied to pane-close, alias-clear, and tab-close events.
src/main/runtime/rpc/orchestration-legacy-compatibility.ts New file: thin routing layer intercepting orchestration.send/check/ask/reply before the main RPC registry.
src/main/runtime/rpc/orchestration-legacy-lifecycle.ts New file: handles legacy worker_done/heartbeat/escalation sends with idempotent commitLegacyLifecycleOperation.
src/main/runtime/orchestration/orchestration-legacy-worker-terminal-recovery.ts New file: planLegacyWorkerTerminalRecovery disambiguates PTY candidates - ambiguous dispatches are deferred rather than silently adopted.
src/main/runtime/rpc/dispatcher.ts Inserts OrchestrationLegacyCompatibility.tryHandle before both streaming and non-streaming dispatch paths.
src/main/runtime/rpc/orchestration-legacy-operation.ts New file: shared parameter types, operationIdentity, and helpers including inferLegacyWorkerOutcome.
src/main/startup/legacy-worker-renderer-recovery.ts New file: startup hook that fences auto-resume before renderer initialises, then triggers reconcileLegacyWorkerTerminals.

Reviews (4): Last reviewed commit: "fix(orchestration): close recovery revie..." | Re-trigger Greptile

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

Actionable comments posted: 9

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)

4181-4195: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

A failing/slow legacy reconcile now blocks recovered SSH session-tab publication.

publishRecoveredSshMobileSessionTabs is only reached if reconcileLegacyWorkerTerminals resolves. Since the reconcile runs behind a shared serial queue (legacyWorkerTerminalRecoveryQueue) and performs adoption + renderer reveals with retries, a throw or a slow reconcile for an unrelated connection delays or entirely skips republishing this target's recovered tabs — a user-visible regression versus the previous unconditional publish.

🛡️ Decouple publication from reconcile outcome
     void (async () => {
-      await this.reconcileLegacyWorkerTerminals({
-        connectionId: targetId,
-        materializeRenderer: this.notifier !== null
-      })
+      try {
+        await this.reconcileLegacyWorkerTerminals({
+          connectionId: targetId,
+          materializeRenderer: this.notifier !== null
+        })
+      } catch (error) {
+        console.warn('[orchestration] legacy worker reconcile failed on relay ready', {
+          targetId,
+          error
+        })
+      }
       await this.publishRecoveredSshMobileSessionTabs(targetId, generation)
     })().catch((error) => {
🧹 Nitpick comments (7)
config/scripts/orchestration-skill-guidance.test.mjs (1)

54-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the bundled guide served by the CLI.

This test reads only skill-guides/orchestration.md, while skills get serves ORCHESTRATION_MARKDOWN from src/cli/bundled-skill-guides.ts:33. Add a parity check or exercise the bundled lookup so stale shipped guidance cannot pass this test.

src/main/runtime/orca-runtime.ts (1)

3712-3728: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Hoist the PTY liveness refresh out of the candidate loop.

refreshPtyWorktreeRecordsFromController issues a full listProcesses inventory RPC (local or over the SSH relay) and, because no targetWorktreeId is passed, already returns the global live-PTY set. Running it once per candidate makes restart recovery O(candidates) round-trips on the reconnect path. Resolve the workspace/liveness once before the loop (or reuse a single in-flight refresh) and index candidates against that set.

tests/e2e/orchestration-worker-terminal-visibility.spec.ts (1)

83-107: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting the ledger harness shared with the sibling spec.

LedgerEvent, readLedger, isProcessAlive, and most of fakeCodexSource are duplicated verbatim in tests/e2e/orchestration-legacy-worker-restart-recovery.spec.ts (lines 27-121); both copies land in this PR. A helper module under tests/e2e/helpers/ (concrete name, e.g. codex-stub-ledger.ts) would keep the stub's event shape from drifting between the two suites.

src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts (1)

177-194: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Make the stale-reconnect outcome explicit.

await staleReconnect silently accepts either resolution or a specific rejection, and muxInstances[2] pins the winner by construction order across three attempts. Asserting the stale promise's expected settlement (and selecting the winning mux by identity, e.g. the last instance) would keep the test from passing for the wrong reason if ownership handling changes.

src/main/runtime/orchestration/types.ts (1)

228-228: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Make delivery_contract required on MessageRow.

MessageRow represents SQLite rows where messages.delivery_contract is NOT NULL DEFAULT 'current_delivery', and the v19 migration backfills existing rows. Making it required matches the persisted shape and avoids treating undefined as a fourth authority state; existing constructed messages can default omitted cases to current_delivery.

src/main/runtime/rpc/orchestration-legacy-compatibility-dispatcher.test.ts (1)

196-242: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a case with no orchestrationCompatibilityEvidence at all.

Every scenario supplies evidence (valid or contradictory). The absent-evidence path is a distinct branch in LegacyCompatibilityAuthority (resolveWorkerDispatch skips its retained-assignment guard, resolveProvenCoordinatorScope still attests), and it is the case a stale/older CLI actually produces after an update.

src/main/runtime/rpc/orchestration-legacy-mail.ts (1)

173-179: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate of legacyCoordinatorReadOnly in orchestration-legacy-authority.ts.

Byte-identical helper (code, message, data) exists at orchestration-legacy-authority.ts Lines 305-311. Export it from one place so the wording can't drift.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a5f5fea-dbb0-458a-a5dc-21ead5fcd75f

📥 Commits

Reviewing files that changed from the base of the PR and between 3f53287 and 4cf26e8.

📒 Files selected for processing (86)
  • .github/workflows/win-update-e2e.yml
  • config/nsis/daemon-host-uninstall.nsh
  • config/reliability-gates.jsonc
  • config/scripts/orchestration-skill-guidance.test.mjs
  • docs/reference/plans/2026-07-28-orchestration-seamless-update-migration.md
  • native/windows-cli-launcher/OrcaCliLauncher.cs
  • skill-guides/orchestration.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/orchestration-migration.test.ts
  • src/cli/handlers/orchestration-timeout-cli.test.ts
  • src/cli/handlers/orchestration-timeout.test.ts
  • src/cli/handlers/orchestration-windows-ask-cli.test.ts
  • src/cli/handlers/orchestration.test.ts
  • src/cli/handlers/orchestration.ts
  • src/cli/runtime-client.test.ts
  • src/cli/runtime/client.ts
  • src/cli/runtime/orchestration-compatibility-envelope.ts
  • src/cli/runtime/runtime-request-timeout.ts
  • src/cli/runtime/transport.ts
  • src/cli/runtime/types.test.ts
  • src/cli/runtime/types.ts
  • src/main/agent-hooks/server-authority-evidence.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/cli/windows-launcher-asset.test.ts
  • src/main/index.ts
  • src/main/ipc/pty.ts
  • src/main/pty/wsl-orca-env.test.ts
  • src/main/pty/wsl-orca-env.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration-compatibility-authority.test.ts
  • src/main/runtime/orchestration/db.test.ts
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/orchestration/formatter.test.ts
  • src/main/runtime/orchestration/formatter.ts
  • src/main/runtime/orchestration/orchestration-legacy-storage-db.test.ts
  • src/main/runtime/orchestration/orchestration-legacy-worker-terminal-recovery.test.ts
  • src/main/runtime/orchestration/orchestration-legacy-worker-terminal-recovery.ts
  • src/main/runtime/orchestration/orchestration-schema-version-skew.ts
  • src/main/runtime/orchestration/orchestration-version-skew-migration.test.ts
  • src/main/runtime/orchestration/types.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/dispatcher.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/orchestration-federation-control-mail.test.ts
  • src/main/runtime/rpc/methods/orchestration-federation.test.ts
  • src/main/runtime/rpc/methods/orchestration-gates.ts
  • src/main/runtime/rpc/methods/orchestration-runs.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/main/runtime/rpc/orchestration-legacy-authority.ts
  • src/main/runtime/rpc/orchestration-legacy-compatibility-dispatcher.test.ts
  • src/main/runtime/rpc/orchestration-legacy-compatibility.ts
  • src/main/runtime/rpc/orchestration-legacy-lifecycle.ts
  • src/main/runtime/rpc/orchestration-legacy-mail.ts
  • src/main/runtime/rpc/orchestration-legacy-operation.ts
  • src/main/runtime/rpc/orchestration-legacy-question.ts
  • src/main/ssh/ssh-relay-session-reconnect-incarnation.test.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/ssh/ssh-remote-cli-host-passthrough.test.ts
  • src/main/ssh/ssh-remote-cli-host-passthrough.ts
  • src/main/ssh/ssh-remote-orca-cli.test.ts
  • src/main/ssh/ssh-remote-orca-cli.ts
  • src/main/window/attach-main-window-services.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/relay/remote-cli-env.test.ts
  • src/relay/remote-cli-env.ts
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/lib/resume-sleeping-agent-session-legacy-worker.test.ts
  • src/renderer/src/lib/resume-sleeping-agent-session.ts
  • src/renderer/src/store/slices/agent-status.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/agent-session-resume.ts
  • src/shared/orchestration-compatibility-evidence.test.ts
  • src/shared/orchestration-compatibility-evidence.ts
  • src/shared/remote-runtime-client.ts
  • src/shared/runtime-rpc-envelope.ts
  • src/shared/workspace-session-sleeping-agents.ts
  • tests/e2e/orchestration-legacy-worker-restart-recovery.spec.ts
  • tests/e2e/orchestration-worker-terminal-visibility.spec.ts
  • tools/win-update-e2e/README.md
  • tools/win-update-e2e/cli-args.mjs
  • tools/win-update-e2e/installer-pair-proof.mjs
  • tools/win-update-e2e/installer-pair-proof.test.mjs
  • tools/win-update-e2e/run.mjs

Comment thread src/cli/handlers/orchestration.ts Resolved
Comment thread src/main/agent-hooks/server.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved
Comment thread src/main/runtime/orchestration/db.ts Resolved
@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Too many files changed for review. (150 files found, 100 file limit)

Bypass the limit by tagging @greptile-apps to review.

@OrcaWin
OrcaWin merged commit 363e478 into main Jul 29, 2026
79 of 80 checks passed
@nwparker nwparker mentioned this pull request Oct 5, 2026
14 tasks done
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…11271)

* fix(orchestration): preserve active workers across updates

* test(ssh): model absent legacy adoption

* test(orchestration): align compatibility contracts

* fix(windows): escape updater PowerShell booleans

* fix(windows): restore stock uninstall process check

* fix(orchestration): keep recovery off renderer startup barrier

* fix(orchestration): harden legacy recovery migration

* fix(orchestration): close recovery review gaps

* fix(orchestration): complete legacy worker cutover recovery

* fix(orchestration): preserve legacy workers across updates

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
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