ReleaseInsight · On RadarHabr AI→ original

Local Coding Agent With External Memory Kept Requirements Across 16 of 16 Context Compactions

After a long coding session gets compacted, a coding agent remembers the task name but loses its constraints. Code Context Engine stores requirements and verified task state on disk and returns them after every compaction. In an eight-hour run on a local model, requirements came back after all 16 compactions, and full state after 15. The model did not finish the whole task, so the method is not yet proven.

AI-processed from Habr AI; edited by Hamidun News
Local Coding Agent With External Memory Kept Requirements Across 16 of 16 Context Compactions
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1A previous PASS is no longer valid if the file was changed after it
Key metric #216 timeouts of 5 minutes each were caused by slow model prefill, not the network
Key metric #3The Current Working State block raised test results from 17/21 to 20/21 in only two of the comparisons

Anyone who has run a coding agent on a big task knows this scenario. First you explain in detail what to change, what must not be touched, and what counts as success. Then the dialogue history grows and stops fitting into the model's window, so the agent compresses it into a short recap (this is called compaction, or "context compression").

After such a compaction, the agent remembers the task name but has lost half the requirements. Or it cites a test that was green long ago, even though it has already edited the source files since. A developer who runs local models on a home machine decided not to add yet another system prompt, but to store the task state separately.

The project is called Code Context Engine (CCE): it is currently version 0.1.0-alpha.

1, written in TypeScript, with an adapter for the Pi agent. The "16 of 16" in the headline means the following: over eight hours of work there were 16 real compactions, and after each one the original requirements were back in the model's context.

Two different problems: finding code and remembering the task

For LLM memory, people usually suggest embeddings and a vector database. That helps find the right code fragment, but it does not answer a different question: what exactly was the agent asked to do? Suppose a Django CRM needs its contact archiving rules changed, tenant data must stay isolated, and the viewer role must not be able to edit records. Perfect code search does not guarantee that these constraints will survive a third context compaction.

So CCE has two layers. Project Memory is a persistent project index on SQLite, using Tree-sitter, FTS5/BM25 full-text search, and a dependency graph. It is not tied to a session, and it filters out stale data using file content hashes. Task Continuity Memory stores the original requirements, versions of the task contract, an event log, and the verified state. The key rule: the model's statement "I fixed it" is not trusted. If a test passed and then the relevant file changed, the earlier PASS automatically loses its validity.

During compaction, CCE does not stack summary on top of summary. A new handoff, meaning the package for resuming work, is assembled from the current contract, the current verified state, and fresh information about the source files, while the detailed history stays on disk.

What the experiments showed

The first failure was in CCE itself. At the third compaction, it refused to build a handoff, deciding there was no room in the 65,536-token window: the safety check estimated the history at 55,025 tokens. In reality, Pi's active history occupied 42,878 tokens, and the upcoming model request was 39,702. The check was counting archived records that no longer went into the request. After the fix, CCE estimates exactly what will go into the next request.

Then came the eight-hour run: a local 35B A3B model quantized to IQ3_XXS, an Intel Arc A770 with 16 GB of VRAM, LM Studio, and 16 real compactions. The original requirements reached the context 16 times out of 16, full current recovery happened 15 times out of 16, and there were no rollbacks to Pi's standard compaction. An independent check accepted phase seven of twelve: 60 of 60 tests. But the model did not bring the task to completion, and the author honestly marks the status as "not evaluated."

A separate finding for anyone working with local models: 16 HTTP timeouts of five minutes each. The cause was not the network but prefill. After compaction the beginning of the prompt changes, the KV cache is barely reused, and the model spends a long time "reading" the input before it starts answering. Raising the timeout to 480 seconds prevents the cutoff but does not speed up processing. The practical takeaway: a request that fits in the window does not necessarily get processed quickly.

Where the method does not work yet

Passing state into a clean session worked technically: the requirements, the project map, and the verification history reached the model. But independent acceptance failed. In one case, the model returned a sqlite3.Row, which cannot be serialized to JSON, even though the requirement about JSON-compatible structures was in context. The model's own tests passed, but the external check caught the error. In the second case, the model kept running the same successful test in a loop instead of fixing the remaining issues.

To address this, the author added a small Current Working State block: the goal, confirmed results, open problems, and the next step. The outcome is ambiguous. In two comparisons where it came second, results rose from 17/21 to 20/21 checks; in two runs with the reverse order, the result stayed at 17/21. Token usage grew by about 3.6%. The author does not treat this as proof, since run order, caching, and model randomness cannot be separated.

For practitioners, the main lesson is this: requirements, knowledge about the code, and evidence of execution are better stored separately rather than in a single summary. The project is open, and the author is looking for independent testers. They need Node.js 22.19+, Git, ripgrep, and a working Pi installation, and reports should specify the model, backend, context size, and the result, including failures.

Story

Key Questions Answered

What are the key details on Two different problems: finding code and remembering the task?

For LLM memory, people usually suggest embeddings and a vector database. That helps find the right code fragment, but it does not answer a different question: what exactly was the agent asked to do? Suppose a Django CRM needs its contact archiving rules changed, tenant data must stay isolated, and the viewer role must not be able to edit records. Perfect code search does not guarantee that these constraints will survive a third context compaction. So CCE has two layers.

What the experiments showed?

The first failure was in CCE itself. At the third compaction, it refused to build a handoff, deciding there was no room in the 65,536-token window: the safety check estimated the history at 55,025 tokens. In reality, Pi's active history occupied 42,878 tokens, and the upcoming model request was 39,702. The check was counting archived records that no longer went into the request. After the fix, CCE estimates exactly what will go into the next request.

Where the method does not work yet?

Passing state into a clean session worked technically: the requirements, the project map, and the verification history reached the model. But independent acceptance failed. In one case, the model returned a sqlite3.Row, which cannot be serialized to JSON, even though the requirement about JSON-compatible structures was in context. The model's own tests passed, but the external check caught the error.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…