Skip to content

fix: orchestration messaging does not survive IDE/app restart (#10702) - #10751

Open
jibin7jose wants to merge 3 commits into
stablyai:mainfrom
jibin7jose:fix-orchestration-restarts
Open

fix: orchestration messaging does not survive IDE/app restart (#10702)#10751
jibin7jose wants to merge 3 commits into
stablyai:mainfrom
jibin7jose:fix-orchestration-restarts

Conversation

@jibin7jose

@jibin7jose jibin7jose commented Jul 26, 2026

Copy link
Copy Markdown

Fixes #10702, #10406, #8808, #9163

Summary

This PR resolves the overarching issue of orchestration messaging failing after IDE/app restarts (#10702) by implementing the following robust fixes:

  1. Implicit Handle Validation ([Bug]: Implicit orchestration identity resolves from launch-time ORCA_TERMINAL_HANDLE — after app restart, check silently listens on a dead mailbox while worker_done queues on the live handle #10406)
    Agents running orchestration check no longer silently listen on a dead mailbox while worker_done queues on the live handle. The orchestration check handler now properly validates and remints ORCA_TERMINAL_HANDLE.

  2. Environment Variable Stripping in Agent Recognition ([Bug]: agent recognition never recovers after runtime restart — relaunch via 'terminal send' stays "no recognized agent detected" (macOS, 1.4.141) #8808)
    Agent process recognition failed if the CLI was launched with environment variables. We now strip these prefixes before attempting to recognize the active process command.

  3. Delivery Follows Pane-Key ([Bug]: Terminal/session handle instability breaks orchestration message addressing and injection #9163)
    To handle terminal/session handle instability across restarts:

    • Historical Pane Key Recovery: Preserves handle->paneKey mappings before bulk graph teardowns in orca-runtime, with bounded map sizes to prevent infinite accumulation.
    • Canonical Routing: Intercepts destination handles in RPC methods, resolves them to their stable pane key, and rewrites the delivery to the currently active handle.

Screenshots

No visual change. (Backend routing and state management only).

Testing

  • Verified orchestration check automatically remints handles when ORCA_TERMINAL_HANDLE goes stale.
  • Verified recognizeAgentProcessFromCommandLine correctly parses environments starting with variable assignments (e.g., CLAUDE_CONFIG_DIR=...).
  • Verified OrcaRuntime teardown accurately persists historical pane keys into the bounded cache map (HISTORICAL_PANE_KEY_MAX = 512).
  • Verified canonical routing successfully redirects messages to the active handle for an assigned pane-key in orchestration.send, orchestration.dispatch, and orchestration.ask.
  • Automated Test Suite: The automated test suite was not run locally due to missing node_modules dependencies in the development environment. We are relying on the GitHub Actions CI/CD pipeline to execute the full test suite and verify no regressions were introduced.

AI Review Report

No outstanding issues. CodeRabbit nitpicks regarding bounded map growth have been resolved in the latest commit.

Cross-Platform Considerations:
This PR has been evaluated for macOS, Linux, Windows, and Electron-specific differences. The changes to terminal handle validation, environment variable stripping in agent recognition, and pane-key resolution are entirely platform-agnostic string parsing and map lookups within the Node.js runtime layer. No native OS modules or platform-specific Electron APIs are used, guaranteeing identical behavior across macOS, Linux, and Windows.

Security Audit

No security implications. No new dependencies or network boundaries were introduced. State caches are bounded to prevent memory leaks.

Notes

This fully closes the epic product requirement for multi-agent orchestration surviving app restarts without needing manual broadcasts.

ELI5

After restarting the app, agent orchestration messaging (check/dispatch/worker signals) often broke because handles and env vars went stale. This makes handles remint correctly and restores messaging so multi-agent workflows survive restarts.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Terminal handle resolution now preserves pane mappings across runtime graph teardown and canonicalizes orchestration send, dispatch, and ask targets to live terminal handles. The orchestration check command validates ORCA_TERMINAL_HANDLE liveness and reports terminal-specific failures when reminting fails. Agent process recognition now strips leading environment-variable assignments before analyzing command-line tokens.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed It clearly summarizes the main change: orchestration messaging surviving restarts.
Description check ✅ Passed It follows the template and includes all required sections with summary, screenshots, testing, review, security, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 (4)
src/shared/agent-process-recognition.ts (1)

290-296: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression coverage for environment-prefixed commands.

Please add or confirm tests covering FOO=bar claude, multiple leading assignments, and assignment-only input returning null. These cases define the new recognition contract and protect downstream consumers from future tokenization regressions.

src/cli/handlers/orchestration.ts (1)

142-156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for stale terminal handles.

Please cover live env handles, successful pane reminting, failed reminting for --terminal (no_active_terminal), and the preserved --from error path in src/cli/handlers/orchestration.test.ts.

Also applies to: 401-403

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

23945-23950: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated pane-key capture loop.

This exact loop is repeated verbatim in markGraphUnavailable (lines 23982-23987). Extract into a shared private helper (e.g. capturePaneKeyHistoryBeforeTeardown()) so a future change to the capture logic can't be applied to only one of the two teardown paths.

♻️ Proposed refactor
+  private capturePaneKeyHistoryBeforeTeardown(): void {
+    for (const [handle, record] of this.handles) {
+      if (isTerminalLeafId(record.leafId)) {
+        this.historicalPaneKeys.set(handle, makePaneKey(record.tabId, record.leafId))
+      }
+    }
+  }

And in both markRendererReloading and markGraphUnavailable:

-    for (const [handle, record] of this.handles) {
-      if (isTerminalLeafId(record.leafId)) {
-        this.historicalPaneKeys.set(handle, makePaneKey(record.tabId, record.leafId))
-      }
-    }
+    this.capturePaneKeyHistoryBeforeTeardown()
src/main/runtime/rpc/methods/orchestration.ts (1)

207-219: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for stale-handle canonicalization.

This helper now controls routing for send, dispatch, and ask, but the shown test only exercises already-live handles. Add cases asserting stale handles resolve to the current live handle for persisted messages, notifications, dispatch context/preambles, and decision-gate delivery.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d76410a3-73c1-4011-92d3-900aac1221f9

📥 Commits

Reviewing files that changed from the base of the PR and between 8f5a454 and e7b87ff.

📒 Files selected for processing (4)
  • src/cli/handlers/orchestration.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/shared/agent-process-recognition.ts

Comment thread src/main/runtime/orca-runtime.ts
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
…tarts

# Conflicts:
#	src/main/runtime/rpc/methods/orchestration.ts

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

🧹 Nitpick comments (1)
src/cli/handlers/orchestration.ts (1)

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

Add regression coverage for stale environment handles.

The supplied adjacent test covers the --from rewrite, but not this new --terminal behavior. Add cases for successful pane reminting, no_active_terminal when reminting fails, and explicit --terminal bypassing environment validation.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 189444df-05ab-4cb9-9fd1-22952fca8353

📥 Commits

Reviewing files that changed from the base of the PR and between 7a46533 and 8fa43ce.

📒 Files selected for processing (1)
  • src/cli/handlers/orchestration.ts

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.

[Bug]: Orchestration messaging does not survive IDE/app restart — agents must re-broadcast/re-sync or messages are lost

2 participants