openai / openai/codex

Main turn can complete before collecting required subagent results; results surface only after the next user prompt

Open
#40,932 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug CLI subagent
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

What version of Codex CLI is running?

OpenAI Codex (v0.149.1)

What subscription do you have?

Pro

Which model were you using?

gpt-5.6-sol (reasoning high, summaries auto)

What platform is your computer?

macOS 15.7.3 (24G419)

What terminal emulator and version are you using (if applicable)?

Ghostty

Codex doctor report
󰀵 liuyang ~   v1.96.0   v3.11.9   01:29  ❯ Codex doctor
Codex Doctor v0.149.1 · macos-aarch64

Notes
   ⚠ rollouts     306 active files · 1.48 GB on disk
   ⚠ updates      update configuration is locally consistent
   ⚠ threads      state DB rows point at missing or unusable rollout files
─────────────────────────────────────────────────────────────

Environment
  ✓ system       zh-Hans-SG
      os                       Mac OS 15.7.3 [64-bit]
      OS language              zh-Hans-SG
      LANG                     en_SG.UTF-8
      VISUAL                   not set
      EDITOR                   not set
  ✓ disk         sufficient free disk space (630.5 GiB)
      warning threshold        5.0 GiB
      failure threshold        1.0 GiB
      CODEX_HOME available     630.5 GiB
      worktree available       630.5 GiB
  ✓ security     no supported endpoint protection detected
      endpoint products        none detected
  ✓ runtime      standalone (unix, package /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin, bin /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/bin, resources /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-resources, path /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-path)
      version                  0.149.1
      install method           standalone (unix, package /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin, bin /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/bin, resources /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-resources, path /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-path)
      commit                   unknown
      executable               ~/.local/bin/Codex
  ✓ install      consistent
      context                  standalone (unix, package /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin, bin /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/bin, resources /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-resources, path /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-path)
      managed by               npm: no · bun: no · pnpm: no · package root —
      PATH entries (2)         ~/.local/bin/codex
                               /opt/homebrew/bin/codex
  ✓ search       file exists (bundled, /Users/liuyang/.codex/packages/standalone/releases/0.149.1-aarch64-apple-darwin/codex-path/rg)
      search command           ~/.codex/packages/standa…le-darwin/codex-path/rg
      search provider          bundled
      search command readiness file exists
  ✓ git          git version 2.50.1 (Apple Git-155)
      selected git             /usr/bin/git
      version                  git version 2.50.1 (Apple Git-155)
      exec path                /Library/Developer/Comma…ls/usr/libexec/git-core
      repo detected            false
      PATH entries (2)         /usr/bin/git
                               /opt/homebrew/bin/git
  ✓ terminal     Ghostty 1.3.1
      terminal                 Ghostty
      TERM_PROGRAM             ghostty
      terminal version         1.3.1
      stdin is terminal        true
      stdout is terminal       true
      stderr is terminal       true
      terminal size            225x53
      color output             enabled
      COLORTERM                truecolor
      TERMINFO                 /Applications/Ghostty.ap…ents/Resources/terminfo (dir)
      effective locale         en_SG.UTF-8
  ✓ title        default · project liuyang
      title source             default
      title items              activity, project-name
      activity item            true
      project source           cwd
      project value            liuyang
  ✓ state        databases healthy
      CODEX_HOME               ~/.codex (dir)
      log dir                  ~/.codex/log (dir)
      sqlite home              ~/.codex (dir)
      state DB                 ~/.codex/state_5.sqlite (file) · integrity ok
      log DB                   ~/.codex/logs_2.sqlite (file) · integrity ok
      goals DB                 ~/.codex/goals_1.sqlite (file) · integrity ok
      memories DB              ~/.codex/memories_1.sqlite (file) · integrity ok
      active rollouts          306 files · 1.48 GB (avg 4.95 MB)
      archived rollouts        0 files · 0 B (avg 0 B)
      queue DB                 ~/.codex/queue_1.sqlite (file)
      queue DB integrity       ok
      thread history DB        ~/.codex/thread_history_1.sqlite (file)
      thread history DB integrity ok
      standalone release cache 13 entries in /Users/liuyang/.codex/packages/standalone/releases
  ⚠ threads      state DB rows point at missing or unusable rollout files
      default model provider   openai
      rollout DB active files  306
      rollout DB archived files 0
      rollout DB scan errors   0
      rollout DB malformed file names 0
      rollout DB scan cap reached false
      rollout DB rows          718
      rollout DB active rows   669
      rollout DB archived rows 49
      rollout DB missing active rows 0
      rollout DB missing archived rows 0
      rollout DB stale rows    412
      rollout DB archive mismatches 0
      rollout DB duplicate rollout thread ids 0
      rollout DB duplicate DB paths 0
      rollout DB model providers openai=718
      rollout DB sources       subagent:thread_spawn=539, vscode=100, cli=76, subagent:other=2, exec=1
      rollout DB stale row sample ~/.codex/archived_sessio…a579-355a52717b96.jsonl
      rollout DB stale row sample ~/.codex/sessions/2026/0…a099-25e886ee13df.jsonl
      rollout DB stale row sample ~/.codex/archived_sessio…86a5-b11e5226f87b.jsonl
      rollout DB stale row sample ~/.codex/archived_sessio…881b-d6d27a2077fd.jsonl
      rollout DB stale row sample ~/.codex/archived_sessio…9080-6c2e6c7c1572.jsonl

Configuration
  ✓ config       loaded
      model                    gpt-5.6-sol · openai
      cwd                      ~
      config.toml              ~/.codex/config.toml
      config.toml parse        ok
      MCP servers              5
      feature flags            42 enabled · 0 overridden (full list with --all)
  ✓ auth         auth is configured
      auth storage mode        File
      auth file                ~/.codex/auth.json
      stored auth mode         chatgpt
      stored API key           false
      stored ChatGPT tokens    true
      stored agent identity    false
  ✓ mcp          5 server (4 stdio, 1 streamable_http) · 1 disabled
      configured servers       5
      disabled servers         1
      stdio servers            4
      streamable_http servers  1
  ✓ sandbox      restricted fs + restricted network · approval OnRequest
      approval policy          OnRequest
      filesystem sandbox       restricted
      network sandbox          restricted
      linux helper             none
      execve wrapper helper    ~/.codex/tmp/arg0/codex-…yQ/codex-execve-wrapper

Desktop App
  ✓ desktop      the desktop application is installed
      version                  26.818.31338
      running                  false
      log directory            $HOME/Library/Logs/com.openai.codex
  ✓ desktop      the desktop application is not running
  ✓ desktop      the desktop application passed available macos security assessments
      gatekeeper               accepted

Updates
  ⚠ updates      update configuration is locally consistent
      startup update check     true
      update action            standalone installer
      version cache            ~/.codex/version.json
      cached latest version    0.149.1
      last checked at          2026-08-26 10:48 UTC
      latest version probe     curl: (56) The requested URL returned error: 403

Connectivity
  ✓ network      network-related environment looks readable
      proxy env vars present   HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY, http_proxy, https_proxy, all_proxy, no_proxy
      system proxy             manual
      respect system proxy     disabled
      managed proxy            not configured
  ✓ websocket    connected (HTTP 101 Switching Protocols) · 15s timeout
      model provider           openai
      provider name            OpenAI
      wire API                 responses
      supports websockets      true
      proxy env vars present   HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY, http_proxy, https_proxy, all_proxy, no_proxy
      connect timeout          15000 ms
      auth mode                chatgpt
      endpoint                 wss://chatgpt.com/backend-api/<redacted>
      DNS                      1 IPv4, 0 IPv6, first IPv4
      handshake result         HTTP 101 Switching Protocols
      reasoning header         false
      server model present     false
  ✓ reachability active provider endpoints are reachable over HTTP
      reachability mode        ChatGPT auth
      ChatGPT inference URL    https://chatgpt.com/backend-api/<redacted> reachable (HTTP 405)
      desktop assets CDN       https://chatgpt.com/backend-api/<redacted> reachable (HTTP 200)

Background Server
  ○ app-server   not running (ephemeral mode)
      daemon state dir         ~/.codex/app-server-daemon
      settings                 ~/.codex/app-server-daemon/settings.json (missing)
      pid file                 ~/.codex/app-server-daemon/app-server.pid (missing)
      update-loop pid file     ~/.codex/app-server-daem…/app-server-updater.pid (missing)
      control socket           ~/.codex/app-server-cont…app-server-control.sock
      status                   not running
      mode                     ephemeral

─────────────────────────────────────────────────────────────
20 ok · 1 idle · 3 notes · 2 warn · 0 fail degraded

--summary compact output   --all expand truncated lists
--json redacted report

󰀵 liuyang ~   v1.96.0   v3.11.9   01:41   in 18s78ms ❯
What issue are you seeing?

Summary

In a Codex CLI multi-agent workflow, the main agent emitted final_answer and completed its turn before collecting the results of three required subagents.

The subagents continued working, but their result messages did not reactivate the completed main turn. They were delivered to the main thread only after I sent another user message approximately 32 minutes later.

This appears to be an orchestration/finalization issue rather than a crash or streaming failure.

Environment

  • Codex CLI: 0.149.1
  • Surface: Codex CLI
  • Model: gpt-5.6-sol
  • Reasoning effort: high
  • Service tier: fast
  • Collaboration mode: Default chat, not /goal
  • OS: macOS <macOS 15.7.3>
  • Shell: Fish
  • In-app feedback session ID: <01a03158-b4a8-7c10-9f70-142be548c65e>

Expected behavior

When required subagents are still running or their requested results have not been collected, the main agent should:

  1. Keep the main turn active.
  2. Use commentary for intermediate progress.
  3. Wait for the required subagent results.
  4. Return final_answer only after all required results have been collected, unless the user explicitly asks to detach the work.

The current OpenAI documentation says Codex handles orchestration, including waiting for results, and waits until all requested results are available before returning a consolidated response:

https://learn.chatgpt.com/docs/agent-configuration/subagents

Actual behavior

The main agent:

  1. Checked the agent states.
  2. Observed the main agent and all three subagents as running.
  3. Sent follow-up instructions to the subagents.
  4. Did not call wait_agent.
  5. Emitted final_answer.
  6. Completed the main turn two seconds later.

The final response itself described the delegated tasks as still in progress and promised future progress updates, even though emitting final_answer made those updates impossible without another user prompt.

Event timeline

All timestamps below are UTC.

2026-08-26T15:55:22.247Z  event      task_started
2026-08-26T15:58:31.630Z  assistant  commentary
2026-08-26T15:58:33.342Z  tool       list_agents
2026-08-26T15:58:50.625Z  tool       send_message
2026-08-26T15:59:05.786Z  tool       send_message
2026-08-26T15:59:49.139Z  tool       exec
2026-08-26T15:59:59.361Z  tool       send_message
2026-08-26T16:00:17.344Z  assistant  final_answer
2026-08-26T16:00:19.736Z  event      task_complete

There was no wait_agent call between the last child instruction and final_answer.

There was also no turn_aborted, crash, or missing tool event in this interval.

Agent-state snapshot

The list_agents result at 2026-08-26T15:58:33.555Z showed:

2026-08-26T15:58:33.555Z  main        running
2026-08-26T15:58:33.555Z  subagent_1  running
2026-08-26T15:58:33.555Z  subagent_2  running
2026-08-26T15:58:33.555Z  subagent_3  running

This was the last explicit agent-state check before the main agent finalized. The parent continued sending instructions after this snapshot but did not check again or wait for completion.

Result delivery after the next user prompt

A new turn began at approximately 2026-08-26T16:32:22Z. The pending subagent messages were then delivered to the main thread:

2026-08-26T16:32:22.910Z  event      task_started
2026-08-26T16:32:22.926Z  user       new_prompt
2026-08-26T16:32:41.203Z  assistant  commentary
2026-08-26T16:32:41.636Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.636Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.637Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.637Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.638Z  subagent   result_delivered_to_main

These five agent_message events contained progress/final messages from the three delegated agents.

Impact

  • The UI makes the workflow appear complete even though required work is still running.
  • Promised live progress updates cannot be delivered after the main turn ends.
  • Completed subagent results remain invisible until the user sends another message.
  • Users may incorrectly assume that development stopped or that subagent results were lost.
  • The behavior conflicts with the documented expectation that Codex waits for requested subagent results before returning a consolidated response.

Suggested safeguards

Any of the following would prevent this failure mode:

  1. Block final_answer while required child agents are active or have uncollected results.
  2. Convert an attempted final response into commentary when required work remains.
  3. Show a confirmation such as: “3 subagents are still active. End this turn and detach them?”
  4. Keep the main controller subscribed to required child-result events until completion or explicit cancellation.
  5. Clearly surface detached subagents and automatically display their results when they finish.

The most important invariant would be:

required_active_children > 0 OR uncollected_required_results > 0
→ main turn must not finalize without explicit detach intent

Reproducibility

Observed in one long-running production session. I have not yet reduced it to a clean minimal repository reproduction.

The full session was submitted through Codex feedback so the OpenAI team can inspect the original transcript using the feedback session ID above. I can provide additional redacted logs privately if needed.

What steps can reproduce the bug?

No repository-specific application code is required. The issue occurs in Codex CLI's parent/subagent orchestration.

Observed reproduction
  1. Start Codex CLI in a normal Default chat, not /goal.
  2. Delegate three required, long-running tasks to subagents.
  3. Explicitly tell the main agent to continue until all three tasks complete and to provide progress updates.
  4. While /agent shows the subagents as active, ask the main agent for a status update and tell it to keep working.
  5. The main agent calls list_agents, sends follow-up messages to the workers, but does not call wait_agent.
  6. The main agent emits final_answer, and the main turn becomes task_complete.
  7. The subagents continue working, but their results are not delivered to the completed main turn.
  8. Send another user message. A new turn starts, and the pending subagent results are immediately delivered to the main thread.
Minimal synthetic setup

Run Codex in a temporary directory:

mkdir -p /tmp/codex-subagent-finalization-repro
cd /tmp/codex-subagent-finalization-repro
git init -q
codex

Send this prompt:

Spawn exactly three subagents. Each subagent must run a read-only command that waits 90 seconds and then returns a unique completion token:

subagent 1: sleep 90; printf 'subagent-1-complete\n'
subagent 2: sleep 90; printf 'subagent-2-complete\n'
subagent 3: sleep 90; printf 'subagent-3-complete\n'

All three results are required. Keep the main turn active, use commentary for progress, and do not send a final response until all three completion tokens have been collected.

While /agent shows the three children as active, queue this follow-up:

Why can't I see live progress? Check all agents, keep the main turn active, continue waiting for all required results, and report milestones. Do not stop after this status update.

The failure occurs if the main agent returns a final response and completes the parent turn before collecting all three required results.

The sleep-based example is a synthetic reproduction intended to exercise the same orchestration path. The event trace below comes from the real observed session.

Thread information
  • Thread/session ID: 01a03158-b4a8-7c10-9f70-142be548c65e
  • In-app feedback session ID: <01a03158-b4a8-7c10-9f70-142be548c65e>
Observed trace
2026-08-26T15:55:22.247Z  event      task_started
2026-08-26T15:58:31.630Z  assistant  commentary
2026-08-26T15:58:33.342Z  tool       list_agents
2026-08-26T15:58:50.625Z  tool       send_message
2026-08-26T15:59:05.786Z  tool       send_message
2026-08-26T15:59:49.139Z  tool       exec
2026-08-26T15:59:59.361Z  tool       send_message
2026-08-26T16:00:17.344Z  assistant  final_answer
2026-08-26T16:00:19.736Z  event      task_complete

The last explicit agent-state snapshot before finalization showed:

2026-08-26T15:58:33.555Z  main        running
2026-08-26T15:58:33.555Z  subagent_1  running
2026-08-26T15:58:33.555Z  subagent_2  running
2026-08-26T15:58:33.555Z  subagent_3  running

There was no wait_agent call between the child instructions and final_answer.

What is the expected behavior?

When the main agent has required subagents whose results have not yet been collected, it should keep the main turn active and wait for those results.

Intermediate status updates should use commentary and must not end the turn. The main agent should emit final_answer only after:

  1. All required subagent results have been collected;
  2. The user explicitly cancels the work; or
  3. The user explicitly asks to detach the subagents and return immediately.

If finalization while children remain active is intentionally supported, Codex should display a warning such as:

Three required subagents are still active. End the main turn and detach them?

A completed main turn should not silently prevent later child results from reaching the user.

The documented behavior says Codex handles waiting for subagent results and waits until all requested results are available before returning a consolidated response:

https://learn.chatgpt.com/docs/agent-configuration/subagents

Additional information
Environment
  • Codex CLI: 0.149.1
  • Model: gpt-5.6-sol
  • Reasoning effort: high
  • Service tier: fast
  • Mode: Default chat, not /goal
  • OS: macOS <macOS version>
  • Shell: Fish
Evidence that results were delayed until the next user turn

The original main turn completed at:

2026-08-26T16:00:19.736Z  event  task_complete

Approximately 32 minutes later, a new user turn started. Pending subagent messages were then delivered to the main thread:

2026-08-26T16:32:22.910Z  event      task_started
2026-08-26T16:32:22.926Z  user       new_prompt
2026-08-26T16:32:41.203Z  assistant  commentary
2026-08-26T16:32:41.636Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.636Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.637Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.637Z  subagent   result_delivered_to_main
2026-08-26T16:32:41.638Z  subagent   result_delivered_to_main

These five agent_message events contained progress/final messages from the three delegated agents.

There was no crash, turn_aborted event, approval wait, or missing tool event. This appears to be a finalization/orchestration issue rather than a transport or rendering failure.

### Impact

- The workflow appears complete while required work is still running.
- Promised progress updates cannot be delivered after the main turn ends.
- Completed subagent results remain invisible until the user sends another message.
- Users may assume that work stopped or that results were lost.

### Suggested invariant

required_active_children > 0 OR uncollected_required_results > 0
→ do not finalize the main turn without explicit detach intent

The full session was submitted through Codex's in-app feedback flow.

Feedback session ID: <01a03158-b4a8-7c10-9f70-142be548c65e>

### Additional information



Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported multi-agent workflow on Codex CLI 0.149.1, using the expected and actual sequences in this issue as the check. Trace the orchestration and finalization behavior to determine why required subagent results do not reactivate the main turn; done means the main turn waits for those results and returns only after collecting them.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
ai-infra-agents, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
47/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.