Skip to content

feat: add remote saved groups (savedGroupReferencesRemote) - #157

Merged
andywhite37 merged 5 commits into
mainfrom
feature/remote-saved-groups
Nov 20, 2026
Merged

andywhite37 merged 5 commits into
mainfrom
feature/remote-saved-groups

Conversation

@vazarkevych

@vazarkevych vazarkevych commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

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_remoteGroupIds attribute.

The savedGroupReferencesRemote spec cases were already in tests/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

  • Evaluation: $savedGroup on a remote entry matches when the group id is in __gb_remoteGroupIds, as in the JS SDK. pruneCondition keeps remote references while the ids are unknown.
  • GrowthBook: new remote_group_ids option, plus set_remote_group_ids() / get_remote_group_ids().
  • GrowthBookClient: new UserContext.remote_group_ids, and add_remote_saved_groups(user_context, resolver), which returns a copy of the context with the ids filled in.
  • New remote_saved_groups.py: helpers, plus redis_resolver(redis), which works with any async Redis client. No new dependency.
  • Fail closed: if the ids are unknown (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.
  • README: new "Remote saved groups" section.

How to test

​bash pytest tests/test_remote_saved_groups.py tests/test_spec_coverage.py ​

  • All savedGroupReferencesRemote spec cases pass, in both the sync and async clients.
  • Full suite: 1817 passed. The 2 test_typing.py mypy failures also happen on main: 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

  • Declare savedGroupReferencesRemote for Python in growthbook-app (sdk-versions/python.json), in a separate PR.

Migration

None. Nothing changes unless a payload contains remote groups.

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[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

Comment thread growthbook/growthbook_client.py Resolved
Comment thread growthbook/remote_saved_groups.py Resolved
Comment thread growthbook/remote_saved_groups.py Resolved
Comment thread growthbook/remote_saved_groups.py Resolved
@vazarkevych

Copy link
Copy Markdown
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
vazarkevych force-pushed the feature/remote-saved-groups branch from e0ec5e9 to 56ee9bd Compare November 16, 2026 11:05
@vazarkevych
vazarkevych changed the base branch from strict-condition-types to main November 16, 2026 11:05
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

Comment thread growthbook/growthbook_client.py Resolved
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.
@vazarkevych

Copy link
Copy Markdown
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
andywhite37 force-pushed the feature/remote-saved-groups branch from 6a3d0f9 to 6a9401d Compare November 20, 2026 23:47

@andywhite37 andywhite37 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@andywhite37

Copy link
Copy Markdown
Contributor

@greptile review

@andywhite37
andywhite37 merged commit f07ce0a into main Nov 20, 2026
8 checks passed
@andywhite37
andywhite37 deleted the feature/remote-saved-groups branch November 20, 2026 23:54
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.

2 participants