Skip to content

Recover stale coordinator runs - #6981

Open
ag-linden wants to merge 2 commits into
stablyai:mainfrom
ag-linden:fix/recover-stale-coordinator-run
Open

ag-linden wants to merge 2 commits into
stablyai:mainfrom
ag-linden:fix/recover-stale-coordinator-run

Conversation

@ag-linden

@ag-linden ag-linden commented Jul 1, 2026 •

Copy link
Copy Markdown

Summary

Reconcile coordinator lifecycle state when the durable DB row says a run is still running but the process-local coordinator handle is gone.

This changes the RPC boundary so:

  • orchestration.run marks a stale durable running row as failed before accepting a new coordinator run.
  • orchestration.runStop marks a stale durable running row as failed when there is no live coordinator to stop.
  • Live stop requests keep the in-memory coordinator handle in place until the background loop finalizes, avoiding a same-process overlap window.

Root cause / impact

Coordinator run status is persisted in SQLite, but the object that can advance or stop a run is process-local memory. If Orca exits while a run is active, the next process can see a durable running row without any live coordinator behind it. That stale row blocks new orchestration, and stop previously reported success without reconciling the row.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test - full suite ran with 23,148 passing tests and one unrelated timeout in src/main/startup/run-electron-vite-dev.test.ts; the failed test passed when reproduced standalone.
  • pnpm build
  • Added focused regression coverage for stale durable coordinator runs with no live handle.

Additional focused checks run:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/methods/orchestration-gates.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/methods/orchestration.test.ts src/main/runtime/orchestration/db.test.ts src/main/runtime/orchestration/coordinator.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/main/startup/run-electron-vite-dev.test.ts -t 'rebuilds the copied Electron app when Chromium resources are missing'
  • pnpm exec oxfmt --check src/main/runtime/rpc/methods/orchestration-gates.ts src/main/runtime/rpc/methods/orchestration-gates.test.ts
  • pnpm exec oxlint --format github src/main/runtime/rpc/methods/orchestration-gates.ts src/main/runtime/rpc/methods/orchestration-gates.test.ts
  • pnpm run typecheck:node
  • pnpm exec lint-staged

AI Review Report

Review checked macOS, Linux, and Windows compatibility; local, remote, and SSH workflows; supported agent and integration compatibility; performance risk; UI impact; and basic security risk. The change is DB-state reconciliation in the existing RPC lifecycle path, with no platform-specific paths, shell behavior, shortcuts, UI changes, or provider-specific behavior. Performance impact is limited to an existing active-run lookup plus a single status update only on lifecycle commands.

Security Audit

No new command execution, path handling, auth, secrets, dependency, or user-input parsing surface is added. The SQL write uses the existing updateCoordinatorRun helper with the already-known run ID. The change only corrects stale lifecycle state for a run that no live coordinator can advance.

Notes

Local build emitted existing/non-patch warnings: baseline oxlint warnings in unrelated files, Vite dynamic-import/chunk-size warnings, a local /usr/local/bin/orca-dev symlink permission warning, and a macOS CGWindowListCreateImage deprecation warning in native code. GitHub profile has no public X handle listed.


Open in Stage

ELI5

Coordinator runs could stay “running” in the DB after the process handle was gone. Stale runs are marked failed on new start or stop so orchestration doesn’t hang forever.

@ghost

ghost commented Jul 1, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Define stale coordinator run recovery utility
2 Recover stale runs during orchestration lifecycle
3 Verify stale run recovery with regression tests
Open in Stage

Chapters generated by Stage for commit 8b3377a on Jul 1, 2026 3:45pm UTC.

@coderabbitai

coderabbitai Bot commented Jul 1, 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: Pro

Run ID: b4c536bc-003c-4bf0-b7c9-3be869eab5eb

📥 Commits

Reviewing files that changed from the base of the PR and between 3a9d914 and 8b3377a.

📒 Files selected for processing (1)
  • src/main/runtime/rpc/methods/orchestration-gates.test.ts

📝 Walkthrough

Walkthrough

This PR updates orchestration-gates to detect stale durable coordinator runs in the database when no live in-memory coordinator exists. It adds a helper that marks such runs as failed, changes orchestration.run and orchestration.runStop to use that helper in stale-run paths, and expands the Vitest suite with a hoisted mock coordinator, cleanup logic, RPC invocation helpers, and tests covering stale-run recovery and active-run rejection.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Title check ✅ Passed The title clearly summarizes the main change: recovering stale coordinator runs.
Description check ✅ Passed The description matches the template and includes summary, screenshots, testing, AI review, security audit, and notes.
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.

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.

@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: 1

🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/orchestration-gates.test.ts (1)

89-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing coverage for the genuinely-active-coordinator throw path.

Both tests cover the "no live coordinator" recovery branch. Neither test exercises the sibling branch in orchestration.run (if (activeCoordinator) throw ...), which is the actual concurrency guard this PR's conditional restructuring depends on. Worth adding a case where activeCoordinator is set (e.g. call orchestration.run twice without resolving the first) and assert the second call throws.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5dc54b30-f2ee-4684-9400-d81a4617a73b

📥 Commits

Reviewing files that changed from the base of the PR and between 8a805e2 and 3a9d914.

📒 Files selected for processing (2)
  • src/main/runtime/rpc/methods/orchestration-gates.test.ts
  • src/main/runtime/rpc/methods/orchestration-gates.ts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants