← Back to PRs

#17757: fix(agents): resolve relative workspace paths against state dir, not CWD

by Phineas1500 open 2026-02-16 05:00 View on GitHub →
agents stale size: S
## Summary - Fixes #17698 — `agents.list[].workspace` was ignored for sub-agent session CWD - `resolveAgentWorkspaceDir` used `resolveUserPath` which calls `path.resolve()` against `process.cwd()`. After a parent agent calls `process.chdir()`, relative workspace paths resolved against the wrong directory - Adds a `resolveWorkspacePath` helper that resolves relative paths against the stable state dir (`~/.openclaw/`) instead, making workspace resolution deterministic regardless of concurrent `process.chdir` calls - Absolute and `~`-prefixed paths continue to use `resolveUserPath` unchanged ## Test plan - [x] New tests: relative workspace resolves against state dir, not CWD - [x] New tests: absolute workspace paths unaffected by CWD changes - [x] New tests: tilde workspace paths expand correctly - [x] New tests: defaults workspace resolves relative paths against state dir - [x] All existing agent-scope, workspace-run, workspace e2e tests pass (31 tests) - [x] All sessions-spawn e2e tests pass (18 tests) - [x] All agent unit tests pass (253 tests) - [x] Build passes - [x] Lint + format clean <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixed agent workspace path resolution to be deterministic by resolving relative paths against the stable state directory (`~/.openclaw/`) instead of `process.cwd()`. This prevents race conditions when parent agents call `process.chdir()` before spawning sub-agents. The new `resolveWorkspacePath` helper maintains backward compatibility for absolute and tilde-prefixed paths while ensuring relative workspace configurations are no longer affected by concurrent directory changes. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix is well-isolated to workspace path resolution logic, maintains backward compatibility for absolute and tilde paths, and includes comprehensive test coverage for all path types (relative, absolute, tilde) and both agent-specific and default workspace configurations. The implementation correctly addresses the race condition without introducing breaking changes. - No files require special attention <sub>Last reviewed commit: 153d4c8</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs