Skip to content

fix(codex): use sessions_spawn as the only subagent surface - #207303

Merged
obviyus merged 6 commits into
mainfrom
core/codex-one-subagent-surface
Nov 28, 2026
Merged

obviyus merged 6 commits into
mainfrom
core/codex-one-subagent-surface

Conversation

@obviyus

@obviyus obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Problem

On the default Codex app-server runtime (native OpenAI models), each request carries three overlapping subagent tool sets: Codex's native multi_agent_v1 (14,898 B: spawn_agent, send_input, resume_agent, wait_agent, close_agent), OpenClaw's sessions_spawn (8,271 B) and agents_wait/agents_list. The developer prompt also spends paragraphs steering the model between native and managed delegation.

  • Native Codex children cannot run OpenClaw tools (thread-prompt.ts). sessions_spawn covers those children, ACP, visible sessions and fork context, with the same contract as on the embedded runtime.
  • A production deployment over 7 days (162 Codex-runtime sessions): 0 native multi-agent calls, against 181 sessions_spawn calls in 21 sessions.

Measured on main through an isolated Gateway (fake provider): 15 tools / 52,346 B per request.

Solution

  • Every thread OpenClaw starts or resumes sets agents.enabled, features.multi_agent and features.multi_agent_v2 to false, through the existing CODEX_DELEGATION_DISABLED_THREAD_CONFIG in buildCodexRuntimeThreadConfig.
  • The per-run native-delegation decision (isCodexNativeDelegationDisabledForRun), the gpt-5.4-nano patch it subsumed, and the native-vs-managed prompt steering are deleted.
  • Native-subagent observation stays. It also owns root model-source authority, supervision of desktop threads, and recovery of native children that already exist.
  • Docs follow, and the Codex prompt budget ratchet drops to the new size.

Upstream note: multi_agent is Stage::Deprecated, default on; multi_agent_v2 is Stage::Stable, default off (openai/codex features/src/lib.rs).

User impact

  • Every Codex-runtime turn, Gateway and one-shot: tools 52,346 → 37,447 B per request (−14,899 B). The Codex app-server developer prompt drops 12,618 → 11,756 B (snapshot). Prompt budget ratchet 13,824 → 12,544 B (CODEX_APP_SERVER_PROMPT_BUDGET_BYTES). The dynamic-tools snapshot is unchanged (62,551 B): the removed tools are Codex-native, not dynamic tools, so the tools ratchet stays.
  • In one-shot agent --local, delegation needs sessions_spawn working without a Gateway (fix(agents): run sessions_spawn children in one-shot agent --local #207243, landing first).
  • Existing threads get the new tool list on their next cold resume: one prompt-cache miss per thread. A loaded thread keeps its tools until then (codex-rs/app-server/src/request_processors/thread_processor.rs:291 ignores config on a running thread; core/src/config/mod.rs:1833 maps agents.enabled=false to MultiAgentVersion::Disabled).
  • Accepted loss (maintainer decision): after a cold resume, a parent that kept a native child open cannot send that child more input. sessions_spawn starts another worker and does not continue that child's assignment. Results already in flight are still observed and delivered. Production showed 0 native multi-agent calls in 7 days. Docs say so (codex-harness.md, Native subagent status).
  • A managed Codex requirement that pins multi-agent on still wins, except where a session-tool deny already rejects it (documented in restricted-turns.md).

Evidence

  • Isolated Gateway bench, fake provider: 15 → 14 tools, 52,346 → 37,447 B.
  • Codex-route behavior suite, gpt-5.4-mini, 3 trials per case, model-judged: main 24/30, this change 27/30. reply-directive is 0/3 on both, an existing gap.
  • Tests: the codex thread-lifecycle, prompt and native-hook tests, the new thread-delegation.test.ts, and prompt-snapshots.test.ts with the lower budget all pass.

- Turn off Codex native multi-agent (agents.enabled, features.multi_agent, features.multi_agent_v2) on every thread OpenClaw starts or resumes.
- Native children cannot run OpenClaw tools; sessions_spawn covers them and is the same contract on the embedded runtime. The native tools added 14.9 KB to every Codex request.
- Delete the per-run native-delegation decision and the native-vs-managed prompt steering; docs follow.
…udget

- Native multi-agent is off on every OpenClaw thread, so the snapshot threads carry the three delegation keys and the native steering paragraphs are gone.
- Codex app-server prompt 12,981 -> 12,119 B; ceiling 13,824 -> 12,800 B (measured + 5%, rounded up to 256 B). The dynamic-tools gate is unchanged: the removed tools are Codex-native.
- After a cold resume, an OpenClaw parent has no native collaboration tools; existing native children are still observed and their results delivered.
@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus

obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Rejected review findings:

  • [P1] Preserve follow-up controls for existing native children (thread-requests.ts:325-328): rejected by maintainer decision. Keeping native collaboration controls on resume would keep the second subagent surface this PR removes. The loss is narrow and visible: after a cold resume, a parent cannot send more input to a native child it kept open; that child's in-flight results are still observed and delivered, and the parent continues with sessions_spawn. Production showed 0 native multi-agent calls in 7 days. The docs state the behavior (docs/plugins/codex-harness.md, Native subagent status).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: codex size: M labels Nov 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 28, 2026
@clawsweeper

clawsweeper Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR disables native Codex delegation by default and directs subagent work through OpenClaw’s sessions_spawn tool.

Example: A Codex agent delegates a repository investigation.

  • Before: The request advertises native Codex collaboration alongside sessions_spawn and includes guidance choosing between them.
  • After: New or cold-resumed threads disable native collaboration and delegate through sessions_spawn.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is focused and has no definite correctness finding, but upgrade proof and prerequisite landing remain incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Codex requests carry duplicate delegation tools and instructions, increasing model context and requiring route selection.
Reason: The collaborator-authored direction removes measured request overhead through an existing owner and explicitly accepts the native-child follow-up limitation.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this maintainer-authored PR coherently removes a duplicate delegation surface, and no definite patch-introduced bug was found.

Reviewed head: 4a192aeb31b8bcd28e20ae383990b64d3c0d42ac

Before merge

Findings

None.

Agent review details

How this fits together

The Codex harness converts OpenClaw turn capabilities into app-server thread configuration and developer instructions; delegated OpenClaw tools then create managed child sessions.

flowchart TD
  A[OpenClaw agent turn] --> B[Thread configuration owner]
  B --> C[Codex app server]
  C --> D[Model calls sessions_spawn]
  D --> E[Managed child session]
  E --> F[Parent receives result]
Loading

Technical review

Best possible solution:

Keep the common configuration-owner change and retained native observation, landing it after the local sessions_spawn prerequisite.

Do we have a high-confidence way to reproduce the issue?

Current-main configuration and prompt source establish overlapping native and managed delegation surfaces; this read-only review executed no target code.

Is this the best way to solve the issue?

Using the existing thread configuration owner is the smallest complete cutover, and retaining native observation is justified by existing execution and recovery responsibilities.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 23ea8a9a3c51.

Merge-risk options

Maintainer options:

  1. Land the local prerequisite first (recommended)
    Merge the local sessions_spawn repair before removing Codex’s native delegation fallback.
  2. Hold this PR
    Pause landing while the local-execution prerequisite remains unresolved.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 30057ae adds extensions/codex/src/app-server/thread-requests.ts:84 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 30057ae514b5; files: extensions/codex/src/app-server/thread-requests.ts)
  • Vincent Koc: Raw commit 2356477 adds extensions/codex/src/app-server/thread-prompt.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 235647734fb5; files: extensions/codex/src/app-server/thread-prompt.ts)
  • Josh Lehman: Raw commit 6448550 adds extensions/codex/src/app-server/thread-requests.ts:59 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 6448550898c2; files: extensions/codex/src/app-server/thread-requests.ts)

PR surface

Source -49, Tests -87, Docs -31. Total -167 across 23 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 17 66 -49
Tests 13 102 189 -87
Docs 6 28 59 -31
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 147 314 -167

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The default native tool surface changes on cold resume, with an explicitly accepted loss of native-child follow-up controls and an unresolved local-execution landing dependency.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.

Label justifications:

  • merge-risk: 🚨 compatibility: The default native tool surface changes on cold resume, with an explicitly accepted loss of native-child follow-up controls and an unresolved local-execution landing dependency.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide the latest-stable upgrade and cold-resume evidence described above.
  • Land the linked local-delegation prerequisite before this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 28, 2026, 2:18 AM ET / 07:18 UTC.

@obviyus

obviyus commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

No override needed: CI is green on e56102e after merging current main.

@obviyus
obviyus merged commit de354e4 into main Nov 28, 2026
118 checks passed
@obviyus
obviyus deleted the core/codex-one-subagent-surface branch November 28, 2026 08:46
@obviyus

obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Landed. Threads that OpenClaw starts or resumes now get one subagent surface (sessions_spawn) instead of three overlapping ones: tools per Codex request 52,346 → 37,447 B, and the Codex prompt budget ratchet drops to 12,544 B. Proof: Codex-route behavior suite 24/30 → 27/30 (gpt-5.4-mini, 3 trials), prompt-snapshot budget test, and CI green on the exact head.

obviyus added a commit that referenced this pull request Nov 28, 2026
… only subagent surface (#207595)

## What Problem This Solves

`src/agents/harness/codex-subagent-tool-policy.test.ts` fails on main: `Codex subagent native tool policy > preserves native tools for OpenClaw admin/status-only denial` gets an `AssertionError` (`agents.enabled` is `false`, the test requires `undefined`). It fails in every scheduled run since #207303, for example job `checks-node-compact-large-31` in run 46154601106 (https://github.com/openclaw/openclaw/actions/runs/46154601106).

The test is stale. #207303 intentionally made every Codex thread set `agents.enabled`, `features.multi_agent` and `features.multi_agent_v2` to false (`extensions/codex/src/app-server/thread-requests.ts:328`, spread of `CODEX_DELEGATION_DISABLED_THREAD_CONFIG` in `buildCodexRuntimeThreadConfig`). Before it, the value was set only when a deny hit native delegation, so an admin/status-only deny left it unset.

Bisect: the parent of #207303 passes this file 17/17; #207303 fails exactly this case.

## Fix

- Line 153: assert `agents.enabled` is `false`, which pins #207303's invariant instead of removing the check.
- The comment in `preserves the effective policy for $name` said session denies are enforced by disabling native delegation. Delegation is now off on every thread; the comment says so.

Test-only. No production change.

## User Impact

None at runtime. Main's `checks-node-compact-large-31` goes green for this file.

## Evidence
- Red on main 3e55ac1: `codex-subagent-tool-policy.test.ts` fails 1 case (the one above).
- Green on this head: that file (17/17) plus the tests of `thread-requests.ts` consumers (thread-delegation, thread-lifecycle, thread-policy, thread-requests.managed-requirements, turn-params, run-attempt-tools and 9 more): 16 files, 337 tests pass.
- Format and oxlint clean on the changed file. Diff: +5 / -4, one test file.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…#207303)

## Problem

On the default Codex app-server runtime (native OpenAI models), each request carries three overlapping subagent tool sets: Codex's native `multi_agent_v1` (14,898 B: `spawn_agent`, `send_input`, `resume_agent`, `wait_agent`, `close_agent`), OpenClaw's `sessions_spawn` (8,271 B) and `agents_wait`/`agents_list`. The developer prompt also spends paragraphs steering the model between native and managed delegation.

- Native Codex children cannot run OpenClaw tools (`thread-prompt.ts`). `sessions_spawn` covers those children, ACP, visible sessions and fork context, with the same contract as on the embedded runtime.
- A production deployment over 7 days (162 Codex-runtime sessions): 0 native multi-agent calls, against 181 `sessions_spawn` calls in 21 sessions.

Measured on main through an isolated Gateway (fake provider): 15 tools / 52,346 B per request.

## Solution

- Every thread OpenClaw starts or resumes sets `agents.enabled`, `features.multi_agent` and `features.multi_agent_v2` to false, through the existing `CODEX_DELEGATION_DISABLED_THREAD_CONFIG` in `buildCodexRuntimeThreadConfig`.
- The per-run native-delegation decision (`isCodexNativeDelegationDisabledForRun`), the gpt-5.4-nano patch it subsumed, and the native-vs-managed prompt steering are deleted.
- Native-subagent observation stays. It also owns root model-source authority, supervision of desktop threads, and recovery of native children that already exist.
- Docs follow, and the Codex prompt budget ratchet drops to the new size.

Upstream note: `multi_agent` is `Stage::Deprecated`, default on; `multi_agent_v2` is `Stage::Stable`, default off (`openai/codex` `features/src/lib.rs`).

## User impact

- Every Codex-runtime turn, Gateway and one-shot: tools 52,346 → 37,447 B per request (−14,899 B). The Codex app-server developer prompt drops 12,618 → 11,756 B (snapshot). Prompt budget ratchet 13,824 → 12,544 B (`CODEX_APP_SERVER_PROMPT_BUDGET_BYTES`). The dynamic-tools snapshot is unchanged (62,551 B): the removed tools are Codex-native, not dynamic tools, so the tools ratchet stays.
- In one-shot `agent --local`, delegation needs `sessions_spawn` working without a Gateway (openclaw#207243, landing first).
- Existing threads get the new tool list on their next cold resume: one prompt-cache miss per thread. A loaded thread keeps its tools until then (`codex-rs/app-server/src/request_processors/thread_processor.rs:291` ignores config on a running thread; `core/src/config/mod.rs:1833` maps `agents.enabled=false` to `MultiAgentVersion::Disabled`).
- Accepted loss (maintainer decision): after a cold resume, a parent that kept a native child open cannot send that child more input. `sessions_spawn` starts another worker and does not continue that child's assignment. Results already in flight are still observed and delivered. Production showed 0 native multi-agent calls in 7 days. Docs say so (`codex-harness.md`, Native subagent status).
- A managed Codex requirement that pins multi-agent on still wins, except where a session-tool deny already rejects it (documented in `restricted-turns.md`).

## Evidence

- Isolated Gateway bench, fake provider: 15 → 14 tools, 52,346 → 37,447 B.
- Codex-route behavior suite, gpt-5.4-mini, 3 trials per case, model-judged: main 24/30, this change 27/30. reply-directive is 0/3 on both, an existing gap.
- Tests: the codex thread-lifecycle, prompt and native-hook tests, the new `thread-delegation.test.ts`, and `prompt-snapshots.test.ts` with the lower budget all pass.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
… only subagent surface (openclaw#207595)

## What Problem This Solves

`src/agents/harness/codex-subagent-tool-policy.test.ts` fails on main: `Codex subagent native tool policy > preserves native tools for OpenClaw admin/status-only denial` gets an `AssertionError` (`agents.enabled` is `false`, the test requires `undefined`). It fails in every scheduled run since openclaw#207303, for example job `checks-node-compact-large-31` in run 46154601106 (https://github.com/openclaw/openclaw/actions/runs/46154601106).

The test is stale. openclaw#207303 intentionally made every Codex thread set `agents.enabled`, `features.multi_agent` and `features.multi_agent_v2` to false (`extensions/codex/src/app-server/thread-requests.ts:328`, spread of `CODEX_DELEGATION_DISABLED_THREAD_CONFIG` in `buildCodexRuntimeThreadConfig`). Before it, the value was set only when a deny hit native delegation, so an admin/status-only deny left it unset.

Bisect: the parent of openclaw#207303 passes this file 17/17; openclaw#207303 fails exactly this case.

## Fix

- Line 153: assert `agents.enabled` is `false`, which pins openclaw#207303's invariant instead of removing the check.
- The comment in `preserves the effective policy for $name` said session denies are enforced by disabling native delegation. Delegation is now off on every thread; the comment says so.

Test-only. No production change.

## User Impact

None at runtime. Main's `checks-node-compact-large-31` goes green for this file.

## Evidence
- Red on main c8c5eec: `codex-subagent-tool-policy.test.ts` fails 1 case (the one above).
- Green on this head: that file (17/17) plus the tests of `thread-requests.ts` consumers (thread-delegation, thread-lifecycle, thread-policy, thread-requests.managed-requirements, turn-params, run-attempt-tools and 9 more): 16 files, 337 tests pass.
- Format and oxlint clean on the changed file. Diff: +5 / -4, one test file.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: codex impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant