Skip to content
Source
Sign inSign up
pingdotgg/t3code

delegate_task async completions are silently starved after two wake deliveries per cohort — parent never wakes for third-wave children (V2 branch) #12285

Closedastarktc(GitHub profile, opens in a new tab) opened this issue 2 comments

Summary

On the Orchestrator V2 branch (t3code/codex-turn-mapping, PR #2829 — this code is not on main), delegate_task with mode: "async" promises the parent a wake on every child terminal (completionWake: "always", OrchestratorMcpService.ts:1282), and its tool description tells the agent to "end the turn instead of polling." But each delegation cohort (the set of children delegated in one parent run) carries a lifetime cap of two wake deliveries: settledDeliveryCount. Any child whose completion lands in a third wave stays completionDelivery: "pending" forever — no wake, no queued message, no re-arm on restart. The orchestrating agent, following the contract, sits idle waiting for a completion that already happened.

With 4–5+ parallel children whose completions straddle wake turns this is near-guaranteed; with 2–3 it almost never fires, which is why it reads as intermittent.

Originally reported as a comment on #2829 (2026-08-30, comment 5466160819); re-filing as an issue per the triage of #11168 (same class: V2 MCP contract violation). Re-verified today on the current V2 head b4cc55c24 (0.0.42) — all three cap sites are still present.

Where the mismatch lives

Three sites in apps/server/src/orchestration-v2/Orchestrator.ts at b4cc55c24:

  1. planDelegatedCompletionDelivery — line 7098:
    if (settledDeliveryCount >= 2) {
      // A cohort permits one initial delivery and one successor. Keep the
      // result pending and inspectable instead of recursively re-arming the
      // parent for every child that finishes after that bounded handoff.
      ... completionDelivery: { state: "pending" ... }, offer: false
  2. finalizeDelegatedCompletionDelivery (the sweep that runs when a wake turn settles) — line 7468: canReserveFollowUp = ... && settledDeliveryCount < 2 && pendingTaskIds.length > 0
  3. dispatchNotificationAccepted (the durable-mailbox re-arm path, added since the original report) — line 7570: pendingTaskIds is computed only when (cohort.settledDeliveryCount ?? 0) < 2, so an accepted delivery never reserves a successor either.

settledDeliveryCount never resets, so this is not a throttle — it is lifetime starvation per cohort. Nothing revisits a "pending" task after the cap engages: handleTerminalRun only sweeps delivery runs, the startup recovery path re-runs the same capped sweep, and finalizeAppOwnedSubagent early-returns on existingResultTransfer.

Evidence (projection forensics from a real thread)

Parent run 7 delegated five async children (t10, t11, t13, t15, t17), so all five share run 7's cohort. From orchestration_v2_projection_*:

time (UTC)eventcohort
01:01:52run 7 delegates t10, t11, t13, t15, t17—
01:05:49t10 completes → delivery 1 → wake run 8settled=0, gen 1
01:05:56–01:07:01t17, t13, t15 complete during run 8 → "pending"
01:07:11run 8 settles → sweep reserves delivery 2 = {t15, t17, t13} → wake run 9settled=1, gen 2
01:07:20t11 completes 8 s into run 9 → "pending"
01:09:12run 9 settles → settledDeliveryCount → 2, pendingTaskIds=[t11], canReserveFollowUp requires < 2 → refusedsettled=2, delivery=null
01:09–01:29parent idle for 20 min; t11's result queryable, no wake exists or ever will
01:29:48human notices and nudges; that run reads task_status → t11 finally acknowledged

Final cohort row: settledDeliveryCount=2, nextGeneration=3, disposition=open, delivery=null with a terminal, never-delivered task. Children delegated during later wake turns started fresh cohorts, so their wakes worked — which masks the bug at moderate parallelism.

(The queued-delivery merging — t13/t15/t17 amending one bundled wake — is the right behaviour. Only the lifetime cap is the problem.)

Steps to reproduce

  1. From a parent thread, delegate_task five async children in a single turn, sized so their completions stagger (e.g. 1 min, 3 min, 3 min, 3 min, 5 min).
  2. Let the parent end its turn after dispatch (as the tool text instructs).
  3. Observe: wake 1 for the first completion; wake 2 bundles the next three; the fifth child completes during wake 2 and is never delivered. task_status shows it completed; the parent never wakes.

The integration test OrchestratorMcpToolkit.integration.test.ts currently asserts the capped behaviour (a third terminal does not reserve a third delivery), so the cap is intentional — the report is that the intent contradicts the tool contract.

Suggested fixes (any one closes it)

  1. Make the cap a concurrency bound, not a lifetime bound. The recursion the comment fears is already bounded by "one delivery in flight + one reserved successor", and each child settles exactly once. Drop the < 2 gates (keep the counter as metadata). We run the V2 branch daily with exactly this patch (all three sites; integration test updated so a third terminal reserves a third delivery) — 800+ server tests green, no runaway re-arming observed across ~3 weeks of heavy delegate_task use. Happy to open it as a PR if wanted.
  2. Sweep pendings on any parent-run settle: extend handleTerminalRun to arm a delivery for terminal app-owned tasks left "pending" whenever the parent goes non-live. The existing generation + alreadyDispatched dedupe in ProviderContinuationService guards duplicates.
  3. At minimum, don't be silent: surface refused deliveries (system line: "N delegated results pending — read with task_status") and soften the tool description's "end the turn instead of polling", which is currently a trap.

Environment

  • V2 branch head b4cc55c24 (0.0.42), packaged macOS arm64 desktop build; also reproduced on the 2026-08-28 and 2026-09-13 heads.
  • Provider-independent (orchestrator code path); observed with Pi and Claude children.
  • macOS 15, Apple Silicon.
  1. Triage

    Confirmed as a real Orchestrator V2 MCP contract bug. The report matches the current V2 branch (t3code/codex-turn-mapping / PR #2829, HEAD 7060b3425, still 0.0.42). This code is not on main. All three lifetime-cap sites cited at b4cc55c24 are still present (line numbers shifted +20).

    What breaks

    delegate_task with mode: "async" sets completionWake: "always" (OrchestratorMcpService.ts:1282) and the tool text tells the agent to “end the turn instead of polling.” That promises a parent wake on every child terminal.

    Delivery is coalesced per parent-run cohort (every child created in one parent turn shares that run’s delegatedCompletion). Coalescing itself is correct: siblings that finish while a wake is queued or in flight join one bundled delivery. The defect is the lifetime counter settledDeliveryCount, which never resets and hard-stops after two settled deliveries:

    1. planDelegatedCompletionDelivery (Orchestrator.ts:7118, was 7098 at b4cc55c24) — if settledDeliveryCount >= 2, mark the task completionDelivery: "pending" and offer: false.
    2. finalizeDelegatedCompletionDelivery (Orchestrator.ts:7488, was 7468) — canReserveFollowUp requires settledDeliveryCount < 2. The sweep that runs when a wake turn settles therefore refuses a third reserved delivery even when pendingTaskIds is non-empty.
    3. dispatchNotificationAccepted (Orchestrator.ts:7590, was 7570; added in 890a84dd5 after the original #2829 comment) — pendingTaskIds is computed only when (cohort.settledDeliveryCount ?? 0) < 2. Mailbox accept does not increment the counter (“does not … spend an idle-wake allowance”), but it still honors the same lifetime gate.

    The comment at the first site states the intent: “A cohort permits one initial delivery and one successor.” That bound was introduced in #5311 (ed837a810) to stop #4499’s one-wake-per-sibling fan-out. It is a lifetime cap, not a concurrency throttle.

    After the cap engages, nothing revisits a leftover "pending" task:

    • handleTerminalRun only finalizes the terminal delivery run (and finalizeAppOwnedSubagent for a child thread). A normal parent-run settle does not sweep leftover pendings.
    • finalizeAppOwnedSubagent returns immediately when a subagent_result transfer already exists, so a later pass cannot re-plan.
    • Startup recovery re-runs the same capped finalizeDelegatedCompletionDelivery and only offers when cohort.delivery is already reserved. A delivery: null + settledDeliveryCount === 2 cohort stays silent across restart.

    task_status can still read and acknowledge the result. The parent agent, following the tool contract, never gets a wake and never calls it.

    The forensic timeline in the report (five children on run 7 → wake 8 → wake 9 → t11 pending forever) is the designed third-wave path, not a race. Children delegated during later wake turns start fresh cohorts, so moderate parallelism masks it. That is why 2–3 children almost never hit it and 4–5+ staggered children almost always do.

    Why this is not “working as documented”

    The cap is intentional and tested. OrchestratorMcpToolkit.integration.test.ts (around 2707–2808) asserts that a third terminal after the successor has started stays pending, settledDeliveryCount === 2, delivery === null, and that no third continuation is offered.

    That test encodes #5311’s product choice. It contradicts the MCP contract shipped in the same branch:

    • async → completionWake: "always"
    • tool description: “An async child's completion wakes this thread … so end the turn instead of polling”

    The recursion #5311 feared is already bounded without a lifetime counter: planDelegatedCompletionDelivery folds into a queued delivery, parks siblings as "pending" while a delivery run is live/blocking, and only arms a successor when delivery is clear. Each child settles once. Dropping the < 2 / >= 2 gates keeps “one in flight + one reserved successor” and restores wake-per-terminal.

    There is no system line, queue row, or tool-result warning when a delivery is refused. Silence is the failure mode.

    • Not a duplicate of #11168 (wait-mode client ~5 min timeout, no taskId). Same class: V2 MCP contract violation. Same reporter.
    • Original report: PR #2829 comment 5466160819 (2026-08-30). Re-filed here per the #11168 triage.
    • #4499 introduced one wake per async child terminal. #5311 coalesced those into a cohort with a two-delivery lifetime cap.
    • #9103 (fix/delegated-completion-idle-wake) already implemented suggested fix 1 (drop the lifetime gates, reserve leftover pendings, update the integration test to expect a third delivery). Closed 2026-09-07 as a contaminated 955-file rebase, not as a rejection of the bug. Worth a clean rebase onto current V2, not a new design debate.
    • Smaller related hole, still present and not this bug: settled_only (wait-mode) returns from planDelegatedCompletionDelivery without even marking "pending" when the parent has a live run (Orchestrator.ts:7008–7017).

    Suggested fix (on the V2 branch)

    Preferred, same as #9103 / the reporter’s daily patch:

    1. Make the cap a concurrency bound, not a lifetime bound. Remove the settledDeliveryCount >= 2 early return and both < 2 follow-up gates. Keep the counter as metadata if useful. Recursion is already bounded by one in-flight delivery plus one reserved successor.
    2. Flip the integration test so a third terminal does reserve a third delivery; keep the coalescing assertions (bundling t13/t15/t17 into one wake is the right behavior).
    3. Optional safety net: if a parent run goes non-live with terminal app-owned tasks still "pending", reserve a delivery. ProviderContinuationService.currentDelegatedCompletionDelivery already drops stale generations / alreadyDispatched offers.

    If the lifetime cap is kept as a product choice, the contract has to change: drop "always" / “end the turn instead of polling,” and surface refused deliveries (system line: N delegated results pending — read with task_status). Leaving both the cap and the current tool text is a trap.

    No change needed on main. Fix belongs on t3code/codex-turn-mapping.

  2. juliusmarminge added labelsbug

  3. juliusmarminge added labelsaccepted

  4. juliusmarminge added labelsvia-triage

  5. Fixed by #13938 (merged).

  6. juliusmarminge closed this

Sign in to join this conversation.