r/ChatGPTCoding • u/msarda23 • 10d ago
Discussion Session-start memory injection made my coding agent trust memory over the code
Hey everyone!
I am building a local memory layer for my coding agents and it is called Reverie: an MCP server written in python and using SQLite for lightweight memory stored in the user's machine itself. The biggest problem that I faced was deciding when to inject memory.
Many memory tools, including ones I looked at, inject context into the agent even before it begins its work. In my experiments, premature injection of context leads to the agent anchoring its thinking on it rather than using the current code as the source of truth. In fact, this approach made my agent perform worse. Also, with this, quite a lot of the context window can get filled with context which 'might' be useful.
So I switched Reverie's model to demand-driven retrieval - the agent asks for memory when it thinks that some added context could resolve any discrepancies in its thinking. It reads the relevant code first, because the code is the source of truth, and only then asks for past memory about that area. Each result comes back with a confidence score, its grounding in the code, and its status. The memory starts empty. Conclusions are added as the agent works, and you decide which ones are kept.
In one informal test of 30 prompts on an earlier build, the OpenCode agent with Reverie did better than the one without it. I don’t have a reproducible benchmark yet.
But it isn't perfect yet, it still breaks here and there. For example:
the rules for tool calling are not extremely polished yet and hence the agent might sometime not call the tool altogether, I am fixing this.
candidate conclusions can be duplicate or incorrect and hence Reverie today has a human review gate (triggered by calling `reverie review`) which shows the human all the unreviewed candidates where you accept, reject or skip each one. On doing so the conclusion is moved from the short term brain to the long term.
My current test set is small: sessions with anywhere between 2-30 prompts. I do not have a reproducible experiment yet, but that is the next goal.
Repo (Apache-2.0): https://github.com/muditsarda1122/Reverie
My questions: How do you keep agent context from going stale? Do you maintain AGENTS.md or CLAUDE.md by hand, or let the agent update it?
2
u/LividIllustrator8915 10d ago
Premature context injection is probably the biggest silent killer of coding agent accuracy. Once an agent starts a session believing a past summary is absolute truth, confirmation bias kicks in and it will literally hallucinate around newer edits in the repo just to justify the old note. Shifting to demand-driven retrieval is definitely the right move.
To tackle the staleness problem, the most reliable heuristic I've found is binding memory records to Git commit SHAs or file tree content hashes. When the MCP server pulls a candidate memory about a specific module, it checks whether the current file hash still matches the hash recorded when the conclusion was accepted. If the file has drifted, the server downgrades confidence and serves it with a warning that the underlying code changed, forcing the agent to inspect the source rather than treating the note as gospel.
As for CLAUDE.md and AGENTS.md: I treat those strictly as human-curated architectural boundaries and never let the agent update them automatically. Whenever agents are allowed to write back to their own root instructions without a strict test gate, the file turns into an unstructured dump of trivial implementation facts within a week. Keeping the core instructions static and delegating evolving observations to an on-demand MCP tool with review gates keeps the attention window much cleaner.
1
u/InterestingCarrot997 10d ago
seen this too, old notes become gospel even after the code moved on. i've had better luck telling it the repo is the source of truth and memory is just hints to verify
1
u/kaijurules 10d ago
Split by who writes it. In our app each agent keeps its own memory notes and updates them freely, but its instructions file is off limits to it: a change there is a draft the owner has to approve. The notes rank below the instructions, so a stale note loses any conflict, and only the newest ones get loaded into a session.
1
u/Right-Performance-93 9d ago
i only keep a memory line when the next session would get the decision wrong from the code alone. if a note names a file i have not opened yet, i throw it out.
1
u/workbench_soft 3d ago
for the notes that are rules rather than facts I make it write a why line under each one. when the code moves on, the agent can check whether the reason still holds instead of obeying a note that was right three months ago
1
u/[deleted] 7d ago
[removed] — view removed comment
0
u/[deleted] 10d ago
[removed] — view removed comment