Skip to content

[Bug]: Thread fires premature "Thread completed" notification during the gap between a delegated subagent finishing and its wake run starting #40879

Closed as duplicate

Description

@KitsuneKode

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

  1. Start a thread and run a turn that spawns an async delegated subagent (delegate_task with mode: "async", origin: "app_owned").
  2. Let the parent turn finish while the delegated subagent is still running (thread enters held/waiting state).
  3. Wait for the delegated subagent to finish.

Expected behavior

The thread stays held (non-settled, no completion notification) until the parent's delegated wake run is created and completes its final turn, firing "Thread completed" once at the end.

Actual behavior

When the delegated subagent finishes, Transaction A marks its subagent turn item terminal (completed) and transitions its completionDelivery to "claimed" before Transaction B (ProviderContinuationService) creates the parent's wake run ~140–160 ms later.

During that window, derivePendingBackgroundWork (and the SQL shell/awareness/settlement queries in ProjectionStore.ts) only check non-terminal turn items and provider rosters, so pendingBackgroundTasks briefly drops to []. The thread shell reports settled, triggering a premature "Thread completed" notification (and making the thread look settled to sidebar, push relay, auto-settlement, and MCP status). Once the wake run starts and finishes, "Thread completed" fires a second time.

Impact

Minor bug or occasional failure

Version or commit

main @ 620cf4770d (v0.1.11)

Environment

Linux, T3 Code web/server (reproduced on Orchestration V2 with app_owned delegated subagents).

Logs or stack traces

Sanitized event timestamps from a single thread where this happened twice in a row:

# Wake 1 (153 ms gap between subagent completion and wake run creation)
11:53:40.096Z  subagent started (origin=app_owned) during run #1
11:53:48.978Z  run #1 completed (held while subagent running)
11:57:19.482Z  subagent completed & completionDelivery -> claimed  <-- pendingBackgroundTasks drops to []
11:57:19.635Z  run #2 (wake run) requested (+153 ms)
11:58:00.717Z  run #2 completed (finalizeDelegatedCompletionDelivery at 11:58:01.175Z)

# Wake 2 (141 ms gap between subagent completion and wake run creation)
12:24:50.331Z  subagent started (origin=app_owned) during run #4
12:24:58.666Z  run #4 completed (held while subagent running)
12:29:17.256Z  subagent completed & completionDelivery -> claimed  <-- pendingBackgroundTasks drops to []
12:29:17.397Z  run #5 (wake run) requested (+141 ms)
12:30:13.057Z  run #5 completed (finalizeDelegatedCompletionDelivery at 12:30:14.032Z)

Activity

  1. juliusmarminge commented on Nov 22, 2026

    @juliusmarminge
    Member

    This is the same problem as #31087, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.

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