Skip to content

fix(diff): read the target commit's blob, not the working tree - #77

Merged
lexasub merged 1 commit into
mainfrom
fix/diff-reads-working-tree
Aug 25, 2026
Merged

fix(diff): read the target commit's blob, not the working tree#77
lexasub merged 1 commit into
mainfrom
fix/diff-reads-working-tree

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Description

Both git-diff paths read the old side from the git object store via
_read_blob and the new side with open(file_path) — the working tree.

compute_diff_for_commits documents "added_nodes: New AST nodes in
to_commit", and ast-rag update takes --from-commit and --to-commit as
required options. So any pair other than <x>..HEAD on a clean tree parses
the current source and stamps it with to_commit.

update_from_git has the same line and that one writes to Neo4j — the graph
ends up holding code that never existed at the commit it is labelled with.
Uncommitted work already has its own path in get_workspace_diff, so the two
were not meant to be the same thing.

The new side now comes from _read_blob at the target commit. Absence there,
rather than absence on disk, decides the deletion branch — which also fixes the
case where a file is deleted at to_commit but still present locally.

When to_commit is HEAD and the tree is clean the blob and the file are
identical, so the common path is unchanged.

Related Issue

None filed — found while auditing the temporal/versioning claims in #59.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the code style of this project
  • I have added tests that prove my fix works
  • All new and existing tests passed
  • I have updated the documentation accordingly
  • I have run ast-rag evaluate --all — needs live services; no query or scoring path touched
  • My changes generate no new warnings

Testing

New tests/test_diff_reads_the_named_commit.py builds a throwaway git repo
where alpha sits on line 1 at A, line 2 at B, and line 7 in an uncommitted
edit, then asks for A..B. No Neo4j, Qdrant or network needed.

Without the fix all three fail, reporting the working tree:

AssertionError: `alpha` spans lines 2-3 at to_commit; got 7-8
 +  where 8 = ASTNode(... name='alpha', ... valid_from='b3817cb3ed9c...')

That valid_from is the point: the node is stamped with a commit whose source
it did not come from.

One of the three asserts the weaker property directly — editing an uncommitted
file must not change the reported diff of two fixed commits.

Suite: 257 passed / 1 skipped / 1 xfailed before, 260 / 1 / 1 after (3 new).

Note for review

update_from_git filters candidates through file_changed_since_last_index,
which hashes the file on disk. That is a separate pre-existing issue —
during a historical replay it can skip files whose current contents happen to
match the cache — and is left alone here.

Both git-diff paths read the old side from the object store and the new side
with `open(file_path)`. `compute_diff_for_commits` promises "added_nodes: New
AST nodes in to_commit", and `ast-rag update` takes --from-commit/--to-commit
as required options, so any pair other than <x>..HEAD on a clean tree parses
the current source and stamps it with to_commit.

`update_from_git` has the same line and writes to Neo4j, so the graph ends up
holding code that never existed at the commit it is labelled with.
Uncommitted work already has its own path in `get_workspace_diff`.

Read the new side with `_read_blob` at the target commit. Absence there, not
absence on disk, now decides the deletion branch.
@r0h1tb
r0h1tb requested a review from lexasub as a code owner August 24, 2026 20:40
@github-project-automation github-project-automation Bot moved this to Backlog in raged kanban Aug 24, 2026
@lexasub
lexasub merged commit 3f8b75c into main Aug 25, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in raged kanban Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants