Repository navigation
Description
Note
Written by Claude Opus 5.5 on behalf of Navid
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
Found by reading the code and reproduced in server tests with a scripted provider and the test clock; not seen in a live
session.
- A delegated child's turn starts background work that the provider lists on the thread's roster
(provider_thread.updatedwith apendingBackgroundTasksentry that holds completion: a subagent, a background task
or an awaited command) and clears it with its own later report, then the turn ends. The run completes and the original
task iswaiting_for_children. Claude is not such a provider: see the edit note at the end. - The parent sends the child a follow-up. Its run claims the provider thread as soon as it is created or leaves the
queue: it writes the thread withlastRunOrdinalset to itself (apps/server/src/orchestration-v2/Orchestrator.ts:8121-8149,
written at:8322-8329; from the queue:2916-2927, written at:3196-3202). - The background work ends before the follow-up's turn starts, and the provider sends the clear
(pendingBackgroundTasks: []). - The follow-up's turn runs and ends.
Expected behavior
The roster is empty and the original task completes, so the parent gets its result.
Actual behavior
The clear is dropped and the follow-up's turn start writes the stale roster back:
- Only the previous run is still subscribed. After its root terminal it writes root snapshots only while it owns the
thread (RunExecutionService.ts:1784-1801), andEventSink.ts:650-659refuses the write becauselast_run_ordinal
has moved on. The run records owner loss (RunExecutionService.ts:1803-1805) and stops ingesting (:1657-1659). - The follow-up subscribes only when its turn starts (
RunExecutionService.ts:1207-1210), to a fresh queue with no
replay (ProviderSessionManager.ts:2268-2280), so it never sees the clear. - Its turn start writes the provider thread it read, roster included, as the running thread
(ProviderTurnStartService.ts:1701-1720,:1752-1760). Nothing replaces the entry until the provider's roster
changes again.
delegatedTaskProgress then stays waiting_for_children (packages/provider-core/src/server/subagentProjection.ts:384-388,
:396-397), and finalize skips the original task (Orchestrator.ts:14759-14760). The Stop and Settle paths reconcile a
refused clear with the live session (Orchestrator.ts:12422-12449); a follow-up does not.
Impact
Minor bug or occasional failure
It is a race, but when it hits, the parent's task stays running and its completion never arrives. t3_thread_wait and
the thread list report the child waiting (apps/server/src/mcp/OrchestratorMcpService.ts:926-934), and the child's
provider process stays pinned, since idle release and delegate release treat any roster entry as live work
(ProviderSessionManager.ts:2224-2245, Orchestrator.ts:14387-14391).
Version or commit
main @ 3ce2145
Environment
Server-side; any OS. Providers whose roster clear stands on its own report, from the code: OpenCode 2.x (its v2 adapter clears a finished shell directly) and Muse (#19287); not Claude (see the edit note), not OpenCode 1.x (no roster), not Pi (always empty).
Workaround
Settling the child's background work should clear the entry when the live session reports none
(Orchestrator.ts:12422-12449).
Related
- [Bug]: Muse thread stays "Waiting on background task" after Workflow completes and parent run finishes; Stop finds nothing #19287 (closed): the same drop for a Muse workflow. The replay posted when it was closed kept the finished workflow in
pendingBackgroundTasks. - fix(server): a thread_send follow-up waits only on background work its own runs started #37793: a follow-up task now ignores earlier runs' roster entries; the original task, thread status and session release
still read the whole roster.
Possible fix: until the follow-up's turn starts, let the older run merge only pendingBackgroundTasks into the claimed
row (one EventSink transaction that checks the claimant has not started) and keep ingesting, and have the running write
at turn start keep a roster stored after the turn start read it. A fix with tests that fail on main is ready; happy to
open it, or a maintainer can take it.
Edited: the first version gave a Claude background subagent as the example. A live run with Claude showed it is not affected: its adapter keeps a finished background command on the roster as an owed wake until Claude's own wake turn, and that turn runs as a later run that clears the roster. Details and the live runs: #38931 (comment).
Activity