#14243: fix: fire session-memory hook on auto-resets + topic-aware memory paths
stale
## Summary
The `session-memory` hook only fires on explicit `/new` commands, **not** on automatic session resets triggered by `evaluateSessionFreshness` (daily at 4 AM or after idle timeout). This means conversations silently lose all context overnight — no memory files are saved, and the bot wakes up with amnesia.
Additionally, for Telegram group topics (forum mode), saved memory files use LLM-generated slugs (`memory/2026-02-11-session-history.md`) that are impossible for the bot to locate later, since semantic search returns stale project files instead of the actual conversation transcripts.
### Changes
**Commit 1 — Fix auto-reset memory loss**
- `session.ts`: Capture `previousSessionEntry` before all reset types (not just explicit resets)
- `get-reply.ts`: Detect auto-resets and emit a new `session:auto-reset` hook event
- `handler.ts`: Accept `session:auto-reset` events in addition to `command:new`
- `HOOK.md`: Declare `session:auto-reset` in event list
**Commit 2 — Topic-aware memory file paths**
- `handler.ts`: When the session key contains a topic/thread ID (e.g., `topic:11`), save to `memory/topics/topic-{id}/YYYY-MM-DD.md` instead of a random slug
- Non-topic sessions (DMs, regular groups) continue using slug-based naming
### Why topic-aware paths matter
Each Telegram forum topic runs as a separate session. With deterministic paths:
- The recursive `walkDir` in the memory system auto-indexes them
- Workspace instructions (`AGENTS.md`) can direct the bot to read `memory/topics/topic-{id}/` on session start
- Conversation history accumulates in date-ordered files per topic
### Testing
| Scenario | Result |
|----------|--------|
| `/new` in topic — memory file created | PASS |
| Idle auto-reset in topic — file saved to `memory/topics/topic-{id}/` | PASS |
| Daily auto-reset in topic — file saved | PASS |
| Bot reads topic memory on new session | PASS |
| Bot recalls correct conversation context | PASS |
| Non-topic sessions still use slug naming | PASS |
| Cross-session memory search still works globally | PASS |
### Related
This issue has been reported by multiple users in community discussions — topic-based sessions losing context after overnight resets, with no way to recover conversation history.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Fixes session memory loss during automatic session resets (daily 4 AM / idle timeout) by emitting a new `session:auto-reset` internal hook event from `get-reply.ts`, and adds topic-aware memory paths (`memory/topics/topic-{id}/`) for Telegram forum sessions so memory files are deterministically locatable.
- `session.ts`: Broadens `previousSessionEntry` capture to include stale-entry auto-resets (not just explicit `/new`), and adds `autoResetTriggered` flag
- `get-reply.ts`: Fires `session:auto-reset` internal hook when auto-reset is detected
- `handler.ts`: Accepts `session:auto-reset` events and routes topic sessions to deterministic paths
- `HOOK.md`: Declares the new `session:auto-reset` event
- **Issue**: Topic memory files use only the date (`YYYY-MM-DD.md`), so multiple resets in the same day will silently overwrite earlier saves — consider adding a time component to avoid data loss
- No tests were added for the new `session:auto-reset` event or topic-aware path logic
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge — addresses a real user-facing bug, but has a data-loss edge case with same-day topic overwrites that should be resolved first.
- The session logic changes (`previousSessionEntry`, `autoResetTriggered`) are well-reasoned and correctly handle the edge cases I checked. The hook plumbing follows existing patterns. However, topic memory files using only the date in the filename means `fs.writeFile` will silently overwrite earlier saves on the same day — this is a correctness issue that could cause unexpected data loss. Additionally, no tests cover the new auto-reset path or topic-aware file routing.
- `src/hooks/bundled/session-memory/handler.ts` — the topic memory file path uses only date, risking overwrites on same-day resets
<!-- 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
#10591: feat(hooks): add session-start-memory bundled hook
by morningstar-daemon · 2026-02-06
82.2%
#18103: fix: session-memory hook reads reset file after /new or /reset
by MisterGuy420 · 2026-02-16
80.5%
#22433: Slack: fix thread context loss after session reset
by stgarrity · 2026-02-21
80.0%
#9026: fix(session-memory): sanitize content to prevent binary data in mem...
by Flamrru · 2026-02-04
79.8%
#15493: feat(telegram): session state memory for diagnostic continuity
by tangcruz · 2026-02-13
79.5%
#6853: fix: fire internal hooks on sessions.reset RPC (TUI/webchat /new)
by hamiltonchua · 2026-02-02
79.3%
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
79.1%
#6858: feat(hooks): improve session-memory with LLM summarization
by alauppe · 2026-02-02
78.4%
#14576: Fix/memory loss bugs
by ENCHIGO · 2026-02-12
78.3%
#16061: fix(sessions): tolerate invalid sessionFile metadata
by haoyifan · 2026-02-14
78.2%