Skip to content

fix(codex): keep native shell for hidden subagents by disabling native delegation - #192599

Merged
jalehman merged 9 commits into
mainfrom
fix/codex-subagent-keep-native-shell
Nov 4, 2026
Merged

jalehman merged 9 commits into
mainfrom
fix/codex-subagent-keep-native-shell

Conversation

@jalehman

@jalehman jalehman commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Hidden subagents carry the built-in session/conversation tool denies (sessions_send, conversations_*, and for leaves sessions_spawn, subagents, …). The Codex harness treats any deny outside CODEX_TOOL_POLICY_SAFE_DENY_NAMES as restricted and disables the whole native Codex surface. On Gateways that also exclude the Gateway-local replacements (read/write/edit/apply_patch/exec/process), as OpenClaw Enterprise dedicated Gateways do, a hidden subagent ends up with no shell or file tools at all.

Change

  • Session, conversation and delegation tools become safe denies for Codex (CODEX_NATIVE_DELEGATION_DENY_NAMES in extensions/codex/native-tool-policy.ts).
  • When any of them is denied, the run disables Codex native delegation instead of the whole native surface: agents.enabled=false and both multi_agent feature flags off (isCodexNativeDelegationDisabledForRun). Those are the native counterparts (spawn_agent, send_input, resume_agent, v2 cross-thread) that can address other threads.
  • Developer instructions stop advertising native helpers in those runs.
  • Any deny not on the safe list still disables the whole native surface (covered by tests).
  • Top-level sessions without such denies keep native delegation.

Related: #192369 handles visible spawned sessions separately. This PR does not change subagent identity, inherited/operator restrictions, depth or child limits.

Real behavior proof

Opt-in live test src/gateway/gateway-codex-subagent-shell.live.test.ts (OPENCLAW_LIVE_CODEX_SUBAGENT_SHELL=1). It starts a real Gateway and the real Codex app-server (0.164.0) with the OCE-equivalent codexDynamicToolsExclude for the Gateway-local tools. The parent session's own model turn spawns hidden subagents with sessions_spawn, as user sessions do. The test then checks:

  1. Shell: a hidden subagent writes a token to a workspace file through its native shell, and the file is read back from disk. The test waits for the child's settled sentinel reply, not its first commentary.
  2. Delegation, from runtime records rather than model self-report: a second hidden subagent is told to call spawn_agent. The test reads the native thread records Codex wrote and requires exactly one child thread with all of the following:
    • multi_agent_version: "disabled" in the thread metadata;
    • none of spawn_agent/send_input/resume_agent/send_message/followup_task/wait_agent/list_agents/interrupt_agent/close_agent in the tools the model was given;
    • no call to any of them;
    • no helper thread started.

Model openai/gpt-6.1-sol through an OpenAI-compatible router configured as a Codex native-command provider in isolated test state, on Linux.

Build Shell probe Delegation probe (child native thread) Result
this branch (fix + review fixes) file written (SUBAGENT-SHELL-8A6A3B) multi_agent_version: disabled, no delegation tools, no delegation calls, no helper thread ✓ pass (72s)
main @ bf10667 (earlier run, same shell probe) NO-SHELL-TOOLS, file not written not reached ✗ fail
[codex-subagent-shell] subagent-shell-probe:shell {"childSessionKey":"agent:dev:subagent:9c3c116d-…","replies":"SUBAGENT-SHELL-8A6A3B"}
[codex-subagent-shell] subagent-shell-probe:delegation {"childSessionKey":"agent:dev:subagent:8f764aa6-…","replies":"NO-NATIVE-DELEGATION","childThreads":[{"multiAgentVersion":"disabled","delegationTools":[],"delegationCalls":[]}]}
 ✓ gateway live (Codex hidden subagent native shell) > keeps native shell and file tools in a hidden subagent without Gateway fallback tools 72171ms

For contrast, the same run's top-level parent threads (no session-tool deny) were given spawn_agent, send_message, followup_task, wait_agent, list_agents and interrupt_agent. Top-level sessions keep native delegation.

Managed configuration cannot re-enable delegation. When a session-tool deny is active, preflight rejects the turn before thread admission in two cases:

  • Codex managed requirements (featureRequirements) pin multi_agent, multi_agent_v2 or collab on.
  • A legacy managed config layer enables delegation in any representation Codex reports: boolean multi_agent_v2 = true, the structured table [features.multi_agent_v2] enabled = true (reported as features.multi_agent_v2: {enabled: true} with its origin on .enabled), or the collab alias.

This follows the existing image_generate → image_generation pattern. The unit cases (thread-lifecycle-managed-feature-pins.test-support.ts, run by the binding suite) use the config/read shapes captured from the real Codex 0.164.0 app-server with /etc/codex/managed_config.toml. A session-overridable layer enabling V2 is still admitted, because OpenClaw's false wins there.

Live proof for managed pins and resume after tightening. Uncommitted test; source and full results are in the PR comments.

Scenario Pre-fix head c5c6c55c This head
/etc/codex/managed_config.toml = [features.multi_agent_v2] enabled = true, agent denies sessions_send (Docker, root-owned /etc/codex) ❌ turn admitted: thread multi_agent_version: "v2", spawn_agent offered and called, helper thread started ✅ turn fails before admission: Codex tool policy cannot override managed feature multi_agent_v2, 0 native threads
Existing session with delegation offered, then operator adds tools.deny: ["sessions_send"], Gateway restart, session resumes and is told to call spawn_agent not run ✅ resumed turn runs on a fresh native thread with multi_agent_version: "disabled" and no delegation tools; no delegation calls, no helper thread

Limits of this proof

  • Linux Gateway, not an OCE cluster or macOS.
  • The router provider wiring used for the run is local proof configuration and is not in this PR; the committed test supports Codex auth and OpenAI API-key modes.
  • Shell access can itself reach a local Codex app-server or the OpenClaw CLI. This change claims no isolation beyond disabling native delegation tools.

Tests

  • Managed-pin preflight cases (requirements and legacy layer) for multi_agent, multi_agent_v2 and collab, alongside the existing image_generation case.

  • Targeted unit tests: codex-subagent-tool-policy.test.ts, thread-prompt.test.ts and related policy tests, covering subagent, visible spawn, capped subagent, sessions_send deny, and an unrelated deny (nodes) still disabling the native surface.

  • Live test above (opt-in).

  • Docs: docs/plugins/codex-harness-reference/restricted-turns.md now lists the session/conversation safe denies and explains delegation-only denial.

  • Test lines: 250 net, allocated in config/test-lines-allocations/codex-subagent-native-shell-delegation-deny.txt. The ratchet's remaining overage (137) is main's own.

@clawsweeper

clawsweeper Bot commented Nov 4, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling extensions: codex size: M labels Nov 4, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 4, 2026
@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves Codex native shell and file tools under session-tool denies by disabling native delegation instead.

Example: A hidden child must write SUBAGENT-SHELL-8A6A3B while Gateway-local shell and file tools are excluded.

  • Before: The child reports NO-SHELL-TOOLS and creates no file.
  • After: The child writes the token through native shell tools while native delegation tools remain unavailable.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with real allowed/forbidden behavior proof, preserved sibling coverage, and no remaining findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Real Linux Gateway turns through Codex 0.164.0 show a hidden child writing the workspace token, forbidden native delegation absent from runtime records, a managed V2 pin rejected before any thread starts, and delegation remaining unavailable after policy tightening and restart; the production patch is unchanged since those runs.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Hidden Codex workers cannot perform shell or file work on Gateways that exclude equivalent Gateway-local tools.
Reason: The maintainer-authored direction restores useful worker capabilities while preserving effective OpenClaw denies and disabling their native delegation counterparts.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current hidden-subagent workflow failure and has no remaining actionable findings. The earlier conflict is resolved; exact-head CI remains pending.

Priority: P1
Reviewed head: 7660eea5dd078c79590713696c804c49f6ce8ef9

Before merge

None.

Findings

None.

Agent review details

How this fits together

Core prepares the effective tool policy, and the Codex plugin translates audited denies into native configuration and developer instructions before starting or resuming a thread.

flowchart TD
 A[Effective OpenClaw tool policy] --> B[Codex deny classification]
 B --> C[Managed configuration preflight]
 C --> D[Thread start or resume configuration]
 D --> E[Native shell and file tools]
 D --> F[Native delegation disabled]
Loading

Technical review

Best possible solution:

Retain the focused delegation-only restriction through the existing Codex configuration owner and complete the repository merge gates.

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

Current-main source establishes the restrictive path, and the contributor supplies real before/after Gateway output; no target code was executed during this review.

Is this the best way to solve the issue?

The smallest complete fix keeps core policy preparation intact and applies targeted native delegation flags, managed-pin rejection, and matching prompt guidance inside the existing Codex owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 64b97d4 adds extensions/codex/native-tool-policy.ts:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 64b97d466332; files: extensions/codex/native-tool-policy.ts)
  • Vincent Koc: Raw commit 9ed1b9d adds extensions/codex/native-tool-policy.ts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9ed1b9d70a88; files: extensions/codex/native-tool-policy.ts)
  • Josh Lehman: Raw commit 284936a adds src/agents/harness/codex-subagent-tool-policy.test.ts:103 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 284936aca1b6; files: src/agents/harness/codex-subagent-tool-policy.test.ts)

PR surface

Source +77, Tests +467, Docs +6, Other +2. Total +552 across 12 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 4 82 5 +77
Tests 6 507 40 +467
Docs 1 14 8 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 12 605 53 +552

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Hidden Codex workers can lose every shell and file tool when Gateway-local replacements are excluded, blocking delegated work.
  • merge-risk: 🚨 security-boundary: The patch changes native capability enforcement under tool denies; the accepted scope and live negative controls establish delegation denial without claiming shell isolation.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-04T06:46:02.259Z sha 8d390fc :: needs real behavior proof before merge. :: [P1] Reject managed V2 requirements when delegation is denied | [P2] Wait for the child outcome before checking its file | [P2] Allocate the added regression-test lines | [P3] Update the documented session-deny behavior
  • reviewed 2026-11-04T08:39:13.525Z sha c5c6c55 :: needs real behavior proof before merge. :: [P1] Reject structured managed V2 feature pins
  • reviewed 2026-11-04T15:10:13.187Z sha a1c6103 :: needs changes before merge. :: none

Reviewed November 4, 2026, 10:56 AM ET / 15:56 UTC (Revision 4).

… for session-tool denies

Session-tool denies are enforced by disabling native delegation, so managed requirements or legacy managed layers that pin multi_agent/multi_agent_v2 on now fail the turn before inference. The live proof waits for the child settled reply and asserts delegation facts from the child native thread record. Docs updated; test lines allocated.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L and removed size: M labels Nov 4, 2026
@jalehman

jalehman commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the ClawSweeper review of 8d390fc75da in 61e8f9d3909 and c5c6c55c8ff:

  • [P1] / [high] Managed V2 requirements re-enabling delegation: when a session-tool deny is active, preflight now adds multi_agent and multi_agent_v2 to the denied managed features, so featureRequirements pinning either of them (or collab) on fails the turn before inference. A legacy managed config layer setting features.multi_agent/features.multi_agent_v2 = true outside a session-overridable layer is rejected as well, mirroring the existing shell_tool legacy-layer check. Tests: thread-lifecycle-managed-feature-pins.test-support.ts (run by the binding suite).
  • [P2] Wait for the child outcome: the live helper now waits for the child's settled sentinel reply (<token>/NO-SHELL-TOOLS, DELEGATED/NO-NATIVE-DELEGATION) instead of the first assistant text.
  • [P2] Test-line allocation: added config/test-lines-allocations/codex-subagent-native-shell-delegation-deny.txt (200). The remaining ratchet overage (137) is main's own.
  • [P3] Docs: restricted-turns.md lists the session/conversation safe denies and documents delegation-only denial and the managed-pin fail-closed behavior.
  • Proof (independent, not self-report): the delegation probe now tells the child to call spawn_agent and asserts on Codex's own native thread record: multi_agent_version: "disabled", no native collaboration tools offered, no such calls, and no helper thread. Live run passed on the new head. Details are in the updated PR description.

Not live-tested: resuming an existing child thread (covered by the shared start/resume preflight), and an OCE cluster rather than a Linux Gateway.

@jalehman

jalehman commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Nov 4, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 4, 2026
@jalehman

jalehman commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main (including #192369) in a20472f0280. The docs conflict in restricted-turns.md keeps both behaviors: hidden children keep native shell and file tools without native delegation, and visible spawns keep the full surface unless another policy restricts them. The merged visible-spawn test case was adapted to the new threadConfig(policy) helper. 7660eea5dd0 corrects the test-line allocation to 248. Targeted suites pass: codex-subagent-tool-policy 7/7, thread-prompt 22/22, thread-lifecycle binding 106/106. No production code changed since a1c61037c6c.

@jalehman

jalehman commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 4, 2026
@jalehman
jalehman merged commit 37d5c24 into main Nov 4, 2026
118 of 130 checks passed
@jalehman
jalehman deleted the fix/codex-subagent-keep-native-shell branch November 4, 2026 16:52
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 5, 2026
…e delegation (openclaw#192599)

* fix(codex): keep native shell for session-tool denies by disabling native delegation

* test(codex): live proof that hidden subagents keep the native shell without gateway fallback

* test(codex): support API-key auth in the hidden subagent shell live proof

* test(codex): spawn live-proof subagents through the parent model turn

* fix(codex): fail closed when managed config pins native delegation on for session-tool denies

Session-tool denies are enforced by disabling native delegation, so managed requirements or legacy managed layers that pin multi_agent/multi_agent_v2 on now fail the turn before inference. The live proof waits for the child settled reply and asserts delegation facts from the child native thread record. Docs updated; test lines allocated.

* fix(codex): restore live-proof path import and keep delegation deny list private

* fix(codex): reject structured and aliased managed delegation pins for session-tool denies

A legacy managed layer can enable native delegation as [features.multi_agent_v2] enabled = true (reported as features.multi_agent_v2: {enabled: true} with its origin on .enabled) or through the collab alias. Preflight now recognizes boolean, table and alias forms and checks the origin of the enabled field, failing the turn before thread admission. Cases use config/read shapes captured from Codex 0.164.0.

* test(codex): match test-line allocation after merging main
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Nov 5, 2026
…ue_delegate is a safe deny

Upstream openclaw#192599 (37d5c24) made the leaf subagent's session-tool denies
safe under the Codex harness, enforcing them by disabling native
delegation so the native shell stays. Continuation also denies
continue_delegate to leaf subagents (agent-tools.policy.ts), and that name
was absent from Codex's audited safe-deny list, so every leaf at the depth
cap still fell back to the restricted native surface and lost the shell:
upstream's own "leaf at the depth cap" case fails at 349dfb3.

continue_delegate has no Codex-native counterpart; the harness enforces its
deny by not exposing the dynamic tool. It joins the audited safe-deny list
(not the native-delegation set: denying continuation delegates must not
switch off Codex's own native agents), and the restricted-turns reference
lists it.

RED: codex-subagent-tool-policy.test.ts "leaf at the depth cap" fails at
349dfb3 and with this line reverted; GREEN with it (7/7), plus the cron
continuation tool-policy test (2/2) and the Codex policy consumers.

Refs #1271

Co-Authored-By: Claude Opus 5.5 <[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 gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant