Parent turn completes while newly spawned child agent is still pendingInit

Open 💬 1 comment Opened Jul 30, 2026 by tongfeifan
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What issue are you seeing?

A parent Codex turn can emit a final assistant message and turn/completed while a child created by spawnAgent is still non-terminal. In the observed trace, the child was still pendingInit when the spawn tool item completed. The parent then finished about six seconds later without calling wait_agent. The child subsequently continued doing work independently after the parent turn was terminal.

Sanitized event sequence:

T+0.000s  item/completed
           item.type = collabAgentToolCall
           item.tool = spawnAgent
           item.status = completed
           item.agents_states[child].status = pendingInit

T+6.334s  assistant/completed
           message says the remaining work has been delegated

T+6.791s  turn/completed
           status = completed

T+~54s   child-owned downstream activity begins
           and continues for roughly 29 minutes

There was no wait_agent call between spawnAgent and the parent final response.

The important distinction is that item.status=completed only means the spawn tool call completed. The nested child status was still pendingInit. Nevertheless, the runtime accepted the parent final response as a terminal turn boundary.

This creates an implicit detach even though no detach/background operation was requested. The parent no longer collects the child result, and integrations that correctly treat turn/completed as terminal stop observing the parent while child work continues.

What steps can reproduce the bug?

  1. Enable multi-agent support in a Codex App Server session.
  2. Ask the main agent to complete a multi-step task and return only after all work is finished.
  3. Have the main agent call spawn_agent / spawnAgent with a long-running child assignment.
  4. Allow the model to emit its final response immediately after the spawn tool call returns, without calling wait_agent.
  5. Observe the App Server event stream.

The parent can emit assistant/completed followed by turn/completed while the child state in the immediately preceding collabAgentToolCall is pendingInit or running. The child thread can then continue independently.

This was observed through the App Server event protocol on macOS on 2026-07-30. Identifiers and application-specific task details have been removed.

What is the expected behavior?

By default, child agents should participate in structured concurrency:

  • A parent turn that spawned a child should not complete while that child is pendingInit or running.
  • The parent should wait for, cancel, or otherwise resolve every owned child before turn/completed.
  • If background execution is intended, it should require an explicit detach/background operation.
  • Detached child status and content should remain observable, and terminal child events should be durably delivered to or wake the owning parent/orchestrator.

A useful invariant would be:

parent turn may complete
only if every owned child is terminal
or every remaining child was explicitly detached

Additional information

This appears related to, but distinct from:

  • #15723, where background subagents do not wake the calling agent on completion.
  • #27352, where a turn completes after a progress/commentary message even though follow-up work remains.
  • #19197, which covers orphaned subagent lifecycle and state reconciliation.

This report adds a concrete App Server trace showing turn/completed immediately after spawnAgent, while the child was explicitly reported as pendingInit. The issue is not an SSE disconnect: the upstream App Server itself emitted the terminal parent event, and child-owned side effects continued afterward.

If background children are an intentional supported mode, the protocol still needs an explicit ownership/detach signal and a durable child lifecycle/content stream so clients can distinguish parent turn completed from agent tree completed.

View original on GitHub ↗

1 Comment

github-actions[bot] contributor · 28 days ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #35815
  • #35781

Powered by Codex Action