Skip to content

fix(flags): canonicalize numeric group keys for local bucketing - #1071

Draft
Kayvan-Zahiri wants to merge 1 commit into
PostHog:mainfrom
Kayvan-Zahiri:codex/fix-group-flag-key-bucketing
Draft

Kayvan-Zahiri wants to merge 1 commit into
PostHog:mainfrom
Kayvan-Zahiri:codex/fix-group-flag-key-bucketing

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

Motivation and context

Numeric group identifiers currently reach the local rollout hash through Python string interpolation. For a group flag called group-beta at 50% rollout, group key 0.00001 hashes as 1e-05, returning false, while its canonical string key "0.00001" returns true. Invalid group keys such as booleans or containers can also return a definitive local result instead of leaving remote evaluation eligible.

Normalize group keys before bucketing in both legacy flag-level aggregation and mixed condition-level aggregation. Strings stay unquoted, finite numbers use the existing backend-compatible JSON rendering, and unsupported values raise the evaluator's existing inconclusive signal. No public method, option, or type is added.

This follows the published group-key bucketing requirement.

Verification

The new tests use the public Client.get_feature_flag() and Client.evaluate_flags() APIs with locally loaded definitions. They cover legacy/mixed aggregation, finite numeric/string controls, unsupported boolean/null/container/non-finite values, and remote fallback. Before the fix there are 16 failing subtests; after it all pass.

Focused flag suites: 293 passed, 37 subtests passed. Full SDK suite: 4,620 passed, 16 skipped, 78 subtests passed (134 warnings). Repository-wide Ruff formatting/lint, mypy across 300 source files, and the public API snapshot check pass. The local SDK was exercised against its own evaluator and mocked remote responses; no hosted production flag configuration was changed.

A patch changeset is included. No public API snapshot changes are expected.

Agent context

Autonomy: Fully autonomous

Codex independently selected and reproduced this defect while exercising the Python SDK, implemented the scoped fix, and ran regression and quality checks. A human authorized contribution work but has not reviewed this implementation. The PR is a draft and requires human review; it will not be auto-approved or merged.

This branch has not been deployed

No deployments
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