codex icon indicating copy to clipboard operation
codex copied to clipboard

Agents are not managing subagents reliably

Open rafaself opened this issue 3 months ago • 10 comments

What issue are you seeing?

The main agent does not handle subagents reliably.

When a subagent task takes a little longer, the main agent often stops or closes the subagent prematurely and continues the task on its own, instead of waiting for the subagent to finish.

When explicitly instructed to wait for the subagent's response and only close it when appropriate, for example, when the task is completed or an error occurs, the opposite problem happens: the main agent starts polling the subagent repeatedly at very short intervals.

While waiting, it also tends to perform unnecessary actions instead of remaining idle. It seems unable to simply wait for the subagent when no other work is required.

What steps can reproduce the bug?

  • Start a new thread;
  • Ask main agent to spawn a subagent to proceed with some task.

What is the expected behavior?

The main agent should manage subagents according to their actual state:

If a subagent is still working, the main agent should not terminate or close it prematurely. If there is nothing useful to do while waiting, the main agent should become idle instead of repeatedly polling or performing unnecessary work.

The main agent should resume execution when it receives a completion/error signal from the subagent, ideally through an event, hook, or similar mechanism.

A subagent should only be closed when its work is complete, it has failed, or cancellation is explicitly required.

Ideally, waiting for a subagent should be event-driven rather than implemented through aggressive polling.

Additional information

I would say that in general, subagents are not being managed reliably, not only in these previous points.

rafaself avatar Aug 24 '26 00:08 rafaself

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

  • #39854
  • #40105
  • #38972

Powered by Codex Action

github-actions[bot] avatar Aug 24 '26 00:08 github-actions[bot]

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

* [Abnormal token consumption: ~678M tokens used while editing 3 resume versions due to repeated multi-agent polling #39854](https://github.com/openai/codex/issues/39854)

* [Remote SSH: `codex_app.wait_threads` has no registered handler while list/read/send remain healthy #40105](https://github.com/openai/codex/issues/40105)

* [Codex Desktop: background turn reported completed/interrupted while JSONL continues without final_answer or task_complete #38972](https://github.com/openai/codex/issues/38972)

Powered by Codex Action

They don't look related.

rafaself avatar Aug 24 '26 00:08 rafaself

Adding a macOS Codex Desktop reproduction with a closely related symptom.

Environment:

  • Codex Desktop 26.825.51511 on macOS
  • Bundled Codex CLI 0.151.0-alpha.7.2
  • Model observed: gpt-5.6-luna
  • Local run window: 2026-08-31 08:57–09:36 UTC (16:57–17:36 Asia/Shanghai)

The main-thread transcript contained repeated user-visible progress/commentary messages while a healthy subagent was still running. The messages were not limited to the Activity/Subagents panel. Examples from the local rollout (UTC):

  • 09:00:21 — “修复子代理仍在运行,尚未返回结果;我保持在工作流规定的等待状态,没有并行触碰代码或审核产物。首轮等待超时不代表失败,继续等待其完成。”
  • 09:01:28 — “修复子代理仍未完成,第二次有效等待也只是超时快照;按工作流约束继续等待,不做主代理重复实现。”
  • 09:03:35 — “代理正在执行多项跨前后端修复及逐项验证,尚未进入最终返回;目前没有失败状态或需要用户介入的请求。我继续按 fix 工作流等待。”
  • 09:10:01 — “仍无完成或错误状态;等待窗口已覆盖约十分钟。”

There was no Goal mode, no user-typed follow-up, and no explicit steer/stop action from the UI. The Desktop preference followUpQueueMode = “steer” was present, but it was not exercised by a user follow-up. At 09:30:32 UTC, the parent independently invoked the multi_agent_v1__send_input path and injected a “do not wait for further user input; complete and return” message into the still-running worker. This was coordinator intervention after a normal wait timeout, not a user action.

Expected behavior: while a subagent is healthy, the parent should remain idle/event-driven, with no periodic main-transcript commentary and no send_input/steer intervention. It should resume only on completion, an explicit error/interruption/blocked state, or a user-input request. A timeout or unchanged status should be treated as normal.

This macOS/Desktop reproduction seems to fit the reliability and unnecessary-action problem described here. It also appears related to the lower-level repeated parent-turn/wait behavior in #35108. A user-controlled silent-wait/non-intervention mode, or a runtime-managed event-driven wait that does not resample the parent for ordinary timeouts, would address the issue.

No repository contents, credentials, email address, or local filesystem paths are included. Redacted logs can be provided privately if maintainers need them.

LuckyPro-X avatar Aug 31 '26 12:08 LuckyPro-X

Added a measured CLI 0.153.3 direct-v2 reproduction and source findings here: https://github.com/openai/codex/issues/35108#issuecomment-5552457213. The default 60-second developer-level wait/commentary guidance defeated AGENTS.md instructions to use a long mailbox wait. A targeted developer exception plus v2 settings let one wait wake on completion after 187.005 seconds without parent status queries. Repeated parent inference creates excessive token consumption for unchanged status. Please track this as a runtime orchestration defect and test that a healthy child does not cause periodic parent-model calls or unsolicited steering. The linked report distinguishes this direct-v2 behavior from the nested-v1 wrapper path.

rezzminator avatar Sep 05 '26 14:09 rezzminator

I have a Codex CLI reproduction that matches both failure modes described here: premature intervention in a healthy subagent and aggressive polling while waiting.

Environment:

  • Codex CLI 0.153.1
  • Windows
  • Parent: gpt-6-astra / low
  • Worker: gpt-5.6-luna / xhigh

In one bounded implementation task, the first Luna worker remained active and was making real progress, but the Astra parent interrupted it twice.

After the second interruption, the parent discovered that the worker had already produced a substantial partial patch:

2 files changed
127 insertions
6 deletions

So the worker was not dead or stuck; the parent intervened while useful work was still in progress.

The same run also showed the opposite behavior while waiting:

  • 47 × wait_agent
  • all 47/47 used timeout_ms = 30000
  • all 47/47 returned timed_out: true
  • the parent repeatedly resumed and polled again instead of remaining idle/event-driven

This seems to reproduce both sides of the reliability problem described in this issue: the coordinator either interferes with a healthy worker too early, or repeatedly re-enters the model to poll unchanged status.

I posted the full rollout telemetry and diagnostics here: https://github.com/openai/codex/issues/35259#issuecomment-5577073962

tagorr avatar Sep 08 '26 00:09 tagorr

Recently, I noticed some improvements on how main agent manage the subagent. Now, agents is waiting for subagents tasks reliably when necessary and not going with "random actions" when it should just wait for the subagent to finish the task.

rafaself avatar Sep 24 '26 12:09 rafaself

I have a Codex CLI reproduction that matches both failure modes described here: premature intervention in a healthy subagent and aggressive polling while waiting.

Environment:

* Codex CLI **0.153.1**

* Windows

* Parent: **gpt-6-astra / low**

* Worker: **gpt-5.6-luna / xhigh**

In one bounded implementation task, the first Luna worker remained active and was making real progress, but the Astra parent interrupted it twice.

After the second interruption, the parent discovered that the worker had already produced a substantial partial patch:

2 files changed
127 insertions
6 deletions

So the worker was not dead or stuck; the parent intervened while useful work was still in progress.

The same run also showed the opposite behavior while waiting:

* **47 × `wait_agent`**

* all **47/47** used `timeout_ms = 30000`

* all **47/47** returned `timed_out: true`

* the parent repeatedly resumed and polled again instead of remaining idle/event-driven

This seems to reproduce both sides of the reliability problem described in this issue: the coordinator either interferes with a healthy worker too early, or repeatedly re-enters the model to poll unchanged status.

I posted the full rollout telemetry and diagnostics here: #35259 (comment)

They apparentely fixed/improved both issues you also found. You look for it now.

rafaself avatar Sep 24 '26 12:09 rafaself

Added a measured CLI 0.153.3 direct-v2 reproduction and source findings here: #35108 (comment). The default 60-second developer-level wait/commentary guidance defeated AGENTS.md instructions to use a long mailbox wait. A targeted developer exception plus v2 settings let one wait wake on completion after 187.005 seconds without parent status queries. Repeated parent inference creates excessive token consumption for unchanged status. Please track this as a runtime orchestration defect and test that a healthy child does not cause periodic parent-model calls or unsolicited steering. The linked report distinguishes this direct-v2 behavior from the nested-v1 wrapper path.

Interesting.

rafaself avatar Sep 24 '26 12:09 rafaself

Adding a macOS Codex Desktop reproduction with a closely related symptom.

Environment:

* Codex Desktop 26.825.51511 on macOS

* Bundled Codex CLI 0.151.0-alpha.7.2

* Model observed: gpt-5.6-luna

* Local run window: 2026-08-31 08:57–09:36 UTC (16:57–17:36 Asia/Shanghai)

The main-thread transcript contained repeated user-visible progress/commentary messages while a healthy subagent was still running. The messages were not limited to the Activity/Subagents panel. Examples from the local rollout (UTC):

* 09:00:21 — “修复子代理仍在运行,尚未返回结果;我保持在工作流规定的等待状态,没有并行触碰代码或审核产物。首轮等待超时不代表失败,继续等待其完成。”

* 09:01:28 — “修复子代理仍未完成,第二次有效等待也只是超时快照;按工作流约束继续等待,不做主代理重复实现。”

* 09:03:35 — “代理正在执行多项跨前后端修复及逐项验证,尚未进入最终返回;目前没有失败状态或需要用户介入的请求。我继续按 fix 工作流等待。”

* 09:10:01 — “仍无完成或错误状态;等待窗口已覆盖约十分钟。”

There was no Goal mode, no user-typed follow-up, and no explicit steer/stop action from the UI. The Desktop preference followUpQueueMode = “steer” was present, but it was not exercised by a user follow-up. At 09:30:32 UTC, the parent independently invoked the multi_agent_v1__send_input path and injected a “do not wait for further user input; complete and return” message into the still-running worker. This was coordinator intervention after a normal wait timeout, not a user action.

Expected behavior: while a subagent is healthy, the parent should remain idle/event-driven, with no periodic main-transcript commentary and no send_input/steer intervention. It should resume only on completion, an explicit error/interruption/blocked state, or a user-input request. A timeout or unchanged status should be treated as normal.

This macOS/Desktop reproduction seems to fit the reliability and unnecessary-action problem described here. It also appears related to the lower-level repeated parent-turn/wait behavior in #35108. A user-controlled silent-wait/non-intervention mode, or a runtime-managed event-driven wait that does not resample the parent for ordinary timeouts, would address the issue.

No repository contents, credentials, email address, or local filesystem paths are included. Redacted logs can be provided privately if maintainers need them.

Exactly, it got some improvements, but I am still testing more complexes orchestrations.

rafaself avatar Sep 24 '26 12:09 rafaself

I ran into a similar issue in the Codex terminal UI. I asked Codex to fork the current conversation, give one subagent ownership of a system repository task, and keep that detour out of the main thread while we were shaping a different project.

Observed. The parent created one subagent. While the subagent was making progress, the parent sent two follow-up instructions, made repeated wait calls, and ran overlapping Git checks. The main terminal showed several cycles of “Waiting for agents,” “Finished waiting,” and “No agents completed yet.” The subagent completed the task and returned a result.

Expected. For a handoff intended to isolate context, give the subagent one complete brief and let it own implementation and verification. While the worker is healthy, wait for completion or an issue that needs intervention. Bring one concise result back to the parent thread. Routine wait events could stay in the activity view.

The local CLI reports codex-cli 0.170.0 on Linux. This was one observed run. I haven't established whether the coordination behavior came from wait scheduling, the parent model's decisions, or their interaction. I didn't measure the token overhead.

junaga avatar Nov 27 '26 22:11 junaga