From 851bbeb7e41af845e01e4812958d898bebdcd9c4 Mon Sep 17 00:00:00 2001 From: Dharit Shah Date: Fri, 6 Nov 2026 15:14:10 -0500 Subject: [PATCH 1/2] refactor(codex): resolve the parent's collaboration version and say why V2 stays off The gate now resolves a parent to collaboration V1 or V2 instead of asking whether it is V1. A V2 parent is declined with the ADR 0159 reason until the child-result delivery path is implemented and verified live; a disabled, unknown-version or unlisted parent gets its own explanation, so no line claims native sub-agents need a parent on V1. The bump re-check table gains the feature-table cap derivation and the child-result delivery path. Signed-off-by: Dharit Shah --- docs/architecture.md | 2 +- docs/contributing/runtime-implementation.md | 4 +- docs/runtimes/codex.md | 19 +++-- internal/runtime/codex_bootstrap.go | 28 ++++--- internal/runtime/codex_bootstrap_test.go | 29 +++---- internal/runtime/codex_personas.go | 84 ++++++++++++--------- internal/runtime/codex_personas_test.go | 71 +++++++++-------- 7 files changed, 135 insertions(+), 102 deletions(-) diff --git a/docs/architecture.md b/docs/architecture.md index b23239a26e..b0c0a8545c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -343,7 +343,7 @@ flowchart TB Decided, not yet implemented. - Plugins are runtime-scoped harness resources: a harness declares `plugins:` as one list of directories in its own repository (same trust and fetch path as skills), and each entry's format decides which runtime loads it — a `plugin.json` bundle is Claude Code's, a directory pi's `-e` loader resolves is uploaded and loaded after a tree-hash preflight computed from the host copy. Each runtime names and skips the entries in the other format, so the list survives a runtime switch. Because `--no-extensions` plus explicit `-e` closes the set of code that can register tools, no per-tool declaration is needed ([ADR 0094](ADRs/0094-pi-extensions-are-harness-resources.md)). - Decided, not yet implemented: extend the runner-owned native Codex child - policy to V2 alongside the 0.166.0 bump. Bootstrap requires the `Agent` tool, + policy to V2. Bootstrap requires the `Agent` tool, harness security and a direct-route parent selecting V1 or V2 in the bundled model catalog (absent means V1); other parents keep delegation off. The runner binds child models and effort, registers roles and admits only diff --git a/docs/contributing/runtime-implementation.md b/docs/contributing/runtime-implementation.md index 5908c2ccbe..805d9242dd 100644 --- a/docs/contributing/runtime-implementation.md +++ b/docs/contributing/runtime-implementation.md @@ -1624,6 +1624,8 @@ Two artefacts of the run are worth knowing about: | JSONL event structs, rollout line types and rollout file naming | the stream parser and transcript extraction; a rollout line type missing from `codexRolloutEnvelopes` discards the whole transcript | `codex-rs/exec/src/exec_events.rs`, `codex-rs/history/src/rollout_payload.rs` (`RolloutItemWire`), `codex-rs/thread-store/src/local/helpers.rs` | | Stderr warning markers (`dropping in-process server notification (queue full)`, `thread/items/list failed during turn completion`, `thread/items/list returned a repeated cursor during turn completion`, and the prefix `thread/read failed while backfilling turn items`), their log targets and levels, and the `RUST_LOG` filter (`error,opentelemetry_sdk=off,opentelemetry_otlp=off,codex_exec=warn,codex_app_server::in_process=warn`; `info` with debug) | `codexStderrDrops` and the debug-log counts match these literals; changed text, targets, levels or filter semantics can silently stop the dropped-notification and failed-backfill warnings | `codex-rs/exec/src/lib.rs` (backfill `warn!` calls, `EXEC_DEFAULT_LOG_FILTER`), `codex-rs/app-server/src/in_process.rs` (drop `warn!` call) | | The multi-agent tool names (`multi_agent_v1*`, `collaboration*`, the bare V1 `spawn_agent`), the block contract (exit 2 with non-empty stderr blocks; a timeout kills the handler and lets the call through), `agent_id` and `agent_type` in a child's payload, the spawn arguments, and what a child start rereads (`hooks.json` and the role file) | the spawn guard's matcher, pass-through set, policy, digest set and deadline rest on them; a renamed tool is denied (loud), but a payload without `agent_id` or `agent_type`, a new model or effort argument, a changed block contract or a child that rereads another file turns a deny into a pass | `codex-rs/core/src/tools/handlers/multi_agents_spec.rs`, `codex-rs/core/src/tools/registry.rs` (`function_hook_tool_name`), `codex-rs/hooks/src/engine/command_runner.rs` (the timeout branch), `codex-rs/core/src/agent/role.rs` (the role file, read at spawn) | -| The bundled catalog's `multi_agent_version`, `default_reasoning_level` and `supported_reasoning_levels` entries, the version codex supplies to an entry that carries none, and the floor model (`codex debug models --bundled`; at 0.166.0 `gpt-5.6-luna` is the listed model that selects `v1` and defaults to `medium`, and `gpt-5.5` carries no version, which the `multi_agent` feature, on by default, resolves to V1, and lists `low` to `xhigh`) | part two of the delegation gate, the child-model floor and the child-effort check rest on them: the floor must stay listed, or every delegating agent without `subagents.default` or `FULLSEND_CODEX_SUBAGENT_MODEL` fails Bootstrap, while the floor's own collaboration version does not matter for children (a child runs under its parent's; moving luna to V2 only stops luna parents from delegating); a bump that turns `multi_agent` off by default, or gives the null entry a version, changes which parents delegate; a changed level set changes which run efforts Bootstrap accepts; and the fixture `internal/runtime/testdata/codex/models-bundled-0.166.0.json` must be regenerated, never edited | `codex-rs/models-manager/models.json` in the bumped tag; regenerate the fixture with the one-liner in `codex_personas_test.go`'s `TestCodexCatalog` comment and run `go test ./internal/runtime/ -run 'TestCodexCatalog\|TestCodexParentResolvesV1\|TestResolveCodexChildModels_Effort'` | +| The bundled catalog's `multi_agent_version`, `default_reasoning_level` and `supported_reasoning_levels` entries, the version codex supplies to an entry that carries none, and the floor model (`codex debug models --bundled`; at 0.166.0 `gpt-5.6-luna` is the listed model that selects `v1` and defaults to `medium`, and `gpt-5.5` carries no version, which the `multi_agent` feature, on by default, resolves to V1, and lists `low` to `xhigh`) | part two of the delegation gate, the child-model floor and the child-effort check rest on them: the floor must stay listed, or every delegating agent without `subagents.default` or `FULLSEND_CODEX_SUBAGENT_MODEL` fails Bootstrap, while the floor's own collaboration version does not matter for children (a child runs under its parent's; moving luna to V2 only stops luna parents from delegating); a bump that turns `multi_agent` off by default, or gives the null entry a version, changes which parents delegate; a changed level set changes which run efforts Bootstrap accepts; and the fixture `internal/runtime/testdata/codex/models-bundled-0.166.0.json` must be regenerated, never edited | `codex-rs/models-manager/models.json` in the bumped tag; regenerate the fixture with the one-liner in `codex_personas_test.go`'s `TestCodexCatalog` comment and run `go test ./internal/runtime/ -run 'TestCodexCatalog\|TestCodexParentCollabVersion\|TestResolveCodexChildModels_Effort'` | | The `[agents]` keys codex reads (`enabled`, `max_concurrent_threads_per_session`, `max_depth`, `default_subagent_model`, `default_subagent_reasoning_effort`, and `[agents.]` `description` and `config_file`) and the order of the child path: with no model argument a child takes `default_subagent_model` and, with no effort argument, `default_subagent_reasoning_effort`, else that model's catalog default; a role file applies after and its effort is checked against its own model | `codexAgentsBlock` writes the keys and Bootstrap checks the child efforts on that order; a renamed key or a changed order silently changes every child's model or effort | `codex-rs/config/src/config_toml.rs` (`AgentsToml`), `codex-rs/core/src/config/mod.rs`, `codex-rs/core/src/agent/child_config.rs` (`apply_requested_spawn_agent_model_overrides`, `apply_spawn_agent_role`), `codex-rs/core/src/agent/role.rs` | | What writes a rollout under the sessions directory in an exec run, rollout naming and the date layout, creation at a child's first recorded item, a PreToolUse block returning before the tool handler, and spawn-slot reservation before thread creation | the disk side of the admission cross-check (the four facts are in `internal/runtime/testdata/codex/README.md`) | `codex-rs/core/src/tools/registry.rs`, `codex-rs/core/src/agent/control/spawn.rs`, `codex-rs/rollout/src/rollout_file_name.rs`, `codex-rs/features/src/lib.rs` (the memories default) | +| The `enabled`, `disable_direct_message`, `expose_spawn_agent_model_overrides` and `max_concurrent_threads_per_session` keys of the `[features.multi_agent_v2]` table (codex parses it with `deny_unknown_fields`) and how codex derives the V2 child cap: the table's own key, else `[agents] max_concurrent_threads_per_session + 1`, else 4, minus one at reservation | ADR 0159 keeps the four-child cap under `[agents]`; once V2 parents delegate, a changed derivation silently gives a V2 parent three or five children, and once the runner renders the table, a renamed table key fails every run's config | `codex-rs/core/src/config/mod.rs` (`resolve_multi_agent_v2_config`, `effective_agent_max_threads`), `codex-rs/features/src/feature_configs.rs` (`MultiAgentV2ConfigToml`), codex's test `multi_agent_v2_uses_agents_max_concurrent_threads_per_session` in `codex-rs/core/src/config/config_tests.rs` | +| The V2 child-result delivery path: `notify_parent_of_terminal_turn` queues a terminal result to the parent, `record_inter_agent_communication` records it, and it reaches the parent's next model request as an `agent_message` item; at 0.166.0 no hook event, config key or app-server method reachable from `codex exec` withholds it before codex records it, and `SubagentStop` treats a deny as a request for the child to continue | ADR 0159 decision 4 requires every V2 child result to pass the ADR 0100 PostToolUse chain before it enters the parent's context, and Bootstrap declines V2 parents until a checked delivery path for those results is implemented and verified live; re-check on every bump whether codex offers a synchronous, fail-closed gate on this path | `codex-rs/core/src/agent/control/completion.rs`, `codex-rs/core/src/session/handlers.rs`, `codex-rs/core/src/hook_runtime.rs` (`inspect_pending_input`), `codex-rs/core/src/session/mod.rs` (`record_inter_agent_communication`), `codex-rs/hooks/src/events/stop.rs` | diff --git a/docs/runtimes/codex.md b/docs/runtimes/codex.md index 578817536e..fa1eb3e6ef 100644 --- a/docs/runtimes/codex.md +++ b/docs/runtimes/codex.md @@ -213,11 +213,18 @@ Delegation needs a parent model Codex resolves to collaboration V1: its entry in the pinned CLI's bundled catalog selects V1, or carries no version and Codex's `multi_agent` feature, on by default, supplies V1 (on the current pin `gpt-5.6-luna`, `gpt-5.5` and a hidden catalog entry). Bootstrap reads that -catalog; for any other parent, a V2 model such as `gpt-5.6-sol` or a model the -catalog does not list included, it keeps Codex's multi-agent tools off, prints -one line saying why (`sub-agents: parent model "gpt-5.6-sol" selects -collaboration "v2"; native sub-agents need a parent Codex resolves to -collaboration V1, running in one context`), and the agent runs in one context. +catalog. [ADR 0159](../ADRs/0159-codex-subagents-on-collaboration-v2.md) admits +a parent that selects V2 (`gpt-5.6-sol`, `gpt-6.1-sol` and most of the current +catalog). Such a parent still runs in one context, because its child results +would reach it outside the PostToolUse chain. Bootstrap prints one line saying +so (`sub-agents: parent model "gpt-5.6-sol" selects collaboration "v2"; V2 +delegation is off until its child-result delivery path is verified live +(ADR 0159), running in one context`). A model the catalog does not list runs +in one context the same way (`sub-agents: parent model "gpt-5.6-nova" is not +in the bundled catalog of the pinned codex, running in one context`), and so +does an entry whose `multi_agent_version` is `disabled`, with a line that says +so. An entry with any other collaboration value runs in one context the same +way, with a line that names the value. A `gateway/` parent runs in one context the same way, whatever its id (`sub-agents: parent model "gateway/gpt-5.6-luna" takes the inference gateway route, where native sub-agents are not supported, running in one context`): @@ -233,7 +240,7 @@ serve, and native children have not been run on that route. | Artifacts | `output.jsonl` (the `codex exec --json` stream), `transcripts/-.jsonl` for the root thread and `transcripts/-sub-.jsonl` for each native child (`generic` for the `default` role, which codex records as no role when the spawn names no `agent_type`; `explore` keeps its name), `metrics.json` with `runtime: codex` (and `per_model_usage` for a delegating agent), plus `codex-debug.log` with `--debug`. Only uncompressed rollouts are extracted — codex compresses older sessions, so a `.jsonl.zst` is never the run's own transcript. The agent's final message is in the stream; `--output-last-message` also drops it in the runner-owned config directory inside the sandbox, which is a convenience when inspecting a kept sandbox rather than a downloaded artifact | | Sub-agents | Native Codex children for an agent whose tools include `Agent` (or that declares no `tools:`), with harness security on, on a parent model Codex resolves to collaboration V1 on the direct route, under a runner-owned policy: registered roles only, fresh context, depth one, four open; see [Sub-agents](#sub-agents) | | Extra knobs | `FULLSEND_CODEX_MODEL` (the runner-side model default for codex runs; see [Models](#models)), `FULLSEND_CODEX_SUBAGENT_MODEL` (the run-level child model; the GitHub fleet workflows do not pass it; see [Child models](#child-models)) | -| Not supported | `plugins:`, fallback chains, non-OpenAI providers (other than through a Responses-capable inference gateway), Chat Completions or Messages on a gateway, delegation from a parent model on collaboration V2 or from a `gateway/` parent (see [Sub-agents](#sub-agents)) | +| Not supported | `plugins:`, fallback chains, non-OpenAI providers (other than through a Responses-capable inference gateway), Chat Completions or Messages on a gateway, delegation from a parent model on collaboration V2 (ADR 0159 admits it; off until its child-result delivery path is implemented and verified live) or from a `gateway/` parent (see [Sub-agents](#sub-agents)) | Cost is recorded as **zero** in `metrics.json` on codex: the `codex exec --json` stream carries no cost field, so the value stays `0`. diff --git a/internal/runtime/codex_bootstrap.go b/internal/runtime/codex_bootstrap.go index 04932a2147..8697f92ce8 100644 --- a/internal/runtime/codex_bootstrap.go +++ b/internal/runtime/codex_bootstrap.go @@ -173,13 +173,17 @@ func (r CodexRuntime) Bootstrap(input BootstrapInput) error { if !ok || repoInput.RepoDir() == "" { return fmt.Errorf("codex bootstrap: the target repository's sandbox path is required") } - // ADR 0126 gate. Part one: tools include Agent and harness security is - // on. Part two needs the pinned CLI's catalog: codex must resolve the - // model Run will launch to collaboration V1, the only version whose spawn - // tool the guard admits (its entry selects V1, or carries no version and - // codex's multi_agent feature, on by default, supplies V1). A V2, - // unlisted or gateway/ parent keeps the multi-agent tools off and runs in - // one context, as an agent that does not delegate does. + // Delegation gate (ADR 0126, extended by ADR 0159). Part one: tools + // include Agent and harness security is on. Part two needs the pinned + // CLI's catalog: the gate takes the collaboration version from the entry + // of the model Run will launch, V1 when the entry selects V1 or carries + // no version (codex's multi_agent feature, on by default, supplies V1) + // and V2 when it selects V2. A V1 parent delegates. A V2 parent is + // declined until its child-result delivery path is implemented and + // verified live (ADR 0159 decision 4); a disabled, unknown-version, + // unlisted or gateway/ parent is declined with its own explanation. A + // declined parent keeps the multi-agent tools off and runs in one + // context, as an agent that does not delegate does. _, securityOn := input.(SandboxHooksBootstrap) var catalog codexCatalog delegating := false @@ -187,8 +191,8 @@ func (r CodexRuntime) Bootstrap(input BootstrapInput) error { if catalog, err = codexPreflightCatalog(sandboxName); err != nil { return err } - var reason string - if delegating, reason = codexParentResolvesV1(catalog, input.ParentModel(), def.Model); !delegating { + version, reason := codexParentCollabVersion(catalog, input.ParentModel(), def.Model) + if delegating = version != "" && reason == ""; !delegating { fmt.Fprintf(os.Stderr, "sub-agents: %s, running in one context\n", reason) } } @@ -393,9 +397,9 @@ func codexDeveloperInstructions(agentName string, def *piAgentDef, roles []codex // codexNoSubagentNote makes the absence of a sub-agent roster explicit so // skills written for Claude Code's Agent tool (pr-review, retro) take their // single-context path deliberately instead of recording a failed dispatch. -// Every agent the ADR 0126 gate declines gets it (tools without Agent, -// security off, a V2 or unlisted parent); a delegating agent gets -// codexSubagentNote. +// Every agent the delegation gate declines gets it (tools without Agent, +// security off, or a V2, disabled, unknown-version, unlisted or gateway/ +// parent); a delegating agent gets codexSubagentNote. const codexNoSubagentNote = "\n## Runtime note\n\n" + "This agent runs on the codex runtime (FULLSEND_RUNTIME=codex). No fullsend sub-agent " + "roster is available. When a skill says to dispatch sub-agents, execute each sub-agent " + diff --git a/internal/runtime/codex_bootstrap_test.go b/internal/runtime/codex_bootstrap_test.go index f76c6e28a9..97336dfe42 100644 --- a/internal/runtime/codex_bootstrap_test.go +++ b/internal/runtime/codex_bootstrap_test.go @@ -863,7 +863,7 @@ func TestCodexPreflightCatalog(t *testing.T) { fakeOpenshellCodex(t, filepath.Join(t.TempDir(), "log"), t.TempDir(), "codex-cli 0.152.1") catalog, err := codexPreflightCatalog("sb") require.NoError(t, err) - assert.True(t, catalog.resolvesV1("gpt-5.6-luna")) + assert.Equal(t, "v1", catalog.collabVersion("gpt-5.6-luna")) }) t.Run("command fails", func(t *testing.T) { fakeOpenshellCodex(t, filepath.Join(t.TempDir(), "log"), t.TempDir(), "codex-cli 0.152.1") @@ -942,13 +942,14 @@ func TestCodexRuntimeBootstrap_WritesRoleFilesForADelegatingAgent(t *testing.T) } } -// len(RoleFiles) > 0 exactly when the ADR 0126 gate holds: part one -// (security on, tools include Agent) and part two (codex resolves the parent -// model to V1: its entry selects V1 or carries no version). With part one -// failed, no catalog is read; with part two failed, the catalog was read and -// nothing else happens: no directory is created, nothing is uploaded and the -// digest set has no role entry. The gpt-5.5 case is the boundary: an entry -// without a version delegates (ADR 0126), so its files are present. +// len(RoleFiles) > 0 exactly when the delegation gate holds: part one +// (security on, tools include Agent) and part two (the gate takes V1 from the +// parent model's entry: it selects V1 or carries no version; a V2 parent is +// declined until ADR 0159 decision 4 is met). With part one failed, no +// catalog is read; with part two failed, the catalog was read and nothing +// else happens: no directory is created, nothing is uploaded and the digest +// set has no role entry. The gpt-5.5 case is the boundary: an entry without +// a version delegates (ADR 0126), so its files are present. func TestCodexRuntimeBootstrap_NoRoleFilesWhenTheGateFails(t *testing.T) { t.Setenv(codexSubagentModelEnv, "") skill := t.TempDir() @@ -976,9 +977,9 @@ func TestCodexRuntimeBootstrap_NoRoleFilesWhenTheGateFails(t *testing.T) { "security off, delegating agent": {bootstrapInput{ sandboxName: "sb", agentPath: writeAgentFile(t, codexTestDelegatingAgentDef), agentName: "review", skillDirs: []string{skill}, }, false, false, ""}, - "security on, definition model selects V2": {delegating(v2Def, ""), true, false, `parent model "gpt-5.6-sol" selects collaboration "v2"; native sub-agents need a parent Codex resolves to collaboration V1`}, - "security on, definition model not in the catalog": {delegating(unlistedDef, ""), true, false, `parent model "gpt-5.6-nova" is not in the bundled catalog of the pinned codex; native sub-agents need a parent Codex resolves to collaboration V1`}, - "security on, run-level V2 model beats a V1 definition": {delegating(codexTestDelegatingAgentDef, "openai/gpt-5.6-sol"), true, false, `parent model "gpt-5.6-sol" selects collaboration "v2"; native sub-agents need a parent Codex resolves to collaboration V1`}, + "security on, definition model selects V2": {delegating(v2Def, ""), true, false, `parent model "gpt-5.6-sol" selects collaboration "v2"; V2 delegation is off until its child-result delivery path is verified live (ADR 0159)`}, + "security on, definition model not in the catalog": {delegating(unlistedDef, ""), true, false, `parent model "gpt-5.6-nova" is not in the bundled catalog of the pinned codex`}, + "security on, run-level V2 model beats a V1 definition": {delegating(codexTestDelegatingAgentDef, "openai/gpt-5.6-sol"), true, false, `parent model "gpt-5.6-sol" selects collaboration "v2"; V2 delegation is off until its child-result delivery path is verified live (ADR 0159)`}, "security on, run-level gateway route to a V1 id": {delegating(codexTestDelegatingAgentDef, "gateway/gpt-5.6-luna"), true, false, `parent model "gateway/gpt-5.6-luna" takes the inference gateway route, where native sub-agents are not supported`}, "security on, definition model has no version (gpt-5.5)": {delegating(noVersionDef, ""), true, true, ""}, } { @@ -1144,9 +1145,9 @@ func TestCodexRuntimeBootstrap_RejectsNonOpenAISubagentModel(t *testing.T) { // The check applies to a delegating agent only. An agent without the Agent // tool, any agent with harness security off, and a delegating agent whose -// parent model codex does not resolve to collaboration V1 (a V2 or unlisted -// parent) keep codex's multi-agent tools off and ignore subagents (ADR 0126: -// "Every other agent runs with Codex's multi-agent tools off"). +// parent the gate declines (a V2, disabled, unknown-version, unlisted or +// gateway/ parent) keep codex's multi-agent tools off and ignore subagents +// (ADR 0126: "Every other agent runs with Codex's multi-agent tools off"). func TestCodexRuntimeBootstrap_NonDelegatingAgentIgnoresSubagents(t *testing.T) { t.Setenv(codexSubagentModelEnv, "") bad := map[string]*string{"correctness": strp("xai-vertex/xai/grok-4.6")} diff --git a/internal/runtime/codex_personas.go b/internal/runtime/codex_personas.go index 0a5e32fd52..02fe9df549 100644 --- a/internal/runtime/codex_personas.go +++ b/internal/runtime/codex_personas.go @@ -13,13 +13,13 @@ import ( "github.com/fullsend-ai/fullsend/internal/config" ) -// codexDelegates is part one of the ADR 0126 gate: an agent gets native +// codexDelegates is part one of the delegation gate: an agent gets native // sub-agent roles when its tools include Agent (an absent tools: includes // it, as on Claude Code and pi; Task is the alias codexToolMatcher maps to // the same calls) and the harness has sandbox security enabled, because // the spawn guard that admits only registered roles is installed with the -// hooks. Part two, codexParentResolvesV1, needs the pinned CLI's catalog and -// is decided in Bootstrap. +// hooks. Part two, codexParentCollabVersion, needs the pinned CLI's catalog +// and is decided in Bootstrap. func codexDelegates(def *piAgentDef, securityEnabled bool) bool { return securityEnabled && piAgentToolEnabled(def) } @@ -52,7 +52,7 @@ const codexSubagentModelEnv = "FULLSEND_CODEX_SUBAGENT_MODEL" // codexChildModel validates one configured child model and returns the bare // OpenAI id: translateCodexModel's rules, less a gateway/ spec (a delegating -// run is on the direct route: codexParentResolvesV1 declines a gateway/ +// run is on the direct route: codexParentCollabVersion declines a gateway/ // parent) and `inherit`, which codex does not resolve for a child. key names // the entry so the error says what to fix. func codexChildModel(key, value string) (string, error) { @@ -324,8 +324,8 @@ func codexDroppedFrontmatterKeys(frontmatter []byte) []string { type codexCatalog map[string]codexCatalogModel // codexCatalogModel is one catalog entry: its multi_agent_version ("v1", -// "v2", or "" when the entry sets none), its default_reasoning_level ("" for -// none) and the efforts of its supported_reasoning_levels, the set codex +// "v2", "disabled", or "" when the entry sets none), its default_reasoning_level +// ("" for none) and the efforts of its supported_reasoning_levels, the set codex // checks a child's effort against at spawn (validate_spawn_agent_reasoning_effort). type codexCatalogModel struct { Version string @@ -336,20 +336,30 @@ type codexCatalogModel struct { // has reports whether the catalog lists the model. func (c codexCatalog) has(slug string) bool { _, ok := c[slug]; return ok } -// resolvesV1 reports whether codex resolves the model to collaboration V1, -// the only version whose spawn tool the guard admits (ADR 0126): the entry -// selects V1, or carries no version and codex's multi_agent feature, on by -// default, supplies V1. -func (c codexCatalog) resolvesV1(slug string) bool { +// collabVersion is the collaboration version the gate takes from the model's +// catalog entry: "v1" for an entry that selects V1 or carries no version +// (codex's multi_agent feature, on by default, supplies V1), "v2" for an +// entry that selects V2, and "" where the gate takes none: an unlisted model +// and any other value, "disabled" included. +func (c codexCatalog) collabVersion(slug string) string { m, ok := c[slug] - return ok && (m.Version == "v1" || m.Version == "") + switch { + case !ok: + return "" + case m.Version == "v1" || m.Version == "": + return "v1" + case m.Version == "v2": + return "v2" + default: + return "" + } } // parseCodexCatalog decodes the dump. Unknown keys are ignored; an empty // model list is an error, because a binary with no catalog cannot run at all. // A null multi_agent_version or default_reasoning_level is stored as "": // encoding/json decodes null into a zero string, which is the "no version" -// resolvesV1 counts as V1. +// collabVersion counts as V1. func parseCodexCatalog(data []byte) (codexCatalog, error) { var dump struct { Models []struct { @@ -378,32 +388,36 @@ func parseCodexCatalog(data []byte) (codexCatalog, error) { return catalog, nil } -// codexParentResolvesV1 is part two of the ADR 0126 gate. The parent is the -// model Run will launch — EffectiveModel(parentModel, agentModel), the -// expression Run launches with, translated by translateCodexModel — and -// codex must resolve it to collaboration V1 (resolvesV1). When it does not, -// a V2 or unlisted parent, the reason is returned for one stderr line and -// Bootstrap keeps codex's multi-agent tools off: the agent runs in one -// context, as an agent that does not delegate does. A parent that does not translate is -// reported by Run with the same error; the gate only declines here. A +// codexParentCollabVersion is part two of the delegation gate (ADR 0126, +// extended by ADR 0159): the collaboration version the gate takes for the +// parent Run will launch ("v1" or "v2", else ""), and the one-line reason +// Bootstrap prints when the parent runs in one context. A V2 parent is +// returned with a reason until its child-result delivery path is implemented +// and verified live (ADR 0159 decision 4). A parent that does not translate +// is reported by Run with the same error; the gate only declines here. A // gateway/ parent is declined whatever its id: children would inherit the -// gateway provider with bare OpenAI ids it may not serve, and native -// children have not run on that route. -func codexParentResolvesV1(catalog codexCatalog, parentModel, agentModel string) (bool, string) { - const needV1 = "; native sub-agents need a parent Codex resolves to collaboration V1" +// gateway provider with bare OpenAI ids it may not serve, and native children +// have not run on that route. +func codexParentCollabVersion(catalog codexCatalog, parentModel, agentModel string) (version, reason string) { model, err := translateCodexModel(EffectiveModel(parentModel, agentModel), true) if err != nil { - return false, err.Error() + needV1 + return "", err.Error() } id := model.ID - switch { - case model.Gateway: - return false, fmt.Sprintf("parent model %q takes the inference gateway route, where native sub-agents are not supported", "gateway/"+id) - case !catalog.has(id): - return false, fmt.Sprintf("parent model %q is not in the bundled catalog of the pinned codex", id) + needV1 - case catalog.resolvesV1(id): - return true, "" - default: - return false, fmt.Sprintf("parent model %q selects collaboration %q", id, catalog[id].Version) + needV1 + if model.Gateway { + return "", fmt.Sprintf("parent model %q takes the inference gateway route, where native sub-agents are not supported", "gateway/"+id) + } + if !catalog.has(id) { + return "", fmt.Sprintf("parent model %q is not in the bundled catalog of the pinned codex", id) + } + switch catalog.collabVersion(id) { + case "v1": + return "v1", "" + case "v2": + return "v2", fmt.Sprintf("parent model %q selects collaboration \"v2\"; V2 delegation is off until its child-result delivery path is verified live (ADR 0159)", id) + } + if catalog[id].Version == "disabled" { + return "", fmt.Sprintf("parent model %q has native sub-agents disabled in the bundled catalog", id) } + return "", fmt.Sprintf("parent model %q selects collaboration %q, which the runner does not support", id, catalog[id].Version) } diff --git a/internal/runtime/codex_personas_test.go b/internal/runtime/codex_personas_test.go index f1d6b51510..5aff594fda 100644 --- a/internal/runtime/codex_personas_test.go +++ b/internal/runtime/codex_personas_test.go @@ -339,9 +339,9 @@ func TestCodexRole_TOMLParsesWithTheThreeKeys(t *testing.T) { } // TestCodexCatalog reads the fixture reduced from the pinned CLI's dump and -// pins the questions Bootstrap asks it: is a model listed, does codex -// resolve it to collaboration V1, and which efforts a child on it may run -// at. The reduction keeps only the four fields Bootstrap reads, so a bump +// pins the questions Bootstrap asks it: is a model listed, which collaboration +// version the gate takes from its entry, and which efforts a child on it may +// run at. The reduction keeps only the four fields Bootstrap reads, so a bump // that changes other catalog fields (0.166.0 rewrote model_messages for // every entry) leaves the fixture untouched; 0.166.0's only visible change // is the added gpt-6.1-terra entry. On a CODEX_VERSION bump regenerate it, @@ -360,23 +360,23 @@ func TestCodexCatalog(t *testing.T) { require.NoError(t, err) assert.True(t, catalog.has(codexDefaultSubagentModel), "the floor must be listed; a child takes its parent's collaboration version, so the floor's own does not matter") - assert.True(t, catalog.resolvesV1("gpt-5.6-luna"), "a luna parent delegates on 0.166.0") + assert.Equal(t, "v1", catalog.collabVersion("gpt-5.6-luna"), "a luna parent delegates on 0.166.0") assert.Equal(t, "medium", catalog["gpt-5.6-luna"].DefaultEffort, "children on the floor run at medium when the run sets no effort") assert.Equal(t, []string{"low", "medium", "high", "xhigh", "max"}, catalog["gpt-5.6-luna"].Efforts) assert.Equal(t, "low", catalog["gpt-5.6-sol"].DefaultEffort) assert.NotContains(t, catalog["gpt-5.5"].Efforts, "max", "the one fullsend effort a listed model lacks at the pin") assert.True(t, catalog.has("gpt-5.6-sol")) - assert.False(t, catalog.resolvesV1("gpt-5.6-sol"), "sol selects V2") + assert.Equal(t, "v2", catalog.collabVersion("gpt-5.6-sol"), "sol selects V2") assert.True(t, catalog.has("gpt-5.5")) - assert.True(t, catalog.resolvesV1("gpt-5.5"), "an entry without a version takes V1 from the multi_agent feature") + assert.Equal(t, "v1", catalog.collabVersion("gpt-5.5"), "an entry without a version takes V1 from the multi_agent feature") assert.False(t, catalog.has("gpt-5.6-nova")) - assert.False(t, catalog.resolvesV1("gpt-5.6-nova")) + assert.Empty(t, catalog.collabVersion("gpt-5.6-nova")) // Hidden entries count: the fixture keeps no `visibility`, so the hidden // V1 entry resolves to V1 like a listed one and a hidden model is listed. assert.True(t, catalog.has("codex-auto-review")) - assert.True(t, catalog.resolvesV1("codex-auto-review"), "a hidden entry that selects V1 resolves to V1") + assert.Equal(t, "v1", catalog.collabVersion("codex-auto-review"), "a hidden entry that selects V1 resolves to V1") assert.True(t, catalog.has("gpt-daybreak-blue-latest"), "a hidden model passes the membership check") - assert.False(t, catalog.resolvesV1("gpt-daybreak-blue-latest"), "hidden and V2") + assert.Equal(t, "v2", catalog.collabVersion("gpt-daybreak-blue-latest"), "hidden and V2") _, err = parseCodexCatalog([]byte("not json")) require.Error(t, err) @@ -384,41 +384,46 @@ func TestCodexCatalog(t *testing.T) { require.Error(t, err, "an empty catalog is a broken binary, not a catalog") } -// TestCodexParentResolvesV1 is part two of the ADR 0126 gate: the parent model -// Run will use (the run-level model, else the definition's) must translate to -// an OpenAI id codex resolves to V1: its entry selects V1 or carries no -// version (codex's multi_agent feature, on by default, supplies V1). A V2 or -// unlisted parent keeps the multi-agent tools off and says why in one line, -// and so does a gateway/ parent whatever its id. -func TestCodexParentResolvesV1(t *testing.T) { +// TestCodexParentCollabVersion is part two of the delegation gate (ADR 0126, +// extended by ADR 0159): the parent model Run will use (the run-level model, +// else the definition's) must translate to an OpenAI id whose catalog entry +// gives the gate V1 or V2: the entry selects one, or carries no version and +// codex's multi_agent feature, on by default, supplies V1. A V1 parent +// delegates. A V2 parent resolves but is declined with the ADR 0159 reason +// until its child-result delivery path is implemented and verified live. A +// disabled, unknown-version or unlisted parent gets no version from the gate +// and says why in one line, and so does a gateway/ parent whatever its id. +func TestCodexParentCollabVersion(t *testing.T) { t.Parallel() - catalog := codexVersionsCatalog(map[string]string{"gpt-5.6-luna": "v1", "gpt-5.6-sol": "v2", "gpt-5.5": "", "gpt-x": "v3"}) + catalog := codexVersionsCatalog(map[string]string{"gpt-5.6-luna": "v1", "gpt-5.6-sol": "v2", "gpt-5.5": "", "gpt-x": "v3", "gpt-d": "disabled"}) tests := []struct { name string parentModel string agentModel string - want bool + wantVersion string wantReason string }{ - {"definition model, V1", "", "openai/gpt-5.6-luna", true, ""}, - {"run-level model wins", "openai/gpt-5.6-luna", "openai/gpt-5.6-sol", true, ""}, - {"run-level V2 beats a V1 definition", "openai/gpt-5.6-sol", "openai/gpt-5.6-luna", false, `parent model "gpt-5.6-sol" selects collaboration "v2"`}, - {"no multi-agent version (multi_agent supplies V1)", "", "gpt-5.5", true, ""}, - {"unknown collaboration version", "", "openai/gpt-x", false, `parent model "gpt-x" selects collaboration "v3"`}, - {"not in the catalog", "", "openai/gpt-5.6-nova", false, `parent model "gpt-5.6-nova" is not in the bundled catalog`}, - {"gateway route declines a listed V1 id", "", "gateway/gpt-5.6-luna", false, `parent model "gateway/gpt-5.6-luna" takes the inference gateway route`}, - {"gateway route declines before the catalog", "", "gateway/vendor/org/model", false, `parent model "gateway/vendor/org/model" takes the inference gateway route`}, - {"run-level OpenAI model beats a gateway definition", "openai/gpt-5.6-luna", "gateway/vendor/org/model", true, ""}, - {"run-level gateway route beats a V1 definition", "gateway/vendor/org/model", "openai/gpt-5.6-luna", false, `parent model "gateway/vendor/org/model" takes the inference gateway route`}, - {"claude alias does not translate", "", "opus", false, "codex takes OpenAI model ids or gateway/ only"}, - {"no model at all", "", "", false, "no model was named"}, + {"definition model, V1", "", "openai/gpt-5.6-luna", "v1", ""}, + {"run-level model wins", "openai/gpt-5.6-luna", "openai/gpt-5.6-sol", "v1", ""}, + {"run-level V2 beats a V1 definition", "openai/gpt-5.6-sol", "openai/gpt-5.6-luna", "v2", `parent model "gpt-5.6-sol" selects collaboration "v2"; V2 delegation is off until its child-result delivery path is verified live (ADR 0159)`}, + {"no multi-agent version (multi_agent supplies V1)", "", "gpt-5.5", "v1", ""}, + {"catalog says disabled", "", "openai/gpt-d", "", `parent model "gpt-d" has native sub-agents disabled in the bundled catalog`}, + {"unknown collaboration version", "", "openai/gpt-x", "", `parent model "gpt-x" selects collaboration "v3", which the runner does not support`}, + {"not in the catalog", "", "openai/gpt-5.6-nova", "", `parent model "gpt-5.6-nova" is not in the bundled catalog of the pinned codex`}, + {"gateway route declines a listed V1 id", "", "gateway/gpt-5.6-luna", "", `parent model "gateway/gpt-5.6-luna" takes the inference gateway route`}, + {"gateway route declines before the catalog", "", "gateway/vendor/org/model", "", `parent model "gateway/vendor/org/model" takes the inference gateway route`}, + {"run-level OpenAI model beats a gateway definition", "openai/gpt-5.6-luna", "gateway/vendor/org/model", "v1", ""}, + {"run-level gateway route beats a V1 definition", "gateway/vendor/org/model", "openai/gpt-5.6-luna", "", `parent model "gateway/vendor/org/model" takes the inference gateway route`}, + {"claude alias does not translate", "", "opus", "", "codex takes OpenAI model ids or gateway/ only"}, + {"no model at all", "", "", "", "no model was named"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() - got, reason := codexParentResolvesV1(catalog, tt.parentModel, tt.agentModel) - assert.Equal(t, tt.want, got) - if tt.want { + got, reason := codexParentCollabVersion(catalog, tt.parentModel, tt.agentModel) + assert.Equal(t, tt.wantVersion, got) + assert.NotContains(t, reason, "need a parent", "no explanation says delegation needs a V1 parent") + if tt.wantReason == "" { assert.Empty(t, reason) } else { assert.Contains(t, reason, tt.wantReason) From b84b5208e73cf7e9b96fc0b96eda209b5bd0fccb Mon Sep 17 00:00:00 2001 From: Dharit Shah Date: Tue, 10 Nov 2026 13:36:55 -0500 Subject: [PATCH 2/2] refactor(codex): admit only a V1 parent in the delegation gate Bootstrap delegated whenever the resolver returned a version and no reason, so a V2 branch that stopped returning a reason would have admitted V2 parents with the V1-only config. The gate now reads the version: only "v1" delegates, and only the change that renders the V2 config and the checked child-result delivery path widens it to V2. The resolver's doc and its test say the reason explains a decline and never decides one. Signed-off-by: Dharit Shah --- internal/runtime/codex_bootstrap.go | 15 ++++++++------- internal/runtime/codex_personas.go | 10 ++++++---- internal/runtime/codex_personas_test.go | 15 ++++++++------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/internal/runtime/codex_bootstrap.go b/internal/runtime/codex_bootstrap.go index 8697f92ce8..3486f32ae0 100644 --- a/internal/runtime/codex_bootstrap.go +++ b/internal/runtime/codex_bootstrap.go @@ -178,12 +178,13 @@ func (r CodexRuntime) Bootstrap(input BootstrapInput) error { // CLI's catalog: the gate takes the collaboration version from the entry // of the model Run will launch, V1 when the entry selects V1 or carries // no version (codex's multi_agent feature, on by default, supplies V1) - // and V2 when it selects V2. A V1 parent delegates. A V2 parent is - // declined until its child-result delivery path is implemented and - // verified live (ADR 0159 decision 4); a disabled, unknown-version, - // unlisted or gateway/ parent is declined with its own explanation. A - // declined parent keeps the multi-agent tools off and runs in one - // context, as an agent that does not delegate does. + // and V2 when it selects V2. Only a V1 parent delegates: the gate reads + // the version, not the reason. Only the change that renders the V2 + // config and the checked child-result delivery path widens the gate to V2, + // once that path is verified live (ADR 0159 decision 4). A V2, disabled, + // unknown-version, unlisted or gateway/ parent is declined with its own + // explanation, keeps the multi-agent tools off and runs in one context, + // as an agent that does not delegate does. _, securityOn := input.(SandboxHooksBootstrap) var catalog codexCatalog delegating := false @@ -192,7 +193,7 @@ func (r CodexRuntime) Bootstrap(input BootstrapInput) error { return err } version, reason := codexParentCollabVersion(catalog, input.ParentModel(), def.Model) - if delegating = version != "" && reason == ""; !delegating { + if delegating = version == "v1"; !delegating { fmt.Fprintf(os.Stderr, "sub-agents: %s, running in one context\n", reason) } } diff --git a/internal/runtime/codex_personas.go b/internal/runtime/codex_personas.go index 02fe9df549..ddbeb6d9e8 100644 --- a/internal/runtime/codex_personas.go +++ b/internal/runtime/codex_personas.go @@ -391,10 +391,12 @@ func parseCodexCatalog(data []byte) (codexCatalog, error) { // codexParentCollabVersion is part two of the delegation gate (ADR 0126, // extended by ADR 0159): the collaboration version the gate takes for the // parent Run will launch ("v1" or "v2", else ""), and the one-line reason -// Bootstrap prints when the parent runs in one context. A V2 parent is -// returned with a reason until its child-result delivery path is implemented -// and verified live (ADR 0159 decision 4). A parent that does not translate -// is reported by Run with the same error; the gate only declines here. A +// Bootstrap prints when the parent runs in one context. Bootstrap delegates +// only a "v1" parent: the reason explains a decline and never decides one. A +// V2 parent is returned as "v2" with the ADR 0159 reason, and Bootstrap +// declines it until its child-result delivery path is implemented and +// verified live (ADR 0159 decision 4). A parent that does not translate is +// reported by Run with the same error; the gate only declines here. A // gateway/ parent is declined whatever its id: children would inherit the // gateway provider with bare OpenAI ids it may not serve, and native children // have not run on that route. diff --git a/internal/runtime/codex_personas_test.go b/internal/runtime/codex_personas_test.go index 5aff594fda..bd43db0688 100644 --- a/internal/runtime/codex_personas_test.go +++ b/internal/runtime/codex_personas_test.go @@ -386,13 +386,14 @@ func TestCodexCatalog(t *testing.T) { // TestCodexParentCollabVersion is part two of the delegation gate (ADR 0126, // extended by ADR 0159): the parent model Run will use (the run-level model, -// else the definition's) must translate to an OpenAI id whose catalog entry -// gives the gate V1 or V2: the entry selects one, or carries no version and -// codex's multi_agent feature, on by default, supplies V1. A V1 parent -// delegates. A V2 parent resolves but is declined with the ADR 0159 reason -// until its child-result delivery path is implemented and verified live. A -// disabled, unknown-version or unlisted parent gets no version from the gate -// and says why in one line, and so does a gateway/ parent whatever its id. +// else the definition's) must translate to an OpenAI id, whose catalog entry +// gives a version: V1 when it selects V1 or carries none (codex's multi_agent +// feature, on by default, supplies V1), V2 when it selects V2. Only a "v1" +// result delegates; a V2 parent gets "v2" and the ADR 0159 reason, and +// Bootstrap declines it until its child-result delivery path is implemented +// and verified live. A disabled, unknown-version or unlisted parent gets no +// version from the gate and says why in one line, and so does a gateway/ +// parent whatever its id. func TestCodexParentCollabVersion(t *testing.T) { t.Parallel() catalog := codexVersionsCatalog(map[string]string{"gpt-5.6-luna": "v1", "gpt-5.6-sol": "v2", "gpt-5.5": "", "gpt-x": "v3", "gpt-d": "disabled"})