ertac.paprat.com
EN

← Writing

Coding Agents and RAG: The Function Was Found, the Contract Was Missed

· 3 min read · English

Rewritten: . Rewritten with AI assistance. Examples and tool references follow the original publication period.

A coding agent receives a bug report: archived projects still appear in search. It finds the search function, adds a filter, and produces a patch. The visible example now works.

Then the export job loses archived records it was supposed to retain.

In this hypothetical repository, search and export share a query helper. The agent found the right code location but missed a rule: archived projects should disappear from ordinary discovery while remaining available to an authorized historical export.

This is a retrieval failure as much as an implementation failure. The missing context is a contract about behavior.

Repository context comes in several forms. A literal search can locate a field such as archived_at and find the exact callers that inspect it. Semantic retrieval can surface a design note using different words, such as “historical records remain exportable.” Dependency information can connect a shared helper to routes, jobs, and tests.

These methods complement one another. Embeddings do not make exact symbol search obsolete. A call graph does not explain every business rule. A relevant document can be outdated.

For this bug, a useful evidence packet includes the failing search path, the shared helper’s callers, tests for exports and permissions, and any maintained explanation of archive behavior. Retrieving a large arbitrary collection of nearby files is less helpful than establishing these relationships.

Ask questions that change the patch

Before editing the helper, the agent should establish where filtering belongs. Does every caller want to exclude archived projects? If not, should the public search path supply an explicit condition? Is the export’s access check independent of archive status?

Answers to those questions can produce a smaller and safer change. The important context is whatever makes one plausible patch inappropriate and another justified.

An age-based filter can remove exactly that evidence. A two-year-old decision about export semantics may remain authoritative, while a new comment describes a temporary workaround. Document freshness and relevance are different properties. Check whether a rule is still in force instead of discarding it because it falls outside an arbitrary recent window.

Evaluate the retrieval through the task

Construct a small benchmark of repository questions with known supporting evidence. For the archive bug, identify the contract and the affected callers before asking the agent to solve it. Then inspect what the retrieval returns and what the proposed patch does.

A result can fail in several places: the evidence is absent from the repository, retrieval misses it, the model ignores it, or the implementation misapplies it. Those failures need different fixes.

Measure both the change and its constraints. Search should exclude archived projects for the intended user. Authorized export should still include them. Unauthorized export should still fail. These checks test the contract more directly than counting retrieved chunks or celebrating a plausible explanation.

Tool use gives retrieval a feedback loop

An agent can search again after discovering a shared helper, inspect a caller, run a focused test, and revise its hypothesis. Research such as SWE-agent examines how an agent’s interface to software-engineering tools affects this work. Calling a system “agentic” does not establish that it completes the loop successfully.

Keep the loop bounded and observable: which question is unresolved, which action gathers evidence, and what result would justify the next edit? Tool output and retrieved files should be treated as evidence, not as authority to follow arbitrary instructions embedded in them.

The archive bug does not require an agent to read the whole repository. It requires the agent to discover that one function serves two different promises. That is the kind of context worth optimizing for.