Skip to content

[agents] max_depth not enforced for nested spawn_agent (0.155.1) #46704

Open

Description

@manwoodgrove

Problem

[agents] max_depth = 1 does not prevent a depth-1 worker from calling spawn_agent to create a depth-2 leaf in codex-cli 0.155.1. Changing the value to 0 and launching a fresh CLI process also permits both spawns. Neither test returns the depth-limit refusal.

Environment

  • Reproduced on 2026-09-19, native Arch Linux, x86_64.
  • codex --version: codex-cli 0.155.1 (standalone x86_64-unknown-linux-musl distribution).
  • Model: gpt-6-astra.
  • codex features list: multi_agent stable/true; multi_agent_v2 stable/false.
  • Scratch directory outside a Git repository, fresh codex exec process for each run.
  • App-server config/read with includeLayers:true confirms agents.max_depth originates from the user ~/.codex/config.toml, with no selected profile. No project-level override or CODEX_HOME override was involved.

Relevant global config, tested separately with values 1 and 0:

[agents]
max_depth = 1
max_concurrent_threads_per_session = 10

Reproduction

  1. Set agents.max_depth = 1 in the global config.
  2. Start a fresh process from an empty scratch directory:
codex exec --skip-git-repo-check -C /tmp/codex-depth-scratch --json \
  'Depth-cap diagnostic: call spawn_agent once to create worker. Tell worker to call spawn_agent once to create leaf, instructing leaf to reply LEAF_OK and never spawn. Wait for both and report exact tool outcomes. Nested spawn is explicitly requested for this test.'
  1. Observe main creates worker; worker creates leaf; leaf replies LEAF_OK.
  2. Change only max_depth to 0, restart through a fresh codex exec process, and repeat. Both spawns still succeed.

Observed evidence

Sanitized metadata from persisted rollout JSONL files (session_meta.payload.source.subagent.thread_spawn):

Config value Thread ID Parent thread ID Depth Agent path
1 01a0bb47-d161-73a1-a613-6d701d1813a4 01a0bb47-ad50-74b2-b55d-bbe92f1e4cd3 1 /root/depth_probe
1 01a0bb47-f2c6-70e0-b8fc-0e2144e48d1e 01a0bb47-d161-73a1-a613-6d701d1813a4 2 /root/depth_probe/depth_leaf
0 01a0bb4d-0470-7ed1-abb0-0f139707c7ee 01a0bb4c-e074-7b11-9ec3-cef74195b45a 1 /root/depth_zero_worker
0 01a0bb4d-189e-7532-b573-ccd3ec23b875 01a0bb4d-0470-7ed1-abb0-0f139707c7ee 2 /root/depth_zero_worker/depth_zero_leaf

For the max_depth=0 run, actual collaboration.spawn_agent tool results were:

{"task_name":"/root/depth_zero_worker"}
{"task_name":"/root/depth_zero_worker/depth_zero_leaf"}

Leaf response: LEAF_OK. Fresh app-server effective config read while testing returned agents.max_depth: 0, origin user config, profile null.

Expected behavior

With max_depth = 1, main (depth 0) may spawn workers (depth 1), but workers must not spawn depth-2 children. The binary contains the refusal string:

Agent depth limit reached. Solve the task yourself.

No such refusal occurred with either value. Whether zero should forbid every spawn or has special semantics needs clarification; it did not provide the desired one-level cap.

Additional checks

codex --help, codex config --help (which prints top-level help; no config subcommand is listed), and executable strings for max_depth|depth_limit|thread_spawn did not expose a replacement depth-setting key. The binary includes max_depth among agent config fields as well as the refusal string. Current online configuration reference omits the field, so it is unclear whether it is intended to remain supported on this spawn path. No speculative alternative keys were installed.

The config has been restored byte-for-byte to its original value of 1. No AGENTS.md workaround was added. Raw rollouts and full config are intentionally omitted to avoid publishing unrelated local data.

Activity

  1. added
    bug
    CLI
    subagent
    config
    on Sep 19, 2026
  2. nilswx commented on Oct 15, 2026

    @nilswx

    Current-source confirmation (stock Codex 0.162.1, 16 Oct 2026)

    The V2 depth gap is still present in the current stock source at b043762f9e3eb65dd5164ff5880f139bc6d084c7: Config.agent_max_depth is documented as “Maximum nesting depth for V1 agent threads. Ignored by V2.” The V2 handler computes next_thread_spawn_depth and passes the depth into thread_spawn_source, but has no depth-limit check (multi_agents_v2/spawn.rs); the refusal check appears in the V1 handler. This confirms the reported behavior remains in the stock 0.162.1 source. I did not run a new live nested-spawn reproduction.

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

    CLIbugconfigsubagent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions