Repository navigation
fix(exec): reject the unsupported cwd parameter instead of running in the default directory - #154248
Conversation
… the default directory
|
🦞👀 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, 12:11 AM ET / 04:11 UTC (Revision 4). ClawSweeper reviewWhat this changesThe exec tool rejects the unsupported cwd argument with guidance to use workdir, with a regression test for that error. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and the latest release still silently ignore cwd. The focused repair has convincing exact-head runtime proof, and no introduced correctness or security defect was found. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s exec tool turns agent requests into shell commands on the selected execution host. Request preparation validates arguments before directory resolution, approvals, and process launch. flowchart TD
A[Agent exec request] --> B[Argument validation]
B --> C{Unsupported cwd supplied}
C -->|Yes| D[Error naming workdir]
C -->|No| E[Resolve directory and approvals]
E --> F[Launch command]
F --> G[Return command result]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +9, Tests +13. Total +22 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep one documented directory selector, workdir, and reject cwd before a command can run in an unintended directory. Do we have a high-confidence way to reproduce the issue? Yes: current main ignores a caller-supplied cwd while resolving the directory from workdir or the tool default, and the recorded baseline runtime demonstrates that outcome. This read-only review did not execute a reproduction. Is this the best way to solve the issue? Yes: extending the existing unsupported-argument guard is a narrow repair that preserves declared parameters and gives the model a proven recovery path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2e705107ff26. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Re-verified against
|
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Landed as cc618e0. Thanks @wangmiao0668000666! |
|
Thanks @obviyus for the review and the merge! Really appreciate you taking the time to verify this one before landing it. |
… the default directory (openclaw#154248) Fixes openclaw#154309. The exec tool now rejects an unsupported `cwd` argument with a hint to use `workdir`, instead of silently running in the workspace default. Proof: real isolated Gateway with real OpenAI. On main an exec call with `cwd=/tmp` printed the workspace path with no error; with this change the call returns the `workdir` hint, the model retries with `workdir`, and the command prints `/tmp`. Explicit `workdir` and plain exec are unchanged. Regression test fails on main and passes here. Co-authored-by: Ayaan Zaidi <[email protected]>
Current-main integration and real OpenAI verification
Candidate:
ac8d3b81a2512c483069f0c1d892bf30b8676b9e. Baseline:64fbbe87c10ae494469cefe3fc493401f45dc411.Merged main only to resolve GitHub-reported conflicts. Retained main's
requiredvalidation and its test cleanup, plus the contributor'scwdrejection and regression. No overlap with Pash/Sarah changes. Thanks to @wangmiao0668000666 for the report and fix.Fresh proof used the built Gateway and
openclaw agent, the native OpenClaw agent runtime, real OpenAIgpt-4.1-mini, and realpwdprocesses in isolated Docker profiles. Cron, heartbeat, memory flushing/search, utility-model work and channel integrations were disabled. A transparent loopback proxy captured requests/results and enforced four real provider calls total; it did not rewrite model requests or synthesize tool calls.The same prompt explicitly requested three calls in its first batch:
{command:"pwd",cwd:"/tmp"},{command:"pwd",workdir:"/tmp"}, and{command:"pwd"}. It instructed a retry usingworkdirif the first call errored.cwd: "/tmp"/state/base/workspace, no tool errorexec parameter "cwd" is unsupported; use "workdir" insteadworkdir: "/tmp"control/tmp/tmp/state/base/workspace/state/cand/workspaceworkdir: "/tmp"; result/tmpCandidate completed its final answer in three real provider calls, accurately describing the error and recovery (four tool calls, one expected tool failure). Baseline used one real provider call and completed all three tools without error. Its next model request was deliberately stopped by the proxy's call budget after capturing those results; the resulting terminal budget error is a fixture stop, not an exec failure.
Focused regression:
node scripts/run-vitest.mjs src/agents/bash-tools.exec.path.test.ts --maxWorkers=1passed all 11 cases on candidate (22.18s total wall, 8.34s Vitest; new case 10ms). With the baseline production guard and unchanged regression, exactly the new case failed: the promise resolved, command output wasok, exit code 0, cwd/work; the other 10 passed (19.18s total wall). An initial test setup raced build output generation; serializing after the build resolved that fixture issue before any tests ran.Both builds produced runnable Gateway artifacts. Both also reported the same unrelated Control UI startup-JS size violation (candidate 372758 B, baseline 372768 B, limit 372347 B); neither touched file participates in the browser bundle.
git diff --checkpassed. No project-wide test/lint run was performed. Task containers, build/install volume and temporary credential were removed after proof.The earlier contributor evidence below applies to its recorded original SHA, not the integrated candidate above.
Closes #154309
What Problem This Solves
A caller that tells the
exectool where to run —{"command":"python3 scripts/studio_space_page_edit.py …","cwd":"/…/skills/studio-space-manager"}— was silently answered from the tool's default directory. The schema declaresworkdir, notcwd; undeclared keys are accepted and then dropped, so the command ran in the session default and its failure surfaced as a path the caller never named:cwdis a trap rather than a typo: it is the name of the tool's own default-working-directory option (createExecTool({ cwd })), just never a model-facing parameter — so a caller reading the tool surface reaches for it.git log -S 'cwd:'over the exec schema is empty; it was never declared.Precedent: #119874 (
fix(exec): make timeout unit explicit) established this exact guard for the other silently-dropped exec name.Why This Change Was Made
assertSupportedExecParamsalready owns "this exec parameter name is unsupported" and rejects the retiredtimeoutwith'exec parameter "timeout" is unsupported; use "timeoutSeconds" instead'(src/agents/bash-tools.exec-request-preparation.ts:69, added in #119874). This extends that same guard tocwd, naming the declared parameter:The guard runs at both real entries —
execute(src/agents/bash-tools.exec-run.ts:196) andprepareBeforeToolCallParams(src/agents/bash-tools.exec-request-preparation.ts:299) — so the call fails before any process is spawned. No new validator, option, configuration, dependency, or validation layer. The only input whose outcome changes is the one whose working-directory selector was already being dropped; unrelated model-added keys stay tolerated.Production LOC is
+10/-1in one file.Classification:
behavior-preserving(a command that ran in the wrong directory becomes an explicit input error; every declared parameter behaves exactly as before)User Impact
A caller that omits
cwdsees no change: the command still runs in the tool default and the declaredworkdirstill selects the directory — the control below pins that on both base and head, and the 43 pre-existing cases inbash-tools.exec.path.test.tspass on both. A caller that passescwdnow gets an actionable error namingworkdiron the first attempt, instead of a command that ran somewhere it did not choose (creating or overwriting files there) and reported a path it never named.Evidence
Exact-head proof receipt
938c5873af3e00a2b80dfa35823c963cf0237c9fc729f693d3fe657782928fe055f9c86853a1d2becreateExecTool({host:"gateway", security:"full", ask:"off", cwd:<tool default>}), driven through its realexecute()on two real working directoriescreateOpenAIResponsesTransportStreamFn()) posts over a real loopback HTTP socket, then the realrunAgentLoopresolves theexectool, assembles and validates its arguments, and calls the realexecute(). Only the provider response tokens are scripted; the wire path, argument assembly, validation, and the tool entry are production code. This also rules out the failure mode where some argument-normalization layer strips the undeclared key before the guard sees it.assertSupportedExecParamsinsrc/agents/bash-tools.exec-request-preparation.ts:69(new branch at:82), reached fromexecuteatsrc/agents/bash-tools.exec-run.ts:196cwdkey on anyexeccallexecute()rejects; the tool-result text andisError; and the observable side effect of the command itself (pwd,cat marker.txt, and whetherecho RAN > ran.txtcreated a file)Tests 2 failed | 1 passed (3), exit 1. The command ran in the tool default (/…/default-cwd), createdran.txtthere, and reportedcat: marker.txt: No such file or directory; the real hop delivered that same text withisError:falseTests 3 passed (3), exit 0. Bothcwdentries throwexec parameter "cwd" is unsupported; use "workdir" instead, noran.txtis created, and the real hop delivers the message withisError:trueTests 1 failed | 43 passed (44), the single failure being the new caseTests 44 passed (44)workdirstill selects the intended directory on both base and head (pwd= the intended directory, marker read back), so the guard is not a general unknown-key rejectionc1c4e3612cde3a6ab59b0aa450305900,95e4ac762b67c3f57e3555e39fef3905); the temporary harness was deleted; no Gateway, session, token, or config was touchedInspectable RED -> GREEN terminal trace
Node
v24.18.0, in the repo's test container. The verified bytes are the committed blobs(
b6264b8ad0f30bf5309433ce6e29203c,485a2a77f54bb98cd177d64e6cb5b93c); the temporary harness(
c1ee41aa80026ee059e08dd9ba311dd4) was byte-identical for the RED and GREEN runs.BEFORE / AFTER
c729f693d)938c5873a)exec {command, cwd}exec parameter "cwd" is unsupported; use "workdir" insteadran.txtcreated in the wrong directoryisError:falseisError:trueexec {command, workdir}exec {command}Impact surface
src/agents/bash-tools.exec-request-preparation.ts:69assertSupportedExecParams)cwdkey beforeisRecord-shaped args continue; declared parameters take the same path as beforesrc/agents/bash-tools.exec-run.ts:196executeentrysrc/agents/bash-tools.exec-request-preparation.ts:299prepareBeforeToolCallParamsVerification
node scripts/run-vitest.mjs run src/agents/bash-tools.exec.path.test.ts— RED1 failed | 43 passed (44), GREEN44 passed (44)on the remote hostisError:false) → GREEN (exec parameter "cwd" is unsupported; use "workdir" insteadwithisError:true), same harness bytes both runsbash-tools.exec-timeout-seconds.test.ts13 passed (the precedent's own file);bash-tools.exec.script-preflight.test.ts69 passed | 4 skippednode scripts/run-tsgo.mjs -p tsconfig.core.json— 14 diagnostics, none in either changed file; cause and owning fix are identified in Typecheck reconciliation belowgit diff --check origin/main...HEAD— cleanprepareBeforeToolCallParamscall site runs the same guard function but was not separately driven end-to-end. The occurrence count comes from one operator's local transcript store (not shareable) covering an older installed build: 1 of 7,459 recordedexeccalls carriedcwd, and none of them also sentworkdir. That is a small footprint, so treat this as a contract fix validated by the reproduction rather than a high-frequency field bug. All samples came from a single model id (Qwen3-235B-A22B). The schema and both call sites were re-checked against currentmain. The shape is re-checkable structurally: for each assistanttoolCallwithname="exec", testarguments.hasOwnProperty("cwd").Focused-suite and CI timing (measured 2026-09-21)
938c5873a:node scripts/run-vitest.mjs run src/agents/bash-tools.exec.path.test.ts→ 44 passed (44), exit 0, Node v24.18.0 in the repo test container. Vitest reportedDuration 48.23s(transform 80%, tests 13%, import 4%, worker 2%); the shard reported54.56s; measured wall clock 55.53s (55,530 ms).938c5873a: 241 check runs — 187 success, 53 skipped, 1 neutral, 0 failures; pipeline2026-09-21T01:25:32Z → 2026-09-21T02:33:15Z(67.7 min). Authoritative production typecheckcheck-prod-types(job 106185326707) success in 187s; alsocheck-test-types340s,check-test-types-core-1541s,check-test-types-core-2508s,preflight42s,openclaw/ci-gatesuccess.Typecheck reconciliation: the 14
tsconfig.core.jsondiagnosticsnode scripts/run-tsgo.mjs -p tsconfig.core.jsonreports 14 diagnostics (162.9s) on the shared proof host. Neither changed file appears in them. All 14 come from three files that do not exist at the reviewed head938c5873aor onmain(21273684d49when re-checked) and had been synced to that host from other, still-unmerged branches:938c5873aandmain)src/agents/subagents/registry/subagent-registry-restart-recovery-accepted.ts18f1c117e6a(#153243)src/gateway/chat-display-projection.message-tool.tsc7bf1ab2303(#150694)src/gateway/control-ui-github-preview.tsa46de01a4a5(#148464)Every one is the same half-synced pair: the newer file imports exports the host's older siblings lack (
resolveInternalSessionEffectsTarget,confirmAcceptedRecoveryResumption,settleAcceptedRecoverySession,shouldConfirmAcceptedRecoveryResumption,ControlUiGitHubPreview) or reads members the host's older types do not declare (clearAcceptedRecovery,clearPendingNotice,getRun,replaceRun,resumeAcceptedRecovery,resumptionNotice,target,status: "accepted"). That is a partially-synced proof-host checkout — the same class as that host also missingextensions/workboard/src/sqlite-store.ts— not a repository baseline and not attributable to this PR.Owning fix: the shared proof host's tree, not this change. Replace that host with a complete checkout at the reviewed revision before typechecking there; the authoritative typecheck for this head is CI's
check-prod-types, which checks out938c5873aand installs from its lockfile (success in 187s, above).Scope and risk
+10/-1in one file (src/agents/bash-tools.exec-request-preparation.ts)+13/-0in one file (src/agents/bash-tools.exec.path.test.ts)assertSupportedExecParamsguard from fix(exec): make timeout unit explicit #119874 rather than adding a check; reuses the repo'sisRecordandToolInputErrorowners; adds no new abstractionMaintainer edits
The alternative shape is to alias
cwdtoworkdirand honor it. I chose rejection because #119874 already made that call for the sibling name on this same tool (timeoutis rejected rather than aliased totimeoutSeconds), and because a second spelling for "where to run" is how the silent wrong-directory execution arose. If you prefer the alias, the change is this branch rewritten to assignargs.workdir ??= args.cwdbefore workdir resolution — but the guard would then have to state which names it accepts for every other parameter too.Scope note
This PR is not linked to an issue: the defect was found by diffing recorded model tool calls against the tool schemas the runtime actually compiled into the prompt, not from a report. I checked before writing it: no open issue describes
execdroppingcwd, and no open PR touchesbash-tools.exec-request-preparation.ts,bash-tools.schemas.ts, orbash-tools.exec-run.ts. Say the word and I will file an issue carrying this evidence if you want the bug tracked separately.