fix(attachment): use raw content hash to prevent false external-change warnings#2534
Merged
tusharmath merged 6 commits intomainfrom Mar 12, 2026
Merged
fix(attachment): use raw content hash to prevent false external-change warnings#2534tusharmath merged 6 commits intomainfrom
tusharmath merged 6 commits intomainfrom
Conversation
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 "modified externally" warnings caused by a hash mismatch between the line-numbered content stored in metrics and the raw file content read back from disk during external-change detection.
Context
When a file attachment was created, the content hash was computed after line numbers were prepended to each line (e.g.
1:content\n2:more\n). The external-change detector later hashed the raw file bytes from disk — without line numbers — so the two hashes never matched, triggering spurious "file modified externally" warnings on every turn even when the file had not changed.Changes
content_hashfield toAttachmentContent::FileContentthat stores the SHA-256 hash of the raw (unformatted, untruncated) file content, computed before line-numbering is appliedAttachmentServiceto compute and store this raw hash at attachment creation timeUserPromptGeneratorto read the pre-computedcontent_hashfrom the attachment instead of re-hashing the already-formatted contentRateLimiterto use interior mutability (Mutex<State>) so it no longer requires&mut self, allowing it to be stored asArc<RateLimiter>without an outerMutexcontext_engine.rsby inlining thewalk_directoryhelper and removing the empty-git-ls-files fallback branch (an empty list is now treated as a valid result)config-provider→providerandconfig-model→model, removed the standaloneconfigcommand and its shell-plugin handlerKey Implementation Details
The root cause was a two-step process:
AttachmentServiceread the raw file bytes, then formatted them with line numbers viato_numbered_from()UserPromptGeneratorhashed the already-formatted string and stored it as the "last seen" hashThe fix moves hash computation to step 1 (before formatting) and threads the raw hash through
AttachmentContent::FileContentso step 2 can store the correct value.Testing
Links