#8896: fix: improve compaction fallback message with recovery hints
agents
stale
Cluster:
Memory Compaction Improvements
## Problem
When compaction fails to generate a summary due to size limits, the agent receives:
`Context contained 45 messages (3 oversized). Summary unavailable due to size limits.`
This is a dead end — the agent has no guidance on how to recover context.
## Solution
Add a recovery hint to the fallback message:
`Context contained 45 messages (3 oversized). Summary unavailable due to context limits. CHECK memory/active_work.json and memory/YYYY-MM-DD.md for recent task state.`
## Why This Matters
Agents configured with memory files (per AGENTS.md best practices) can recover from compaction by reading their state files. This message reminds the agent to do that instead of starting fresh.
This is a small change but addresses a real pain point in batch processing recovery.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the final compaction fallback message in `src/agents/compaction.ts` to be more actionable when summarization fails due to context/size limits, adding a hint to consult the agent’s persisted memory state (e.g., `memory/active_work.json` and dated markdown files).
This fits into the existing progressive summarization flow (`summarizeWithFallback`) by improving the last-resort string returned after both full and partial summarization attempts fail, helping agents recover context instead of dead-ending.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge; it’s a small, user-facing messaging change.
- Change is limited to the final fallback string in the compaction flow, with no control-flow or data-structure modifications. Main concern is the guidance being overly specific to one memory-file layout, which could confuse setups that don’t use those paths.
- src/agents/compaction.ts
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#5380: fix(compaction): include recent messages as fallback when summary u...
by Glucksberg · 2026-01-31
85.9%
#8903: fix: improve compaction summary instructions to preserve active work
by joetomasone · 2026-02-04
84.3%
#8900: fix: improve default memory flush prompts with urgency and specifics
by joetomasone · 2026-02-04
79.8%
#9620: fix: increase auto-compaction reserve buffer to 40k tokens
by Arlo83963 · 2026-02-05
78.9%
#18997: fix: improve context overflow error messages and docs
by realhoratiobot · 2026-02-17
78.8%
#6108: Fix compaction producing empty summary when ctx.model is undefined ...
by GangEunzzang · 2026-02-01
77.8%
#5360: fix(compaction): add emergency pruning for context overflow
by sgwannabe · 2026-01-31
77.5%
#9012: fix(memory): resilient flush for large sessions [AI-assisted]
by cheenu1092-oss · 2026-02-04
77.2%
#15749: fix: improve context overflow error with diagnostic details
by superlowburn · 2026-02-13
77.1%
#4223: fix: compaction safeguard falls through when ctx.model is unavailable
by hanxiao · 2026-01-29
76.5%