#20336: fix(sessions): resolve transcriptPath using agentId when storePath is non-absolute
agents
size: XS
## Problem
When multiple agents are configured, `sessions.list` returns `"(multiple)"` as the `path` field (or a template string like `{agentId}/sessions.json`). The `sessions-list tool` then used `path.dirname(storePath)` to compute `sessionsDir`, which resolves to the process CWD (typically `~/.openclaw/workspace`) instead of the actual agent sessions directory (`~/.openclaw/agents/<id>/sessions`).
This caused `transcriptPath` in every session's metadata to point to a file that does not exist, causing:
- Dashboard lag/unresponsiveness due to repeated ENOENT errors when reading non-existent transcript files
- Incorrect session metadata visible via `sessions_list` tool
## Root Cause
```ts
// sessions-list-tool.ts (before)
sessionsDir: path.dirname(storePath), // path.dirname("(multiple)") === "." → resolves to CWD
```
## Fix
Use `resolveSessionFilePathOptions()` instead of manually computing `path.dirname(storePath)`. The helper already handles the multi-agent case: when `storePath` is not a valid absolute file-system path, it falls back to `agentId`-based directory resolution, which correctly maps to `~/.openclaw/agents/<id>/sessions/`.
```ts
// sessions-list-tool.ts (after)
const effectiveStorePath = storePath && path.isAbsolute(storePath) ? storePath : undefined;
const opts = resolveSessionFilePathOptions({ agentId, storePath: effectiveStorePath });
transcriptPath = resolveSessionFilePath(sessionId, sessionFile ? { sessionFile } : undefined, opts);
```
## Affected configurations
- Multi-agent setups (most common case)
- Any config where `session.store` uses a template (e.g. `~/.openclaw/agents/{agentId}/sessions/sessions.json`)
- Single-agent configs are unaffected (storePath is a real absolute path in that case)
Fixes #20320
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes `transcriptPath` resolution in the `sessions_list` tool for multi-agent configurations. Previously, when multiple agents were configured, the gateway returned `"(multiple)"` as the store path, and `path.dirname("(multiple)")` resolved to `"."` (current working directory), producing incorrect transcript file paths. This caused ENOENT errors and dashboard lag.
The fix:
- Removes the `storePath` truthiness requirement from the `if (sessionId)` guard, so transcript paths are resolved even when `storePath` is absent or invalid
- Uses the existing `resolveSessionFilePathOptions()` helper instead of manual `path.dirname()`, which properly falls back to `agentId`-based directory resolution when `storePath` is not an absolute path
- Adds a `path.isAbsolute()` check to only pass real filesystem paths to the resolver
The change is well-scoped and uses existing infrastructure (`resolveSessionFilePathOptions`) rather than introducing new logic. Single-agent configs are unaffected since their `storePath` is always a valid absolute path.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it correctly fixes a real bug using existing helper infrastructure with no behavioral change for single-agent setups.
- Score of 4 reflects a well-targeted bug fix that uses existing, tested helper functions (`resolveSessionFilePathOptions`) rather than introducing new logic. The change is small, the root cause is clearly identified, and single-agent configurations are unaffected. Deducted one point because there are no new unit tests covering the multi-agent `transcriptPath` resolution path.
- No files require special attention. The single changed file (`src/agents/tools/sessions-list-tool.ts`) is straightforward.
<sub>Last reviewed commit: a4673d0</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#15792: fix: pass agentId to resolveSessionFilePath in additional call sites
by MisterGuy420 · 2026-02-13
87.7%
#15888: fix: store relative session file paths instead of absolute
by devAnon89 · 2026-02-14
85.8%
#16171: fix: trust absolute sessionFile paths in multi-agent setups [AI-ass...
by iJaack · 2026-02-14
84.4%
#20188: fix: Update sessionFile path when rolling to new session in cron jobs
by jriff · 2026-02-18
84.1%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
83.9%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
83.8%
#15793: fix(sessions): gracefully handle stale cross-agent session file paths
by lxcong · 2026-02-13
83.7%
#15982: fix: pass agentId to resolveSessionFilePath in reply flow (NX-003)
by automagik-genie · 2026-02-14
83.6%
#15744: fix: allow cross-agent session path validation
by scottgl9 · 2026-02-13
83.5%
#3410: fix(sessions): always compute session paths from current environment
by sakunsylvi · 2026-01-28
83.5%