Skip to content

fix(agents): preserve whitespace in node-host exec workdir paths - #172814

Merged
RomneyDa merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/node-host-cwd-trim-200
Oct 20, 2026
Merged

RomneyDa merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/node-host-cwd-trim-200

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Running a system.run command on a node host with a workdir whose name legitimately ends in whitespace (e.g. /srv/data ) silently executed the command in a different directory (/srv/data).

  • Problem: The node-host workdir flowed through normalizeXxxString calls that trim whitespace. The plan normalizer, approval binding/context resolvers, resolveExecutablePathCandidate, and collectAllowAlwaysPatterns all re-trimmed cwd, so a preserved-whitespace value was trimmed before reaching child_process.spawn's options.cwd, and the plan-match check broke.
  • Solution: Switch all cwd read sites on the node-execution path to readNonBlankString (preserves whitespace, rejects blank). Files: bash-tools.exec-workdir.ts, invoke-system-run-plan.ts, invoke-system-run.ts, system-run-approval-plan.ts, system-run-approval-binding.ts, system-run-approval-context.ts, system-run-normalize.ts, executable-path.ts, exec-approvals-allowlist.ts.

Why This Change Was Made

Fixing only the cwd read sites was cancelled out by downstream trimming. resolveExecutablePathCandidate trimmed cwd before pinning ./tool. collectAllowAlwaysPatterns trimmed cwd for grant hashing, scoping persisted authorization to the wrong directory — a security concern where approval for /srv/data could authorize /srv/data or vice versa.

User Impact

Commands on a node host whose working directory name contains leading or trailing whitespace now execute in the intended directory. Relative executables resolve correctly. Approval bindings and reusable grants distinguish whitespace-distinct paths, preventing cross-directory approval reuse. Non-whitespace paths are unaffected.

Evidence

Gateway-level proof (running Gateway kernel + real child_process.spawn)

Scenario Before (main) After (this PR)
1. Authorized spawn in data allowlist miss ❌ ok: true, stdout: from-space-dir ✅
2. Sibling grant rejected (grant data, launch data ) ok: true ❌ (cross-dir) allowlist miss ✅
3. Revocation after launch (grant → ok → revoke → denied) always miss ❌ ok: true → allowlist miss ✅
4. Plan-match rejects mismatched cwd ok: true ❌ approval requires matching plan ✅
5. Record→replay→launch plan cwd trimmed ❌ plan cwd preserved, spawn ok ✅

RED on main: all 5 fail. GREEN after fix: all 5 pass.

Cancelled approval replayed through node.invoke (terminal output)

A previously allowed, unconsumed approval is cancelled via forceDenyDetailed(cancelled), then replayed through the production node.invoke(system.run) guard (sanitizeSystemRunParamsForForwarding); consumeAllowOnce returns false, no process spawns.

--- Scenario 1: Cancelled approval, node.invoke guard rejects ---
[1] Creating approval (allow-once, unconsumed)...
  [create] record id=cancel-mvau0ndz cwd="/tmp/test-data " host=node
  [resolve] allow-once: ok=true (allowed, unconsumed)
[1] Cancelling via forceDenyDetailed(cancelled)...
[1] Cancel outcome=already-terminal
[1] Sending node.invoke(system.run) approved=true runId=cancel-mvau0ndz...
[1] Guard result: ok=false code=APPROVAL_REQUIRED message=approval required
VERDICT 1: PASS — cancelled approval rejected before spawn

--- Scenario 2 (control): Valid allow-once, node.invoke guard passes ---
[2] Creating approval (allow-once, unconsumed)...
  [create] record id=valid-mvau0ql0 cwd="/tmp/test-data " host=node
  [resolve] allow-once: ok=true (allowed, unconsumed)
[2] Sending node.invoke(system.run) approved=true runId=valid-mvau0ql0...
[2] Guard result: ok=true approved=true
VERDICT 2: PASS — valid approval forwarded, spawn authorized

Chain: ExecApprovalManager.create → register → resolve(allow-once)
  → forceDenyDetailed(cancelled) sets approvalAuthority=()=>false
  → node.invoke guard: sanitizeSystemRunParamsForForwarding
  → consumeAllowOnce → isExecApprovalRuntimeActive=false → APPROVAL_REQUIRED

Recorded-approval revocation + sibling-redirection (running Gateway)

A.1 First spawn (allowed, cwd="data "): spawn code=0 stdout="from-space-dir" → PASS
A.2 Second spawn (authority consumed): ok=false error=APPROVAL_REQUIRED → PASS
B.1 Sibling cwd (request 'data', approval 'data '): redirected to approved → PASS
C.1 Denied authority: ok=false error=APPROVAL_REQUIRED → PASS (denied before spawn)
Overall: ALL PASS ✅

Data-model compatibility (v2026.10.5 → candidate)

Swapped stable v2026.10.5 (1b58cb9) → candidate (this PR, 6f26987) on the same SQLite state; candidate runs its normal doctor --fix credential migration, then loads the same store.

Phase 1 — stable v2026.10.5 bootstraps state + config
  [stable] approval request: ok=true id=dm-stable-mvgb6io4 (cwd="/tmp/test-data ")

Phase 1.5 — candidate doctor --fix: "Moved client credentials and native socket material to the local store"
  [doctor] credentials.sqlite created: true   → credential migration: PASS

Phase 2 — candidate loads same state, sidecars start, Gateway ready
PASS (a) candidate loads stable SQLite (schema migration ok, 102 tables preserved, Gateway ready)
PASS (b) config preserved — openclaw.json intact
PASS (c) candidate creates approval on same store — ok=true id=dm-cand-mvgb6io4
PASS (d) candidate reads grants from same store — ok=true
PASS (e) non-ws cwd grant hash identical — SHA-256 match (backward compat)
Overall: ALL PASS — existing data loads and works after upgrade

Regression tests

exec-approvals-allow-always.test.ts: 44 passed
executable-path.test.ts: 34 passed | 2 skipped
invoke-system-run-plan.test.ts: 25 passed
system-run-approval-binding.test.ts: 33 passed

Follow-up validation (18f2d02ba690)

The shell-script argument-boundary lookup now preserves cwd too. The existing regression now exercises production grant creation and matching: relative/absolute replay succeeds, changed arguments are rejected, and the whitespace-distinct sibling cwd cannot reuse the grant.

  • Red/green: the strengthened regression failed on the previous PR head because changed arguments were accepted; it passes with the one-line repair.
  • pnpm test src/infra/exec-approvals-allow-always.test.ts --maxWorkers=1: 44 passed, 28.00 s wall time including compiler preparation; the regression itself took 5 ms.
  • Core typecheck, targeted lint, formatting, and git diff --check passed. Fresh AutoReview found no P0/P1 issues in the follow-up delta.
  • The test-type runner completed all 29 type graphs successfully but returned exit 1 from the existing test-root budget guard: gateway-root has 726 roots and plugins-platform has 727, above 720. This follow-up changes no test roots, imports, typegraph configuration, or budget tooling.
  • Updated-head CI is pending; CI seconds are not yet available.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR preserves working-directory whitespace through node execution, executable lookup, approval plans, and reusable grants.

Example: A node command targets /srv/data while /srv/data also exists.

  • Before: Whitespace trimming can select the sibling directory or produce inconsistent approval identity.
  • After: Execution retains /srv/data , and reusable grants distinguish the two directories.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A useful, focused repair with inspected production-path and upgrade evidence and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Updated running-Gateway output exercises real process launch in a whitespace-bearing cwd, sibling-grant rejection, recorded-plan replay, and consumed or cancelled authority rejection before spawn, satisfying the preceding review’s requested scenarios.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A node command targeting a whitespace-bearing directory can execute in its sibling or encounter inconsistent approval matching.
Reason: Literal filesystem identity and directory-scoped authorization are existing contracts, and the patch repairs their propagation without new configuration or capability.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it fixes a current working-directory identity bug, with no actionable correctness findings; the enforced security review remains pending.

Priority: P2
Reviewed head: 6f26987496393bd7230f7c4d039bf0e0f66a7811

Before merge

  • Complete next step - Complete the enforced security-sensitive review for head 6f26987.

Findings

None.

Agent review details

How this fits together

The exec tool forwards a working directory through Gateway approval recording and replay to the node host, which resolves executables, validates current authorization, and launches the process.

flowchart LR
  A[Exec tool] --> B[Gateway approval owner]
  B --> C[Stored execution plan]
  C --> D[Node host]
  D --> E[Executable and grant resolution]
  E --> F[Final authorization check]
  F --> G[Process spawn]
Loading

Technical review

Best possible solution:

Preserve literal cwd identity through the existing execution and approval owners while retaining current directory-binding and final authorization checks.

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

Current-main source visibly trims cwd before node planning and execution; the contributor also supplies before/after Gateway results, which were inspected without executing target code.

Is this the best way to solve the issue?

The patch uses the existing string reader and approval owners to preserve one directory identity across the affected boundaries without adding another policy or storage mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 01fe067c9d17.

Provenance checked

  • Node workdir selection changes intended behavior with a stated reason (6038480: Gateway and node folder browsing added the node-specific cwd fallback; the inspected history does not establish trimming as an intentional filesystem contract.)
  • Approval plan, binding, and context normalization changes intended behavior with a stated reason (2d31126: A shared-helper extraction retained generic trimming for metadata; this PR explains why filesystem cwd must preserve its bytes while other metadata remains normalized.)
  • Executable candidate and PATH resolution changes intended behavior with a stated reason (e36c563: Candidate-resolution deduplication retained trimming; later cwd-aware PATH resolution in 4f8f762 used the same convention.)
  • Reusable approval cwd identity keeps the original intent (1c37c8c: Reusable grants intentionally bind canonical cwd and exact arguments so approval cannot transfer to another directory.)
  • Node execution authorization keeps the original intent (9b1c36d: The prior repair introduced locked policy validation and grant mutation to prevent revoked authority from authorizing execution; those checks remain in place.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Avant: Raw commit 1c37c8c adds src/node-host/invoke-system-run-plan.ts:44 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1c37c8cdc71b; files: src/node-host/invoke-system-run-plan.ts)
  • Peter Steinberger: Raw commit 5046876 adds src/node-host/invoke-system-run-plan.ts:103 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 504687668a7f; files: src/node-host/invoke-system-run-plan.ts)
  • Renaud Cerrato: Raw commit 95b97e5 adds src/agents/bash-tools.exec-workdir.ts:336 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 95b97e5b0b5e; files: src/agents/bash-tools.exec-workdir.ts)

PR surface

Source +22, Tests +222. Total +244 across 16 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 9 40 18 +22
Tests 7 223 1 +222
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 263 19 +244

Review metrics

Metric Value Why it matters
Production versus tests Production +40/−18; tests +222/−1 Production growth mostly adds imports for the existing whitespace-preserving reader; tests cover independently trimming execution, lookup, plan, binding, and grant boundaries.

Labels

Label changes:

  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: A focused fix for legal but uncommon whitespace-bearing working directories that can otherwise select the wrong directory.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (25 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-16T07:13:37.770Z sha 821fa0d0f0c9908ba7791f3f0879dc0c20ad3f27 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T08:53:00.702Z sha 821fa0d0f0c9908ba7791f3f0879dc0c20ad3f27 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T09:10:41.796Z sha 821fa0d0f0c9908ba7791f3f0879dc0c20ad3f27 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T09:44:45.069Z sha 821fa0d0f0c9908ba7791f3f0879dc0c20ad3f27 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T10:46:28.369Z sha 821fa0d0f0c9908ba7791f3f0879dc0c20ad3f27 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-16T10:54:26.927Z sha 821fa0d0f0c9908ba7791f3f0879dc0c20ad3f27 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-16T12:00:48.182Z sha 821fa0d0f0c9908ba7791f3f0879dc0c20ad3f27 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-20T05:03:20.271Z sha 6f26987 :: needs real behavior proof before merge. :: none

Reviewed October 20, 2026, 3:01 AM ET / 07:01 UTC (Revision 26).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/node-host-cwd-trim-200 branch from 774a6c1 to 08c56d4 Compare October 15, 2026 05:52
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 15, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/node-host-cwd-trim-200 branch from 1bb2809 to 7afa927 Compare October 15, 2026 07:14
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

✅ Maintainer security changes approved

A maintainer approved this revision with an explicit security approval comment.

A later push requires a fresh approval comment for an external contributor's PR.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925
SunnyShu0925 force-pushed the fix/node-host-cwd-trim-200 branch 2 times, most recently from a892552 to 2fbaead Compare October 15, 2026 09:38
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925
SunnyShu0925 force-pushed the fix/node-host-cwd-trim-200 branch from 2fbaead to b0ed11f Compare October 15, 2026 10:00
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925
SunnyShu0925 force-pushed the fix/node-host-cwd-trim-200 branch from b0ed11f to 50f4f98 Compare October 15, 2026 10:06
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 16, 2026
Rebuild of PR openclaw#172814 onto latest main. Preserve whitespace in node-host
exec workdir cwd values by reading non-blank strings instead of trimming
via normalizeOptionalString. Covers exec-workdir resolution, system.run
approval planning, and invoke matching. Whitespace tests moved to a
sibling isolated test file to keep the grandfathered approval-plan test
under its line cap.
@SunnyShu0925
SunnyShu0925 force-pushed the fix/node-host-cwd-trim-200 branch from 22ca500 to 6f26987 Compare October 20, 2026 04:52
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RomneyDa

Copy link
Copy Markdown
Member

/allow-security-sensitive-change

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

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants