-
Notifications
You must be signed in to change notification settings - Fork 2
feat(memory): store session summary on shutdown for short sessions without compaction #1816
Description
Problem
Cross-session recall via memory_search (Key Facts + Session Summaries) requires a hard compaction event to fire in the previous session. Short sessions (< hard compaction threshold) leave no searchable trail in Qdrant — so `memory_search` returns nothing from prior sessions unless compaction was triggered.
Root cause (verified in code):
- `memory_tools.rs:103-106`: Recalled Messages filtered by `conversation_id: Some(current)` at app + Qdrant level
- Key Facts (`zeph_key_facts`) written in `store_key_facts()` — called only from `summarize_and_store_with_structured()` (hard compaction path)
- Session Summaries (`zeph_session_summaries`) written in `store_session_summary()` — same hard compaction path only
Expected behavior
Even short sessions should store a lightweight summary to Qdrant on clean shutdown (or next-session startup), so cross-session recall is available regardless of whether compaction fired.
Proposed solution
Add an on-shutdown (or next-session-start) hook that:
- Checks if
store_session_summary()was ever called for the currentconversation_id - If not, generates a minimal LLM summary from the last N messages and stores it
- Also extracts key facts from the session and stores them to
zeph_key_facts
This mirrors the ACON / context-engineering pattern of proactive context handoff rather than only reactive compaction-triggered storage.
Severity
Medium — affects discoverability of context across sessions; workaround is ensuring sessions are long enough to trigger compaction.
Evidence
Observed during live testing (Session 62, 2026-03-15) with Qdrant running: session 1 stored memory_save fact, session 2 with fresh SQLite + same Qdrant could not recall it via memory_search (Recalled Messages scoped to current conv; Key Facts/Session Summaries empty because no compaction triggered in session 1).