Feat: hash result set in org vaultsts is order sensitive risking spurious change notifications on tied sort results - #1490
Merged
Merged
Conversation
…parison Sort IDs before computing the SHA-256 hash so the stored hash represents set membership rather than row ordering. When a saved search's sort_by field has duplicate values across rows, two evaluations of an otherwise- unchanged result set can produce different orderings, causing spurious 'new results' notifications purely from reordering rather than any real change in vault membership. Sorting the IDs before hashing makes the comparison reflect set-membership changes only, independent of row order.
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.
closes #1385
Problem
hashResultSet in src/routes/orgVaults.ts computed a SHA-256 hash over the raw ids array via JSON.stringify(ids) . Since JSON.stringify preserves array element order, the resulting hash was order-sensitive.
When a saved search's sort_by field had duplicate values across rows (e.g., multiple vaults with the same created_at ), two evaluations of an otherwise-unchanged result set could produce different row orderings — even with the id DESC secondary sort. This caused saved-search.evaluate to detect a spurious "new results" notification purely from reordering rather than any real change in vault membership.
Fix
src/routes/orgVaults.ts — Sorted a copy of the IDs array before hashing:
// diff
[...ids] creates a shallow copy to avoid mutating the original array, and .sort() normalizes the element order so the hash reflects set membership only, independent of row order.
src/tests/orgVaults.savedSearches.test.ts — Updated the order-independence assertion:
// diff
Changes
File │ Change │
src/routes/orgVaults.ts:337 │ Sort IDs before hashing │
src/tests/orgVaults.savedSearches.test.ts:136 │ Assert order-independent hash │
Testing