PROOF LIBRARY / TechArticle
Repository context needs freshness, provenance and exact lines
A technical design for coding-agent retrieval that treats context as versioned evidence rather than a bag of relevant-looking text.
Executive summary
Coding agents fail before generation when they begin from the wrong repository context. The retrieval system can return text that is topically similar, syntactically valid and obsolete. It can return an accurate summary that no longer matches its file. It can also return a useful claim with no path for a reviewer to verify it.
This paper proposes three non-negotiable properties for repository context: freshness, provenance and exact source lines. Relevance remains necessary, but relevance without these properties is not evidence.
The design described here is the basis of ProofGit: model-written summaries stored in a versioned companion repository; retrieval by meaning, words and names; read-time freshness policy; and evidence bundles that carry source coordinates into the agent response.
Failure scenario: the correct answer from the wrong version
A platform agent is asked whether a webhook can bypass approval. It retrieves a summary produced before a safety patch. The old summary is internally accurate and ranks highly because it uses the same nouns as the question. The agent reports the bypass. Engineering pauses a release and starts an incident review. The current source, however, already refuses that path.
The retrieval score did not fail in the conventional sense. It found a semantically relevant document. The system failed because it did not treat the relationship between summary and source blob as part of truth.
The evidence object
Repository context should not be represented as anonymous text. A useful evidence object contains at least:
- repository identity and source path;
- source commit and blob identity;
- a statement or typed fact;
- the exact source span supporting that statement;
- the summary schema, prompt and model provenance;
- freshness status;
- retrieval lane and ranking metadata;
- a stable URL for human inspection.
These fields separate three questions that are often collapsed: “Is this relevant?”, “Did this summary describe the source it claims to describe?”, and “Can a reviewer inspect the basis?”
Freshness: compare objects, not dates
Timestamps are a weak freshness signal. A summary produced yesterday can be stale after a commit today. A summary produced months ago can still be current if the source blob is unchanged.
The stronger mechanism is object identity. Record the blob SHA the summary describes. At read time, compare it with the blob at the requested ref. If they match, the summary has a concrete freshness relationship. If they differ, mark it stale and exclude it by default. If the file is absent at the ref, say so rather than presenting evidence from another branch as current.
This policy is deliberately conservative. A small comment change can stale a summary even when its substantive claim remains valid. That costs refresh work, but it avoids asking the retrieval layer to guess which source changes matter.
Provenance: preserve how the explanation was made
Generated summaries are transformations. The model, prompt, schema and source coordinates are part of their provenance. Storing only the prose removes information needed to reproduce, compare and challenge the artifact.
ProofGit stores summaries in Git because Git already gives engineering teams a mature language for identity, history and diff. A summary mirror can be cloned, reviewed and moved. A change to a typed fact is visible. The source repository remains authoritative; the companion repository records the model-written map.
Provenance also applies at query time. A result should say whether it came from semantic search, lexical search or exact-name lookup. It should report whether reranking ran rather than allowing callers to infer behaviour from score fields. In the current public product, no cross-encoder reranking claim is made.
Exact lines: the handoff from model to reviewer
File-level citations are better than none and still too broad for serious review. A 1,500-line authorization handler can support opposing interpretations. Exact line spans let the reviewer evaluate the actual statement.
The retrieval layer should therefore return a compact evidence bundle: the claim, its source span and enough adjacent text to understand it. This is not full-repository dumping. It is a bounded handoff to the person or agent that needs to reason about the claim.
Exact lines also improve error handling. When the summary overstates the source, a reviewer can identify the mismatch and correct the summary pipeline rather than merely down-voting an opaque answer.
Retrieval lanes and fusion
Repository questions arrive in different forms. “Where is tenant isolation enforced?” is conceptual. “Where is verify_csrf_token defined?” is a name lookup. “Which file says approve_in_portal?” is exact text.
A robust system uses multiple lanes:
- semantic retrieval over structured summaries when embeddings are enabled;
- lexical ranking over summary text;
- exact source search for names and strings;
- rank fusion with clear per-lane metadata;
- policy filters for stale, excluded or unreadable files;
- a shared token budget across repositories.
Agent Retrieval Bench reinforces the premise that repository retrieval deserves its own evaluation. Generation quality cannot compensate for consistently retrieving the wrong files.
Security and policy boundaries
Repository evidence may contain secrets, generated files, vendored code or customer-specific material. A retrieval design needs read-time policy, not only ingest-time convention. Excluded paths should remain excluded from every lane. Recognised secrets should be redacted from responses. A repository-scoped credential should not silently become fleet-wide access.
The evidence response should also distinguish recorded facts from interpretation. “Function X writes table Y” can be anchored. “This architecture is compliant” is a separate judgement and should not be manufactured from code coordinates.
Evaluation methodology
Evaluate retrieval before evaluating generated answers. Build questions whose expected answer file and source span are known. Measure top-k hit rate, reciprocal rank, freshness correctness, citation-span correctness and the rate at which the system refuses stale or unavailable evidence.
Then evaluate agent outcomes: time to the first correct source, unsupported-claim rate, reviewer correction time and task completion. Keep held-out questions written after tuning. Record model and index settings. Internal measurements should be labelled as estimates with date, method and limitations; they are not independent evaluations.
Limitations
The approach cannot see truth outside the repository: runtime flags, external APIs, production data and verbal decisions may change behaviour. It also inherits limitations from model-written summaries and embedding models. Exact lines make an error inspectable; they do not prevent error.
Freshness checks require a defined ref. Monorepos and generated code need explicit skip policy. Cross-repository questions need a shared budget so one large repository does not crowd out the rest. Binary and excluded files remain outside the evidence surface.
Implementation checklist
- Pin every summary to source commit and blob.
- Store summaries as inspectable, versioned artifacts.
- Keep semantic, lexical and exact-name lanes distinguishable.
- Exclude stale evidence by default.
- Return exact source spans and stable links.
- Apply skip and secret policy at read time.
- Report fallbacks and omitted results.
- Test retrieval independently of generation.
- Preserve human review for engineering effects.
Failure modes and the control that catches each one
Repository context can fail at several independent layers. A search can miss the owning file because the question uses product language while the code uses an internal identifier. A summary can describe an earlier blob. A retrieved line can be current but irrelevant because it is a test fixture or a deprecated branch. A synthesis can overstate what the evidence proves. A caller can apply a condition that the cited function does not expose.
Those failures should not collapse into “the model was wrong.” Each has a different control. Hybrid retrieval helps bridge concepts and identifiers. Blob comparison catches stale summaries. Path and language metadata help distinguish generated files, fixtures and production sources. Exact-line citations expose overstatement to reviewers. A follow-up search of callers, configuration and tests expands the evidence graph when one excerpt is insufficient.
A mature evaluation records the layer that failed. That diagnosis makes improvement possible and prevents a larger model from becoming the default answer to every retrieval problem.
Designing the evidence packet
The useful output of repository retrieval is an evidence packet, not merely a paragraph. At minimum it should identify the repository, revision, file and line range. It should preserve the source excerpt, the generated explanation or summary, and whether the summary still matches the recorded blob. Search scores may help the system rank candidates, but they should not be presented as probability that a claim is true.
The packet should also carry limitations. If only one file was inspected, say so. If the relevant behavior crosses repositories, identify the missing authority. If generated or vendored code was excluded by policy, make that boundary visible. If a source file is too large or unsupported for summarisation, do not silently treat the absence as proof that the behavior does not exist.
For an agent, this structure makes instructions clearer: use the excerpt for repository fact, use the explanation as navigation, and ask for more evidence when the claim exceeds the cited lines. For a person, it shortens the path from output to review.
Freshness across branches and generated artifacts
Freshness is simple only when one branch and one source tree matter. Real repositories contain long-lived release branches, generated clients, vendored dependencies and build artifacts. A summary current for the default branch may be wrong for a hotfix branch. A generated file may reflect a schema that changed after the last build. A monorepo can contain several deployable products at different release points.
The evidence object therefore needs a revision boundary. “Current” means current for the target Git object, not current in the abstract. If a user asks about a branch, the retrieval and citations should resolve inside that branch. If the tool falls back to another revision, it should disclose the fallback rather than present the result as exact.
Generated artifacts require policy. Teams may choose to index them, exclude them or treat them as secondary evidence. The right answer depends on whether the generated output is reviewed and deployed or recreated during every build. What matters is that the policy is explicit and represented in retrieval, so an agent does not confuse derived text with the authority that produced it.
Access control and evidence minimisation
Exact evidence is valuable only when the requester is allowed to see it. Repository pairing, search, summary access and citation retrieval must respect the same tenant and repository boundaries. A model response is not a safe place to repair an authorisation mistake after the source has already been disclosed.
Minimisation also improves quality. The tool should retrieve the smallest excerpt that supports the claim, with enough surrounding lines to understand the control flow. Sending whole files by default increases secret exposure, token cost and the chance that an unrelated instruction inside source or documentation influences the model.
Teams should decide how to handle secrets, large files, binaries, generated code and excluded paths before indexing. Logs and evaluation fixtures should avoid copying sensitive excerpts unnecessarily. A repository evidence product still needs ordinary security engineering: authentication, authorisation, isolation, audit, abuse controls and incident response.
Operating and measuring the system
An evidence service needs operational signals beyond uptime. Track the age and object match of summaries, failed or skipped files, retrieval latency, zero-result questions and the frequency with which users open citations. Review a sample of real questions with engineers who know the repository. Record whether the owning source appeared, whether the cited lines were sufficient and whether the synthesis stayed within the evidence.
Do not optimise citation count. An answer with eight weak excerpts can be harder to verify than one decisive source. Measure whether citations support material claims and whether the system clearly refuses claims it cannot ground. Include branch changes and force-push scenarios in freshness tests, as well as file moves where content survives under a new path.
At trial level, first value is concrete: pair a repository and complete a source-cited query. Later measures can include repeated use, time to reach the owning file and the share of material answers that reviewers can substantiate from the cited evidence. These measures remain product signals, not independent proof of developer productivity.
The next action
A staged adoption checklist
Begin with one repository and a short set of questions whose answers are known by maintainers. Pair the repository, wait for eligible sources to be summarised and verify that the evidence object points to the expected Git revision. Ask both conceptual questions and exact-identifier questions. Include one question the repository cannot answer.
Before expanding access, review the indexing policy: excluded paths, generated artifacts, maximum file sizes, supported languages and the treatment of branches. Confirm that a user without repository access cannot retrieve summaries or excerpts through another endpoint. Inspect logs to ensure they contain operational metadata rather than unnecessary source bodies.
For each evaluation answer, ask five questions: did retrieval find the owning area, are the cited lines current, do they materially support the claim, were important limitations stated, and could a reviewer reproduce the conclusion? Record the failure category instead of only pass or fail.
Once the evidence path is reliable, connect it to an agent workflow in read-only mode. Require the agent to cite before proposing a change. Keep code writes, merges and deployments behind their existing approvals. Repository evidence should improve the information available to those controls, not bypass them.
Finally, establish an operating review. Sample real queries, investigate stale or zero-result cases, and update policies when repository structure changes. If a summary or retrieval rule is wrong, correct that layer and rerun the question. The goal is a system that can show how its repository claims were formed and be repaired where they fail.
Treat changes to retrieval as production changes. A new embedding model, query expansion rule or fusion weight can improve one class of question while burying another. Run the known-question set before release, preserve the previous configuration long enough to compare results and inspect the actual cited sources rather than relying on an aggregate score. When the repository itself changes, refresh the reference answers instead of labelling a newly correct result as regression.
The same discipline applies to model-written summaries. Record which source object and generation path produced them. If the generation route changes, sample summaries for omitted conditions and invented relationships. A summary is navigation material; exact source remains the authority. Keeping that hierarchy explicit is what lets a team benefit from compression without mistaking it for proof.
Select one repository with a known architecture and twenty real engineering questions. Record the expected file and lines before testing. Pair the repository, run the questions and review every miss. The purpose is not to manufacture a flattering score. It is to discover whether your context system can tell the difference between relevance and evidence.