Skip to content

fix(orchestration): let the owning Run address a Dispatch after its assignee binds a child Run - #24974

Merged
nwparker merged 1 commit into
stablyai:mainfrom
lorenzozanee:fix/orchestration-nested-run-dispatch
Oct 28, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
lorenzozanee:fix/orchestration-nested-run-dispatch

Conversation

@lorenzozanee

@lorenzozanee lorenzozanee commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A coordinator gives a task to a worker, and the worker then starts its own sub-team. After that, if the coordinator messaged the worker about the task and named its own project, Orca refused the message and said it belonged somewhere else. Now Orca delivers the message to the worker's new sub-team mailbox and adds a short note saying where it went.

What Changed

  • Before: A coordinator in Run R1 dispatches to terminal B. B runs run-create, which creates R2, so B now coordinates R2. After that:
    • orca orchestration send --run R1 --to dispatch:<id> failed with recipient_run_mismatch ("belongs to Run R2").
    • --run R2 failed with dispatch_run_mismatch ("Dispatch belongs to R1").
    • Only leaving out --run worked.
  • After: --run R1 (the Dispatch's own Run) works the same as leaving out --run. The mail is redirected to run:R2 and returns the recipient_run_bound_redirect warning. --run R2, and any other Run, are still rejected.
  • Mechanism: In recipient-routing.ts, resolveRunBoundDispatchRecipient compared the explicit --run with the assignee's current bound Run (R2). But resolveMessageRun had already required --run to equal the Dispatch's owning Run (R1). So every explicit --run on a redirected Dispatch failed one check or the other. The function now skips runMismatch when explicitRunId === dispatch.run_id.
  • Tests: In run-bound-mailbox-safety.test.ts, the old "refuses an explicit sender Run that would silently redirect" case is replaced. Its assertion is now inverted, and the redirect was never silent because it returns a warning. The new test checks two things:
    • the owner Run is accepted and redirected, with the warning;
    • the child Run is still rejected with dispatch_run_mismatch.

Why

Naming the Dispatch's own Run is the most explicit way to send this message, and it should not be stricter than leaving --run out. This doesn't open a new mailbox to anyone: the same sender already reaches the same run:R2 mailbox without --run. The exception only applies when the explicit Run equals the Dispatch's owning Run. The payload-scoped Dispatch guard (runMismatch) still applies in every other case. Dispatch ownership is unchanged, and settled Dispatches are still refused earlier by assertDispatchMailboxDeliverable.

Linked Issue

Fixes #24699

Visual Proof

N/A. This is server-side orchestration routing (RPC/CLI behavior) with no UI change. The before and after are shown by tests:

  • Before (only recipient-routing.ts restored to main): the new test fails with OrchestrationError: dispatch:ctx_… belongs to Run run_…, not explicitly requested Run run_…, thrown at recipient-routing.ts:87.
  • After: the same test passes.

Testing

  • Reproduced the bug on main using the new test case in run-bound-mailbox-safety.test.ts (1 of 28 tests failed with recipient_run_mismatch). It passes with the fix.

  • Ran scratch probes on the branch:

    • an owner-Run send reaches the worker's child Run mailbox;
    • a third, unrelated Run is still refused;
    • a send to a completed Dispatch is still refused with dispatch_inactive.
  • pnpm test src/main/runtime/rpc/methods/orchestration/messaging/: 12 files, 255 tests passed after rebasing onto current main. orchestration-party-addressing.test.ts passed 27/27.

  • oxlint (anti-slop, code-quality), ast-grep, the changed-code quality gate and oxfmt are clean on the touched files.

  • Tested on macOS. The change is platform-agnostic server routing. There are no CLI, wire or schema changes, so mixed client/server versions are unaffected. It has no impact on folder workspaces or SSH.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Notes

  • Tradeoff: mail sent with an explicit --run R1 is stored with run_id R2, so it doesn't appear in R1's Run-scoped history. This is the same as leaving out --run, and the redirect warning tells the sender.
  • Possible follow-up: a bare handle with --run R1 (--to term_lead --run R1) still fails with recipient_run_mismatch.

Original fix by @lorenzozanee in #24974.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@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 new issues found.

Reviewed changes

  • Owner Run can reach a nested worker Dispatch — resolveRunBoundDispatchRecipient now skips the runMismatch guard when the explicit run: equals dispatch.run_id, so an owner coordinator's send redirects to the assignee's current Run (with the existing recipient_run_bound_redirect warning) instead of failing with recipient_run_mismatch. Dispatch ownership is untouched.
  • Positive test added — run-bound-recipient-mail.test.ts covers the owner-Run redirect and asserts the Dispatch stays owned by the root Run.
  • Rejection test repointed — run-bound-mailbox-safety.test.ts now names the assignee Run (leadRun.id) and expects dispatch_run_mismatch, preserving the non-owner rejection.

Verified: the three focused routing suites pass (40 tests), and reverting the source hunk makes the new test fail with recipient_run_mismatch, so it is genuine coverage rather than theatre.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 642f2419-e21e-49da-93d7-4cca7110d81e
Commits

Reviewing files that changed from the base of the PR and between 32adeea and 3610e30.

Files selected for processing: 2
  • src/main/runtime/rpc/methods/orchestration/messaging/recipient-routing.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/run-bound-mailbox-safety.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

When the explicit Run matches the Dispatch’s owning Run, the recipient resolver skips the Run mismatch check. Tests verify that this case redirects the message to the child Run with a recipient_run_bound_redirect warning. Tests also verify that an explicit child Run is rejected with dispatch_run_mismatch.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 3610e

No actionable merge-blocking risk remains in the reviewed routing change.

Security architecture risk: Low · up to 32ade

The exception is limited to the Dispatch’s owning Run and reaches the same worker mailbox already reachable when the Run is omitted. Dispatch ownership remains unchanged. No newly unauthorized delivery path was established, but the intended authorization role of explicit Run selection and production concurrency behavior remain uncertain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The changed redirect applies to active, current-contract, non-federated Dispatches whose assignee has a different current Run. Session identity or terminal pane/process identity determines the assignee Run; this branch does not select an arbitrary caller-supplied destination Run.

Security Findings and Attack Paths

  • inferred — No newly reachable mailbox was established for ordinary Dispatch sends: a caller could already reach the same assignee Run by omitting the explicit Run. The new accepted request shape alone does not establish an authorization bypass. This comparison is bounded to the inspected routing path, not a claim of complete security coverage.

Trust Boundaries and Controls

  • observed — The production routing check requires the selected Run to match Dispatch ownership. It does not require an explicitly selected owner Run to equal the sender’s current Run. The child-Run regression checks target-scope mismatch using a coordinator sender, rather than proving that all child-origin senders are barred from naming the owner Run. This distinction predates the exception.

Resilience and Maintainability Implications

  • observed — The exception changes mailbox selection, not downstream settlement or acknowledgement transitions. Persistence precedes notification, and worker_done retains its transaction wrapper. Existing test assertions exercise replay, handoff/interruption, and process-reuse isolation; they do not establish arbitrary concurrent-writer or crash behavior.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main routing change: allowing the owning Run to address a Dispatch after the assignee creates a child Run.
Description check Passed The description is mostly complete. It explains the user-visible behavior, mechanism, rationale, linked issue, testing, compatibility impact, and UI-proof exception. The AI Disclosure, Review, and Age…
Linked Issues check Passed Issue #24699 requires a Dispatch to remain addressable from its owning Run after its assignee creates a nested Run. resolveRunBoundDispatchRecipient now accepts an explicit Run that matches the Disp…
Out of Scope Changes check Passed The changed routing code and regression test address Issue #24699 recipient routing and Run-bound safety. The reviewed change contains no unrelated functionality.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Description check

Explanation

The description is mostly complete. It explains the user-visible behavior, mechanism, rationale, linked issue, testing, compatibility impact, and UI-proof exception. The AI Disclosure, Review, and Agent skill upstream boundary sections are not included, but the core required information is present.

Full details: Linked Issues check

Explanation

Issue #24699 requires a Dispatch to remain addressable from its owning Run after its assignee creates a nested Run. resolveRunBoundDispatchRecipient now accepts an explicit Run that matches the Dispatch owner and redirects delivery to the assignee's current Run. The updated regression test verifies the redirect warning and message delivery. The test also preserves rejection for an unrelated child Run with dispatch_run_mismatch.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Naming a Dispatch's own Run with --run is equivalent to omitting it, so
mail to a Dispatch whose assignee now coordinates a child Run redirects
to that Run's mailbox instead of failing recipient_run_mismatch.

Fixes stablyai#24699

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
@nwparker
nwparker force-pushed the fix/orchestration-nested-run-dispatch branch from 32adeea to 3610e30 Compare October 28, 2026 03:57
@nwparker nwparker changed the title fix(orchestration): allow owner Run to address a nested worker Dispatch fix(orchestration): let the owning Run address a Dispatch after its assignee binds a child Run Oct 28, 2026
@nwparker
nwparker merged commit 57c2b53 into stablyai:main Oct 28, 2026
48 of 49 checks passed
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.

[Bug]: run-create inside a worker terminal makes its Dispatch unreachable from both Runs (recipient_run_mismatch / dispatch_run_mismatch)

2 participants