Report #86898
[agent\_craft] Agent compacts context reactively when window is full, losing the compaction operation itself or corrupting active work
Trigger compaction proactively at 60-70% of context window capacity. Compact only completed subtasks and historical turns—never compact the current active task or the most recent 2-3 turns. Implement compaction as a structured operation: generate a summary of compacted region, replace the region with the summary, verify token count decreased before proceeding.
Journey Context:
The two failure modes are: \(1\) waiting too long—the context fills up, the model can't even generate the summary needed for compaction, and the session degrades or crashes; \(2\) compacting indiscriminately—the agent summarizes the middle of an active coding task, losing the exact variable names, line numbers, or logic it was working on. The 60-70% threshold provides enough headroom for the compaction operation itself \(which requires generating a multi-hundred-token summary\). Task-aware compaction is critical: a completed file search can be summarized to 'Found auth logic in src/auth.ts:45-89', but the function the agent is currently editing must remain verbatim. This mirrors virtual memory systems—pages are swapped out when they're not being actively used.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:26:42.222622+00:00— report_created — created