Skip to content

fix(relay): charge overlapping shared selectors once per item - #33

Closed
albertovincenzi wants to merge 1 commit into
masterfrom
fix/deduplicate-overlapping-shared-charge
Closed

fix(relay): charge overlapping shared selectors once per item#33
albertovincenzi wants to merge 1 commit into
masterfrom
fix/deduplicate-overlapping-shared-charge

Conversation

@albertovincenzi

Copy link
Copy Markdown
Collaborator

Problem

A document may legally declare two budgets with the same sharedKey when their window parameters agree. This is useful for disjoint whenOp selectors, 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. A photo.delete matching photo.* and photo.delete therefore 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 -- --check
  • cargo test --workspace
  • cargo clippy --workspace --all-targets -- -D warnings

@albertovincenzi

Copy link
Copy Markdown
Collaborator Author

Duplicata della #9: entrambe deduplicano il contributo per messaggio e chiave fisica dopo la risoluzione di whenOp/scopeBy. Manteniamo #9 come PR canonica; #22 è già impilata su quella correzione.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant