Repository navigation
feat: add remote saved groups (savedGroupReferencesRemote) - #157
Merged
Merged
Conversation
[Medium impact] The PR appears safe to merge; no new actionable issue remains. Reviews (6) · Last reviewed commit: "fix: batch Redis lookups and keep remote..." · Reviewed by Greptile |
Collaborator
Author
|
@greptile review |
pytest_generate_tests only parametrizes the sections a test asks for, so a section nothing runs was skipped silently: savedGroupReferencesRemote has been in cases.json since the spec 0.12.0 sync without any test. test_spec_coverage fails if cases.json has a section that no test runs and that isn't excluded with a reason. Excluded: urlRedirect (browser only) and savedGroupReferencesRemote (not implemented yet).
Port of growthbook/growthbook#7277. A remote saved group keeps its members outside the payload, which only carries {"type": "remote", "attributeKey": ...}. Conditions read the user's remote group ids from the __gb_remoteGroupIds attribute. - $savedGroup on a remote entry matches when its id is in __gb_remoteGroupIds; a reference with another attributeKey (a derived group) doesn't match, and pruneCondition leaves it undecided while the ids are unknown. $inGroup on a remote entry stays undecided. - UserContext.remote_group_ids, GrowthBook(remote_group_ids=...) and GrowthBook.set_remote_group_ids. The ids win over an attribute of the same name in evaluation and are sent with remote evaluation; the caller's attributes are not modified. - GrowthBookClient.add_remote_saved_groups(user_context, resolver) looks the groups up with an async resolver given only the attributes they use, looks up again if the payload changes mid-lookup, and returns the context unchanged when there are no remote groups or the resolver raises. redis_resolver reads the loader's gb:member:<attribute>:<value> sets from any async client with smembers, with no new dependency. - None means unresolved, so rules using remote groups fail, "not in group" included; one warning is logged, with no attribute values. - Runs the savedGroupReferencesRemote spec sections.
From review of the remote saved groups change: - add_remote_saved_groups looked up again only once when a payload refresh landed mid-lookup; a second refresh left ids that never checked the newest groups, so a member could match its "not in group" rule. It now rechecks after every lookup and, if the payload is still changing after three tries, leaves the groups unresolved so their rules fail closed. - A remote entry without a string attributeKey was skipped by the resolver but evaluated as "not a member", so $not turned it into a match. Evaluation now treats it as undecided, which fails under $not too, and pruneCondition keeps it as written. - get_remote_saved_groups no longer shares one cached list across the process: a resolver could change the cached entries for later users, and two clients with different payloads kept evicting each other's scan. It returns a new list per call, and each client keeps its own RemoteSavedGroupsCache for the missing-ids warning.
vazarkevych
force-pushed
the
feature/remote-saved-groups
branch
from
November 16, 2026 11:05
e0ec5e9 to
56ee9bd
Compare
Collaborator
Author
|
@greptile review |
add_remote_saved_groups passed user_context.attributes to the resolver and returned replace(user_context, ...), which shares that dict. If another task changed the attributes (say account_id) while the resolver awaited, the result paired the new attributes with group ids looked up for the old ones, so rules could treat one account as a member of another's groups. It now snapshots the context once, before the first lookup, and uses that snapshot both for the resolver and for the returned context.
Collaborator
Author
|
@greptile review |
… cache key - redis_resolver sends every SMEMBERS in one redis-py pipeline instead of one round trip per key, as the Go SDK does. Clients now need pipeline(). - With cache_key_attributes set, the remote-eval cache key left out __gb_remoteGroupIds, so a user whose groups changed could get a cached response for the old groups. It's always included now, as in sdk-js. - add_remote_saved_groups docstring: it returns the context itself when there are no remote groups or the lookup fails. - Test that booleans aren't looked up in Redis.
andywhite37
force-pushed
the
feature/remote-saved-groups
branch
from
November 20, 2026 23:47
6a3d0f9 to
6a9401d
Compare
andywhite37
approved these changes
Nov 20, 2026
andywhite37
left a comment
Contributor
There was a problem hiding this comment.
Evaluation, the resolver contract, Redis keys and number formatting match sdk-js, and the Greptile threads are fixed. I pushed 6a9401d: redis_resolver now uses one pipeline (tested against real Redis, standalone and cluster), and the remote-eval cache key keeps __gb_remoteGroupIds when cache_key_attributes is set. This PR only adds the async version of the resolver. We'll go ahead and merge this now, and we can add a sync version later if needed.
Contributor
|
@greptile review |
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.
What and why
Port of growthbook/growthbook#7277: support for remote saved groups.
A remote saved group keeps its members outside the payload, because the lists can be too large to ship (millions of ids). The payload only says which attribute the group uses. So the SDK can't work out membership by itself: the app passes the user's remote group ids in, directly or through a resolver. Conditions read them as the reserved
__gb_remoteGroupIdsattribute.The
savedGroupReferencesRemotespec cases were already intests/cases.json, but no test ran them. A new coverage test now fails when a spec section is neither run nor excluded with a reason.What changed
$savedGroupon a remote entry matches when the group id is in__gb_remoteGroupIds, as in the JS SDK.pruneConditionkeeps remote references while the ids are unknown.GrowthBook: newremote_group_idsoption, plusset_remote_group_ids()/get_remote_group_ids().GrowthBookClient: newUserContext.remote_group_ids, andadd_remote_saved_groups(user_context, resolver), which returns a copy of the context with the ids filled in.remote_saved_groups.py: helpers, plusredis_resolver(redis), which works with any async Redis client. No new dependency.None), every rule that uses remote groups fails, including "not in group" rules. Lookups are protected against payload refreshes and attribute changes happening mid-lookup.How to test
bash pytest tests/test_remote_saved_groups.py tests/test_spec_coverage.py savedGroupReferencesRemotespec cases pass, in both the sync and async clients.test_typing.pymypy failures also happen onmain: my environment has mypy 1.20, while the project pins 1.18.2.Size
Production code +332 / −4, tests +418, README +32.
Limitations / follow-ups
savedGroupReferencesRemotefor Python ingrowthbook-app(sdk-versions/python.json), in a separate PR.Migration
None. Nothing changes unless a payload contains remote groups.