fix(attachment): hash full file content instead of range content and consolidate FileInfo#2578
Merged
tusharmath merged 2 commits intomainfrom Mar 16, 2026
Merged
fix(attachment): hash full file content instead of range content and consolidate FileInfo#2578tusharmath merged 2 commits intomainfrom
tusharmath merged 2 commits intomainfrom
Conversation
d09b545 to
c9ac261
Compare
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 attachment content hashing to always use full file content instead of the requested range, and consolidate file metadata fields into a
FileInfostruct for cleaner APIs.Context
The external-change detector compares stored content hashes against hashes of subsequent file reads. Previously, the hash was computed from only the range of lines requested (e.g., lines 2-4 of a 10-line file), meaning a full-file read and a ranged read of the same unmodified file would produce different hashes. This caused the change detector to incorrectly flag files as externally modified when they hadn't been touched.
Additionally,
ReadOutputandAttachmentContenthad four separate flat fields (start_line,end_line,total_lines,content_hash) that were always set and used together, creating unnecessary boilerplate at every construction and access site.Changes
range_read_utf8inforge_fsnow hashes the full file content (all lines) rather than only the requested range, ensuring consistent hashes across full and partial reads of the same fileFileInfo::new(start_line, end_line, total_lines, content_hash)constructor and consolidated the four flat metadata fields into a singleinfo: FileInfofield onReadOutputandAttachmentContentforge_app,forge_services, andforge_domainto use the newFileInfostructsha2dependency toforge_fsfor computing full-file content hashes in the read layerFileReaderInfra::range_read_utf8to clarify the hashing contractKey Implementation Details
The hash is now computed over the complete file content (joined with
\n) before slicing to the requested range. This means callers that store a hash from a ranged read can correctly compare it with a hash from a subsequent full-file read to detect external modifications — both will match as long as the file hasn't changed.Use Cases
content_hashvalues from different read operations on the same file now gets consistent resultsTesting
The test
test_full_vs_ranged_file_hashes_are_equal(and related attachment tests) explicitly verifies that a full-file read and a ranged read of the same file produce identicalcontent_hashvalues.Links
attachement-hash-bugbranch