#9154: fix(doctor): resolve symlinks before comparing state directories
commands
stale
Cluster:
Session File Path Management
## Summary
Fixes false positive "Multiple state directories detected" warning on Fedora Silverblue and other systems where `/home` is a symlink to `/var/home`.
## The Problem
On Fedora Silverblue (and other immutable Fedora variants), `/home` is a symlink to `/var/home`. When `findOtherStateDirs()` searches `/home` for `.openclaw` directories, it finds paths like `/home/user/.openclaw`, but the active state dir is `/var/home/user/.openclaw`. The string comparison fails because `path.resolve()` only normalizes paths without resolving symlinks.
## The Fix
- Add `safeRealpath()` helper that uses `fs.realpathSync()` to resolve symlinks
- Falls back to `path.resolve()` if the path doesn't exist (graceful degradation)
- Use `safeRealpath()` in `findOtherStateDirs()` and when comparing default vs configured state dir
## Testing
- Added test file `doctor-state-integrity.symlink-resolution.test.ts` with 3 tests
- Tests verify symlink resolution behavior for the Silverblue scenario
- All tests pass locally
Fixes #9136
🤖 Generated by Claw overnight build
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the doctor “state integrity” checks to resolve symlinks via a new `safeRealpath()` helper before comparing the active state directory against candidates (notably fixing Fedora Silverblue’s `/home -> /var/home` case) in `src/commands/doctor-state-integrity.ts`.
It also adds a new Vitest file intended to cover the symlink-resolution scenario. However, the added tests currently only validate Node’s `fs.realpathSync`/`path.resolve` behavior and do not exercise the OpenClaw doctor logic (`findOtherStateDirs()` / `noteStateIntegrity()`), so they won’t actually prevent regressions of the reported warning in future changes.
<h3>Confidence Score: 3/5</h3>
- This PR is likely safe to merge, but the new tests do not currently enforce the intended behavior change.
- The production change is small and targeted (realpath before comparisons), but the accompanying test suite doesn’t exercise the affected doctor code paths, so regressions are not well-guarded.
- src/commands/doctor-state-integrity.symlink-resolution.test.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#18593: fix: resolve symlinks in session path validation (#18553)
by EpaL · 2026-02-16
82.0%
#7007: Fix security audit false-positive for symlinked state dir
by MohammadErfan-Jabbari · 2026-02-02
79.3%
#11602: fix(config): skip stale legacy config files when openclaw.json exists
by akoscz · 2026-02-08
78.3%
#16957: fix(doctor): skip false positive permission warnings for Nix store ...
by soumikbhatta · 2026-02-15
77.8%
#23432: Doctor: prevent permissive secret file modes during --fix
by bmendonca3 · 2026-02-22
77.7%
#22910: fix(browser): resolve symlinks in upload path validation
by erdinccurebal · 2026-02-21
77.1%
#11408: Security: resolve symlink target permissions in safeStat; skip doct...
by lailoo · 2026-02-07
76.8%
#15345: fix(daemon): doctor --fix pollutes service PATH with dirs that don'...
by yinghaosang · 2026-02-13
75.9%
#17026: fix(doctor): handle invalid session file paths gracefully
by Limitless2023 · 2026-02-15
75.9%
#18939: fix: tighten permissions on cron/, browser/, settings/, logs/ in do...
by sriram369 · 2026-02-17
74.6%