-
-
Notifications
You must be signed in to change notification settings - Fork 52.7k
Description
Summary
Compaction can truncate a large amount of session history even when summary generation fails, leaving only the fallback summary text:
"Summary unavailable due to context limits. Older messages were truncated."
This causes catastrophic context loss (“amnesia”) within the same sessionKey .
I believe the issue is in the compaction safeguard extension: when summarization fails / model is missing / apiKey is missing, it still returns a compaction result with firstKeptEntryId , allowing truncation to proceed. The fallback summary is hard-coded and not a usable summary.
Code pointers:
- Fallback summary constant: src/agents/pi-extensions/compaction-safeguard.ts (FALLBACK_SUMMARY)
- Error path explicitly says “truncating history” on summarization failure: src/agents/pi-extensions/compaction-safeguard.ts (catch block logs: Compaction summarization failed; truncating history )
Steps to reproduce
- Start a long-running conversation until compaction triggers (very large token history).
- Make summary generation fail during compaction (e.g. invalid/missing API key, provider outage, forced timeout, or otherwise making session_before_compact summarization throw).
- Continue the conversation and observe that history is truncated while the summary becomes the fallback “Summary unavailable…” text.
(Alternative deterministic path) - Run with a configuration/environment where ctx.model or apiKey cannot be resolved during compaction.
- Trigger compaction.
- Observe compaction still proceeds with fallback summary and truncation.
Expected behavior
If summary generation fails (or model/apiKey is unavailable), compaction should NOT truncate history.
Possible acceptable fallbacks:
- Abort compaction and keep original history intact.
- Retry summarization with a more conservative strategy.
- Degrade by keeping more raw history (instead of truncating to a tiny tail) until a valid summary is produced.
Actual behavior
- Summary becomes: "Summary unavailable due to context limits. Older messages were truncated."
- A massive drop in retained context occurs within the same sessionKey (example evidence below shows tokensBefore dropping from ~181k to ~378).
- The assistant appears to “forget everything” because old messages are truncated and no meaningful summary is preserved.
Environment
- Version: 2026.1.24-3
- OS: ubuntu
- Install method: npm
Logs or screenshots
Compaction event 1
sessionKey: agent:main:feishu:dm:ou_2f460687acb188f14f3c8d6af3fd30e7
tokensBefore: 181134
summary: "Summary unavailable due to context limits. Older messages were truncated."
Compaction event 2
tokensBefore: 378
summary: "Summary unavailable due to context limits. Older messages were truncated."