#21521: fix: re-resolve skill paths at runtime for cross-machine portability
agents
size: S
Cluster:
Skill and Session Management Fixes
## Summary
- When a session is created on machine A and later loaded on machine B, the cached `skillsSnapshot.prompt` contains absolute paths from machine A (e.g. `/Users/alice/...`) that are meaningless on machine B
- Modified `resolveSkillsPromptForRun()` to re-generate the prompt from `resolvedSkills` at runtime using `compactSkillPaths()` against the current machine's home directory, instead of blindly returning the cached prompt
- Legacy snapshots without `resolvedSkills` still fall back to the cached prompt for backward compatibility
Fixes #21508
## Test plan
- [x] Existing e2e tests updated and passing (3 tests)
- [x] New test verifies that a snapshot with a foreign home path produces correct `~/` paths on the current machine
- [x] All `src/agents/skills/` unit tests passing (7 tests)
- [ ] Manual: create a session on machine A, move state to machine B, verify skill paths resolve correctly
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a cross-machine portability issue where skill paths cached in session snapshots from one machine (e.g., `/Users/alice/...`) were not updated when the session was loaded on a different machine (e.g., `/home/node/...`). The fix modifies `resolveSkillsPromptForRun()` to re-generate the prompt at runtime using `compactSkillPaths()` against the current machine's home directory when `resolvedSkills` is available, while maintaining backward compatibility by falling back to the cached prompt for legacy snapshots.
Key changes:
- Re-generates skill prompts at runtime from `resolvedSkills` instead of blindly returning cached prompt
- Uses `compactSkillPaths()` to convert absolute paths to `~/` relative paths based on current machine's home directory
- Preserves backward compatibility for legacy snapshots without `resolvedSkills`
- Adds comprehensive test coverage for the portability fix
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low risk
- The implementation is clean, well-tested, and maintains backward compatibility. The logic correctly re-generates prompts at runtime using the existing `compactSkillPaths()` helper, which has its own test coverage. The new test validates the portability fix scenario. The change is narrowly scoped to fix a specific portability issue without affecting other functionality. One point deducted only because tests couldn't be executed in this environment to verify they pass.
- No files require special attention
<sub>Last reviewed commit: e6126c7</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22525: [Bug]: Session snapshot not reloading skills after gateway restart ...
by zwffff · 2026-02-21
81.3%
#19707: fix(agents): apply per-agent skills filter to all run paths
by mcaxtr · 2026-02-18
79.4%
#22568: fix(gateway): bump skills snapshot version on startup so sessions r...
by zwffff · 2026-02-21
78.9%
#20533: fix: strip resolvedSkills from session store to prevent snapshot bloat
by echoVic · 2026-02-19
78.3%
#16654: fix: refresh skills snapshot when managed skills change
by PhineasFleabottom · 2026-02-15
78.3%
#8873: fix: document skill loading locations in system prompt
by ytfh44 · 2026-02-04
76.7%
#9221: fix(skills): use skillKey for env config lookup in snapshots
by gavinbmoore · 2026-02-05
76.7%
#22198: fix(skills): treat empty allowBundled array as block-all
by haitao-sjsu · 2026-02-20
76.3%
#23749: fix some issues
by tronpis · 2026-02-22
76.2%
#11250: fix: expand skills watcher ignore list and improve session repair l...
by zhangzhefang-github · 2026-02-07
76.0%