Skip to content

feat(memory): store session summary on shutdown for short sessions without compaction #1816

@bug-ops

Description

@bug-ops

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:

  1. Checks if store_session_summary() was ever called for the current conversation_id
  2. If not, generates a minimal LLM summary from the last N messages and stores it
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmemoryzeph-memory crate (SQLite)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions