Skip to content

spawn_agent creates child thread but initial task is treated as context #20543

Closed

Description

@Osso

What version of Codex are you using?

codex-cli rust-v0.120.0-osso, built from a fork whose origin/main is a9c111da54 ([rollout_trace] Trace sessions and multi-agent edges (#18879)). The failing path is in the current MultiAgentV2 spawn_agent/InterAgentCommunication implementation.

What subscription do you have?

Pro / ChatGPT OAuth.

What platform is your computer?

Linux (Arch).

What issue are you seeing?

spawn_agent creates a child thread and reports success, but the child does not execute the assigned task. It starts a turn and immediately returns a generic final answer like:

Context loaded for `/home/osso/Repos/ask`. Ready for task.

The parent then receives that as the subagent completion notification, so wait_agent/close_agent report the agent completed without doing the requested work.

This is not the same as the model refusing to call spawn_agent: the tool is called, a child thread is created, and the child turn runs. The assigned task text appears in the child rollout as an inter-agent/developer-style message, but not as an actual user task the child follows.

What steps can reproduce the bug?

From a Codex session, ask the model to run a small subagent task, or call the tool directly with equivalent arguments:

{
  "agent_type": "explorer",
  "task_name": "subagent_exec_smoke",
  "message": "Run exactly this read-only command in /home/osso/Repos/ask and report the output: pwd. Then run: test -f AGENTS.md; echo AGENTS=$?. Do not modify files. Final answer must include both command outputs.",
  "fork_turns": "none",
  "reasoning_effort": "low"
}

Observed parent rollout:

{"type":"function_call","name":"spawn_agent","arguments":"{...}","call_id":"call_..."}
{"type":"function_call_output","call_id":"call_...","output":"{\"task_name\":\"/root/subagent_exec_smoke\",\"nickname\":\"Chandrasekhar\"}"}

Observed child rollout:

{"type":"event_msg","payload":{"type":"task_started", ...}}
{"type":"response_item","payload":{"type":"message","role":"developer","content":[{"type":"input_text","text":"... {\"recipient\":\"/root/subagent_exec_smoke\",\"content\":\"Run exactly this read-only command ...\",\"trigger_turn\":true}"}]}}
{"type":"event_msg","payload":{"type":"agent_message","message":"Context loaded for `/home/osso/Repos/ask`. Ready for task.","phase":"final_answer"}}
{"type":"event_msg","payload":{"type":"task_complete","last_agent_message":"Context loaded for `/home/osso/Repos/ask`. Ready for task.", ...}}

What is the expected behavior?

The spawned agent should treat the message passed to spawn_agent as the task for its first turn and execute it. In the reproduction above, it should run/report pwd and the AGENTS check, or at least answer based on the assigned task instead of only acknowledging context initialization.

Additional technical notes

Current code path appears to be:

  • core/src/tools/handlers/multi_agents_v2/spawn.rs converts the initial message into Op::InterAgentCommunication for thread-spawn subagents.
  • core/src/agent/control.rs calls send_input(new_thread.thread_id, initial_operation) after creating the thread.
  • core/src/session/handlers.rs handles Op::InterAgentCommunication by enqueueing mailbox communication and calling maybe_start_turn_for_pending_work_with_sub_id when trigger_turn is true.
  • InterAgentCommunication::to_response_input_item serializes the communication as an assistant-role message containing JSON.

The child turn does start, but the model-visible prompt shape seems to be interpreted as context rather than a user/task instruction. A direct user turn or a clearer task wrapper for the initial spawn message may be needed.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    subagentIssues involving subagents or multi-agent features
    on May 1, 2026
  2. jif-oai commented on May 1, 2026

    @jif-oai
    Contributor

    Multi-agents v2 is not meant to be used right now. We're still in exploration phases

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 isn't workingsubagentIssues involving subagents or multi-agent features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions