← Back to PRs

#5638: fix: rewrite sessionFile paths during state dir migration

by lailoo open 2026-01-31 19:24 View on GitHub →
commands
## Summary Fixes #5631 When migrating from legacy state directories (`.clawdbot`, `.moltbot`, `.moldbot`) to `.openclaw`, the `sessionFile` paths inside `sessions.json` were not being updated. This caused the old directory to be recreated when sessions were written. ## Root Cause `sessions.json` contained hardcoded paths like: ```json { "sessionFile": "/Users/username/.clawdbot/agents/main/sessions/xxx.jsonl" } ``` The migration moved the file itself but didn't rewrite the paths inside. ## Changes - Add `rewriteSessionFilePath()` to update legacy paths in session entries - Detect `.clawdbot`/`.moltbot`/`.moldbot` patterns and rewrite to target dir - Add regression test to verify path rewriting ## Testing - Added regression test that verifies `sessionFile` paths are rewritten - All 16 state migration tests pass <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes legacy state-dir migrations so that `sessionFile` paths embedded in `sessions.json` are rewritten from `.clawdbot`/`.moltbot`/`.moldbot` to the new OpenClaw state directory during `migrateLegacySessions`. Implementation adds a small helper that detects legacy state-dir substrings (cross-platform path separators) and rewrites the stored path to point at the migrated sessions directory, preventing the old legacy directory from being recreated later when sessions are persisted. A regression test exercises the migration by seeding a legacy `sessions.json` containing a hardcoded legacy path and verifying the stored entry no longer references the legacy dir. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with low risk; changes are localized and covered by a targeted regression test. - The migration behavior change is narrow (rewrite of `sessionFile` only when a legacy dir pattern is present) and is applied during the existing normalization pass. The added test reduces regression risk, though it could be strengthened to assert the exact rewritten target path. - src/commands/doctor-state-migrations.test.ts (tighten assertion to match intended target path). <!-- greptile_other_comments_section --> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs