fix(relay): charge overlapping shared selectors once per item - #33
Closed
albertovincenzi wants to merge 1 commit into
Closed
fix(relay): charge overlapping shared selectors once per item#33albertovincenzi wants to merge 1 commit into
albertovincenzi wants to merge 1 commit into
Conversation
Collaborator
Author
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.
Problem
A document may legally declare two budgets with the same
sharedKeywhen their window parameters agree. This is useful for disjointwhenOpselectors, but overlapping selectors exposed a grouping bug: both budget declarations resolved to the same physical KV key and the same message contributed its cost twice. Aphoto.deletematchingphoto.*andphoto.deletetherefore consumed two tokens from one shared counter.That disagrees with the physical model used elsewhere (one key is one counter), makes the effective limit depend on how selectors are factored, and can throttle traffic at half the declared ceiling.
Fix
Deduplicate each message's contributions by resolved KV-key index while building the charge group. Different messages still accumulate normally, and disjoint selectors keep their existing behavior; only a second match for the same message and same physical counter is suppressed.
A focused regression builds two overlapping selectors over one shared key and proves two messages produce a delta of 2, not 3.
Notes for Alice
The deduplication is deliberately per message, not per batch and not per declaration. A message passing through two different nodes may still charge a shared counter twice because those are two node visits. This PR only corrects duplicate declarations/selectors inside one node evaluation that resolve to the exact same key.
Verification
cargo fmt --all -- --checkcargo test --workspacecargo clippy --workspace --all-targets -- -D warnings