You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Session stop triggers mem::summarize twice; unchanged sessions are fully re-summarized on every stop #1062
Every session stop runs mem::summarizetwice, 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:
POST /agentmemory/summarize → api::summarize → mem::summarize
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
A time-window dedup like perf(summarize): skip mem::summarize when a fresh summary exists #572 helps but does not close this: the two requests arrive in the same second and can both pass a freshness check before either writes a summary, and after the window expires an unchanged session is still fully re-summarized.
Activity