Before submitting#
Area#
apps/server
Steps to reproduce#
- Start a thread and run a turn that spawns an async delegated subagent (
delegate_task with mode: "async", origin: "app_owned").
- Let the parent turn finish while the delegated subagent is still running (thread enters held/waiting state).
- 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)
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.