Skip to content

fix: expand leading tilde in exec workdir paths#94462

Closed
sheyanmin wants to merge 2 commits into
openclaw:mainfrom
sheyanmin:fix/issue-94434-exec-workdir-tilde-fallback
Closed

fix: expand leading tilde in exec workdir paths#94462
sheyanmin wants to merge 2 commits into
openclaw:mainfrom
sheyanmin:fix/issue-94434-exec-workdir-tilde-fallback

Conversation

@sheyanmin

Copy link
Copy Markdown
Contributor

Summary

Fixes #94434 — exec workdir with leading ~ was treated literally, causing the path check to fail and the command to run from an unintended fallback directory. Use resolveUserPath to expand ~ before checking the directory.

Root Cause

resolveWorkdir in bash-tools.shared.ts called statSync(workdir) on the raw path without expanding ~ (a shell feature not handled by Node.js statSync). The path check always failed for ~/ paths, falling through to the fallback directory.

Fix

Call resolveUserPath(workdir) before statSync to expand the leading ~ consistently with other user-facing path inputs.

Testing

  • src/agents/bash-tools.shared.test.ts — 11 tests passed
  • Lint: clean (oxlint)

Real behavior proof

Behavior or issue addressed: exec workdir ~/path silently falls back to wrong directory.

Real environment tested: Windows 10 LTSC 2019, Node.js v24.14.0, OpenClaw worktree on main.

Exact steps or command run after this patch:

npx oxlint --config .oxlintrc.json src/agents/bash-tools.shared.ts
node scripts/run-vitest.mjs src/agents/bash-tools.shared.test.ts

Evidence after fix:

Lint: no issues found
bash-tools.shared.test.ts: 11 tests passed

Observed result after fix: resolveWorkdir now expands ~ before checking path existence.

What was not tested: Full E2E exec with ~/ workdir path (no agent available).

resolveWorkdir did not expand ~ in workdir paths, causing
statSync to fail and falling back to an unintended directory.
Use resolveUserPath to expand ~ before checking the path.

Closes openclaw#94434
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 18, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 19, 2026
@clawsweeper

clawsweeper Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close: this PR is superseded by a stronger open expansion candidate that uses OS-home semantics, adds regression coverage, and has sufficient real behavior proof; the canonical bug remains open until one fix lands.

Canonical path: Close this branch and continue with one canonical fix for #94434, preferably the OS-home expansion candidate at #94449 if maintainers choose expansion semantics.

So I’m closing this here and keeping the remaining discussion on #94434 and #94449.

Review details

Best possible solution:

Close this branch and continue with one canonical fix for #94434, preferably the OS-home expansion candidate at #94449 if maintainers choose expansion semantics.

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

Yes. Source inspection shows local exec with workdir: "~/..." reaches resolveWorkdir(), which currently stats the literal value and falls back before command execution.

Is this the best way to solve the issue?

No. Expanding before statSync() is the right layer, but this PR uses the OpenClaw-home helper; #94449 is the cleaner expansion candidate with OS-home coverage.

Security review:

Security review needs attention: The diff touches host command cwd resolution and can route ~/... exec workdirs into the OpenClaw home/state tree when OPENCLAW_HOME is set.

  • [medium] Host exec may run from OpenClaw home instead of shell home — src/agents/bash-tools.shared.ts:186
    Using resolveUserPath() for exec workdir expansion makes ~ honor OPENCLAW_HOME, which can place a host command in OpenClaw-managed state rather than the user's OS home path.
    Confidence: 0.78

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • Peter Steinberger: Commit e2f89099829c added src/agents/bash-tools.exec.ts and src/agents/bash-tools.shared.ts during the agent tools split. (role: introduced behavior and exec area contributor; confidence: high; commits: e2f89099829c; files: src/agents/bash-tools.exec.ts, src/agents/bash-tools.shared.ts)
  • vincentkoc: Commit 710e0eff9d98 in the superseding candidate implements OS-home tilde expansion and matching regression coverage for this resolver. (role: recent candidate-fix owner; confidence: medium; commits: 710e0eff9d98; files: src/agents/bash-tools.shared.ts, src/agents/bash-tools.shared.test.ts)
  • openperf: Commit 323bc9d8c764 changed remote-node workdir routing on the same exec workdir surface. (role: adjacent exec workdir contributor; confidence: medium; commits: 323bc9d8c764; files: src/agents/bash-tools.exec.ts)

Codex review notes: model internal, reasoning high; reviewed against f18ff7551edc.

@clawsweeper

clawsweeper Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: exec workdir with leading ~ falls back and still executes command

1 participant