Skip to content

PreToolUse matcher bypassed for namespaced MultiAgentV2 spawn_agent #36519

Open

Description

@brad-dietz

PreToolUse matcher bypassed for namespaced MultiAgentV2 spawn_agent

Codex version

Reproduced on codex-cli 0.146.0 and 0.147.0-alpha.4.

Problem

A managed PreToolUse hook whose matcher is spawn_agent (or its Agent
alias) blocks the non-namespaced/v1 native spawn path, but does not block the
MultiAgentV2 tool exposed as collaboration.spawn_agent. The namespaced spawn
executes even though the managed requirements and hook are loaded.

This makes a blanket native-subagent deny policy bypassable whenever
MultiAgentV2 is enabled.

Root cause

MultiAgentV2NamespaceOverride in codex-rs/core/src/tools/spec_plan.rs
forwards execution to the wrapped handler but does not forward
pre_tool_use_payload. The default runtime payload therefore uses the exposed
namespaced tool identity rather than the canonical hook identity expected by
the existing spawn_agent/Agent matcher mapping.

Minimal correction

Implement pre_tool_use_payload on MultiAgentV2NamespaceOverride, delegate
to the wrapped handler, and normalize the V2 spawn payload to
HookToolName::spawn_agent(). A regression test can construct the namespaced
V2 spawn handler and assert that its pre-tool payload has canonical tool name
spawn_agent and preserves the decoded input.

Verification

With that narrow patch applied to tag rust-v0.146.0:

  • the focused Rust regression test passes;
  • a real TUI call to collaboration.spawn_agent reaches the managed
    PreToolUse hook;
  • the hook returns a blocked function-call result; and
  • no child session is created.

Without the patch, equivalent live attempts on 0.146.0 and 0.147.0-alpha.4
create child sessions.

Activity

  1. added
    bug
    CLI
    hooks
    subagent
    on Aug 1, 2026
  2. Yinghai75 commented on Sep 23, 2026

    @Yinghai75

    Reproduced a related failure on Codex Desktop for macOS, bundled codex-cli 0.155.0-alpha.16, with hooks, multi_agent, and multi_agent_v2 all enabled.

    A user-level, synchronous PreToolUse command hook uses matcher ^(Agent|spawn_agent|collaboration\.spawn_agent)$. A fresh app-server hooks/list reports it as enabled: true, trustStatus: trusted, with no warnings or errors. The hook script logs only the event's session ID, tool name, and task name for this probe. Feeding the script a local control event writes one receipt. A real Desktop collaboration.spawn_agent call with explicit model, reasoning_effort, and fork_turns: "none" created a child, but wrote no hook receipt. The receipt instrumentation was removed after the probe.

    This does not isolate whether the V2 tool skipped the local hook path or supplied a different matcher name (for example, the flattened name reported in #33284). It does establish that the trusted hook above did not enforce policy on this real dispatch. Please normalize the V2 spawn's hook identity or provide another documented synchronous pre-dispatch policy surface. A SubagentStart notification cannot replace this because the child has already been created.

    Concrete acceptance case: a hook inspects the visible model, reasoning_effort, and fork_turns fields and denies a spawn when reasoning_effort is omitted or fork_turns is not "none"; the denial prevents child creation. Explicit valid values pass. This requires no access to the encrypted task message. Please cover the namespaced V2 path with an end-to-end regression test, including a fresh Desktop/app-server session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbughookssubagent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions