Skip to content

Session stop triggers mem::summarize twice; unchanged sessions are fully re-summarized on every stop #1062

Closed

Description

@yulin0629

Summary

Every session stop runs mem::summarize twice, and each run re-summarizes the entire session from scratch. For long-lived sessions that stop repeatedly (e.g. periodic/heartbeat-style automations), this compounds into very large duplicate LLM bills.

Root cause

The stop hook (src/hooks/stop.ts) fires two requests:

  1. POST /agentmemory/summarize → api::summarize → mem::summarize
  2. POST /agentmemory/session/end → api::session::end → fans out event::session::stopped (src/triggers/api.ts), whose handler calls mem::summarize again (src/triggers/events.ts)

Both paths always fire on every stop, and mem::summarize (src/functions/summarize.ts) has:

  • no per-session lock / in-flight guard (unlike mem::observe, which uses DedupMap + withKeyedLock)
  • no "input unchanged" short-circuit — the only skip is compressed.length === 0

So a single stop = 2 full-history LLM runs, and every subsequent stop re-summarizes the whole history again even when nothing changed.

Observed impact (self-hosted, v0.9.27)

Provider-side logs show byte-identical summarize request pairs on every stop of a session that woke every 30 minutes, growing each cycle as observations accumulated:

03:24:33  222635B   ← same request
03:24:33  222635B   ← twice, same second
03:54:27  229115B
03:54:27  229115B
04:24:22  235636B
04:24:22  235636B
...

By the end this was ~110K input tokens per call, 3 heavy calls per 30-minute cycle, with the LLM output being an equivalent summary each time (identical input, nondeterministic titles — sessions also show 2–3 near-identical stored summaries generated seconds apart).

Notes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions