#15982: fix: pass agentId to resolveSessionFilePath in reply flow (NX-003)
scripts
agents
stale
size: XL
## Problem
When `resolveSessionFilePath()` is called without the `agentId` parameter, it defaults to `DEFAULT_AGENT_ID` ('main'), causing path resolution to use the wrong agent's sessions directory.
This manifested as errors when accessing sessions for non-main agents, especially in the TUI and heartbeat flows where `sessionEntry.sessionFile` might contain an absolute path from a different agent's directory.
## Root Cause
`resolveSessionFilePath(sessionId, entry)` falls back to `DEFAULT_AGENT_ID` when `opts.agentId` is missing, but the calling context (get-reply-run.ts, commands-compact.ts) has the correct `agentId` available and should pass it through.
## Solution
Pass `agentId` explicitly to `resolveSessionFilePath()` in:
- `src/auto-reply/reply/get-reply-run.ts` (line 319): Main reply flow
- `src/auto-reply/reply/commands-compact.ts` (line 82): /compact command flow
## Impact
Fixes "Session file path must be within sessions directory" errors for non-main agents.
## Testing
Tested with multi-agent setup (main + pagbank + others) where the bug was originally discovered. The TUI and heartbeat flows now work correctly for all agents.
Related: NX-001 (cross-gateway sessions), NX-002 (per-agent apiKey preservation)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR contains multiple unrelated features and fixes bundled together (12 commits total), though the title and description focus only on the `agentId` fix (NX-003):
**Main fix (NX-003):** Correctly passes `agentId` parameter to `resolveSessionFilePath()` in two locations:
- `src/auto-reply/reply/get-reply-run.ts:319`
- `src/auto-reply/reply/commands-compact.ts:82-84`
This fixes "Session file path must be within sessions directory" errors for non-main agents by ensuring the correct agent's sessions directory is used instead of defaulting to `DEFAULT_AGENT_ID` ('main').
**Additional changes included:**
- NX-001: Cross-gateway support (`gatewayUrl`/`gatewayToken` parameters added to session tools)
- NX-002: Per-agent API key preservation in `models-config.ts`
- New Jenkinsfile for CI/CD pipeline
- New installation scripts (`install-client.sh`, updates to `install.sh` and others)
- Build script changes (pnpm → bun)
**Recommendation:** The core fix in NX-003 is correct and well-targeted. However, bundling multiple features (NX-001, NX-002, CI infrastructure) in a single PR makes review and rollback more difficult. Consider splitting unrelated changes into separate PRs following the repository's commit guidelines.
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge, with the core fix being correct and well-targeted
- The main fix (NX-003) correctly addresses the session path resolution bug for non-main agents. However, the PR bundles multiple unrelated features (NX-001, NX-002, CI infrastructure) which makes review complex and violates single-responsibility principles. The additional changes appear functional but would benefit from separate review. Score reduced from 5 to 4 due to PR scope concerns rather than code quality issues.
- Pay close attention to the new installation scripts and Jenkinsfile, as these involve system-level operations and CI/CD configuration that weren't mentioned in the PR description
<sub>Last reviewed commit: 4bf82ef</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
#15792: fix: pass agentId to resolveSessionFilePath in additional call sites
by MisterGuy420 · 2026-02-13
87.1%
#22977: fix(ui): resolve agent names from config in session dropdown
by NikhilGaddam · 2026-02-21
84.0%
#20336: fix(sessions): resolve transcriptPath using agentId when storePath ...
by Limitless2023 · 2026-02-18
83.6%
#21679: fix: Mission Control dashboard issues for agent status, stale sessi...
by thejawdoc · 2026-02-20
82.9%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
82.8%
#7301: fix(hooks): use resolveAgentIdFromSessionKey instead of split(":")[0]
by tsukhani · 2026-02-02
82.3%
#13215: fix: pass agentId to loadCostUsageSummary in /usage cost command
by veast · 2026-02-10
82.1%
#15852: fix: pass agentId when resolving IRC session paths
by MisterGuy420 · 2026-02-14
81.9%
#15793: fix(sessions): gracefully handle stale cross-agent session file paths
by lxcong · 2026-02-13
81.8%
#19177: fix: use parseAgentSessionKey instead of fragile split pattern
by El-Patronum · 2026-02-17
81.5%