Skip to content

Enforce bounded MultiAgent V2 nesting - #1

Merged
jessatech merged 8 commits into
mainfrom
codex/multi-agent-v2-shallow-policy
Jul 13, 2026
Merged

jessatech merged 8 commits into
mainfrom
codex/multi-agent-v2-shallow-policy

Conversation

@jessatech

Copy link
Copy Markdown
Owner

Summary

  • remove the unintended per-root lifetime spawn quota while retaining active-thread concurrency limits
  • add features.multi_agent_v2.max_depth with default 2 and supported range 1–4
  • enforce V2 depth consistently across tool exposure, direct/replayed spawn calls, and CSV agent jobs
  • keep route selection independent from depth and preserve explicit child model/effort through non-pinning role layers

Root cause

The previous remediation conflated lifetime usage with concurrency and left V2 depth advisory. Separately, applying an explicit model before rebuilding a non-empty role layer could silently restore the parent model when the role did not pin one.

Behavior

The default topology is root → subagent → child. Maximum-depth agents keep management tools but cannot spawn. Sequential completed children do not consume a permanent lifetime budget. Fresh explicit routes may choose a different child model—for example, a Sol orchestrator can route a Terra reader—unless the selected role explicitly pins a conflicting route.

The removed max_total_spawns_per_root key is intentionally unsupported; developer configs carrying it must delete it.

Validation

  • just write-config-schema
  • just test -p codex-features (55 passed)
  • just test -p codex-config (200 passed)
  • focused codex-core V2 tests (75 relevant tests passed across focused runs)
  • public integration tests for maximum-depth tool omission and active concurrency
  • just test -p codex-core multi_agents_spec (10 passed)
  • just fix -p codex-core -p codex-config -p codex-features
  • just fmt
  • git diff --check

Full workspace tests were not run.

jessatech and others added 7 commits July 13, 2026 01:59
MultiAgent V2 collapsed an omitted `fork_turns` to a full-history fork
before considering routing intent, so any spawn that requested an
`agent_type`, `model`, or `reasoning_effort` while omitting `fork_turns`
was rejected outright by `reject_full_fork_spawn_overrides`.

Make `SpawnAgentArgs::fork_mode` intent-aware: an omitted or blank
`fork_turns` combined with an explicit route now resolves to a fresh
child so the override is honored, while a spawn with no routing override
keeps the inherited full-history default. Explicit `fork_turns` semantics
are unchanged (`none`/`all`/positive integer), and explicit
`fork_turns = "all"` still rejects overrides.

Add unit coverage over the fork-resolution matrix and repurpose the test
that encoded the old sharp edge into a handler-level test of the new
behavior. Start PATCHES.md to track fork customizations.

Upstream: openai#32031
Co-Authored-By: Claude <[email protected]>
Add a ResolvedSubagentRoute record capturing how a spawned child's route
resolved — agent_type, model, reasoning effort, service tier, and fork
mode — with each value tagged by provenance (explicit argument, custom
agent file, parent inheritance, model-catalog default, or client
default). Effective values are read from the child's runtime config
snapshot rather than any self-report, and an explicit request that does
not match the effective value is recorded as a warning.

The route is returned only on the un-hidden WithNickname result, so the
reserved collaboration.spawn_agent (HiddenMetadata) schema stays
byte-for-byte compatible. Permission profile and per-child usage are
deferred to the surfacing patch. The route is boxed in the result enum
to satisfy large_enum_variant.

Co-Authored-By: Claude <[email protected]>
Add features.multi_agent_v2.require_explicit_agent_type (default false,
opt-in). When enabled, a spawn_agent call that omits agent_type is
rejected before a child thread is created, so strict swarms never fall
back to a generic inherited child instead of an explicitly routed role.

Default behavior is unchanged. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>
Add features.multi_agent_v2.reject_route_substitution (default false,
opt-in). When enabled, a spawn_agent call whose explicit model or
reasoning_effort conflicts with the value pinned by the selected role is
rejected before a child thread is created, instead of silently
substituting the role's value.

Detection reads the role file's declared model/model_reasoning_effort, so
it never false-rejects a role that does not pin the field. Also backfills
the require_explicit_agent_type field in a features-crate test
initializer and regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>
Add features.multi_agent_v2.max_total_spawns_per_root (default none =
unbounded). A shared, never-decremented counter on AgentControl tracks
how many sub-agents a root has spawned via the multi-agent spawn tool;
the V2 spawn handler rejects a spawn before creating a child once the
budget is reached, so a swarm cannot fan out past a configured limit.

The counter is an Arc<AtomicUsize> shared across a root's sibling control
handles; it counts model-driven spawn_agent fan-out (not forks or
resumes) and is checked in the handler rather than threaded through the
concurrency-critical reservation flow. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>
Rebased the subagent-routing stack from 9e552e9 onto upstream
c888e8e (composer completion work, openai#32628). The synced commit is
TUI-only with no file overlap, so the rebase was conflict-free and the
stack re-validated green (fmt/clippy clean; codex-core + codex-features
tests pass). Updates the recorded fork base in PATCHES.md.

Co-Authored-By: Claude <[email protected]>
@jessatech
jessatech marked this pull request as ready for review July 13, 2026 18:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d47fae000

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jessatech
jessatech changed the base branch from claude/subagent-routing-v2 to main July 13, 2026 19:09
@jessatech
jessatech merged commit 70136ef into main Jul 13, 2026
@jessatech
jessatech deleted the codex/multi-agent-v2-shallow-policy branch July 13, 2026 19:10
jessatech added a commit that referenced this pull request Jul 13, 2026
* Fix intent-incompatible fork default for routed subagent spawns

MultiAgent V2 collapsed an omitted `fork_turns` to a full-history fork
before considering routing intent, so any spawn that requested an
`agent_type`, `model`, or `reasoning_effort` while omitting `fork_turns`
was rejected outright by `reject_full_fork_spawn_overrides`.

Make `SpawnAgentArgs::fork_mode` intent-aware: an omitted or blank
`fork_turns` combined with an explicit route now resolves to a fresh
child so the override is honored, while a spawn with no routing override
keeps the inherited full-history default. Explicit `fork_turns` semantics
are unchanged (`none`/`all`/positive integer), and explicit
`fork_turns = "all"` still rejects overrides.

Add unit coverage over the fork-resolution matrix and repurpose the test
that encoded the old sharp edge into a handler-level test of the new
behavior. Start PATCHES.md to track fork customizations.

Upstream: openai#32031
Co-Authored-By: Claude <[email protected]>

* Report resolved subagent route with provenance on spawn

Add a ResolvedSubagentRoute record capturing how a spawned child's route
resolved — agent_type, model, reasoning effort, service tier, and fork
mode — with each value tagged by provenance (explicit argument, custom
agent file, parent inheritance, model-catalog default, or client
default). Effective values are read from the child's runtime config
snapshot rather than any self-report, and an explicit request that does
not match the effective value is recorded as a warning.

The route is returned only on the un-hidden WithNickname result, so the
reserved collaboration.spawn_agent (HiddenMetadata) schema stays
byte-for-byte compatible. Permission profile and per-child usage are
deferred to the surfacing patch. The route is boxed in the result enum
to satisfy large_enum_variant.

Co-Authored-By: Claude <[email protected]>

* Add strict-routing option to require an explicit agent_type

Add features.multi_agent_v2.require_explicit_agent_type (default false,
opt-in). When enabled, a spawn_agent call that omits agent_type is
rejected before a child thread is created, so strict swarms never fall
back to a generic inherited child instead of an explicitly routed role.

Default behavior is unchanged. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Reject route substitution when a role pins a conflicting model or effort

Add features.multi_agent_v2.reject_route_substitution (default false,
opt-in). When enabled, a spawn_agent call whose explicit model or
reasoning_effort conflicts with the value pinned by the selected role is
rejected before a child thread is created, instead of silently
substituting the role's value.

Detection reads the role file's declared model/model_reasoning_effort, so
it never false-rejects a role that does not pin the field. Also backfills
the require_explicit_agent_type field in a features-crate test
initializer and regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Add a per-root total-spawn budget cap

Add features.multi_agent_v2.max_total_spawns_per_root (default none =
unbounded). A shared, never-decremented counter on AgentControl tracks
how many sub-agents a root has spawned via the multi-agent spawn tool;
the V2 spawn handler rejects a spawn before creating a child once the
budget is reached, so a swarm cannot fan out past a configured limit.

The counter is an Arc<AtomicUsize> shared across a root's sibling control
handles; it counts model-driven spawn_agent fan-out (not forks or
resumes) and is checked in the handler rather than threaded through the
concurrency-critical reservation flow. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Record upstream sync: rebase stack onto c888e8e

Rebased the subagent-routing stack from 9e552e9 onto upstream
c888e8e (composer completion work, openai#32628). The synced commit is
TUI-only with no file overlap, so the rebase was conflict-free and the
stack re-validated green (fmt/clippy clean; codex-core + codex-features
tests pass). Updates the recorded fork base in PATCHES.md.

Co-Authored-By: Claude <[email protected]>

* Enforce bounded MultiAgent V2 nesting

Co-Authored-By: Codex <[email protected]>

* Keep V2 depth rooted in parent session

Co-Authored-By: Codex <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
jessatech added a commit that referenced this pull request Jul 15, 2026
* Fix intent-incompatible fork default for routed subagent spawns

MultiAgent V2 collapsed an omitted `fork_turns` to a full-history fork
before considering routing intent, so any spawn that requested an
`agent_type`, `model`, or `reasoning_effort` while omitting `fork_turns`
was rejected outright by `reject_full_fork_spawn_overrides`.

Make `SpawnAgentArgs::fork_mode` intent-aware: an omitted or blank
`fork_turns` combined with an explicit route now resolves to a fresh
child so the override is honored, while a spawn with no routing override
keeps the inherited full-history default. Explicit `fork_turns` semantics
are unchanged (`none`/`all`/positive integer), and explicit
`fork_turns = "all"` still rejects overrides.

Add unit coverage over the fork-resolution matrix and repurpose the test
that encoded the old sharp edge into a handler-level test of the new
behavior. Start PATCHES.md to track fork customizations.

Upstream: openai#32031
Co-Authored-By: Claude <[email protected]>

* Report resolved subagent route with provenance on spawn

Add a ResolvedSubagentRoute record capturing how a spawned child's route
resolved — agent_type, model, reasoning effort, service tier, and fork
mode — with each value tagged by provenance (explicit argument, custom
agent file, parent inheritance, model-catalog default, or client
default). Effective values are read from the child's runtime config
snapshot rather than any self-report, and an explicit request that does
not match the effective value is recorded as a warning.

The route is returned only on the un-hidden WithNickname result, so the
reserved collaboration.spawn_agent (HiddenMetadata) schema stays
byte-for-byte compatible. Permission profile and per-child usage are
deferred to the surfacing patch. The route is boxed in the result enum
to satisfy large_enum_variant.

Co-Authored-By: Claude <[email protected]>

* Add strict-routing option to require an explicit agent_type

Add features.multi_agent_v2.require_explicit_agent_type (default false,
opt-in). When enabled, a spawn_agent call that omits agent_type is
rejected before a child thread is created, so strict swarms never fall
back to a generic inherited child instead of an explicitly routed role.

Default behavior is unchanged. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Reject route substitution when a role pins a conflicting model or effort

Add features.multi_agent_v2.reject_route_substitution (default false,
opt-in). When enabled, a spawn_agent call whose explicit model or
reasoning_effort conflicts with the value pinned by the selected role is
rejected before a child thread is created, instead of silently
substituting the role's value.

Detection reads the role file's declared model/model_reasoning_effort, so
it never false-rejects a role that does not pin the field. Also backfills
the require_explicit_agent_type field in a features-crate test
initializer and regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Add a per-root total-spawn budget cap

Add features.multi_agent_v2.max_total_spawns_per_root (default none =
unbounded). A shared, never-decremented counter on AgentControl tracks
how many sub-agents a root has spawned via the multi-agent spawn tool;
the V2 spawn handler rejects a spawn before creating a child once the
budget is reached, so a swarm cannot fan out past a configured limit.

The counter is an Arc<AtomicUsize> shared across a root's sibling control
handles; it counts model-driven spawn_agent fan-out (not forks or
resumes) and is checked in the handler rather than threaded through the
concurrency-critical reservation flow. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Record upstream sync: rebase stack onto c888e8e

Rebased the subagent-routing stack from 9e552e9 onto upstream
c888e8e (composer completion work, openai#32628). The synced commit is
TUI-only with no file overlap, so the rebase was conflict-free and the
stack re-validated green (fmt/clippy clean; codex-core + codex-features
tests pass). Updates the recorded fork base in PATCHES.md.

Co-Authored-By: Claude <[email protected]>

* Enforce bounded MultiAgent V2 nesting

Co-Authored-By: Codex <[email protected]>

* Keep V2 depth rooted in parent session

Co-Authored-By: Codex <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
jessatech added a commit that referenced this pull request Aug 6, 2026
* Fix intent-incompatible fork default for routed subagent spawns

MultiAgent V2 collapsed an omitted `fork_turns` to a full-history fork
before considering routing intent, so any spawn that requested an
`agent_type`, `model`, or `reasoning_effort` while omitting `fork_turns`
was rejected outright by `reject_full_fork_spawn_overrides`.

Make `SpawnAgentArgs::fork_mode` intent-aware: an omitted or blank
`fork_turns` combined with an explicit route now resolves to a fresh
child so the override is honored, while a spawn with no routing override
keeps the inherited full-history default. Explicit `fork_turns` semantics
are unchanged (`none`/`all`/positive integer), and explicit
`fork_turns = "all"` still rejects overrides.

Add unit coverage over the fork-resolution matrix and repurpose the test
that encoded the old sharp edge into a handler-level test of the new
behavior. Start PATCHES.md to track fork customizations.

Upstream: openai#32031
Co-Authored-By: Claude <[email protected]>

* Report resolved subagent route with provenance on spawn

Add a ResolvedSubagentRoute record capturing how a spawned child's route
resolved — agent_type, model, reasoning effort, service tier, and fork
mode — with each value tagged by provenance (explicit argument, custom
agent file, parent inheritance, model-catalog default, or client
default). Effective values are read from the child's runtime config
snapshot rather than any self-report, and an explicit request that does
not match the effective value is recorded as a warning.

The route is returned only on the un-hidden WithNickname result, so the
reserved collaboration.spawn_agent (HiddenMetadata) schema stays
byte-for-byte compatible. Permission profile and per-child usage are
deferred to the surfacing patch. The route is boxed in the result enum
to satisfy large_enum_variant.

Co-Authored-By: Claude <[email protected]>

* Add strict-routing option to require an explicit agent_type

Add features.multi_agent_v2.require_explicit_agent_type (default false,
opt-in). When enabled, a spawn_agent call that omits agent_type is
rejected before a child thread is created, so strict swarms never fall
back to a generic inherited child instead of an explicitly routed role.

Default behavior is unchanged. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Reject route substitution when a role pins a conflicting model or effort

Add features.multi_agent_v2.reject_route_substitution (default false,
opt-in). When enabled, a spawn_agent call whose explicit model or
reasoning_effort conflicts with the value pinned by the selected role is
rejected before a child thread is created, instead of silently
substituting the role's value.

Detection reads the role file's declared model/model_reasoning_effort, so
it never false-rejects a role that does not pin the field. Also backfills
the require_explicit_agent_type field in a features-crate test
initializer and regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Add a per-root total-spawn budget cap

Add features.multi_agent_v2.max_total_spawns_per_root (default none =
unbounded). A shared, never-decremented counter on AgentControl tracks
how many sub-agents a root has spawned via the multi-agent spawn tool;
the V2 spawn handler rejects a spawn before creating a child once the
budget is reached, so a swarm cannot fan out past a configured limit.

The counter is an Arc<AtomicUsize> shared across a root's sibling control
handles; it counts model-driven spawn_agent fan-out (not forks or
resumes) and is checked in the handler rather than threaded through the
concurrency-critical reservation flow. Regenerates config.schema.json.

Co-Authored-By: Claude <[email protected]>

* Record upstream sync: rebase stack onto c888e8e

Rebased the subagent-routing stack from 9e552e9 onto upstream
c888e8e (composer completion work, openai#32628). The synced commit is
TUI-only with no file overlap, so the rebase was conflict-free and the
stack re-validated green (fmt/clippy clean; codex-core + codex-features
tests pass). Updates the recorded fork base in PATCHES.md.

Co-Authored-By: Claude <[email protected]>

* Enforce bounded MultiAgent V2 nesting

Co-Authored-By: Codex <[email protected]>

* Keep V2 depth rooted in parent session

Co-Authored-By: Codex <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant