Skip to content

Review-delegate MCP tool calls hang forever: approval elicitation is unanswerable in delegated sub-agents (forward_events has no ElicitationRequest arm) #31565

Done

Description

@martijnwalraven

What issue are you seeing?

Under codex exec review (and any review flow that delegates to a sub-Codex), the first call to an MCP tool that requires approval is announced in the transcript (mcp: <server>/<tool> started) but never dispatched: the JSON-RPC tools/call frame is never written to the server process's stdin, and codex waits indefinitely — the 300s default tool_timeout_sec never fires (observed 23 min on 0.142.5 and 15+ min on 0.143.0 before manual kill). Plain codex exec and interactive Codex dispatch the same tool against the same server fine (review-flow calls 0/5, elsewhere 16/16 on the same machine/server/day).

Because unannotated tools default to approval-required, this hits any local stdio MCP server whose tools don't declare annotations — which is most of them — on the first tool call of every review run.

Versions: codex-cli 0.142.5 and 0.143.0 (Homebrew cask), macOS aarch64 (Mac OS 26.5.2), model gpt-5.5. Code references below are at current main (f1affba); the mechanism is unchanged since at least rust-v0.142.5. codex doctor clean (runtime brew 0.143.0, install consistent).

Root cause

Chain verified by a trace-logged repro and a discriminating config experiment on the stock binary:

  1. The review task runs as a delegated one-shot sub-Codex with approval_policy pinned to Never (core/src/tasks/review.rs:118, via codex_delegate.rs).
  2. MCP tools without annotations default to approval-required — requires_mcp_tool_approval(None) treats missing destructive_hint/open_world_hint as destructive/open-world (core/src/mcp_tool_call.rs:2163).
  3. mcp_permission_prompt_is_auto_approved does not auto-approve: policy is Never but the sandbox is not full-disk-write (codex-mcp/src/mcp/mod.rs:79).
  4. The in-session guardian route is off: it requires OnRequest/Granular, and the delegate is pinned to Never (core/src/guardian/review.rs:173).
  5. tool_call_mcp_elicitation (stable, default-enabled) sends the approval as EventMsg::ElicitationRequest and awaits a oneshot with no timeout: rx_response.await in request_mcp_server_elicitation (core/src/session/mcp.rs:280).
  6. forward_events in core/src/codex_delegate.rs intercepts and answers ExecApprovalRequest, ApplyPatchApprovalRequest, RequestPermissions, and RequestUserInput from the delegate — but has no arm for ElicitationRequest; it falls through the catch-all as a display event. The gap is acknowledged in the code (codex_delegate.rs:731): "TODO(ccunningham): Support delegated MCP approval elicitations here too … Today guardian only auto-reviews the RequestUserInput compatibility path for delegated MCP approvals." One-shot delegates additionally return a closed ops channel (codex_delegate.rs:262-266), so no Op::ResolveElicitation can ever reach the delegate session.
  7. McpToolCallBegin is emitted before the approval gate (mcp_tool_call.rs:227 vs :236), so the transcript says "started".
  8. tool_timeout_sec wraps only the rmcp service operation inside execute_mcp_tool_call, downstream of the approval gate — it never starts, so it never fires.

Why plain codex exec works: the exec main session runs approval: on-request with the auto-review guardian, so step 4 routes the approval to the guardian in-session and the call proceeds.

What steps can reproduce the bug?

  1. Register a local stdio MCP server whose tools carry no annotations, e.g.:

    [mcp_servers.myserver]
    command = "node"
    args = ["my-mcp-server.js"]
  2. Run a review that calls one of its tools:

    codex exec review "Review commit HEAD. Additionally, call the <tool> tool via MCP."
    
  3. Within ~a minute the transcript shows mcp: myserver/<tool> started and never completes; the server child's stdin has received exactly the initialize handshake + tools/list and nothing more.

Discriminating experiment (stock 0.143.0, no code changes): the same prompt wedges with default config (5/5 across 0.142.5–0.143.0) and completes in seconds when the approval gate is short-circuited with -c 'mcp_servers.<name>.default_tools_approval_mode="approve"'. A trace-logged wedge run (RUST_LOG=codex_mcp=trace,rmcp=trace,...) shows both the main and delegate sessions completing initialize+tools/list, the delegate's FunctionCall, the begin event — and zero rmcp trace activity after it: the call never reaches the rmcp client. Byte-level: live inspector autopsy of both spawned server processes of a wedged run — stdin bytesRead = initialize handshake + tools/list exactly, streams flowing and healthy, zero bytes after the handshake; children idle in kevent; the delegate rollout ends at the function_call entry with no output.

Annotating the server's tools (readOnlyHint: true, or destructiveHint: false + openWorldHint: false) also makes the wedge disappear, confirming the approval gate as the choke point — but servers shouldn't have to annotate to avoid an infinite hang.

What is the expected behavior?

A review-delegate MCP approval surfaces somewhere answerable (guardian or user) or resolves per policy — and tool_timeout_sec (or any bound) limits the wait in every case. Two defects as read: (1) delegated sub-agents emit MCP approval elicitations that nothing can answer; (2) an announced tool call can wait forever with no timeout.

Additional information — suggested minimal fix (patch available)

In run_codex_thread_interactive, disable Feature::ToolCallMcpElicitation on the delegate config, pinning delegated MCP approvals to the RequestUserInput compatibility path that forward_events already answers (guardian auto-review under exec; the parent's real user in interactive flows) — removable once the elicitation TODO is implemented. Regression test included: a review delegate calling an approval-requiring MCP tool must surface an answerable prompt on the parent session and complete once answered (it times out at the approval wait on unpatched source, passes with the pin).

A working implementation of exactly this shape — the pin, the regression test, and a managed-features caveat handled (an admin pin that force-enables the feature is kept and warned about) — is public at https://github.com/martijnwalraven/codex/tree/fix-delegated-mcp-approval-hang, shared as a fix outline per the contribution policy; happy to file it as a PR if invited. Caveats: the exec-review path is live-proven (patched binary runs the wedging repro to completion); the interactive-TUI-review path is analyzed at source but not live-tested; the pin applies to all delegated sub-agents, and a review-task-scoped variant is the more conservative alternative.

Activity

  1. added
    bug
    CLI
    mcp
    code-review
    exec
    subagent
    tool-calls
    on Jul 8, 2026
  2. rpelevin commented on Jul 8, 2026

    @rpelevin

    This is a clean authority-boundary bug report. The part I would make explicit in the fix/test is that "tool started" should not be emitted as an execution-begin receipt until the authority path has either resolved or failed closed.

    The minimal invariant I would want covered is:

    • delegated MCP approval requests are always routed to an answerable authority surface, auto-resolved by policy, or fail with a bounded no-dispatch result;
    • the timeout/bound includes the approval wait, not only the downstream rmcp service call;
    • an unanswerable elicitation produces a terminal no-effect result rather than an apparent in-progress tool call;
    • begin/started telemetry is separated from "approval requested" and "call dispatched";
    • compatibility-path and elicitation-path approvals share the same parent/delegate correlation id.

    The suggested pin back to the compatibility path seems like a reasonable narrow mitigation if the full delegated elicitation route is not ready yet. Long term, I would treat delegated MCP approval as a first-class event with an explicit requester/delegate/tool identity tuple and a terminal receipt for approved, denied, timeout, unavailable-authority, and not-dispatched outcomes.

    I have not tested the patch or verified the source locally. This is only a boundary/test-shape pass on the issue as described.

  3. aldi949 commented on Sep 23, 2026

    @aldi949

    @martijnwalraven hey — I found this while looking into failures that only appear once tools/MCP cross an agent boundary.

    The 15–23+ minute hangs sound particularly painful.

    Is this still something you run into? And outside this specific bug, have you had other cases where it was difficult to tell whether a delegated agent was waiting on approval, a tool, MCP, or something else?

  4. etraut-openai commented on Nov 29, 2026

    @etraut-openai
    Contributor

    (Response from codex)

    I reproduced the stalled review with an unannotated stdio tool on 0.143.0. On 0.172.0 the same tool call completed with MCP tool call requires approval, but approval policy is never, and the review finished. The delegate no longer waits for approval it can't receive. Closing as fixed.

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

    CLIbugcode-reviewexecmcpsubagenttool-calls

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions