Skip to content

[Bug]: A roster clear that arrives before a follow-up's turn starts is dropped, so the delegated task never completes #38930

Open

Description

@navidnadali

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.

  1. A delegated child's turn starts background work that the provider lists on the thread's roster
    (provider_thread.updated with a pendingBackgroundTasks entry 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 is waiting_for_children. Claude is not such a provider: see the edit note at the end.
  2. 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 with lastRunOrdinal set to itself (apps/server/src/orchestration-v2/Orchestrator.ts:8121-8149,
    written at :8322-8329; from the queue :2916-2927, written at :3196-3202).
  3. The background work ends before the follow-up's turn starts, and the provider sends the clear
    (pendingBackgroundTasks: []).
  4. 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), and EventSink.ts:650-659 refuses the write because last_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

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

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

    vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions