Repository navigation
fix(flags): don't panic on a numeric group key in local evaluation - #332
Merged
Merged
Conversation
Groups is map[string]interface{}, but computeFlagLocally asserted
groups[groupType].(string). A numeric key such as Groups{"company": 42}
panicked in GetFeatureFlag, GetAllFlags and in Enqueue of a Capture with
SendFeatureFlags, and a mixed-targeting condition skipped it silently.
The flags service accepts a string or a JSON number as a group key and
buckets the number by its decimal form, so do the same; other types fall
back to the API.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
dustinbyrne
force-pushed
the
fix/numeric-group-key-panic
branch
from
September 29, 2026 21:52
8f85bab to
f172107
Compare
dustinbyrne
approved these changes
Sep 29, 2026
Contributor
|
thank you again @breken-ai! |
4 of 5 tasks
eli-r-ph
added a commit
that referenced
this pull request
Oct 1, 2026
main's numeric group key fix (#332) added a test whose server fails on any path it does not expect, and it accepts capture only on the legacy /batch/ path. This branch sends capture to /i/v1/analytics/events, so the test reported an unexpected request. The handler now answers capture first with serveCaptureOK, as the other flag tests on this branch do, and drops the dead /batch/ branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
💡 Motivation and Context
Groupsismap[string]interface{}, andGroups{"company": 42}is a natural way to pass a database ID. With local evaluation enabled, any group-aggregated flag then panics:computeFlagLocallydoesgroups[groupType].(string)without a check. The panic happens on the caller's goroutine in:GetFeatureFlag,IsFeatureEnabled,GetFeatureFlagPayloadandGetAllFlags;Enqueueof aCapturewithSendFeatureFlags, which evaluates every flag, so a plain capture call panics once any group flag exists.The mixed-targeting path (#192) uses a checked assertion but then
continues, so a numeric key silently skips a condition-level group condition and the flag comes backfalse.The flags service accepts a JSON number as a group key and buckets it by its decimal form (
hashed_identifierinrust/feature-flags/src/flags/flag_matching.rs:Value::Number(n) => n.to_string()). posthog-python and posthog-node build the hash input with string formatting, so42hashes as"42"there too.The fix adds
groupKeyToString. A string is used as-is. A Go number orjson.Numberis bucketed by its JSON encoding, the same bytes the SDK sends to/flags. Any other type returns an error fromcomputeFlagLocally, so the flag falls back to the API instead of panicking. The mixed path uses the same helper. The assertion dates from the first local evaluation release (#6, 2022-08).💚 How did you test it?
TestFlagNumericGroupKey. For group IDs 0–19 against the 35% rollout fixture, it checks thatint,int64andfloat64keys give the same local result as the string key. It also checks thatEnqueue(Capture{Groups: {"company": 42}, SendFeatureFlags: true})doesn't panic.TestMixedTargetingLocalEvaluation.main, the first test panics onint(0), and the mixed case returnsfalseinstead oftrue.go test ./...,go test -raceon the group/mixed tests,go vet,gofmt -landbin/api-diff(no public API change).📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous
/flags. Bools, maps and similar keys still fall back.