fix(server): a delegated result whose steer never landed wakes the parent after it settles #14732
A delegated result can remain reserved after its provider rejects a steer and the receiving run settles. That strands the unread result, or leaves an empty reservation blocking later siblings after the result was read.
Extend the existing delivery finalizer to reconcile delegated steers as well as initial delivery messages. Unread reservations are offered again; empty ones release pending siblings, including settled-only results when a queued user message starts. Recovery checks the current receiving run and open reservation under the thread lock, including persisted steers found during startup. A rolled-back receiver releases its reservation without waking work; unread results return to pending and acknowledged results stay acknowledged. A late continuation tied to a rolled-back originating or receiving run gets an accepted no-op receipt. Stop retains its existing stopped/disposed behavior.
Rebuilt from @juliusmarminge's original #14732, preserving its commits and merging current main. Removed the one-off 544-line test file and custom replay-harness changes. The final diff changes only the orchestrator and its existing delivery suite; notification acceptance, contracts, clients, and provider adapters are unchanged.
Verification on the rebuilt head:
- Before: the existing suite passed 20 tests. The six focused regressions produced five assertion failures (three missing wakes, two rollback revivals); Stop already passed.
- After: all 28 delivery tests pass, plus 122 adjacent tests across nine files in total, covering continuation delivery, run-completion reads, Stop, rollback, queue order, steering completion, bounded control reads, and command policy. The review follow-up reproduced a missing startup wake and a stale rollback reservation before fixing them.
- Server typecheck, targeted lint, formatting, and diff checks pass. Lint retains two warnings in unchanged code.
- Before/after behavior proof records the assertion failures and final passing run on
2fae83e2007592e39bfe8a096c8cef92824e1b62. The regressions start from persisted rejected-steer state and exercise the real event sink, run-update subscriber, continuation queue, acknowledgment, Stop, and message dispatch. They synchronize on persisted work rather than sleeps. They do not exercise actual provider retry timing.
Screenshots are not applicable to this server-only change. No live provider CLI or packaged macOS, Windows, Electron, iOS, or Android verification is claimed. The visible behavior is shared by all clients through the server. Human review of the asynchronous recovery and rollback semantics remains required before merging.
Two independent full-diff review rounds (Claude Opus 5.5 and GPT-6-Sol) found and verified fixes for startup recovery missing steers and rolled-back receivers retaining reservations. Round two found no blocking code issues. After merging main at 9f52dc28a9, the reviewed diff remained byte-for-byte identical and all 150 focused tests passed again.
Rollback intentionally offers no immediate wake, including for a never-seen pending sibling. If no sibling finishes later, pending results remain available through explicit task_status. This avoids starting a turn immediately after rollback and needs maintainer acceptance alongside the recovery/rollback semantics.
Implementation: GPT-6.1-Sol in the Codex harness through T3 Code. Tests: GPT-6-Astra. Independent reviews: Claude Opus 5.5 and GPT-6-Sol.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/Orchestrator.ts line 8944OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -8894,0 +8924,21 @@8924+ cohort?.disposition !== "open" ||8925+ delivery == null ||8926+ delivery.messageId !== steer.id ||8927+ delivery.generation !== ownership.generation8928+ ) {8929+ continue;8930+ }8931+ if (delivery.taskIds.length > 0) {8932+ yield* offerDelegatedCompletionDelivery(threadId, parentRun.id);8933+ continue;8934+ }8935+ const parentIsLive = hasLiveRun(projection);8936+ const pendingTasks =8937+ projection.thread.archivedAt === null && projection.thread.deletedAt === null8938+ ? projection.subagents.filter(8939+ (task) =>8940+ task.origin === "app_owned" &&8941+ task.runId === parentRun.id &&8942+ task.completionDelivery?.state === "pending" &&8943+ isTerminalDelegatedTaskStatus(task.status) &&8944+ (!parentIsLive || task.completionWake === "always"),
🟠 High
orchestration-v2/Orchestrator.ts:8944Pending default
settled_onlychild results are permanently left undelivered when an unrelated queued turn is promoted beforerecoverSettledDelegatedSteersruns.handleTerminalRuncallsstartNextQueuedRunfirst, sohasLiveRun(projection)is true and the empty reservation's filter excludes those children;nextDeliverybecomesnull, clears the reservation, and later terminal events have no steer message to recover. Preserve the pre-promotion liveness state or otherwise keep the reservation until these pending results can be scheduled.🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/orchestration-v2/Orchestrator.ts around line 8944: Pending default `settled_only` child results are permanently left undelivered when an unrelated queued turn is promoted before `recoverSettledDelegatedSteers` runs. `handleTerminalRun` calls `startNextQueuedRun` first, so `hasLiveRun(projection)` is true and the empty reservation's filter excludes those children; `nextDelivery` becomes `null`, clears the reservation, and later terminal events have no steer message to recover. Preserve the pre-promotion liveness state or otherwise keep the reservation until these pending results can be scheduled.Real, fixed in 3075a2a2aa. Releasing an empty steered delivery now reserves pending siblings as if the parent weren't live, matching finalizeDelegatedCompletionDelivery after its receiving run settles. A queued message promoted at settlement no longer filters out settled_only results. The new test case 'reserves a settled-only sibling when a queued message starts at settlement' fails without this change (no wake for task:b) and passes with it.
🟠 High
orchestration-v2/Orchestrator.ts:8915A rollback that occurs before this handler acquires the lock does not stop the stale terminal event from re-offering its delegated delivery, so a discarded turn can start a continuation. The guard checks only the old
settledRun.status; check the current projected run status and return when it isrolled_back.const projection = yield* projectionStore.getThreadRecords(threadId, ["runs", "subagents"]); + const currentSettledRun = projection.runs.find((run) => run.id === settledRun.id); + if (currentSettledRun?.status === "rolled_back") return;🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/orchestration-v2/Orchestrator.ts around line 8915: A rollback that occurs before this handler acquires the lock does not stop the stale terminal event from re-offering its delegated delivery, so a discarded turn can start a continuation. The guard checks only the old `settledRun.status`; check the current projected run status and return when it is `rolled_back`. Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This production patch changes delegated-completion wakeups, reservation state, rollback handling, and startup recovery across asynchronous orchestration paths. The focused tests improve coverage, but the scheduling and recovery semantics are sufficiently nontrivial to merit human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Fixed in 3075a2a2aa. Recovery now rereads the settled run under the thread lock and returns if it is rolled_back. Per-cohort parent rollbacks were already skipped.
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_commitssetting.- Last reviewed commit: 2fae83e2007592e39bfe8a096c8cef92824e1b62
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto 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: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
52400e94-1675-4205-b56d-bf6acb8ae879
📥 Commits
-
Reviewing files that changed from the base of the PR and between 2e1becd8e0042e18468d532a4aea28469d192f73 and 2fae83e2007592e39bfe8a096c8cef92824e1b62.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.tsapps/server/src/orchestration-v2/Orchestrator.ts
Limit details: You’ve used all 10 included reviews currently available.
-
📝 Walkthrough
-
The orchestrator now handles delegated-completion messages and deliveries across rollback, receiving-run settlement, and recovery. Integration tests cover delivery outcomes, queued messages, stale wakes, rollback, and restart recovery.
Changes: Delegated completion settlement
Layer / File(s) Summary Handle delegated messages after rollback
apps/server/src/orchestration-v2/Orchestrator.tsWhen the referenced parent run or receiving run was rolled back, dispatchMessageupdates thread metadata without waking work.Settle and recover delegated deliveries
apps/server/src/orchestration-v2/Orchestrator.ts,apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.tsSettlement examines delegated-completion messages on the receiving run, updates claimed tasks, and offers eligible deliveries. Recovery identifies terminal receiving runs through messages on open reservations. Tests cover settlement, rollback, queued messages, stale wakes, and restart recovery. Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Suggested reviewers:
t3dotgg
Merge Risk: ⚪ Minimal · up to
2fae8-
This change ensures that a delegated result whose steer never landed is offered again, or that its reservation is released, after the receiving run settles. No concrete defect remains at the current head. Because the rollback and recovery semantics are intricate, owners should still confirm that they match the intended behavior.
Pre-merge checks:
4-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly identifies the server fix for delegated results whose steers never land and the resulting parent wake. Description check The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the behavior, implementation, test coverage, limitations, and review context in substa… Full details: Description check
-
Explanation
The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the behavior, implementation, test coverage, limitations, and review context in substantial detail.
-
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.Autopilot is currently an internal CodeRabbit preview.
juliusmarminge assignedjuliusmarminge
Taking over this one for batch composer-chat-18. I will reduce the regression coverage, rebuild against current main, and run independent adversarial reviews. No merge is planned.
tanstack-source added labelsbug
Thanks for working on the delegated-completion recovery path. I've reproduced a related failure involving a live parent run, without a rejected steer.
When a delegated child completes, its completion wake is queued behind an active parent run (
queue_after_active). If that parent callstask_statusbefore settling, the acknowledgement can clear the pending delivery and cancel the wake. The parent then settles without receiving the queued continuation.I also reproduced the inverse problem: if the parent already observed and answered the completion in its active turn, promoting another wake can cause a duplicate response.
I've added five regression cases in
DelegatedCompletionDelivery.test.ts, including repeated observations and recovery. Against upstreamf52fba48d9, they produce 5 failures and 63 passes; with the proposed fix, all 68 pass, plus 89 adjacent tests.The changes concern the completion acknowledgement and queued-run promotion paths, so I believe this is adjacent to the rejected-steer scenario addressed here.
Would you prefer that I contribute the regression tests to this PR, prepare a separate focused fix, or hold off while your implementation is evolving?
AI disclosure: DeepSeek V4.1 Flash via Mistral Vibe, using T3 Code's acpRegistry harness.
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
9f52dc2· PR result:2fae83e· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.