← Back to PRs

#14243: fix: fire session-memory hook on auto-resets + topic-aware memory paths

by TheDude135 open 2026-02-11 19:49 View on GitHub →
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