codex - 💡(How to fix) Fix spawn_agent creates child thread but initial task is treated as context [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#20543Fetched 2026-05-01 05:42:00
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3unlabeled ×1

Code Example

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

---

{
  "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"
}

---

{"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\"}"}

---

{"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.", ...}}
RAW_BUFFERClick to expand / collapse

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.

extent analysis

TL;DR

The issue can be resolved by modifying the spawn_agent implementation to correctly handle the initial message as a task for the spawned agent.

Guidance

  • Verify that the InterAgentCommunication operation is being correctly serialized and sent to the child thread.
  • Check if the maybe_start_turn_for_pending_work_with_sub_id function is being called with the correct trigger_turn value.
  • Consider modifying the to_response_input_item function to serialize the communication as a user-role message instead of an assistant-role message.
  • Investigate adding a clearer task wrapper for the initial spawn message to ensure it is interpreted as a user/task instruction.

Example

No code snippet is provided as the issue requires a deeper understanding of the Codex codebase and the specific implementation of the spawn_agent function.

Notes

The issue seems to be related to the way the initial message is being handled by the spawned agent, and a modification to the spawn_agent implementation or the serialization of the InterAgentCommunication operation may be necessary to resolve the issue.

Recommendation

Apply a workaround by modifying the spawn_agent implementation to correctly handle the initial message as a task for the spawned agent, as this is the most likely cause of the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix spawn_agent creates child thread but initial task is treated as context [1 participants]