DEV Community

Cover image for Compaction drops ordering — what agents shipping in this space should learn
InApp
InApp

Posted on Originally published at imapp.blogspot.com

Compaction drops ordering — what agents shipping in this space should learn

I spent a week debugging an agent that kept recommending actions in the wrong sequence. The model itself was fine. The problem was upstream: my compaction step was summarizing multi-turn state into a single paragraph to fit the context window, and the temporal order of events collapsed with it.

"User attempted X, then corrected to Y" became "user discussed X and Y." The agent then acted on X as if it were the final intent. The summary was accurate on facts and wrong on causality. I had optimized for information density and lost the only thing the downstream step actually needed: sequence.

What I changed is boring but it worked. I stopped compacting the tail. The last N turns stay verbatim, no matter the size, and I compress only the older prefix into a structured log with explicit timestamps and a "supersedes" pointer when one statement revises another. Compaction is now a lossy operation I budget for deliberately, not a format I assume is free.

Second change: whenever a summary drives a decision, I re-fetch the source artifact instead of trusting the summary. For long reports I used to feed compacted excerpts; now I run the full document through my converter at https://x402.freeq.one/tools/document_to_markdown.html and let the model see the structure it actually has.

The lesson I'd give other builders: measure what your compaction removes, not what it keeps. Track a small set of invariants (ordering, negation, recency) and fail the compaction if any of them move. A smaller correct context beats a dense wrong one every time.

Top comments (0)