[Bug]: Self-settle is dropped when delegated-completion wakes were cancelled because the turn already took the results
Before submitting
- [x] I searched existing issues and did not find a duplicate.
- [x] I included enough detail to reproduce or investigate the problem.
Related but different: #36891 / #36892 / #36896 cover a cancelled run whose human message was steered into the settling turn. Here the cancelled runs are automatic delegated-completion wakes whose message stays on the cancelled run. #38840 is about settle disposing queued wakes; this is the reverse, cancelled wakes blocking a settle.
Area
apps/server
Steps to reproduce
- In one turn, an agent starts async
delegate_taskchildren. - It waits for each child inside the same turn with
t3_thread_wait(untilDelegatedWorkSettled: true), then reads the result withtask_status. - When each child finishes, the server queues a delegated-completion wake run behind the running turn. The wake ends
cancelleda few seconds later without ever starting (startedAt: null), because the turn has already taken the result. Its user message keepsrunId= the cancelled wake run and carriesdelegatedCompletion. - As its last tool call the agent calls
t3_thread_organize {"action":"settle"}on its own thread. It gets{"settlesWhenTurnEnds":true}. - The turn ends
completed.
Expected behavior
The thread settles when the turn ends. The cancelled wakes were automatic, never started, and their results were already handled by the settling turn.
Actual behavior
The thread stays unsettled (settledAt null) and shows as cancelled, because latestRunId points at the last cancelled wake. The tool reported success, so neither the agent nor the user learns the settle was dropped.
Cause, from settleAfterRun in apps/server/src/orchestration-v2/ThreadManagementService.ts (same code in the 0.1.10 bundle and on main at 8d5e0b241d):
later= the three cancelled wake runs. None of their messages hasrunId === run.id, sosteeredMessageIdsis empty and all three stay infollowing.- Their user messages all have
delegatedCompletion, so the "non-automatic message" check passes. - No run is non-terminal, so it doesn't return
false. - Then
following.some(c => c.status !== "queued" && c.status !== "completed")is true forcancelled, sotrySettlereturnstruewithout dispatchingthread.settle. The stream stops on thattrue, and the settle is gone for good.
That branch makes sense when a follow-up actually ran and failed. A cancelled automatic wake that never started shouldn't count as a follow-up.
Store snapshot of the affected thread (orchestration v2 projections):
run 1 completed requested 16:30:27Z completed 16:33:42Z (settle requested 16:33:35Z)
run 2 cancelled requested 16:31:15Z startedAt null message.delegatedCompletion.parentRunId = run 1, message.runId = run 2
run 3 cancelled requested 16:32:20Z startedAt null message.delegatedCompletion.parentRunId = run 1, message.runId = run 3
run 4 cancelled requested 16:33:27Z startedAt null message.delegatedCompletion.parentRunId = run 1, message.runId = run 4
thread settledAt = null
Suggested fix: in trySettle, leave out of following any cancelled run that never started and whose user message is automatic (delegatedCompletion or notification), the same way steered messages are left out today. A cancelled human follow-up would still drop the settle, as it does now.
Impact
Minor bug or occasional failure
It is deterministic for agents that wait on their own delegates in-turn and then self-settle. Unattended threads that run on a schedule or webhook pile up in the sidebar.
Version or commit
0.1.10 (also present on main at 8d5e0b241d)
Environment
Linux arm64, self-hosted t3 serve run as a service, orchestration v2. Parent is claudeAgent / claude-opus-5-5; children are codex and claudeAgent.
Workaround
Settle the thread by hand. Or have the agent take delegate results from the completion wake instead of t3_thread_wait in the same turn.
Diagnosed and written by Claude Opus 5.5 in Claude Code (inside T3 Code); filed with the owner's approval.