codex icon indicating copy to clipboard operation
codex copied to clipboard

Long-horizon multi-agent monitoring trap in 0.172.0: 3600s wait_agent cap, unhookable short functions.wait loops (62.1M tokens), and 60s polling prompt in gpt-6.2

Open dengoswei opened this issue 6 days ago • 3 comments

What version of Codex CLI is running?

codex-cli 0.172.0 (x86_64-unknown-linux-musl)

What subscription do you have?

ChatGPT Pro (20x)

Which model were you using?

gpt-6.2-astra (xhigh parent), gpt-6.2-sol (high), gpt-6.1-terra (low/medium workers)

What platform is your computer?

Linux 6.8.0-134-generic x86_64 unknown

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

VS Code Remote-SSH + Linux CLI (code_mode + multi_agent_v2)

What issue are you seeing?

While running multi-hour monitoring and delegation trees on codex-cli 0.172.0, we audited an 80.15M-token (1,091-request) multi-agent session tree and observed four interacting runtime and prompt constraints that either burn tens of millions of tokens in empty polling loops or break real-time child alert preemption:

1. Asymmetry between multi_agent_v2.max_wait_timeout_ms (<= 3600000 ms) and code-mode functions.exec (43200000 ms+) silently blocks child failure alerts

  • Code-mode functions.exec / functions.wait supports multi-hour yield_time_ms (measured holding silently for 21,601s / 6h and 43,200s / 12h with zero intermediate inference, returning early in a few seconds when the child process exits).
  • However, features.multi_agent_v2.max_wait_timeout_ms is hard-capped at 3600000 ms (1 hour) in config.toml:
    Error loading configuration: features.multi_agent_v2.max_wait_timeout_ms must be at most 3600000
    
  • Production failure mode: Because wake_on_agent_messages is disabled by default (under development / false), a parent agent that needs to react to background subagents must stay inside wait_agent. On 8–34 hour jobs, wait_agent repeatedly times out every 30–60 minutes and re-meters the full frontier parent context. When asked by the user to stop repeating timeout/wait status cycles, the gpt-6.2-astra parent replaced wait_agent with a 6h–12h functions.exec polling loop — which silently blocked urgent child send_message alerts for hours, because child mailbox messages wake wait_agent immediately but do not preempt an active parent functions.exec / functions.wait cell.
  • Note on wake_on_agent_messages (#54961 / #56330) in 0.172.0: In an isolated local codex app-server --listen stdio:// --enable multi_agent_v2 --enable wake_on_agent_messages --disable hooks test (gpt-6.1-terra, 8-second child functions.exec hold), the parent cleanly ended Turn 1 after spawn_agent, made 0 wait_agent calls and 0 intermediate requests across a 28.56s idle window, and automatically woke 24 ms after child completion to emit a non-empty Turn 2 final response (2 Turn 1 requests + 1 Turn 2 request). Graduating wake_on_agent_messages to stable/enabled-by-default would remove the need for wait_agent polling altogether; until then, the 1h max_wait_timeout_ms cap traps multi-hour parents.

2. Unhookable short outer yield_time_ms + functions.wait loop burned 62,114,204 tokens in one worker (#38495, #57604, #59042)

  • One worker watching for a pair of output files wrapped an inner write_stdin(..., yield_time_ms: 300000) inside a short outer pragma (// @exec: {"yield_time_ms": 1000}), then called functions.wait({"cell_id": ..., "yield_time_ms": 20000}) 852 consecutive times on unchanged empty state.
  • That single worker consumed 62,114,204 tokens in empty wait turns (62,917,760 cached input out of 63,143,294 total across 869 requests — 77.5% of the entire 5-agent tree).
  • Because neither functions.wait nor empty write_stdin polls fire PreToolUse hooks (#59042) and there is no configurable minimum yield_time_ms floor (#57604), users cannot enforce a runtime guardrail when a worker omits a long outer // @exec pragma.

3. gpt-6.2-astra and gpt-6.2-sol built-in instructions_template still explicitly nudges 60-second polling (#45974, #38495)

In 0.172.0 (models_cache.json), both gpt-6.2-astra and gpt-6.2-sol ship with:

"When the user asks you to wait or monitor through completion or if it's needed for a longer horizon task, you can sleep for as long as is required (generally 60 seconds by default) between checks."

On long-horizon tasks with 100k–300k context windows, a 60-second check cadence drives hundreds of redundant full-context model turns even when an external deterministic observer is already watching the target.

4. Streaming --follow observers only wake functions.exec on process exit (#29922, #32188)

Because an active subprocess inside functions.exec does not return early when a new stdout JSONL line arrives, any streaming --follow observer must implement a custom exit-on-event protocol and remount after every single actionable line. Even a 30-minute safety heartbeat inside the watcher still generated 21 empty waits + 21 status checks (4.32M tokens over ~10h).

What steps can reproduce the bug?

  1. 1-hour wait_agent cap: Set features.multi_agent_v2.max_wait_timeout_ms = 43200000 in ~/.codex/config.toml and run codex features list -> fails immediately with features.multi_agent_v2.max_wait_timeout_ms must be at most 3600000.
  2. Parent functions.exec blocks child send_message: Have a parent session spawn a child, then call functions.exec({yield_time_ms: 60000}) running sleep 30. Have the child call send_message to /root at T+5s -> send_message does not preempt the parent functions.exec cell, whereas it wakes wait_agent immediately.
  3. Unhookable short outer functions.wait loop: Inside code mode, start a long silent command with // @exec: {"yield_time_ms": 1000} and inner write_stdin(..., yield_time_ms: 300000). Once the cell returns Script running with cell ID ..., call functions.wait({cell_id, yield_time_ms: 20000}) -> PreToolUse never sees functions.wait, and each 20s empty yield triggers a full-context model request.

What is the expected behavior?

Concrete asks for @openai/codex-core-agent-team:

  1. Raise or remove the 3600000 ms cap on multi_agent_v2.max_wait_timeout_ms (e.g., allow multi-hour wait_agent waits or an until_event wait mode matching functions.exec), and graduate wake_on_agent_messages (#54961 / #56330) to stable so delegating parents can go idle at zero inference cost and resume reliably on child messages/completion.
  2. Support configurable minimum yield floors (min_exec_yield_time_ms / min_empty_poll_yield_time_ms, #57604) or keep empty functions.wait / write_stdin continuations inside the runtime (#38495) until output, process exit, or user preemption occurs.
  3. Revise the (generally 60 seconds by default) between checks instruction in gpt-6.2-* model templates so models prefer event-driven blocking / exit-on-event waits over 60s model-turn polling.
  4. Add native background line/exit wakeup (monitor / wake-on-exit, #29922 / #32188) so --follow tools do not require exit-per-event wrappers.

Additional information

Related open issues covering individual slices of this problem: #38495, #15723, #46120, #63464, #57604, #59042, #45974, #29922, #32188.

dengoswei avatar Nov 26 '26 07:11 dengoswei

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

  • #63464

Powered by Codex Action

github-actions[bot] avatar Nov 26 '26 07:11 github-actions[bot]

Thanks for the automated pointer to #63464 — we reviewed it carefully (and noted #63464 in our related-issues footer when filing). These two issues are complementary rather than duplicates, so we are keeping #64090 open:

  • #63464 is an enhancement proposal for a new runtime-enforced batch-delegation-and-yield tool (dispatch_batch) that deterministically terminates the parent turn upon delegation on top of existing native wake-up/wait primitives (explicitly noting it does not classify current timeout behavior as a bug).
  • #64090 reports four reproducible codex-cli 0.172.0 runtime and prompt bugs/gaps measured on long-horizon multi-agent trees:
    1. features.multi_agent_v2.max_wait_timeout_ms hard schema cap at 3600000 ms (1h) vs 43200000 ms (12h) on functions.exec, plus the fact that a parent functions.exec wait blocks urgent child send_message preemption. (Additional 0.172.0 test datapoint: we also verified in an isolated stdio:// probe that features.wake_on_agent_messages = true wakes an idle Normal-mode root session on both mid-run non-final child send_message and final child completion — however, automatic wakes remain under development/off by default and are intentionally disabled in Plan mode, after user interrupts, and inside child agents, where wait_agent and its 3600000 ms cap still govern.)
    2. Unhookable short outer yield_time_ms + functions.wait polling loops (62.1M tokens across 852 empty 20s polls in one worker), since PreToolUse hooks do not observe functions.wait (#59042) and there is no configurable minimum yield floor (#57604).
    3. Built-in instructions_template (generally 60 seconds by default) between checks nudging 60-second model-turn polling on 100k–300k context windows (#45974).
    4. Process-exit-only wakeup in functions.exec requiring custom exit-per-event wrappers for --follow observers (#29922 / #32188).

dengoswei avatar Nov 26 '26 09:11 dengoswei

Excellent analysis, and thanks for referencing #63464.

Your measurements independently highlight the scale of the architectural problem. Spending 62.1M tokens on empty polling cycles in a single worker is particularly striking.

Your wake_on_agent_messages experiment also aligns with my findings. The native wake-up mechanism works. What remains missing is a deterministic runtime guarantee that the delegating parent actually completes its turn without requiring another model decision.

My modified Codex core addresses that specific part of the lifecycle through an explicit delegation-and-yield operation.

The implementation has now passed 30 validation scenarios, including a native child failure after partial, uncommitted code modifications, with correct child correlation, a single parent wake-up and preservation of the actual Git worktree state.

I fully agree that these issues are complementary. Your findings on functions.wait, minimum yield floors and child-message preemption address additional runtime gaps that my current implementation does not attempt to solve.

Together, these findings make a strong case for moving deterministic coordination out of model inference and into the runtime.

Intelligence should be used for decisions, not polling.

Thanks for the automated pointer to #63464 — we reviewed it carefully (and noted #63464 in our related-issues footer when filing). These two issues are complementary rather than duplicates, so we are keeping #64090 open:

BrunoP9 avatar Nov 26 '26 13:11 BrunoP9