Skip to content

fix(orchestration): enforce honest recipient routing - #14964

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/sta3767-recipient-reachability
Aug 17, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/sta3767-recipient-reachability

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​787 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​778
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​436 $\color{#cf222e}{\Huge{\mathbf{−}}}$​52 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​384

Summary

Enforce honest orchestration recipient routing at the authoritative send boundary.

ok:true means the address resolves to a durable reader, or the receipt explicitly reports the delivery limitation; it never silently creates unreachable mail.

This supersedes #13639. That PR predates the canonical Run/Dispatch mailbox work in #13717 and its fork rejects maintainer pushes despite maintainerCanModify, so this branch rebuilds the fix directly on current main.

Fixes #13363.

Semantics

  • Explicit run: and dispatch: addresses remain canonical.
  • Current or historical coordinator handles normalize to run:.
  • Active Dispatch owners normalize to dispatch:, including detached panes.
  • Live unowned terminals retain compatibility delivery with a legacy_terminal_recipient warning.
  • Unknown or closed terminals fail with terminal_not_found and create no message or mutation receipt.
  • Stale leaf handles cannot adopt a replacement pane's Run; a proven historical owner still routes to its original canonical mailbox.
  • Ambiguous historical owners fail with recipient_ambiguous; explicit Run mismatches fail with recipient_run_mismatch.
  • Group members are re-resolved after discovery. Disappearing recipients are skipped and reported without making the whole fan-out all-or-nothing.
  • Group inserts are atomic and savepoint-safe inside caller-owned transactions; completed mutation receipts survive post-insert notification failure, and canonically identical recipients are deduplicated.
  • Run-bound pane identity takes precedence over overlapping Dispatch ownership, matching orchestration check.
  • Uniquely proven pre-update coordinators keep routing to their adopted canonical Run; mixed coordinator/worker identity fails closed.

No schema migration, protocol bump, stream opcode, provider-specific path, or platform-specific behavior is introduced.

Reproduction and oracle

Latest affected main reproduced the original defect through the public CLI: invented and closed terminal handles returned ok:true, persisted unread orphan rows, and replayed mutation receipts. Cross-Run bare coordinator mail and group fan-out were stored under the sender Run and invisible to the intended reader. #13717 already fixed same-Run stale coordinator aliases and active Dispatch compatibility; this PR preserves those paths and narrows the remaining gap.

The deterministic routing oracle checks both receipt/error behavior and persisted DB/check visibility. The byte-identical red/green/revert matrix used test bytes with SHA-256 64415fea11974799f95e1392a75db319393ee1765cf9e26753bdbe397dd06166:

  • candidate: 17/17 pass;
  • reachability guard disabled: 6/17 fail, visibly accepting unknown, closed, stale, and disappearing recipients and dishonest retries;
  • restored candidate: 17/17 pass.

The final rebased candidate adds a nested-transaction regression and a single-Dispatch wrong-Run proof; its routing oracle is 18/18 green.

Rebase and validation

Final commit 0d44f4a is directly based on main c7995a6.

Main's orchestration DB modularization conflicted with the old monolithic db.ts hunk. The conflict resolution kept main's facade and ported the five DB changes into message-insert, run-lookup, dispatch-lookup, and legacy-coordinator-mail-takeover modules with their exports and prototype attachments intact.

  • Final changed-test slice: 11 files, 1,333 passed, 1 existing skip.
  • Routing oracle: 18/18 passed.
  • Node and CLI TypeScript typechecks passed.
  • Changed-code and type-aware quality checks: zero findings across 22 files.
  • Formatting, diff check, reliability manifest, and max-lines ratchet passed.
  • Earlier broader validation remains green: 99-file orchestration slice, compatibility suites, adopted-storage, CLI warnings, mixed-version wire contract, and Electron receipt/DB/check visibility.

Compatibility

Resolution uses host-authoritative runtime and database state, so local, folder-workspace, SSH, paired/headless, and reminted-handle paths share the same boundary. Existing RPC shapes only gain optional receipt warnings; older clients ignore them, while hard errors use the existing structured RPC error path. Federation, acknowledgements, deduplication, restart reconciliation, and lifecycle settlement behavior remain unchanged.

Review disposition

Three independent gpt-5.6-luna reviewers covered routing/#13717 compatibility, adversarial cross-Run/stale-handle/fan-out/SSH/paired/mixed-version behavior, and test non-vacuity/DB/performance/scope.

One legitimate final-round finding was fixed: insertMessages used a top-level transaction and could roll back a caller-owned outer transaction. It now uses a SAVEPOINT with a regression that proves the outer write survives while the failed inner batch is fully removed.

Two claims were rejected with evidence:

  • A sole detached Dispatch in the wrong explicit Run already reaches runMismatch after selectDispatch; the added RPC regression proves recipient_run_mismatch and zero persisted rows.
  • Pane lookup is indexed by fix(orchestration): preserve mailbox delivery identity #13717's idx_dispatch_assignee_pane_leaf and idx_dispatch_active_assignee_pane_key migration indexes.

All three reviewers returned CLEAN on the exact final diff. After main advanced with two unrelated UI/IME commits, all three independently confirmed the final rebase preserved the reviewed patch byte-for-byte and kept main as the direct parent.

@coderabbitai

coderabbitai Bot commented Aug 16, 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 52db5562-a916-42d7-aa89-22f073400bbc

📥 Commits

Reviewing files that changed from the base of the PR and between 47a53b6 and c5ddef4bf659ae033e3f8235329298be589aac0d.

📒 Files selected for processing (22)
  • src/cli/handlers/orchestration-send-receipt-warnings.test.ts
  • src/cli/handlers/orchestration.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration-cli-subprocess.test.ts
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/orchestration/db/dispatch-context/dispatch-lookup.ts
  • src/main/runtime/orchestration/db/messages/message-insert.ts
  • src/main/runtime/orchestration/db/runs/legacy-coordinator-mail-takeover.ts
  • src/main/runtime/orchestration/db/runs/run-lookup.ts
  • src/main/runtime/orchestration/message-batch-atomicity.test.ts
  • src/main/runtime/orchestration/orchestration-legacy-storage-db.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/orchestration-check.test.ts
  • src/main/runtime/rpc/methods/orchestration-recipient-routing.test.ts
  • src/main/runtime/rpc/methods/orchestration-recipient-routing.ts
  • src/main/runtime/rpc/methods/orchestration-rpc-test-harness.ts
  • src/main/runtime/rpc/methods/orchestration-send.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/main/runtime/rpc/orchestration-legacy-coordinator-race.test.ts
  • src/main/runtime/rpc/orchestration-runtime-update-settlement.test.ts
  • src/main/ssh/ssh-remote-orca-cli.test.ts
🚧 Files skipped from review as they are similar to previous changes (16)
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/rpc/methods/orchestration-send.test.ts
  • src/cli/handlers/orchestration-send-receipt-warnings.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/orchestration-rpc-test-harness.ts
  • src/main/runtime/rpc/orchestration-runtime-update-settlement.test.ts
  • src/main/runtime/rpc/orchestration-legacy-coordinator-race.test.ts
  • src/main/runtime/rpc/methods/orchestration-check.test.ts
  • src/main/runtime/orchestration-cli-subprocess.test.ts
  • src/main/ssh/ssh-remote-orca-cli.test.ts
  • src/main/runtime/rpc/methods/orchestration-recipient-routing.test.ts
  • src/cli/handlers/orchestration.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/main/runtime/rpc/methods/orchestration-recipient-routing.ts
  • src/main/runtime/orchestration/orchestration-legacy-storage-db.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The change adds durable run and dispatch mailbox lookup for terminal handles. Bare recipients now resolve to canonical run: or dispatch: addresses, with structured errors and warnings for ambiguity, mismatches, unreachable terminals, and legacy delivery. Point-to-point and group sends use resolved mailbox targets and runs. CLI receipts display recipient warnings. Tests cover routing, fan-out, deduplication, mailbox ownership, pane resolution, and receipt formatting.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% 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 The changes satisfy #13363 by rejecting unknown or closed terminals, preventing unreachable writes, and reporting legacy delivery limitations explicitly.
Out of Scope Changes check ✅ Passed The production and test changes support recipient validation, routing, atomicity, warnings, and compatibility requirements without unrelated scope.
Title check ✅ Passed The title clearly and concisely describes the main change: enforcing correct orchestration recipient routing.
Description check ✅ Passed The description clearly covers the problem, behavior changes, linked issue, compatibility, implementation scope, and extensive validation.
✨ 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.

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

615-629: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

The relay branch drops recipient warnings.

src/main/runtime/rpc/methods/orchestration.ts wraps the federated control-mail receipt with withSendWarnings at Line 641, so a relay receipt can carry warnings. The CLI type at Lines 120-129 omits warnings on the relay variant, and the relay branch returns the line without withWarnings. If a resolved dispatch: recipient ever produces a warning, the CLI hides it. Apply withWarnings to the relay lines and add the field to the relay variant.

♻️ Proposed fix
       if ('relay' in r) {
         if (r.relay.destination === 'worker') {
-          return `Queued ${r.relay.messageId} for worker Dispatch ${r.relay.dispatchId}`
+          return withWarnings(`Queued ${r.relay.messageId} for worker Dispatch ${r.relay.dispatchId}`)
         }
-        return `Queued ${r.relay.messageId} for Run home (Dispatch ${r.relay.dispatchId})`
+        return withWarnings(
+          `Queued ${r.relay.messageId} for Run home (Dispatch ${r.relay.dispatchId})`
+        )
       }

Add the field to the relay variant at Lines 120-129:

       lifecycle?: LifecycleSendResult
+      warnings?: SendRecipientWarning[]
     }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ec3d491-7ff0-488d-8913-048237845122

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3e583 and 7b884cd598290dd7a849f7c54c058186858eab5b.

📒 Files selected for processing (13)
  • src/cli/handlers/orchestration-send-receipt-warnings.test.ts
  • src/cli/handlers/orchestration.ts
  • src/main/runtime/orchestration-cli-subprocess.test.ts
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/orchestration/orchestration-legacy-storage-db.test.ts
  • src/main/runtime/rpc/errors.ts
  • src/main/runtime/rpc/methods/orchestration-check.test.ts
  • src/main/runtime/rpc/methods/orchestration-recipient-routing.test.ts
  • src/main/runtime/rpc/methods/orchestration-recipient-routing.ts
  • src/main/runtime/rpc/methods/orchestration-send.test.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/main/runtime/rpc/orchestration-legacy-coordinator-race.test.ts
  • src/main/runtime/rpc/orchestration-runtime-update-settlement.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review.

@Jinwoo-H
Jinwoo-H force-pushed the fix/sta3767-recipient-reachability branch 3 times, most recently from a1696af to 58ffc86 Compare August 17, 2026 04:40
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Jinwoo-H
Jinwoo-H force-pushed the fix/sta3767-recipient-reachability branch from 58ffc86 to c5ddef4 Compare August 17, 2026 08:10
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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]: orchestration send accepts an unknown terminal handle silently, creating a message nobody can read

1 participant