Skip to content

Delegated task reports finished while its child thread still has running work #16603

Description

@PrivateVictories-Main

Area: apps/server

Steps to reproduce

  1. From a parent thread, delegate_task to a Codex child that starts a long-running shell command (a bot, a test watcher) and ends its turn without waiting for it.
  2. Read task_status, or look at the parent once it settles.

Expected: The task stays in progress (or reports waiting_for_children) while the child's command is still running, and the parent stays Waiting.

Actual: The task finalizes as completed / result_available and the parent can settle to Done, while the child thread still has a running command_execution item and the process is alive. delegatedTaskProgress (SubagentProjection.ts:207-259) checks runs, subagent entities and the provider roster, but not active turn items, and finalizeAppOwnedSubagent (Orchestrator.ts:8472-8488) finalizes on that result.

A related path: t3_thread_send into an already-finalized child (ThreadManagementService.sendToThread) starts new runs there, but the parent task stays completed and its later result is never delivered (OrchestratorMcpService.ts:1058-1077, Orchestrator.ts:8537-8546).

Evidence (0.0.46-nightly.20261004 state DB): 3 of 145 completed delegated tasks since Oct 1 finalized while their child had live command items (2 still running now, one confirmed alive with pgrep). 5 later runs across 3 finalized children.

Possible fix: include pendingBackgroundTurnItems({ turnItems, runs }) in delegatedTaskProgress (and load turn items in both callers), retrying finalization when those items end. For the send path, reject sends into finalized app-owned children or reopen task tracking.

Impact: Minor bug or occasional failure.

Activity

  1. juliusmarminge commented on Oct 6, 2026

    @juliusmarminge
    Member

    Note

    Grok responding on behalf of Julius.

    Confirmed on current main: an app-owned delegated task can finalize as result_available / completed while the child still has live background command_execution work.

    Main bug

    delegatedTaskProgress decides working / waiting_for_children / result_available from:

    • non-terminal work runs
    • active child subagents / pending completion delivery
    • provider-thread pendingBackgroundTasks

    It does not look at active turn items. finalizeAppOwnedSubagent loads the child without turnItems, calls that helper, and finalizes as soon as progress.state === "result_available".

    So a Codex child that starts a long-lived shell (countsForRun: false / turn ends without waiting) can look “done” to the parent while the process is still alive — matching the state-DB evidence in the report.

    The shared pendingBackgroundTurnItems helper already exists and is used elsewhere in the orchestrator (e.g. interrupt cleanup). It is the natural check to fold into delegatedTaskProgress (with callers loading turnItems).

    Secondary path (distinct)

    t3_thread_send into an already-finalized child can start new runs without reopening parent task tracking / delivering the later result. That overlaps open #13490 and open PR #15004 (follow-up result delivery). Those do not fix the premature-finalize case above.

    Loosely related: #13625 (completion sound while background work runs), #15993 (stale background banner).

    Fix direction: include pendingBackgroundTurnItems({ turnItems, runs }) in delegatedTaskProgress (and load turn items in both finalize / status callers); keep finalization deferred until those items end. Separately, for send-into-finalized-child, either reject or reopen tracking (coordinate with #15004).

    Labeling bug + via-triage.

  2. added
    bugSomething is broken or behaving incorrectly.
    via-triageFiled through npx t3 triage
    on Oct 6, 2026
  3. emilvakhitov commented on Oct 7, 2026

    @emilvakhitov

    Additional user-observed scenario with nested subagents:

    Root thread: completed
    `-- Subagent A: completed
        `-- Subagent B: still running
    

    From the original root thread, the remaining descendant activity is not visible, so the delegated workflow appears finished while B continues working.

    This is an observation, not an independently reproduced case. It is unclear whether it has the same underlying cause as the command_execution gap described above.

    Consolidating the related report from #16902 here to avoid parallel tracking.

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

    bugSomething is broken or behaving incorrectly.via-triageFiled through npx t3 triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions