Skip to content

[Bug]: Claude CLI live-session bridge ignores control_request (can_use_tool) — sessions stall until 180/600s timeout — reproduces on 2026.5.3-1 #80819

Closed

Description

@guthirry

What happened?

When the Claude CLI live-session backend (src/agents/cli-runner/claude-live-session.ts, bundled as dist/claude-live-session-*.js) is used as the claude-cli provider, the bridge does not respond to Claude CLI control_request messages of subtype can_use_tool. Claude CLI emits these control_request events when it wants to use one of its native tools (e.g. native Bash, Read, Edit) and is waiting for a permission decision. Because OpenClaw's bridge silently ignores them, the CLI sits forever waiting for a control_response, and the live session eventually times out:

queued_work_without_active_run
classification=stale_session_state
recovery skipped: active_reply_work
... CLI produced no output for {180,600}s and was terminated.

From the user's perspective, the model answered the first turn, then made one tool call, and the session simply stopped — no error in the UI until the timeout fires.

What did you expect to happen?

The bridge should consume type: "control_request" messages from Claude CLI's stream-json output and write a matching type: "control_response" to stdin so Claude CLI can either run the native tool or fail fast with a meaningful error.

It should also map decisions to OpenClaw's effective exec policy for the agent:

  • If the resolved exec policy is security: full, ask: off, allow native Bash (matches the existing --dangerously-skip-permissions semantics OpenClaw uses elsewhere when the policy is fully permissive).
  • Otherwise, deny native Bash cleanly with a message that points the agent at OpenClaw MCP tools instead.
  • For non-Bash native tools (Read, Edit, Write, etc.), deny with a message that says "use OpenClaw MCP tools instead", since OpenClaw's policy/audit pipeline expects the MCP path.

Reproduction steps

  1. Configure a Claude CLI backend in agents.defaults.cliBackends.claude-cli so it runs the bundled binary with stream-json (-p, --output-format stream-json, --input-format stream-json, --verbose, --setting-sources user, --allowedTools mcp__openclaw__*, --permission-mode default).
  2. Pick any agent and switch its model to claude-cli/claude-opus-4-6 (or 4-7) in the OpenClaw Control UI.
  3. In a fresh dashboard session, ask the model to do something that triggers a Claude native tool — e.g., "tail the last 50 lines of /var/log/syslog" (Claude will try native Bash).
  4. Observe: the model runs one tool call, then nothing further. After 180s (or 600s for resumed turns) you'll see the stuck-detector + termination log lines above. Earlier turns may succeed if they happened to use only OpenClaw MCP tools.

Reproduces on

  • openclaw 2026.5.3-1 (Docker container, Linux 6.12.24-Unraid x64, node v24.14.0)
  • dist/claude-live-session-D20mQ3LE.js (bundle hash visible in install) — source: src/agents/cli-runner/claude-live-session.ts
  • Claude Agent SDK CLI bundled at /app/node_modules/@anthropic-ai/claude-agent-sdk-linux-x64/claude
  • Claude models: claude-opus-4-6, claude-opus-4-7

Workaround / patch we are running locally

We patched the live bundle to:

  1. Resolve and persist a controlRequestPolicy per session derived from agent-level tools.exec (falling back to global tools.exec), with { allowNativeBash, ask, security }.
  2. On stream-json parsed.type === "control_request":
    • For subtype: "can_use_tool":
      • If tool_name === "Bash" and controlRequestPolicy.allowNativeBash, write a control_response of { behavior: "allow", updatedInput }.
      • Otherwise write { behavior: "deny", message, decisionClassification: "user_reject" } with a message that explains the policy and points at OpenClaw MCP tools.
    • For other subtypes, write a control_response error explaining the bridge does not yet support that subtype.
  3. Silently ignore parsed.type === "control_response" (we never originate requests).

The patch wires the resolved policy through params.controlRequestPolicy in the helpers that hash params/build sessions, so the policy is captured at session-start time rather than recomputed mid-stream.

A diff of the patched bundled JS (against the unpatched bundle in the same install) is small (~80 lines, mostly the new helpers and the dispatch lines).

Suggested upstream fix

A real source-tree fix in src/agents/cli-runner/claude-live-session.ts that:

  • Resolves an effective exec policy per session/agent at start time and threads it into the session record.
  • Adds a control_request handler that maps can_use_tool decisions through that policy and emits control_response to stdin.
  • Logs the decision (tool name, decision, policy), and treats unsupported subtypes as a structured error response rather than a no-op.

Without this, any Claude CLI-backed session that triggers a native tool prompt will appear to hang and only fail at the global no-output timeout, which is a confusing UX for OpenClaw operators.

Anything else?

Happy to open a draft PR against src/agents/cli-runner/claude-live-session.ts mirroring the local patch — let me know if maintainers prefer that, and whether there's a preferred shape for the policy-resolution helper (some helpers.ts patterns exist in the same directory).

Reported for openclaw 2026.5.3-1.

Activity

  1. clawsweeper commented on May 12, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

    Summary
    Keep open: current main still starts Claude live sessions in stdio permission-prompt mode but has no control_request handling or control_response write path, so the reported stall remains source-proven on main and on the latest shipped tag.

    Reproducibility: yes. source-level reproduction is high confidence: a Claude stream-json control_request reaches handleClaudeLiveLine, is appended to the turn, and then returns because it is not a result. I did not run a live Claude CLI session because this checkout does not include the Claude binary or auth material.

    Next step
    The root cause and likely files are clear, but the fix changes native Claude tool permission decisions around Bash and file tools, so it should get maintainer policy confirmation before a repair PR is queued.

    Review details

    Best possible solution:

    Add focused Claude live-session handling that writes tested control_response frames for can_use_tool, denies native tools by default with MCP guidance, and only allows native Bash when the resolved OpenClaw exec policy is fully permissive.

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

    Yes, source-level reproduction is high confidence: a Claude stream-json control_request reaches handleClaudeLiveLine, is appended to the turn, and then returns because it is not a result. I did not run a live Claude CLI session because this checkout does not include the Claude binary or auth material.

    Is this the best way to solve the issue?

    Mostly yes: handling can_use_tool inside src/agents/cli-runner/claude-live-session.ts is the narrow fix. A maintainer should confirm the native Bash allow/deny boundary before implementation because this touches Claude's native permission surface.

    What I checked:

    • Current main enables Claude stdio permission prompts: buildClaudeLiveArgs forces --input-format stream-json, --output-format stream-json, and --permission-prompt-tool stdio for Claude live sessions, making the bridge responsible for responding to permission prompts. (src/agents/cli-runner/claude-live-session.ts:174, 3abb2ee78108)
    • Current main drops non-result records: handleClaudeLiveLine parses and stores each JSONL record, then returns for every parsed.type !== "result"; there is no special case for control_request or can_use_tool. (src/agents/cli-runner/claude-live-session.ts:522, 3abb2ee78108)
    • No current control-response write path: A targeted search only found the live-session argument setup, line handler, and user-turn stdin write; it found no control_request, control_response, or can_use_tool implementation in the relevant source, tests, docs, or Anthropic plugin paths. (src/agents/cli-runner/claude-live-session.ts:673, 3abb2ee78108)
    • OpenClaw already defines the Claude exec-policy mapping: Docs and Anthropic plugin code map OpenClaw YOLO exec policy (tools.exec.security: full, tools.exec.ask: off) to Claude --permission-mode bypassPermissions, with per-agent exec policy overriding global exec policy. Public docs: docs/gateway/cli-backends.md. (docs/gateway/cli-backends.md:181, 3abb2ee78108)
    • Latest release still lacks the handler: The v2026.5.7 tag has the same stdio permission-prompt arguments and the same non-result return path, so the latest shipped release does not contain a fix for this report. (src/agents/cli-runner/claude-live-session.ts:563, eeef4864494f)
    • Upstream permission contract supports the stall diagnosis: Claude Code docs say unresolved tool approvals call canUseTool, pause execution until a response returns, and accept allow/deny responses shaped as { behavior: "allow", updatedInput } or { behavior: "deny", message }. (code.claude.com)

    Likely related people:

    • @steipete: Available blame for the central Claude live-session parser, stdio argument setup, stdin write path, Anthropic CLI policy mapping, and related docs points to c192604; deeper feature provenance is limited by the local history available in this checkout. (role: recent area contributor; confidence: medium; commits: c192604e36a2; files: src/agents/cli-runner/claude-live-session.ts, extensions/anthropic/cli-shared.ts, docs/gateway/cli-backends.md)

    Remaining risk / open question:

    • No live Claude CLI session was run in this review, so the proof is source-level plus upstream permission-contract evidence rather than an observed end-to-end stall.
    • The implementation should verify the exact raw stdio control_request frame fields against the installed Claude Code version while adding tests, because the public docs cover the callback semantics more directly than the low-level wire shape.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 3abb2ee78108.

  2. self-assigned this
    on May 25, 2026
  3. locked as resolved and limited conversation to collaborators on May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions