mahesha.godekere
← all writing
agentic ai · compaction

The 3-compaction problem

Four hours into a session, the agent suggested the exact thing it had rejected an hour earlier. It had not gotten dumber. It had forgotten why.

M Mahesha Godekere · May 2026 · 8 min read · Bengaluru
The 3-compaction problem. After three compactions, the agent forgets why.

Every agent you have used has a wall in it. Not a wall of intelligence. A wall in its memory of why decisions were made. Long enough sessions hit it. Most people notice the symptom and not the seam, and the seam is where the work that matters lives.

// the moment of forgettingThe agent re-proposed the rejected thing

Four hours into a session, the agent suggested the exact thing I had told it not to do.

Not something similar. The same approach. The same flaw. An hour earlier we had gone back and forth about why it wouldn't work, and it had agreed, and we had moved on. Now it was proposing it again, cheerfully, as if that conversation had never happened. Because for the agent, it hadn't.

It had not gotten dumber. The model behind it was the same model it had been at minute zero. Same weights, same capability. What it lost was not intelligence. It was the memory of why decisions were made. The reasoning was gone and only the surface remained, and the surface was confidently wrong.

I scrolled back to find the moment it forgot. It was easy to spot. One line in the log: the session had been compacted. Then, later, compacted again. Somewhere around the third one the thread that held the work together had quietly been cut, and neither of us noticed until the agent walked face-first into a wall it had already mapped.

That is when I went looking for what actually happens when a harness compacts a session. What it keeps. What it throws away. And why almost every agent you have used has this wall in it, waiting for the session that runs long enough to hit it.

// what compaction actually isTwo ways to make room

To see why the agent forgot, you have to know what a compaction is. The word makes it sound technical. The mechanism is simple, and it has only two real flavours.

Every agent runs a loop. The model at the centre of it has no memory between calls. Each call is a fresh slate. Whatever was said three turns ago is gone, as far as the model is concerned, unless someone shows it again. That someone is the harness. Every turn, it ships the whole conversation back to the model along with the new user message, and that is the only reason the agent appears to remember anything at all. The model reads it, decides what to do, writes a response. The harness appends the response to the conversation, and the next turn ships the whole thing back again. The conversation grows, turn by turn, like a transcript that gets longer every minute. The mechanics of that loop got a full unpacking in the previous piece; this one is about the part of it that decides what you remember.

// turn 1
user
→ ship 1 msg
← asst
append
// turn 2
user
asst
user
→ ship 3 msgs
← asst
append
// turn 3
user
asst
user
asst
user
→ ship 5 msgs
← asst
append
// turn N
user
asst
user
asst
user
asst
user
asst
···
→ ship ALL msgs
approaches limit
user = user prompt  ·  asst = model response
every turn ships the whole conversation back to the model · the log only ever grows

A model has a maximum amount of text it can read in one go. Once the conversation gets close to that limit, something has to give. The harness has to make room. That is compaction. There are two ways to do it.

// preferred
Reversible compaction
Strip out things the agent can retrieve again on demand. The contents of a file it read. The output of a command. The body of a page it fetched. Put a pointer in their place. The information is not lost, only moved.
Survives: raw reasoning, conversation flow, the why of every decision. Anything reachable by a fresh tool call is retrievable.
// last resort
Lossy summarization
Ask a model to summarize the older portion of the conversation into a shorter description, then replace those older messages with the summary. The originals no longer exist for the agent. Only the summary remains. Cannot be reversed.
Survives: whatever the summary chose to capture. Typically the what, not the why. That asymmetry is where the wall is built.

The two are easiest to see side by side. Same starting history, two different things a harness can do to it when the context window fills up.

// before · history at the context limit
user
asst
file-read
~800 tok
asst
bash output
~1200 tok
asst
user
asst
↓   compaction fires
// reversible · re-fetchable info replaced by pointers
user
asst
→ ref:file.py
asst
→ ref:cmd:0x1f
asst
user
asst
shape intact · big content removed · reasoning preserved · agent can re-fetch on demand
// lossy · older turns collapsed into a single summary
summary of
all prior turns
user
asst
history flattened · originals gone · only what the summary captured survives

The strategic preference is obvious once you say it out loud, and has been written down before. Raw history first. Reversible compaction when raw stops fitting. Lossy summarization only as a last resort. That order is how a session keeps its memory intact for as long as possible.

The trouble is that the third step comes faster than people realise. And it is where the wall lives.

// the wallAfter three compactions, the agent forgets why

After two or three lossy compactions, the agent's reasoning is gone.

This is the claim a pseudonymous engineer has been documenting for months, and once you have seen it once you cannot unsee it. After one summarization, the conversation can still cohere. The summary captures the broad shape of what happened. After the second, things start to thin. By the third, the agent is operating on a third-generation copy of its own past. A summary of a summary of what once was a conversation. The detail is gone. The branches it considered and rejected are gone. The constraints it agreed to are blurred into general guidelines. The conclusions are preserved by the kind of summary an LLM tends to write. The reasoning behind them is thrown out.

What disappears, specifically, is recognisable once you watch for it.

The shape of the wall is easier to see as a picture. What survives at each compaction, by category:

What the agent knows Raw C1 C2 C3 · the wall
Conversation flow
Decision conclusions (the what)
Decision reasoning (the why)
Rejected approaches
Multi-step task state
Side-task / parallel state
preserved partial blurred / generic gone

You can see all of this by paying attention. The tells are precise. The agent suggests the rejected idea again. The agent forgets which file it just edited. The agent declares a task complete when only the first half is done. The agent stops mentioning a problem it was halfway to solving. Each one is a specific thing the summary did not carry forward, and the agent, working only from the summary, has no way to know it is missing.

That is the wall. It is not made of intelligence. It is made of what a summary cannot encode about a conversation that mattered.

// the harness tourWhat each agent actually does

Different agents hit the wall at different points, and they hit it differently. The table below is what I found after reading the compaction code of nine of the popular ones. Names belong in the data, where the comparison can be checked. Patterns belong in the prose.

Harness Approach What it preserves
Pi Walk backward summing tokens; structured-summarize everything before the ~20K most-recent Goal, constraints, progress, decisions, next steps, critical context; recent ~20K kept raw; CompactionEntry appended cumulatively to the JSONL log
Claude Code Detailed structured summary (7–12k chars); regenerated fresh each compaction cycle Decisions, file modifications, current task; not cumulative across compactions
OpenAI Codex /compact endpoint returns opaque compressed representations Optimised for reconstruction fidelity, not for human readability
Factory Anchored iterative summarization with persistent named sections Session intent, file modifications, decisions, next steps
Cline Auto Compact + manual /smol / /compact; detects duplicate file reads Technical details, code changes, decisions; duplicate reads replaced with a [DUPLICATE FILE READ] marker
Aider Recursive chunk-and-summarize when history overflows the configured limit Configurable; uses a smaller, faster "weak" model for the summarization call; context split into system / repo map / chat / active files
Microsoft AF LLM-summary replacement; configurable summarizer model Key facts, decisions, user preferences, tool outcomes
Google ADK Sliding window with overlap; writes the summary back into the session as a new event Event stream with an explicit "compaction" action; traceable
Manus Context-rot threshold (~128K) Recent tool calls kept in raw, full-detail form; reasoning: maintain the model's rhythm and formatting style

Reading the table, the differences are in what each chose to keep, not in how aggressively each compresses. Two harnesses can hit the same compression ratio and produce dramatically different quality on the work that depends on what was lost. The reduction percentage is not the achievement. The achievement is what the harness chose to keep before it threw the rest away.

The split that matters most is the one between the harnesses that summarize cumulatively and the ones that regenerate from scratch. A cumulative summary carries the chain forward across compactions. A from-scratch summary at each compaction means the third summary is reading the second summary as raw context, and the third generation loses what the second generation had already lost. This is the structural reason the third compaction is so often the one where the wall appears.

One vendor's published evaluation of three commercial systems, including its own, surfaces one weakness worth naming. Awareness of files and artifacts is the lowest-scoring dimension across all three. None handle it well through summarization alone. The honest finding is that this is not a summarization problem. It is a retrieval problem dressed as a memory problem.

// surviving twelveThe four pieces that hold the line

The same engineer who documented the wall has published a fix that, in their own production use, survives it. The claim, in their words: "sessions regularly survive 12+ compactions with full context intact." The author is candid about what kind of evidence sits behind that line: "no formal benchmarks. This comes from daily production use, not a research lab." That makes it a practitioner technique, not a peer-reviewed result. Worth taking seriously for what it proposes; worth holding loosely until others build on or contradict it.

The four pieces are not a clever trick. They are mostly the patient engineering a default compaction prompt does not bother with.

// piece 02 · before
Pre-compaction hook
A small piece of code that fires just before the event. Injects continuity rules into the model's context one last time, so the compaction prompt has the right instructions in scope, and attaches the current state of the work that lives outside the conversation: the branch the agent is on, recent commits, files touched. Facts about the world the conversation cannot summarize on its own.
// the compaction event itself
summarize older history → replace it
// piece 01 · the instruction
Better compaction prompt
Default prompts ask for a summary. The right one asks the model to detect any previous compaction summaries already in the conversation, preserve them cumulatively in a dedicated section, and capture for every important decision the why, not just the what. A summary that says "tried X and rejected it because the input is unbounded" survives the next compaction. A summary that says "considered X" does not.
// piece 03 · after
Post-compaction hook
A small piece of code that fires just after the event. Detects any external agents or parallel processes that were active at the moment of compaction and warns the freshly-compacted session that they exist, so the agent does not accidentally re-start work another process is still doing.
← - - - manual trigger
// piece 04 · on-demand
Manual escape hatch
A short command the user fires when they sense a long session is about to compact. Outputs an explicit delta of what has changed since the last compaction. Implicit knowledge made explicit, on demand, before the lossy summarization gets to choose what survives.
four pieces · before · inside · after · on-demand · together they survive past twelve compactions

Read those four pieces together and the pattern becomes plain. The default compaction is a single step of summarization in an empty room. The fix is to surround that step with structure and external information so that the summarization is not the only thing carrying the work forward. Most of the why lives outside the conversation. Compaction by itself cannot preserve it. A harness that adds the surrounding structure can.

The numbers people publish about how aggressively a harness compresses do not capture any of this. A harness can hit a 99 percent reduction with no hooks and no continuity rules and feel impressive in a demo, then collapse silently on the third real session that runs long enough to need it. The reduction is the achievement that markets well. The structure around the reduction is the achievement that ships.

// the seam nobody marketsWhere the next year of work happens

Once you have seen the wall, you stop talking about agents the same way.

The marketing of these tools is about the model. A new model arrives, the demo videos play, the leaderboards shuffle. Most of what people argue about lives in that layer. The model that just shipped is better than the one before it at a benchmark.

The thing that decides whether your eight-hour session falls apart at 2 a.m. is not the model. It is the compaction. The model is the same. The compaction is what one harness writer thought about more carefully than another. That writer's choices, made in a code file that almost nobody reads, are why the agent at 2 a.m. either remembers why it rejected an approach an hour ago, or proposes it again as if for the first time.

The seam between the model and the harness keeps showing up here. The intelligence is in one place. The decision about what to remember is in another. The model is replaceable. The compaction is not.

The model is a commodity now. The compaction strategy is the product.

I think about the session where I noticed all of this, four hours in. The agent had not gotten dumber. The harness had thrown out the part that knew why. The wall was not a property of the model behind it. The wall was a single function in someone's codebase that had decided, on my behalf, which sentences of our conversation were worth keeping. It made a defensible choice. It did not make the right one for the work we were doing.

That is the part that is going to keep me reading the code. Every harness has this function. Every team that ships one has chosen what it preserves. Most teams have not published their choice. The next year of agent tooling will be decided by how well that choice is made, by people patient enough to think about it more carefully than a default prompt.

If you are building one of these, or buying one, you now know where to look. Open the source. Find the function. Read what it keeps. That tells you, more honestly than any benchmark, whether the agent you are holding will still be useful at hour four.

M
Mahesha Godekere

Principal Architect at StanceBeam. Building Agentic AI & edge computer-vision systems. Ex-Syniverse, VeriSign · MMS Picture Messaging at carrier scale (40M+ Sprint subscribers). Bengaluru.