← Back to PRs

#19177: fix: use parseAgentSessionKey instead of fragile split pattern

by El-Patronum open 2026-02-17 13:41 View on GitHub →
agents size: XS
## Summary - Replace `params.sessionKey?.split(":")[0]` with `parseAgentSessionKey(params.sessionKey)?.agentId` in two hook contexts - The split pattern silently returns the wrong agentId for agent session keys (e.g. `"agent:mybot:abc"` yields `"agent"` instead of `"mybot"`) - The `parseAgentSessionKey()` utility in `src/sessions/session-key-utils.ts` already handles this correctly ## Files changed (2 files, ~4 lines each) - `src/agents/pi-embedded-runner/compact.ts` — `before_compaction` hook context - `src/auto-reply/reply/commands-core.ts` — `before_reset` hook context ## Test plan - [x] `pnpm build` passes - [x] `pnpm check` (lint + format) passes - [x] `pnpm test` — no new failures (pre-existing failures unrelated to this change) - [ ] Verify hooks fire with correct agentId for subagent sessions 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> Correct bug fix that replaces a broken `sessionKey?.split(":")[0]` pattern with the existing `parseAgentSessionKey()` utility in two hook contexts (`before_compaction` and `before_reset`). - The old `.split(":")[0]` pattern always extracted the literal `"agent"` prefix from session keys like `"agent:mybot:abc"`, rather than the actual agent ID (`"mybot"`). This meant hooks always received `"agent"` as the `agentId`, which is wrong. - `parseAgentSessionKey()` from `src/sessions/session-key-utils.ts` correctly returns the second colon-delimited segment as `agentId`, and returns `null` for non-agent or malformed keys (falling back to `"main"` via `?? "main"`). - No remaining instances of the fragile split pattern exist in the codebase. All other call sites already use `parseAgentSessionKey` or `resolveSessionAgentId`. - The change is minimal, well-scoped, and introduces no new behavior beyond the bug fix. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge — it's a straightforward, correct bug fix with no risk of regression. - The change is minimal (2 lines changed + 2 import additions), uses an existing well-tested utility function, and fixes a clear bug where the agentId was always incorrectly set to the literal string "agent". No behavioral change for the main agent case (both old and new code produce "main" as fallback). No other instances of the broken pattern remain. - No files require special attention. <sub>Last reviewed commit: 221230b</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