#15888: fix: store relative session file paths instead of absolute
stale
size: XS
Cluster:
Session Management Enhancements
## Problem
The auto-reply agent runner was storing absolute session file paths in `sessions.json`, which caused validation errors when those paths were later read and validated by `resolvePathWithinSessionsDir()`.
The validation logic in `src/config/sessions/paths.ts` expects session file paths to be relative to the sessions directory, but the agent runner was storing the full absolute path returned by `resolveSessionTranscriptPath()`.
This resulted in the error: `Session file path must be within sessions directory`
## Root Cause
In `src/auto-reply/reply/agent-runner.ts` (line 261), the code was:
```typescript
nextEntry.sessionFile = nextSessionFile;
```
Where `nextSessionFile` is the return value of `resolveSessionTranscriptPath()`, which returns an absolute path like:
`/home/user/.openclaw/agents/agentId/sessions/sessionId.jsonl`
## Solution
Store only the basename (relative path) instead of the absolute path:
```typescript
nextEntry.sessionFile = path.basename(nextSessionFile);
```
This ensures the stored path is just `sessionId.jsonl`, which passes the validation check in `resolvePathWithinSessionsDir()`.
## Testing
- Verified that Telegram bots using OpenClaw gateway now successfully create and access session files without validation errors
- Confirmed that existing absolute paths in `sessions.json` are normalized correctly by the existing logic in `resolvePathWithinSessionsDir()`
- All session file operations work correctly with relative paths
## Notes
The validation code in `paths.ts` already has logic to handle legacy absolute paths by converting them to relative paths:
```typescript
const normalized = path.isAbsolute(trimmed) ? path.relative(resolvedBase, trimmed) : trimmed;
```
However, this doesn't work when the absolute path points to a different sessions directory than expected. By storing relative paths from the start, we avoid this edge case entirely.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Fixes a bug where `resetSession()` in `agent-runner.ts` stored the full absolute path from `resolveSessionTranscriptPath()` into `sessionEntry.sessionFile`, which then failed validation in `resolvePathWithinSessionsDir()` when the absolute path pointed to a different sessions directory than expected.
- Stores `path.basename(nextSessionFile)` (e.g., `sessionId.jsonl`) instead of the full absolute path, which passes the containment check in `resolvePathWithinSessionsDir()`
- The in-memory `followupRun.run.sessionFile` correctly retains the full absolute path for runtime use
- A similar absolute-path-to-`sessionFile` pattern exists in `src/auto-reply/reply/session.ts:347` (session initialization) and `src/auto-reply/reply/session.ts:342` (fork), which may warrant the same treatment for full consistency
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it's a small, targeted fix that aligns persisted session file paths with the expected validation contract.
- Single-line change that correctly converts an absolute path to a basename before persisting. The fix is well-justified by the validation logic in `resolvePathWithinSessionsDir()`. The only concern is that the same pattern exists in other code paths (`session.ts`) and wasn't addressed, but that doesn't affect the correctness of this change. No tests were added, but the change is straightforward and low-risk.
- Consider also reviewing `src/auto-reply/reply/session.ts` lines 342 and 347 for the same absolute-path storage pattern.
<sub>Last reviewed commit: 03069fc</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
87.0%
#16171: fix: trust absolute sessionFile paths in multi-agent setups [AI-ass...
by iJaack · 2026-02-14
86.5%
#15684: fix(telegram): persist relative session transcript paths
by Jdo300 · 2026-02-13
86.2%
#17132: fix: filter out invalid session entries with empty sessionFile
by Limitless2023 · 2026-02-15
85.9%
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
85.8%
#15744: fix: allow cross-agent session path validation
by scottgl9 · 2026-02-13
85.2%
#18593: fix: resolve symlinks in session path validation (#18553)
by EpaL · 2026-02-16
85.0%
#15941: fix(sessions): allow session file paths from other agents' sessions...
by LiJianLi128 · 2026-02-14
84.9%
#15793: fix(sessions): gracefully handle stale cross-agent session file paths
by lxcong · 2026-02-13
84.5%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
84.3%