Context EngineeringTool and branch provenancePrincipal
How would you keep a coding agent’s source reads and symbol index on a consistent repository snapshot?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A symbol index describes commit A, while a coding agent reads tests from commit B and live uncommitted edits. Its patch matches neither API version. Design snapshot identity and invalidation for its inputs, explain how to apply and test a patch safely as developers continue editing, and compare a pinned private worktree with a live working-tree overlay.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
First identify what the agent was supposed to work against. A Git commit has a tree of versioned files, while a working tree can contain newer and uncommitted edits. Git's data model distinguishes those states. If retrieval says “current repository” but combines an index from commit A with files at commit B plus uncommitted changes, that is not a consistent snapshot. More context can make the contradiction more convincing rather than resolving it.
Consider a hypothetical API change from fetchUser(id) at commit A to fetchUser({id, region}) at commit B. The old symbol summary recommends the positional argument, while a new test expects the object and a required region. Merely including both inputs leaves the model to invent a reconciliation. Read the implementation, tests and dependency contracts from B together, then rebuild or bypass the affected A-derived summary. If the task is explicitly pinned to A, the B test belongs to a later rebase or integration step instead.
I would trace each piece of evidence: repository ID, commit or tree ID, working-tree revision if applicable, index build revision, path and content hash. Find when the index last processed the changed API and whether its references now point to different line numbers. The agent should not silently treat an old symbol summary as authoritative after seeing a new test. It can flag a revision mismatch, inspect the actual source, and refresh or bypass stale derived context. A generated embedding or graph edge is an acceleration structure, not a source of truth.
For a single-agent task, one choice is a pinned commit plus a private worktree. The agent reads and patches that snapshot, then tests and merges against the current target with conflict detection. If the requirement is to incorporate live uncommitted work, take an explicit snapshot or maintain revisioned overlays, and tell the agent which paths may have changed. Snapshot capture itself needs a consistency rule. Reading HEAD, copying files and then reading HEAD again cannot detect uncommitted writes that leave HEAD unchanged. An immutable tree or filesystem snapshot is one option. A live overlay can use a revisioned manifest of relevant content hashes, provided reads are served from those captured bytes. A directory of independently copied files can still mix moments in time.
At the edit boundary, compare expected file hashes or commit ancestry before applying a patch. The comparison and write must be protected against a concurrent edit, for example by workspace ownership or a suitable compare-and-apply operation. A successful hash check followed by an unguarded write leaves another race. Include relevant newly added files and changed dependencies in the precondition, not only the file receiving the patch. At the merge boundary, rerun relevant tests against the actual merged tree. One cannot guarantee that a long run sees a moving repository atomically by checking HEAD once at the beginning.
Should every index update block the agent? No. A stale index entry for an unrelated path may not matter. Track dependencies and invalidate the affected symbol or file context, then refetch on demand. But if the old API signature is central to the patch, fail the read as stale or mark the response so the agent must inspect source. Test a race where the API changes between retrieval and edit, and another where tests change after the patch but before merge. The important property is provenance that survives into the decision. Several coding agents edit one repository. What can you safely merge? asks how several agents' edits can merge. This question asks whether even one agent's inputs described the same repository.
Related questions
Keep practising context engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux