fix: preserve AI attribution when human edits file after AI checkpoint (fixes #1444)#1667
Open
IanMcNelly wants to merge 1 commit into
Open
fix: preserve AI attribution when human edits file after AI checkpoint (fixes #1444)#1667IanMcNelly wants to merge 1 commit into
IanMcNelly wants to merge 1 commit into
Conversation
When a human modifies a file after an AI checkpoint fires but before committing — without triggering a known_human checkpoint — the carryover snapshot could be stale (holding the AI version). This caused the overlap filter to incorrectly strip the human-modified line from unstaged_hunks, leaving it attributed to AI. Fix: skip the committed-vs-unstaged overlap filter entirely when a carryover snapshot is present. With a snapshot, Replace-type unstaged lines represent lines where committed content differs from the AI checkpoint — they should flow to INITIAL, not be re-attributed. Also replace the content-based guard in recover_adjacent_edges with a displaced_to_initial_lines set derived from initial_attributions ∩ recovery_hunks. This prevents edge recovery from re-claiming human-modified lines that were explicitly sent to INITIAL, while still allowing edge recovery for adjacent uncheckpointed lines (inserts/appends) that were never in the attribution loop at all. Fixes git-ai-project#1444 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a human modifies a file after an AI checkpoint fires but before committing — without a
known_humancheckpoint being triggered — AI attribution for the AI's own lines was lost (shown as 100% untracked).Reported in #1444.
Root cause
The carryover snapshot stays stale (holds the AI checkpoint version). An overlap filter in the attribution loop was then stripping the human-modified position from
unstaged_hunksbecause it also appeared incommitted_hunks— incorrectly crediting that committed line to AI. For the modify case (human replaces an AI-written line), this meant the human's content was attributed to AI.Fix
virtual_attribution.rs: Skip the committed-vs-unstaged overlap filter when a carryover snapshot is present. With a snapshot, Replace-type unstaged lines represent content divergence between the AIcheckpoint and the commit — they should flow to INITIAL, not be silently re-attributed.
attribution_recovery.rs/post_commit.rs: Replace the content-based guard inrecover_adjacent_edgeswith adisplaced_to_initial_linesset (intersection ofinitial_attributionsandrecovery_hunks). This blocks edge recovery from re-claiming lines explicitly sent to INITIAL, while preserving edge recovery for genuinely adjacent uncheckpointed inserts/appends.Tests
Added
tests/integration/human_edit_after_ai_checkpoint.rswith four regression tests covering:All existing tests pass including the
delayed_checkout/switch_merge_trace_replaytests.Fixes #1444