Skip to content

[Bug]: Self-settle is dropped when delegated-completion wakes were cancelled because the turn already took the results #39206

Closed

Description

@dilbagh

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: #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

  1. In one turn, an agent starts async delegate_task children.
  2. It waits for each child inside the same turn with t3_thread_wait (untilDelegatedWorkSettled: true), then reads the result with task_status.
  3. When each child finishes, the server queues a delegated-completion wake run behind the running turn. The wake ends cancelled a few seconds later without ever starting (startedAt: null), because the turn has already taken the result. Its user message keeps runId = the cancelled wake run and carries delegatedCompletion.
  4. As its last tool call the agent calls t3_thread_organize {"action":"settle"} on its own thread. It gets {"settlesWhenTurnEnds":true}.
  5. 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 8d5e0b2):

  • later = the three cancelled wake runs. None of their messages has runId === run.id, so steeredMessageIds is empty and all three stay in following.
  • 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 for cancelled, so trySettle returns true without dispatching thread.settle. The stream stops on that true, 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 8d5e0b2)

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.

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