#15744: fix: allow cross-agent session path validation
stale
size: XS
Cluster:
Session Management Enhancements
Fixes validation error when Discord bound channels create sessions in their agent's directory but are validated against main agent's sessions directory.
## Problem
When a Discord message arrives on a channel bound to a non-main agent (e.g., `#general` → `general-agent`), the session file is created in `agents/general-agent/sessions/` but validated against `agents/main/sessions/`. The relative path starts with `'..'` and fails the security check, causing all bound Discord channels to fail with:
```
[discord] handler failed: Error: Session file path must be within sessions directory
```
**Debug output:**
```
sessionsDir=/home/user/.openclaw/agents/main/sessions
candidate=/home/user/.openclaw/agents/general-agent/sessions/abc.jsonl
relative=../../general-agent/sessions/abc.jsonl
```
## Solution
Widen the security boundary from `agents/<agentId>/sessions/` to `agents/**/sessions/` while still preventing path traversal outside the agents directory. When the first validation fails, check against the wider agents root boundary.
## Security
Still validates that session files are within the agents root directory (`~/.openclaw/agents/`), preventing path traversal attacks to system files.
## Testing
Tested with 11 bound Discord channels - all now working correctly without handler failures.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates session transcript path validation so that if a session file path isn’t within the current agent’s `sessionsDir`, it falls back to allowing any path under the broader `~/.openclaw/agents/` root (to support Discord channels bound to non-main agents).
The intent matches the reported failure mode (cross-agent sessions being validated against the main agent’s sessions directory), but the new fallback check currently widens the boundary beyond `agents/**/sessions/**` to *any* path under `agentsRoot`, which changes the security/behavioral contract of `resolveSessionFilePath` and will also invalidate existing expectations in `paths.test.ts`.
<h3>Confidence Score: 3/5</h3>
- This PR is close, but the fallback path validation currently widens file access more than intended.
- The change likely fixes the Discord cross-agent session issue, but the fallback allows any file under the agents root (not just sessions directories) and breaks an existing test expectation; this needs tightening/adjustment before merge.
- src/config/sessions/paths.ts
<sub>Last reviewed commit: c51ddfc</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
#15941: fix(sessions): allow session file paths from other agents' sessions...
by LiJianLi128 · 2026-02-14
88.0%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
87.3%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
86.4%
#15793: fix(sessions): gracefully handle stale cross-agent session file paths
by lxcong · 2026-02-13
86.2%
#16171: fix: trust absolute sessionFile paths in multi-agent setups [AI-ass...
by iJaack · 2026-02-14
85.8%
#15888: fix: store relative session file paths instead of absolute
by devAnon89 · 2026-02-14
85.2%
#16249: fix(sessions): allow cross-agent session paths in multi-agent bindings
by 0xbrak · 2026-02-14
84.8%
#16135: fix: handle session file paths from other agents in doctor command
by MisterGuy420 · 2026-02-14
84.0%
#18593: fix: resolve symlinks in session path validation (#18553)
by EpaL · 2026-02-16
83.7%
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
83.5%