feat: Support device_id as bucketing identifier for local evaluation#424
Open
feat: Support device_id as bucketing identifier for local evaluation#424
Conversation
Add support for `bucketing_identifier` field on feature flags to allow using `device_id` instead of `distinct_id` for hashing/bucketing in local evaluation. - When `bucketing_identifier: "device_id"`, use device_id for hash calculations instead of distinct_id - device_id can be passed as method parameter or resolved from context via `get_context_device_id()` - If device_id is required but not provided, raises InconclusiveMatchError to trigger server fallback - Group flags ignore bucketing_identifier and always use group identifier
83cbc1f to
03d2ff8
Compare
Contributor
posthog-python Compliance ReportDate: 2026-02-06 09:56:38 UTC
|
| Test | Status | Duration |
|---|---|---|
| Format Validation.Event Has Required Fields | ✅ | 516ms |
| Format Validation.Event Has Uuid | ✅ | 1507ms |
| Format Validation.Event Has Lib Properties | ✅ | 1507ms |
| Format Validation.Distinct Id Is String | ✅ | 1507ms |
| Format Validation.Token Is Present | ✅ | 1507ms |
| Format Validation.Custom Properties Preserved | ✅ | 1507ms |
| Format Validation.Event Has Timestamp | ✅ | 1506ms |
| Retry Behavior.Retries On 503 | ✅ | 7924ms |
| Retry Behavior.Does Not Retry On 400 | ✅ | 3506ms |
| Retry Behavior.Does Not Retry On 401 | ✅ | 3508ms |
| Retry Behavior.Respects Retry After Header | ❌ | 7312ms |
| Retry Behavior.Implements Backoff | ✅ | 20618ms |
| Retry Behavior.Retries On 500 | ✅ | 6687ms |
| Retry Behavior.Retries On 502 | ✅ | 7172ms |
| Retry Behavior.Retries On 504 | ✅ | 6811ms |
| Retry Behavior.Max Retries Respected | ✅ | 21019ms |
| Deduplication.Generates Unique Uuids | ✅ | 1496ms |
| Deduplication.Preserves Uuid On Retry | ✅ | 6529ms |
| Deduplication.Preserves Uuid And Timestamp On Retry | ✅ | 14044ms |
| Deduplication.Preserves Uuid And Timestamp On Batch Retry | ✅ | 6779ms |
| Deduplication.No Duplicate Events In Batch | ✅ | 1503ms |
| Deduplication.Different Events Have Different Uuids | ✅ | 1507ms |
| Compression.Sends Gzip When Enabled | ✅ | 1507ms |
| Batch Format.Uses Proper Batch Structure | ✅ | 1507ms |
| Batch Format.Flush With No Events Sends Nothing | ✅ | 1005ms |
| Batch Format.Multiple Events Batched Together | ✅ | 1505ms |
| Error Handling.Does Not Retry On 403 | ✅ | 3509ms |
| Error Handling.Does Not Retry On 413 | ✅ | 3507ms |
| Error Handling.Retries On 408 | ❌ | 6509ms |
Failures
retry_behavior.respects_retry_after_header
Retry delay too short: 803ms < 2500ms
error_handling.retries_on_408
Expected at least 2 requests, got 1
…aluation - Rename _hash param from distinct_id to identifier since it now receives device IDs, group keys, and distinct IDs - Replace skip_bucketing_identifier boolean with explicit hashing_identifier param so callers pass the resolved identifier directly for group flags - Make hashing_identifier a required keyword arg in is_condition_match, removing a dead fallback that silently masked potential bugs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Problem
Feature flags need to support using
device_idinstead ofdistinct_idfor bucketing/hashing in local evaluation. This allows consistent flag experiences across anonymous and identified users on the same device.Changes
bucketing_identifierfield support onflag["filters"]- can be"distinct_id","device_id", or null/missing (defaults to"distinct_id")bucketing_identifier: "device_id", use device_id for hash calculations instead of distinct_idget_context_device_id()InconclusiveMatchErrorto trigger server fallbackbucketing_identifierand always use group identifier (viaskip_bucketing_identifierparameter)Question to the feature flags team: If a flag is configured to use
device_idhas bucketing identifier, but none is provided, should we:a) raise an error and return "false" (current behavior)
b) fall back to use
distinct_idand return whatever that resolves toPersonally I prefer a), as I would like to know when this happens and fix my code.
Testing
bucketing_identifier: "device_id"uses device_id for hashingbucketing_identifieruses distinct_idget_context_device_id()is used when param not providedaggregation_group_type_indexcontinues to use group identifieronly_evaluate_locally=Truereturns None when device_id required but missingget_all_flagsproperly handles device_id bucketing