fix(file_tracking): use raw content hash for consistent change detection#2381
Merged
tusharmath merged 5 commits intomainfrom Feb 11, 2026
Merged
fix(file_tracking): use raw content hash for consistent change detection#2381tusharmath merged 5 commits intomainfrom
tusharmath merged 5 commits intomainfrom
Conversation
Instead of re-hashing the truncated/formatted content returned by FsReadService, use ReadOutput.content_hash directly which is always computed from the full raw file content. This fixes false positives where files with long lines or >2000 lines were incorrectly reported as externally modified. Co-Authored-By: ForgeCode <noreply@forgecode.dev>
fc5545d to
03a559d
Compare
Add 8 new tests covering real-world scenarios: - Read then write same file (no change / externally modified) - Write then read back (no false positive) - Mixed read and write across multiple files - Read-only file externally modified (correctly detected) - Multiple patches then detect - Write then undo then detect - Truncated read then write Co-Authored-By: ForgeCode <noreply@forgecode.dev>
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.
Summary
Fix false positives in file change detection by using the raw content hash (
ReadOutput.content_hash) directly instead of re-hashing truncated/formatted content. This ensures both the stored hash and the comparison hash are always derived from the same unprocessed file content, eliminating spurious "externally modified" notifications for files with long lines, 2000+ lines, or trailing newlines.Problem
Files that were not modified were being reported as "externally changed." This affected both read-only and written files whenever the displayed content diverged from the raw file content.
Root Cause
The hash comparison in
FileChangeDetector::detect()was inconsistent:fs_read.rs:164—compute_hash(&full_content)).lines().join("\n")reconstructionThese two representations diverge whenever a file has:
max_line_length(truncated bytruncate_line)resolve_range).lines().join("\n"))Fix
Changed
FileChangeDetectorto useReadOutput.content_hashdirectly — the hash already computed from the full raw file by the read service — instead of re-hashing the processedoutput.content.Before (
file_tracking.rs):After:
Tests
test_read_file_with_matching_hash_not_detectedtest_truncated_content_does_not_cause_false_positivetest_truncated_written_file_not_false_positiveChanged Files
crates/forge_app/src/file_tracking.rs— UseReadOutput.content_hashdirectly; update mock to simulate raw vs truncated content divergence (+134 −17)