fix: expand leading tilde in exec workdir paths#94462
Conversation
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
|
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 detailsBest 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 Is this the best way to solve the issue? No. Expanding before Security review: Security review needs attention: The diff touches host command cwd resolution and can route
AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against f18ff7551edc. |
|
ClawSweeper applied the proposed close for this PR.
|
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. UseresolveUserPathto expand~before checking the directory.Root Cause
resolveWorkdirinbash-tools.shared.tscalledstatSync(workdir)on the raw path without expanding~(a shell feature not handled by Node.jsstatSync). The path check always failed for~/paths, falling through to the fallback directory.Fix
Call
resolveUserPath(workdir)beforestatSyncto expand the leading~consistently with other user-facing path inputs.Testing
src/agents/bash-tools.shared.test.ts— 11 tests passedReal behavior proof
Behavior or issue addressed: exec workdir
~/pathsilently 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:
Evidence after fix:
Observed result after fix:
resolveWorkdirnow expands~before checking path existence.What was not tested: Full E2E exec with
~/workdir path (no agent available).