#6853: fix: fire internal hooks on sessions.reset RPC (TUI/webchat /new)
gateway
## Summary
Fixes #6799 — internal hooks (e.g. `session-memory`, `command-logger`) are never triggered when `/new` is issued from the TUI or webchat.
## Problem
The TUI handles `/new` by calling the `sessions.reset` RPC method directly, which bypasses the hook dispatch in `commands-core.ts handleCommands()`. Hooks only fire when `/new` is sent as a text message through a channel (WhatsApp, Telegram, etc.).
## Changes
**`src/gateway/server-methods/sessions.ts`** — Added hook dispatch to the `sessions.reset` RPC handler:
1. **Captures the previous `SessionEntry`** before the store is overwritten (inside the `updateSessionStore` mutator)
2. **Resolves the transcript file path** for the old session via `resolveSessionTranscriptCandidates`, so the `session-memory` hook can read the conversation
3. **Fires `triggerInternalHook`** with the same event shape (`type: 'command', action: 'new'`) as `commands-core.ts`, including `previousSessionEntry`, `sessionEntry`, `commandSource`, and `cfg`
4. **Runs async after `respond()`** — the hook dispatch is non-blocking so it doesn't delay the RPC response
## Testing
- TypeScript compiles cleanly (`tsc --noEmit` passes)
- Existing `sessions.reset` e2e test still passes
- Manual verification: after this patch, `/new` from TUI produces `[session-memory] Hook triggered` in gateway logs and creates the expected memory file
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the `sessions.reset` RPC handler to trigger internal hooks (matching the `/new` command path), so hook-based features like `session-memory` and `command-logger` run when `/new` is initiated from TUI/webchat (which uses `sessions.reset` directly).
Implementation-wise, it snapshots the prior session entry + resolves an existing transcript path before overwriting the session store, responds to the RPC call, then fires `createInternalHookEvent('command','new', …)` via `triggerInternalHook` in a non-blocking async task with `commandSource: 'rpc'`.
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge, with one logic edge case around capturing the previous session when session keys are aliased.
- The change is localized and follows existing hook-dispatch patterns, but `previousSessionEntry` can be missed when the stored session lives under an alias key and gets moved during reset, which would partially reintroduce the original bug for those cases.
- src/gateway/server-methods/sessions.ts
<!-- 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
#9782: feat(hooks): implement session:start and session:end lifecycle events
by kentaro · 2026-02-05
83.4%
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
80.7%
#18103: fix: session-memory hook reads reset file after /new or /reset
by MisterGuy420 · 2026-02-16
80.6%
#14243: fix: fire session-memory hook on auto-resets + topic-aware memory p...
by TheDude135 · 2026-02-11
79.3%
#18694: fix(ui): reset session key to main after /new in webchat
by Phineas1500 · 2026-02-17
78.9%
#19313: fix(session-memory): preserve rotated transcript selection on /new
by ayanesakura · 2026-02-17
78.5%
#13032: feat(hooks): add unified session:before_end hook event
by TGambit65 · 2026-02-10
78.0%
#6653: fix: persist archived session entry on /new or /reset
by leicao-me · 2026-02-01
77.8%
#21155: reply: add cancellable before_reset guard for /new and /reset
by LiShengYang-yiyi · 2026-02-19
77.6%
#7537: fix(sessions): reset token counts on /new for channel sessions
by SoniAssist · 2026-02-02
77.4%