#15792: fix: pass agentId to resolveSessionFilePath in additional call sites
app: web-ui
gateway
agents
stale
size: XS
## Summary
This PR fixes additional call sites where `resolveSessionFilePath()` was called without passing `agentId` in the opts parameter, which caused non-default agents to fail with "Session file path must be within sessions directory" error.
## Changes
- `src/config/sessions/transcript.ts`: Pass `agentId` to `resolveSessionFilePath` in `appendAssistantMessageToSessionTranscript`
- `src/agents/tools/sessions-list-tool.ts`: Pass `entryAgentId` to `resolveSessionFilePath` in session list tool
- `src/agents/subagent-announce.ts`: Extract and pass `agentId` from sessionKey to `resolveSessionFilePath` in `buildSubagentStatsLine`
- `src/gateway/server-methods/chat.ts`: Add `agentId` parameter to `resolveTranscriptPath` and `appendAssistantTranscriptMessage`, and pass it through from callers
## Testing
- Verified that the code compiles without errors
- All existing tests should continue to pass
- The fix follows the existing pattern used in other call sites that were already fixed
Fixes openclaw/openclaw#15761
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates several call sites to pass an `agentId` into `resolveSessionFilePath()` so transcripts resolve under the correct per-agent sessions directory (fixing failures for non-default agents).
The main behavioral change is in `src/gateway/server-methods/chat.ts`, where transcript path resolution now optionally threads through an `agentId` derived from the session key before appending injected assistant messages to the session transcript.
<h3>Confidence Score: 3/5</h3>
- This PR is close to mergeable but has one path-resolution bug that can misplace transcripts when storePath is customized.
- Most changes correctly add `agentId` alongside `sessionsDir`, matching how `resolveSessionFilePath` expects to be called. However, `resolveTranscriptPath` in `src/gateway/server-methods/chat.ts` drops `sessionsDir` whenever `agentId` is present, which changes semantics and can resolve to the wrong sessions directory for custom store paths.
- src/gateway/server-methods/chat.ts
<sub>Last reviewed commit: 55385e3</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
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
87.7%
#15982: fix: pass agentId to resolveSessionFilePath in reply flow (NX-003)
by automagik-genie · 2026-02-14
87.1%
#15852: fix: pass agentId when resolving IRC session paths
by MisterGuy420 · 2026-02-14
83.1%
#7301: fix(hooks): use resolveAgentIdFromSessionKey instead of split(":")[0]
by tsukhani · 2026-02-02
82.7%
#15744: fix: allow cross-agent session path validation
by scottgl9 · 2026-02-13
82.6%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
82.1%
#15793: fix(sessions): gracefully handle stale cross-agent session file paths
by lxcong · 2026-02-13
82.1%
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
81.8%
#8270: fix: support snake_case 'tool_use' in transcript repair (#8264)
by heliosarchitect · 2026-02-03
81.6%
#15941: fix(sessions): allow session file paths from other agents' sessions...
by LiJianLi128 · 2026-02-14
81.5%