Skip to content

[Bug]: Settling a thread while a delegate_task wake is queued drops the completion wakes of every sibling child, permanently #38840

Closed as not planned

Description

@SwitchOCE

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Related but different: #31448 (settle ends provider-native background work) and #26097 (auto-settle on merge for coordinator threads). Here the children are server-owned delegate_task tasks. They keep running and finish fine, but their completion wakes are thrown away for good.

Area

apps/server

Steps to reproduce

Default settings (sidebarAutoSettleOnMerge is true by default).

  1. A Claude thread has a linked open PR. In one turn, its agent starts two async delegate_task children: child A is short, child B takes minutes. Each call returns "next":"Completion wakes this thread. Do not wait on it or poll it."
  2. While that turn (or a later queued one) is still running, child A finishes. The server queues a delegated-completion wake run behind the running turn (run.created, status: "queued", command command:fixture:delegated-completion:dispatch:…).
  3. Before that turn ends, the PR merges (in our case the agent merged it itself with gh pr merge).
  4. The turn ends. Auto-settle-on-merge settles the thread one second later, while the wake run is still queued.
  5. Child B finishes later. Optionally, unsettle the thread first by sending it a message from another thread.

Expected behavior

delegate_task keeps its contract: each child's completion wakes the parent. Settling the thread, automatically or by hand, either waits for the queued wake, as settleAfterRun already does, or at least leaves the wakes of children that are still running pending. The children aren't stopped by settle, so their results should still be delivered.

Actual behavior

No wake ever arrives for either child. The parent only finds out by calling task_status by hand.

Event log from one real run (0.1.10, orchestration v2 store, UTC):

00:01:37 subagent.updated  child A completed  completionDelivery=claimed
00:01:38 run.created       ordinal 5 (wake for A)  status=queued
00:06:45 PR merged (by the agent, during run 4)
00:06:52 run.updated       ordinal 4 completed
00:06:53 thread.settled    command=server:auto-settle:<thread>:<uuid>
00:06:53 run.updated       parent run 3 delegatedCompletion={"disposition":"disposed",...}
00:06:53 subagent.updated  child B status=running   completionDelivery={"state":"disposed"}
00:06:53 subagent.updated  child C status=running   completionDelivery={"state":"disposed"}
00:06:53 run.updated       ordinal 5 cancelled
00:07:32 thread.unsettled  (t3_thread_send from another thread)
00:47:08 subagent.updated  child B completed, context-transfer created, no run.created
00:47:19 subagent.updated  child C completed, context-transfer created, no run.created

Why, from reading the 0.1.10 server bundle:

  1. Settle disposes the whole cohort. thread.settle cancels queued automatic runs with dispatchQueuedRunCancel(…, events, "cohort"). In "cohort" mode interruptedWakeTaskIds isn't passed, so disposeDelegatedCompletionCohort keeps no tasks. It marks every task of that parent run disposed, including children that are still running. In "wake" mode it would keep them.
  2. Disposed is permanent. Unsettling doesn't restore it. When a child later finishes, the wake dispatch only picks tasks with completionDelivery.state === "pending", so nothing runs.
  3. Auto-settle doesn't see the pending work. isAutoSettlementCandidate checks pendingBackgroundTasks, but derivePendingBackgroundWork only reads provider threads, turn items and PR watches, not app-owned delegate_task children. So the thread list shows pendingBackgroundTasks: [] while children run. The queued wake run is also ignored: threadHasQueuedTurnStart only looks at latestUserMessageAt within QUEUED_TURN_START_GRACE_MS (120 s), and this wake had been queued for 5 minutes behind the running turns.

Control runs on the same server, with minimal Haiku parents and children:

  • Idle parent, child finishes: the wake arrives.
  • Parent settled by hand while its child is running, no wake queued: the wake still arrives.
  • Parent self-settles (t3_thread_organize settle) while a wake is queued: settleAfterRun waits for the wake run, then settles, and a later child's wake still arrives and unsettles the thread.

So the loss needs a settle that lands while a delegated-completion wake is queued. Auto-settle on merge does exactly that, because it fires as soon as a run ends.

Suggested fixes (any one would have prevented this):

  • Use "wake" instead of "cohort" when thread.settle cancels a queued delegated-completion run, so children still running stay pending.
  • Treat non-terminal app-owned delegate_task children, and queued delegated-completion runs, as blocking in isAutoSettlementCandidate.
  • On unsettle, or when a disposed task later completes, deliver its wake anyway.

Impact

Major degradation or frequent failure

Version or commit

0.1.10 (service-managed server, Linux x86_64), orchestration v2. Parent: claudeAgent / claude-opus-5-5. Children: codex gpt-6.2-sol and claudeAgent claude-opus-5-5.

Environment

Linux server run as a systemd user service; clients are the desktop app and the T3 MCP tools.

Activity

  1. juliusmarminge commented on Nov 19, 2026

    @juliusmarminge
    Member

    I tried to reproduce this on the current build and could not.

    Commit e58d0e9 (origin/main). I did not run the app end to end: that needs a real provider parent starting two async delegate_task children, plus a pull request merging mid-turn so settle on merge fires while a completion wake is queued. Instead I reproduced the mechanism against the real orchestrator, event sink and projection. The new test, in apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts, reuses the queueCompletionWakeBesideRunningSibling fixture: task A finished and its completion wake is queued behind a busy run, while sibling task B is still running. The test completes the busy run, holds the wake in the queue (the window before it starts), and dispatches thread.auto-settle. Command: cd apps/server && vp test run src/orchestration-v2/DelegatedCompletionDelivery.test.ts -t "queued completion wake". Result on main: AssertionError: expected 'disposed' to not equal 'disposed'. Running sibling B's completionDelivery is marked disposed, so B's later result cannot wake the parent. This matches the reporter's event log (child B/C completionDelivery={state:disposed} at thread.settled, no run.created on completion). Code path: Orchestrator.ts thread.settle calls dispatchQueuedRunCancel(..., "cohort"), so disposeDelegatedCompletionCohort gets no interruptedWakeTaskIds and disposes every app-owned task of the parent run. thread.auto-settle dispatches the same thread.settle mutation.

    Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions