Skip to content

feat(flags): Bucket rollouts by feature name for new flags - #184

Merged
jaydgoss merged 10 commits into
mainfrom
jaygoss/vdy-161-feature-specific-bucketing
Sep 29, 2026
Merged

jaydgoss merged 10 commits into
mainfrom
jaygoss/vdy-161-feature-specific-bucketing

Conversation

@jaydgoss

@jaydgoss jaydgoss commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR targets main and keeps the existing BigInt remainder calculation. #187 is a possible future optimization, not a dependency.

Use the feature name in the rollout hash for new features: sha1("name:key:value:..."). This prevents all new features from using the same rollout population at a given percentage.

  • Add the public FeatureContext::bucket_id(feature_name) method.
  • Pass the feature name to Feature::from_json(), and use chrono to parse the created_at date when it constructs a feature during evaluation. Store the cutoff comparison in buckets_by_feature. Each check constructs a new Feature, so this result is not cached across checks.
  • Feature::matches() passes its name to Segment::in_rollout only when that flag is set.
  • Cache the serialized context identity so repeated checks can reuse it. Clear this cache and the existing ID cache when context data or identity fields change.
  • Feed the feature name and separator into SHA-1 separately to avoid allocating a temporary prefix string.

Compatibility

The cutoff is the date 2026-10-05, compared by date only.

  • Use the feature-specific hash only when the created_at date is after the cutoff, so the first features to use it are dated 2026-10-06.
  • Keep the identity-only hash for features dated on or before the cutoff, including any time on 2026-10-05. Missing or invalid created_at values also keep that hash.
  • Datetimes are reduced to their date. Values with a UTC offset are converted to UTC first, so 2026-10-05T23:00:00-02:00 counts as 2026-10-06.
  • Keep the behavior of FeatureContext::id() and its existing ID cache. Existing partial rollouts keep their organization assignments.

Test plan

  • Rust tests cover identity-only and feature-specific buckets, cutoff parsing and the date boundary (including datetimes on the cutoff date and offsets that cross it), and the first matching segment.
  • A regression test checks both hash modes after changes to context data and identity fields.
  • Compare explicit feature-name/context cases, including a name long enough to span multiple SHA-1 blocks, against the original BigInt calculation.
  • Expected bucket values match the reference tests in the closed feat(flagpole): Bucket rollouts by feature name for new flags sentry#125364. That PR is historical test context, not a release dependency.
  • Python client tests cover fixtures before and after the cutoff. Benchmarks use fixtures on both sides of the cutoff.
  • Local validation passed: all 103 Rust library tests, the formatting check, and workspace Clippy with clippy::all denied. Python client results are shown in the PR checks.

Release order

  1. Release this package.
  2. Update the package dependency in sentry, getsentry, and seer.
  3. Deploy the updated clients before the cutoff.

If deployment cannot finish before the cutoff, move FEATURE_BUCKETING_EPOCH in this repo to a later date before release.

Refs VDY-161

@linear-code

linear-code Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

VDY-161

DI-2478

@jaydgoss

jaydgoss commented Sep 25, 2026 •

Copy link
Copy Markdown
Member Author

Rust has() benchmark: Apple M4 Max, release build, 60 samples, reused context, 50% org-ID rollout.

Feature creation date Base fd5a3fac PR 1ce09a2 Change
At or before October 5, 2026, 00:00 UTC 438 ns 499 ns +14%
After October 5, 2026, 00:00 UTC 437 ns 630 ns +44%

New features require a separate hash for each feature, rather than reusing the cached identity-only hash. A possible follow-up, #187, could reduce their check time to ~576 ns (~9% faster), based on a prototype benchmark.

These are Rust microbenchmarks, not request-level timings.

@jaydgoss
jaydgoss marked this pull request as ready for review September 25, 2026 01:27
@jaydgoss
jaydgoss marked this pull request as draft September 25, 2026 01:52
@jaydgoss
jaydgoss force-pushed the jaygoss/vdy-161-feature-specific-bucketing branch from e561ddf to 00704a5 Compare September 25, 2026 01:54
@jaydgoss
jaydgoss changed the base branch from main to jaygoss/optimize-feature-hash-arithmetic September 25, 2026 01:54
@jaydgoss
jaydgoss added this pull request to stack #188 September 25, 2026 01:55
@jaydgoss
jaydgoss force-pushed the jaygoss/vdy-161-feature-specific-bucketing branch from 00704a5 to d2dd4fb Compare September 25, 2026 01:56
@jaydgoss
jaydgoss removed this pull request from stack #188 September 25, 2026 02:10
@jaydgoss
jaydgoss force-pushed the jaygoss/vdy-161-feature-specific-bucketing branch from d2dd4fb to 1ce09a2 Compare September 25, 2026 02:10
@jaydgoss
jaydgoss changed the base branch from jaygoss/optimize-feature-hash-arithmetic to main September 25, 2026 02:10
@jaydgoss
jaydgoss marked this pull request as ready for review September 25, 2026 02:17
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}(?:T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:[-+]\\d{2}:?\\d{2})?)?$",
"description": "The datetime when this feature was created."
"description": "The datetime when this feature was created. This value selects the rollout hash. Keep it unchanged: moving it across the feature-bucketing cutoff can change which organizations are included in a partial rollout."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"description": "The datetime when this feature was created. This value selects the rollout hash. Keep it unchanged: moving it across the feature-bucketing cutoff can change which organizations are included in a partial rollout."
"description": "The datetime when this feature was created. This value impacts the rollout hash method, and should not be changed. Changing the `created_at` value will change which organizations are included in a partial rollout."

We can be more direct here.

Comment thread docs/architecture.md Outdated
- A feature's `segments` are tried in order; the **first** segment whose conditions all match (logical AND) decides the result via its rollout. If no segment matches, the feature is off. A feature with `enabled: false` is always off.
- Rollout: `rollout: 0` → off, `>= 100` → on, otherwise the context is in the rollout iff `id % 100 <= rollout`. The `<=` matches flagpole, so migrating a feature does not move orgs between buckets, even though it means a partial rollout covers one bucket more than its number suggests.
- The context `id` is a SHA-1 hash built from the identity fields: each identity field present in the data, sorted, joined as `key:value:...`. If no `identity_fields` are set, **all** data keys are used (so the id — and the rollout bucket — changes whenever any field differs).
- Features with a `created_at` after 2026-10-05 at 00:00:00 UTC bucket by feature name as well: their id is the same hash over `name:key:value:...`, so two such features at the same rollout reach different orgs, and the same orgs no longer land in the low buckets of every new flag. Features created at or before that instant, or with a `created_at` that does not parse, keep the identity-only id so their in-flight rollouts do not move.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
- Features with a `created_at` after 2026-10-05 at 00:00:00 UTC bucket by feature name as well: their id is the same hash over `name:key:value:...`, so two such features at the same rollout reach different orgs, and the same orgs no longer land in the low buckets of every new flag. Features created at or before that instant, or with a `created_at` that does not parse, keep the identity-only id so their in-flight rollouts do not move.
- Features with a `created_at` after `2026-10-05 00:00:00 UTC` will include the feature name in the context id, so that rollout rates for different features select different groups of organizations. Features created before `2026-10-05` do not include the feature name in context id.

We can be be less verbose here.

Comment thread clients/rust/src/features.rs Outdated
Comment on lines +20 to +21
///
/// Must not predate the deploy of this rule.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not helpful to keep around forever.

Suggested change
///
/// Must not predate the deploy of this rule.

Comment thread clients/rust/src/features.rs Outdated
Comment on lines +22 to +24
const FEATURE_BUCKETING_EPOCH: NaiveDateTime = NaiveDate::from_ymd_opt(2026, 10, 5)
.unwrap()
.and_time(NaiveTime::MIN);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your comment says UTC, but this is a Naive datetime. Why the discrepancy? All of these operations could be handled with NaiveDate objects (after parsing NativeDateTime) as we don't need time precision.

@jaydgoss jaydgoss Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, I’ll switch to NaiveDate and update.

The parser normalizes to UTC, which is why the comment says that.

Comment thread clients/rust/src/features.rs Outdated
/// Accepts a date, a naive datetime with an optional fraction, or a datetime
/// with a UTC offset; naive values are taken as UTC. Values that do not parse
/// return `None`.
fn parse_created_at(raw: &str) -> Option<NaiveDateTime> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need the time components? It seems overly precise given that most values in use are date only.

Comment thread clients/rust/src/features.rs Outdated
}

fn matches(&self, context: &FeatureContext) -> bool {
fn matches(&self, feature_name: &str, context: &FeatureContext) -> bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should feature names be an input to from_json() instead? Now that features need to know their names, doing it when the struct is initialized is a better design.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call.

Comment thread clients/rust/src/features.rs Outdated
context.identity_fields(vec!["organization_id"]);
let feature_name = format!(
"organizations:{}-{organization_id}",
"x".repeat(organization_id % 128)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why 128? Seems like a magic number.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No special reason for 128, just varying the feature name length.

I’ll make those cases explicit so it’s clearer what we’re testing.

@jaydgoss
jaydgoss requested a review from markstory September 28, 2026 17:39
Comment thread clients/rust/src/features.rs Outdated

#[test]
fn test_bucket_id_align_with_python() {
// Pinned against the reference tests in getsentry/sentry#125364.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: Should this be pointing to a specific line of code instead of a pr?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated

The referenced Sentry PR was closed after flagpole moved to
sentry-options, so replace the link with the formula that reproduces
the expected buckets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The debug log recorded the identity-only context id, which is not the
bucket that features created after the cutoff roll out on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jaydgoss
jaydgoss merged commit 29a66c2 into main Sep 29, 2026
28 checks passed
@jaydgoss
jaydgoss deleted the jaygoss/vdy-161-feature-specific-bucketing branch September 29, 2026 16:20
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.

3 participants