Scope Brazil2026ElectionFilter to viewers in Brazil - #64
Open
keithadler wants to merge 1 commit into
Open
Conversation
Brazil2026ElectionFilter is added to the For You pre-scoring chain
unconditionally and never reads the viewer's country, so it currently
applies to every viewer in every country rather than to the viewers the
Electoral Court order covers.
The scoping mechanisms already exist and were simply unused:
- ScoredPostsQuery carries country_code
- Filter::enable(&self, query) gates a filter per request, and is
honoured by the pipeline at candidate_pipeline.rs:352
Eight other filters in the same chain already use enable() for this
purpose (VideoFilter, TopicIdsFilter, NewUserMinEngagementFilter,
InventoryHoldoutFilter and others).
Unknown or empty country codes leave the filter disabled, matching the
existing convention for legal withholding in visibility-filtering, where
viewer_in_withheld_country returns false when the viewer country is not
known.
Adds tests for the enabled, disabled, case-insensitive and unknown-country
cases. Existing tests call filter() directly and are unaffected.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Hi. |
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.
Brazil2026ElectionFilternever reads the viewer's country, so as written it applies to every For You request in every country rather than to the viewers the Electoral Court order covers.Evidence
should_removetakes only the candidate and the viewer's follow list (filter L1363), and the filter is added to the pre-scoring chain unconditionally (pipeline L368).Both mechanisms needed to scope it already exist and are unused:
ScoredPostsQuerycarriescountry_code(query.rs L46)Filter::enable(&self, query)gates a filter per request (filter.rs L21) and is honoured by the pipeline (candidate_pipeline.rs L352)Eight other filters in the same chain already use
enable()for exactly this:VideoFilter,TopicIdsFilter,NewUserMinEngagementFilter,InventoryHoldoutFilterand others.There is also a layering signal. Every other jurisdiction-scoped rule in the repo lives in
visibility-filteringand checks viewer country. No filter inhome-mixer/filters/reads viewer country at all, so this is the only geo-scoped rule in a service with no geo-scoping convention.Change
Adds an
enable()override gating the filter oncountry_code == "br", case-insensitively.Unknown or empty country codes leave the filter disabled, which matches the existing convention for legal withholding:
viewer_in_withheld_countryinvisibility-filtering/rules/tes_rules.rsreturnsfalsewhen the viewer country is not known. Happy to invert that to fail-closed if you would rather over-apply than under-apply on unknown geo.Adds four tests. Existing tests call
filter()directly and are unaffected.If this is intentional
Applying globally does guarantee compliance regardless of geolocation accuracy, which matters with VPNs and travel. If that is the reasoning, please close this, though a comment recording the decision might be worth adding, since the surrounding conventions read the other way.
Caveat
home-mixerships noCargo.toml, so I could not compile or run the tests. The file isrustfmt --checkclean under edition 2021. Verification of the change is on you.