Reject duplicate pasted images by content hash - #420
Merged
TheGreatAxios merged 4 commits intoAug 8, 2026
Conversation
Repeated presses of the paste-image shortcut on an unchanged clipboard should not add a second copy of the same screenshot, but nothing currently compares attachments by content, so identical pastes stack up unbounded. Also carries the content hash onto PendingImageAttachment so the test can express identical bytes independent of filename or id.
The clipboard is read into a timestamped file every time, so filename gave no identity to dedupe against and an unchanged clipboard produced unlimited distinct attachments -- an operator hit eleven copies of one screenshot. Comparing the SHA-256 of the decoded bytes against the pending set before adding catches an identical re-paste while leaving genuinely different images untouched, and flashes a clear "already attached" message instead of failing silently.
PendingImageAttachment now always carries a contentHash, so every test fixture that built one by hand needs a value too, and the SHA-256 digest call needs a plain ArrayBuffer-backed view to satisfy BufferSource's type.
…he hash source The rejection flash was reporting the rejected paste's own name, which the operator never saw -- every clipboard read gets a fresh clipboard-<timestamp>.png, so the message pointed at a filename that didn't match the chip already in their prompt. Report the attachment already in the pending set instead. Also add a producer-level test against imageAttachmentFromPath with an oversized fixture, so the pre-cap hashing is pinned by more than the comment above it; make the hash helper module-private since nothing outside this file needs it.
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
Test plan
bun run typecheckbun run buildbun run test