Skip to content

fix(orchestration): reject task messages for another implicit Run - #32037

Merged
nwparker merged 4 commits into
mainfrom
nwparker/implicit-task-message-run
Oct 23, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/implicit-task-message-run

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​153 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​153
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30

ELI5

An agent can run orca orchestration send --type status --task-id <task> without saying where the message goes. Orca then guesses the destination Run from who it thinks the sender is. When that guess was wrong (#30402: a Codex worker was mistaken for an unrelated terminal), the report went into the wrong Run's inbox, the CLI printed Sent msg_... with exit 0, and the real coordinator never got it.

With this PR, if the message names a Task that belongs to a different Run than the one Orca guessed, Orca refuses the send. Nothing is stored and nobody is woken, and the error gives the exact command that will work:

task_run_mismatch: Task task_A belongs to Run run_A, not the inferred Run run_B. Nothing was sent;
rerun with --run run_A to reach the Task's Run, or --run run_B to keep the inferred Run.

A worker that has an active Dispatch can only send to that Dispatch's Run (anything else hits dispatch_run_mismatch), so its error only offers that Run: rerun with --run run_B to send to your Dispatch ctx_...'s Run.

Unchanged:

  • Explicit --to / --run sends go where the sender asked, even across Runs.
  • Nested coordinators: a worker that also coordinates a child Run can still report on its child Run's Task without --to/--run. The message goes to its parent Run, the same as on main.
  • Lifecycle messages (worker_done, heartbeat, escalation, decision_gate) from a worker with a Dispatch keep their current handling. A stale Task ID there is still refused by the lifecycle check (task_dispatch_mismatch / missing_dispatch_id), and the coordinator still sees that refusal in its inbox.
  • Messages with a resolving --dispatch-id, unknown Task IDs, Tasks with no Run, and malformed payloads behave as before.

What changed

  • routing.ts (resolveMessageRun): when there's no --to or --run, a known Task owned by another Run raises task_run_mismatch. Three cases skip the check:

    • a Dispatch resolves and the payload named it;
    • a Dispatch resolves and the message is a lifecycle type;
    • the sender has an active Dispatch and is the bound coordinator of the Task's Run (nested-coordinator reporting).

    The check costs one primary-key Task read, plus a coordinator-binding lookup only on the mismatch path.

  • send-methods.ts: passes the message type into resolveMessageRun.

  • errors.ts: adds task_run_mismatch to the RPC passthrough allowlist. Without it, the CLI got a generic runtime_error.

Built-in flows that use implicit targeting

I searched skill-guides/, skills/, resources/skills, the CLI specs/help, and the worker preamble (src/main/runtime/orchestration/preamble.ts) for orchestration send. Every built-in worker command (heartbeat, escalation, worker_done) passes --task-id <own> --dispatch-id <own>, so it skips the guard. The coordinator follow-ups use --to dispatch:<id>. No built-in flow sends a foreign Task without a destination. Nested coordinators also need nestedWorkerMaxDepth set to 2 or more (the default is 1; see src/shared/nested-worker-depth.ts), so the nested case is opt-in.

Validation

Real CLI round trip. I built the CLI and main from this branch and ran electron . --serve against a throwaway isolated profile (ORCA_USER_DATA_PATH=/tmp/oe32037/profile, background launch, nestedWorkerMaxDepth: 2). I created three real PTY terminals in a fixture repo: coordinator C, nested coordinator N and child worker X. Every command ran inside its terminal, so it used that terminal's real ORCA_TERMINAL_HANDLE/ORCA_PANE_KEY identity. Setup: C ran run-create (R1), task-create (T1) and dispatch T1 --to N. N ran run-create (R2), task-create (T2) and dispatch T2 --to X. Results:

Sender Implicit send --type status --task-id Result
N (nested coordinator) T2 (its child Run) delivered to R1 (parent), as on main
N T1 (its own Dispatch's Task) delivered to R1
X (child worker) T2 (own) delivered to R2
X T1 (another Run) task_run_mismatch, offering only --run R2. --run R2 then succeeded. --run R1 / --to run:R1 fail with dispatch_run_mismatch, which is why the message no longer suggests them.
C (root coordinator) T2 (child Run) task_run_mismatch offering --run R2 or --run R1. --run R2 then succeeded.
X worker_done --task-id T2 --dispatch-id D2 completed

C's check showed exactly the two N reports in R1. Afterwards I stopped the server and deleted the profile.

Rebased onto origin/main 28c726855e1d (head c202c7d7d26a), which includes #32168 (main's max-lines and typecheck fix). No conflicts. After the rebase: pnpm test src/main/runtime/rpc/methods/orchestration src/main/runtime/rpc/errors gives 91 files and 1004 tests passing; full pnpm tc is clean; oxlint, oxfmt and check:code-quality:changed are clean.

Tests.

  • implicit-task-run-routing.test.ts has 14 tests. That includes a new nested-coordinator case, which fails without the exemption and passes with it.
  • TMPDIR=/private/tmp pnpm vitest run src/main/runtime/rpc/methods/orchestration/messaging src/main/runtime/rpc/errors.test.ts src/main/runtime/rpc/orchestration-party-addressing.test.ts: 15 files, 326 tests pass.
  • check:code-quality:changed, oxlint and oxfmt pass.

Not exercised: remote, WSL or Windows hosts. The change is in the host-local orchestration.send handler, with no new wire fields and no platform-specific code. Each host enforces only its own copy. An older CLI that doesn't recognise task_run_mismatch still prints the message text.

Linked issue

Partial repair for #30402: this covers the routing half. The sender-identity half was addressed by #30406 (merged). Plain-text send receipts remain open. This PR must not close #30402. #13696 is a separate report.

Remaining risks / tradeoffs

  • A send without a destination that names another Run's Task, and that main used to misdeliver, now fails loudly with the exact --run to use. Scripts that relied on the misdelivery need that flag. No built-in skill or preamble does this.
  • The nested-coordinator exemption keeps main's behavior in one narrow case: if a child-Run worker were misidentified as its own nested coordinator, its report about a child Task would still go to the parent Run, as on main. This is not a regression, but the guard doesn't close that case.
  • Older servers keep the old behavior until they're updated.

Visual proof

N/A: backend message admission, with no rendered UI.

Agent skill upstream boundary

  • Not applicable; no upstream skill source or bundled guide is copied or changed.

@coderabbitai

coderabbitai Bot commented Oct 22, 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: 43e7e996-4b0c-459a-bc50-28f90011c43c
📥 Commits

Reviewing files that changed from the base of the PR and between b062279 and 074df3fad9b2d96ed067407dd8b80451ff05b57b.

📒 Files selected for processing: 4
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/implicit-task-run-routing.test.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/send-methods.ts
  • src/main/runtime/rpc/methods/orchestration/routing.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 a message uses an inferred Run, routing checks whether its payload task ID belongs to that Run. A mismatch raises task_run_mismatch. Tests cover coordinator and worker messages, messages naming the sender’s own task, explicit Run or recipient selection, explicit terminal delivery, stale-task lifecycle handling, and payloads with absent, malformed, or unknown task IDs.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 074df

An empty Dispatch ID can still let a message naming another Run’s Task bypass the new routing check. Address the existing finding or explicitly accept this bounded risk before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning For #30402, the PR implements the implicit Task/Run mismatch guard and adds regression tests for rejected writes, explicit cross-Run delivery, lifecycle handling, and nested coordinators. `terminal-id… Expose the resolved sender and destination in the orchestration send result or CLI receipt. Add automated tests for the receipt fields. Keep the existing routing and lifecycle regression coverage.
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: rejecting task messages that target another implicitly inferred Run.
Out of Scope Changes check Passed The production changes stay within #30402. routing.ts validates implicit Task/Run ownership, send-methods.ts passes the message type, and errors.ts preserves the structured mismatch code. The te…
Description check Passed The pull request description is complete and relevant. It explains the problem, implementation, rationale, linked issue, testing, validation results, risks, and visual proof. The template's checklist …
Full details: Out of Scope Changes check

Explanation

The production changes stay within #30402. routing.ts validates implicit Task/Run ownership, send-methods.ts passes the message type, and errors.ts preserves the structured mismatch code. The tests cover the changed routing behavior. No unrelated production change is demonstrated.

Full details: Description check

Explanation

The pull request description is complete and relevant. It explains the problem, implementation, rationale, linked issue, testing, validation results, risks, and visual proof. The template's checklist and Review section are not fully completed, but the missing items do not prevent review.

Full details: Linked Issues check

Explanation

For #30402, the PR implements the implicit Task/Run mismatch guard and adds regression tests for rejected writes, explicit cross-Run delivery, lifecycle handling, and nested coordinators. terminal-identity.ts also retains structured session identity and refuses ambiguous fallback. The linked issue still requires send receipts that show the resolved sender and destination. message-send-handler.ts still formats a normal send as Sent ${value.message.id} and does not expose those fields.

Resolution

Expose the resolved sender and destination in the orchestration send result or CLI receipt. Add automated tests for the receipt fields. Keep the existing routing and lifecycle regression coverage.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · 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.

@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


ℹ️ 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: 10dfc05b-a520-45be-afc4-c2a9d18a9415
📥 Commits

Reviewing files that changed from the base of the PR and between bb9cc5c and 3a2ada6.

📒 Files selected for processing: 3
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/orchestration/messaging/implicit-task-run-routing.test.ts
  • src/main/runtime/rpc/methods/orchestration/routing.ts

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

// Lifecycle validation owns malformed payload errors; routing simply cannot derive a Dispatch.
}
}
const payloadNamesDispatch = dispatchId !== undefined

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Do not treat an empty dispatchId as a resolved payload Dispatch.

If a worker sends a status payload with dispatchId: "" and a Task from another Run, payloadNamesDispatch is true. The empty ID makes Dispatch lookup fall back to the worker’s active Dispatch. The condition at Line 83 then skips the Task ownership check, so routing accepts the foreign Task in the inferred Run. Require a nonempty payload Dispatch ID before applying this exception.

Proposed fix
--- "a/src/main/runtime/rpc/methods/orchestration/routing.ts"
+++ "b/src/main/runtime/rpc/methods/orchestration/routing.ts"
@@ -46,7 +46,7 @@
       // Lifecycle validation owns malformed payload errors; routing simply cannot derive a Dispatch.
     }
   }
-  const payloadNamesDispatch = dispatchId !== undefined
+  const payloadNamesDispatch = Boolean(dispatchId)
   if (!dispatchId && params.to?.startsWith('dispatch:')) {
     dispatchId = params.to.slice('dispatch:'.length)
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const payloadNamesDispatch = dispatchId !== undefined
const payloadNamesDispatch = Boolean(dispatchId)

@nwparker
nwparker force-pushed the nwparker/implicit-task-message-run branch 2 times, most recently from 074df3f to a35dfa0 Compare October 23, 2026 03:55
nwparker and others added 4 commits October 22, 2026 21:00
…ispatch scope

Add task_run_mismatch to the RPC passthrough allowlist so clients see the
code instead of runtime_error, skip the guard when the payload names a
resolved Dispatch so lifecycle validation keeps its audited
task_dispatch_mismatch rejection, and tell the sender how to recover.

Co-Authored-By: Claude <noreply@anthropic.com>
…sk mismatches

Lifecycle sends (worker_done/heartbeat/escalation/decision_gate) from a worker with
an active Dispatch now skip task_run_mismatch so the rejection is recorded in the
Dispatch Run, as on main, instead of throwing advice that loops into
dispatch_run_mismatch.

Co-Authored-By: Claude <noreply@anthropic.com>
…ve runnable task_run_mismatch steps

A worker that coordinates the Task's child Run still reports to its parent Run implicitly, as on main.
The refusal now names the exact --run that will be accepted; Dispatch-bound senders are only offered their own Run.

Co-Authored-By: Claude <noreply@anthropic.com>
@nwparker
nwparker force-pushed the nwparker/implicit-task-message-run branch from a35dfa0 to c202c7d Compare October 23, 2026 04:02
@nwparker
nwparker merged commit 601e900 into main Oct 23, 2026
46 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.

Structured worker reports successful send, but reply is attributed to another terminal and routed to the wrong Run

1 participant