[Bug]: A parent is woken twice with the same delegated task result (after a restart cuts the delivery run, or when a follow-up repeats it) #32279
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
Case A, restart:
- A parent waits on
delegate_task; the child completes; the delivery run starts on the parent and the agent reads the result, writes a reply and calls tools. - Restart the server before that run finishes.
- After the restart, the same completion is delivered again.
Case B, repeated or unlabelled follow-up:
- A child returns its result, then runs again on its own (a background-command wake) and replies with the same text, or with a new text.
- The parent receives a second "Delegated task () [completed]" with no sign that it follows the first task.
Deterministic: in DelegatedCompletionDelivery.test.ts terms: (A) cut a delivery run that already wrote assistant output and finalize it; the task returns to pending and is re-sent. (B) start a child follow-up whose reply equals the last result; the parent gets a second delivery.
Expected behavior#
A: a delivery the agent already answered counts as delivered, even if a restart cuts its run. A delivery run that started but wrote nothing is still re-offered, as #15323 intends.
B: a follow-up wake names the task it follows ("..., a follow-up of task after the child ran again"), and a follow-up the child started on its own whose reply repeats the last result is recorded (readable with task_status) without waking the parent. A follow-up started by a parent send or a user message always wakes.
Actual behavior#
A: finalizeDelegatedCompletionDelivery returns every task of a cancelled delivery run to pending, so a restart that cut a run the agent had acted on sends the same completion again. B: the parent gets a second wake that looks identical to the first. Agents reacted with "This is the same review result again"; five parents saw a repeat between 24 Oct and 6 Nov.
Impact#
Minor bug or occasional failure
Version or commit#
0.1.8-nightly.20261106.4262 (c55db3e9c7); code read at main 6577c6b618, unchanged at 240446e2d9.
Environment#
macOS and Linux; Claude and Codex parents and children.
Logs or stack traces#
None kept beyond the agents' replies; the deterministic cases fail on main.
Workaround#
None; agents usually notice and ignore the repeat, at the cost of a turn.
Proposed fix (for the PR, once triaged)#
A cut delivery run counts as delivered when it wrote answer items (assistant message, reasoning, tool calls). The follow-up wake label names the original task. A self-started follow-up whose reply equals the last result does not wake the parent. Follow-up command ids are deterministic so restart replays do not duplicate. Tests: "a delivery its run already answered is not sent again when the run is cut", "a restart that cuts an answered delivery does not send it again", "a follow-up wake names the task it follows", "a follow-up repeating the last result does not wake the parent" (fail on main); guards "a delivery cut before its run started is sent again once" and "a parent-sent repeat still wakes" pass on both.
tanstack-source added labelsbug
Sign in to join this conversation.
Don't wake a parent for a child delivery it already has: 2,761 quiet orchestrator runs in one week.
Additional evidence, seen on T3 0.1.9, from a single-user host running about 20 orchestrator threads. A Nov 8–15 audit counted 2,761 of 8,065 orchestrator runs with no tool call, dispatch or compaction, exposing 1.49B input-side tokens. Of these, 2,627 runs accounted for 606M agent-message and 822M child-finished input-side tokens (1.43B combined). The median quiet agent-message run used about 520K input-side tokens. These are token counts, not money; quiet runs include useful deliveries, so the removable share is unmeasured and 1.49B is only a ceiling, not a demonstrated saving.
The follow-up pattern matters too: after a delegated child finishes, a background-job completion or a message to that child can produce another “Delegated task … finished” delivery. A message to a running child can become its own task node, and one follow-up can wake the parent two or three times even when its result has not changed.
Request: deliver each actionable child result once, keyed by delivery identity; already-collected, superseded or unchanged results should not start another parent run. Batch non-actionable completion records into the parent's next run while keeping them inspectable. Please make the gate durable delivery/result state, not a model saying “nothing new”; that could suppress needed work. A child “no change” marker could be supplementary metadata, not the sole safety check.
#32327 addresses part of this family. Acceptance should exercise restart after an answered delivery, restart before any answer, repeated unchanged follow-ups, supersession and delivery arriving during a parent run. Preserve one actionable delivery and leave no stranded job. Compare quiet runs per day per thread before and after; shorter-context savings overlap this exposure and must not be added to it.