Repository navigation
fix: let long Claude shell jobs release chat turns - #161780
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 11:57 AM ET / 15:57 UTC (Revision 5). ClawSweeper reviewWhat this changesRoutes ordinary local Claude CLI shell jobs through OpenClaw’s managed process tools so long commands can release chat turns and report completion later. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and v2026.9.7 lack the default handoff. Both earlier findings are resolved, and no new blocking correctness defect was found in the pinned changes. Priority: P1 Review scores
Verification
How this fits togetherThe Claude CLI backend receives agent turns and accesses OpenClaw tools through the Gateway’s local MCP connection. Managed execution returns process handles and queues completion for the originating conversation. flowchart TD
A[Claude chat turn] --> B[Backend preparation]
B --> C{Run and tool policy}
C --> D[Managed shell tools]
C --> E[Existing native or node tools]
D --> F[Process handle releases turn]
D --> G[Completion queue]
G --> H[Originating conversation]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +121, Tests +144, Docs +15. Total +280 across 21 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing execution and completion owners while preserving configured targets, permissions, and notification behavior. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that ordinary Claude MCP turns lack managed shell ownership, matching the reported long native Bash waits; this reviewer did not execute a failing Claude turn. Is this the best way to solve the issue? Yes, the patch reuses existing managed execution, grant enforcement, and completion queues rather than adding another process owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7f232d4e6421. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
a943904 to
951deef
Compare
|
Rebased onto Validation: focused CLI preparation, native-shell permission, Anthropic argument, prompt, Gateway tool-resolution, and exec-liveness tests passed; core and extension typechecks, changed-file lint, formatting, and diff checks passed. No draft/readiness change. |
|
Rebased onto main Resolved the exec notification conflict by retaining main’s canonical Current-head validation: 207 tests pass across eight focused files (183.20s), including real background-child notifications, exec liveness, CLI preparation/host precedence, native Bash denial, and Gateway tool policy. Core typecheck, conflict-file formatting, and diff checks pass. Prior full-build and registered-tool completion proof apply to unchanged code. No new authenticated Claude or live Telegram replay. Waiting for current-head hosted CI and ClawSweeper before merge. |
bae0d2d to
e802647
Compare
* fix: let long Claude shell jobs release chat turns * fix(agents): preserve native shell for node exec defaults --------- Co-authored-by: VACInc <[email protected]>
What Problem This Solves
Fixes long foreground shell calls holding a local Claude CLI chat turn until the command finishes.
User Impact
Local Claude CLI turns using bundled Gateway MCP can return a managed process handle after the existing default 10-second yield window. The agent is told to report that the job is running and end the turn when only waiting remains. Completion targets the originating conversation and waits when that conversation is busy.
Exec permissions, configured yield windows, command deadlines, and notification overrides still apply. Exact tool selections, tool-free side questions, standalone CLI runs, rooted runs, and paired-node runs retain their existing contracts. Plugin tools such as remote SSH are outside this fix. Managed processes retain their existing in-memory lifecycle; this adds no restart durability.
Summary
High Level TLDR
Claude's native shell could keep a chat occupied for minutes. Route ordinary local Claude shell work through OpenClaw's existing managed
execandprocesstools so the job can continue after the foreground tool call returns.Why This Change Was Made
The Anthropic backend declares host-owned shell tools. CLI preparation projects their permitted catalog into the final loopback grant; execution disables native
Bashwhile retaining existing native denials. The native permission callback rejects equivalent shell calls as well. Managed coding tools receive the original admitted operational run. Completion guidance uses the existing process owner, notification receipt, and session wake queue.Binding the managed catalog does not make an ordinary run's MCP configuration exclusive. Existing exact-tool restrictions still exclude ambient servers. Other providers retain their existing ownership.
Related: #161546 (Telegram progress visibility).
Root Cause
Observed native Claude
Bashcalls took approximately 590 and 560 seconds with 600-second tool limits. Those commands belonged to the CLI subprocess. They had no OpenClaw managed process handle or completion handoff, so the foreground turn remained active.Before this patch,
resolveMcpLoopbackToolsexcludes native coding tools unless the grant explicitly mediates them; the bundled Anthropic backend selects native tools and disallows native background Bash. The normal local CLI projection therefore lacks managed shell tools. OpenClaw cannot safely transfer ownership of a child that remains inside the native CLI simply by ending the turn.Baseline proof: with the production patch removed, the new real resolver regression
exposes managed shell without bypassing tool denies (denied=false)fails because the projected catalog has noexec. The denied case still passes. With the patch restored, both pre-grant and final-grant catalogs exposeexec/processonly when policy permits them; nativereadremains excluded.The deployed overlay touching mediated execution does not supply the default ownership transfer or disable native Bash. This PR includes the admitted operational run when materializing the managed shell tool; that is required for its existing execution owner.
Evidence
Verification
Current-main necessity checked at
37ae73947bf07fc562ba935c4581283b4b80ecb2: the bundled Claude backend still deniesBash(run_in_background:true)while ordinary MCP grants exclude native coding tools. Default local calls therefore still lack the managed process handoff; this PR is not superseded.Revision
bae0d2d6677addresses the two verified review findings. On the prior PR head, both global and agenttools.exec.host="node"select managed shell ownership even though the canonical exec resolver selects the node. The fix consults that same resolver before takeover, retaining global/agent/session/run precedence. A missingOpenClawConfigtype import is also repaired. The existing node-only search fixture now explicitly selects node execution; its routing, native-authority, and search assertions remain intact.Focused validation: 189 tests pass, four shards, 124.79 seconds. Preparation suite: 123 tests / 75.97 s; Gateway suite: 16 / 10.18 s; search and native-permission suites: 8 / 12.34 s combined; Anthropic arguments: 42 / 2.98 s. Added cases reuse the preparation fixture and took 0.55–1.93 s each. Core, Gateway-test, and agent-test typechecks plus changed-file lint pass. Final isolated
pnpm buildpassed in 6m 19.4s. Hosted exact-head CI/review are pending.pnpm test extensions/anthropic/cli-shared.test.ts src/agents/cli-runner/execute-plugin-native-bash.test.ts src/agents/cli-runner/prepare.test.ts src/gateway/tool-resolution.test.ts --maxWorkers=1passed in 94.42 seconds. Existing file-suite wall times: gateway 13.52s, preparation 44.55s, native permission 5.02s, adapter 2.50s. Added cases: approximately 250ms and 220ms for preparation, approximately 140ms per catalog case, and a few milliseconds for adapter/permission checks. No new sleep, polling loop, or process boot is added to per-PR tests. CI seconds unavailable before publication.pnpm buildpassed (exit 0); changed core and extension lint passed; final export, formatting, line-cap, and diff checks passed. Full build preceded the final prompt wording and Boolean cleanup; three focused regressions were rerun after the final edits (40.39s including compiler setup), and lint passed for both core and extension sources. The build also printed a Control UI gzip advisory (largest JS 216.0 KiB versus 215.0 KiB); UI sources are untouched and this advisory was not investigated.Real behavior proof
Isolated Linux / Node 24.19.0, fresh synthetic state, real admission and registered Gateway tool factories, no provider request or live service changes. A 14-second Node shell command is started through the ordinary managed catalog with no explicit
yieldMsor background flag. After it returnsrunning, close the first admission and start a six-second foreground command in a second admission for the same synthetic conversation. The first completion queues while the second command runs. Poll through the second turn and acknowledge delivery; only then is the completion event removed.Copied output:
{"stage":"foreground-released","seconds":15.9917188,"status":"running"} {"stage":"completion-queued-during-other-turn","seconds":22.049880532,"queueCount":1,"contextKeyMatchesJob":true} {"stage":"original-result-collected-on-next-turn","status":"completed","originalCommandReplayed":false}The first call includes cold lazy initialization. Warm timing, same 14-second command, one warmup and three sequential samples: 10.0288s, 10.0208s, 10.0227s until the foreground call returns. Completion is collected and acknowledged after each sample. This measures the managed tool boundary, not end-to-end Telegram latency. Source-loaded proof-process peak RSS was approximately 1.6 GiB; it is not a production memory comparison.
Repeatable isolated job and queue proof
From the checkout on Node 24.19.0, save the following as
/tmp/managed-shell-proof.mjs, then runnode --import ./scripts/tsx.mjs /tmp/managed-shell-proof.mjs:For timing samples, warm the tool once with an immediate command, then repeat the same 14-second command three times; measure each
exec.executecall withperformance.now(), awaitwaitForExecScope, poll the handle, and acknowledge its result before the next sample.What was not tested
No live Telegram Test Server roundtrip, authenticated Claude CLI turn, deployment, or service restart. The isolated registered-tool proof establishes the handoff and completion ownership; it does not prove the model will always follow the instruction to end its turn. Exact native-CLI versus managed-CLI before/after chat latency was not benchmarked: the baseline catalog has no managed shell entry, and an authenticated native CLI/provider replay was not exercised. Remote SSH waits remain unchanged. Full repository tests and hosted CI were not run or manually dispatched.
The initial fixture incorrectly returned an unrestricted catalog for an explicit tool cap; its mock was corrected to obey the supplied allowlist. Preparation initially retained a removed grant variable, corrected before passing the full suite. A later extraction temporarily widened the owner-context type; the exact required context type was restored. Running the test compiler concurrently with build changed generated plugin artifacts and triggered its topology guard; final execution is serialized. These failed attempts are not counted as passing proof.