Skip to content

fix(Mappers): Env document includes feature-specific segments with no FeatureSegment in env#7346

Merged
khvn26 merged 1 commit intomainfrom
fix/scope-feature-specific-segments-by-feature-segment
Apr 27, 2026
Merged

fix(Mappers): Env document includes feature-specific segments with no FeatureSegment in env#7346
khvn26 merged 1 commit intomainfrom
fix/scope-feature-specific-segments-by-feature-segment

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented Apr 24, 2026

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7333

map_environment_to_engine loaded every canonical project segment into every environment document, including feature-specific segments (Segment.feature_id IS NOT NULL) that had no FeatureSegment pointing at them in that environment. _get_segment_feature_states already env-scopes each segment's feature-states list, so those segments ended up as {id, name, rules, feature_states: []} — but their rules payload stayed, and that's what drove per-env document size.

After computing the per-env feature-states dict, drop feature-specific segments with no entry in it. Project-wide segments (feature_id IS NULL) remain unfiltered.

Feature-specific segments are schema-scoped to one feature and reach evaluation only via FeatureSegment(feature=F, segment=S, environment=E). If no such row exists for env E, S has no evaluation path in E.

On one project we measured (178 envs, substantial feature-level targeting), this drops per-env feature-specific-segment count from ~8,270 to ~46 — large enough to fit a project that currently overflows DynamoDB's 400 KB BatchWriteItem limit.

How did you test this code?

Red-green TDD:

  • test_map_environment_to_engine__feature_specific_segment_not_in_env__excludes_segment — feature-specific segment with no FeatureSegment in the env is dropped from the document.
  • test_map_environment_to_engine__feature_specific_segment_in_env__includes_segment — feature-specific segment with a FeatureSegment in the env is retained.
  • test_map_environment_to_engine__project_wide_segment_not_in_env__includes_segment — project-wide segments remain in the document regardless.

Full mapper test suite passes (25/25); make typecheck clean.

… FeatureSegment in env

Feature-specific segments (Segment.feature_id IS NOT NULL) reach
evaluation only via a FeatureSegment in the target environment. Without
one they have no evaluation path, but their rules still shipped in the
environment document and inflated its size.

beep boop
@khvn26 khvn26 requested a review from a team as a code owner April 24, 2026 20:37
@khvn26 khvn26 requested review from Zaimwa9 and removed request for a team April 24, 2026 20:37
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, reopen this pull request to trigger a review.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Apr 24, 2026 8:37pm
flagsmith-frontend-preview Ignored Ignored Apr 24, 2026 8:37pm
flagsmith-frontend-staging Ignored Ignored Apr 24, 2026 8:37pm

Request Review

@github-actions github-actions Bot added api Issue related to the REST API fix labels Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-7346 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-7346 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-7346 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-7346 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-7346 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7346 Finished ✅ Results

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.43%. Comparing base (dbd79bb) to head (f4c4723).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7346   +/-   ##
=======================================
  Coverage   98.43%   98.43%           
=======================================
  Files        1395     1395           
  Lines       52495    52510   +15     
=======================================
+ Hits        51672    51687   +15     
  Misses        823      823           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  11 passed

Details

stats  11 tests across 8 suites
duration  44.2 seconds
commit  f4c4723
info  🔄 Run: #16336 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  11 passed

Details

stats  11 tests across 8 suites
duration  28.3 seconds
commit  f4c4723
info  🔄 Run: #16336 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  17 passed

Details

stats  17 tests across 14 suites
duration  60 seconds
commit  f4c4723
info  🔄 Run: #16336 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  47.3 seconds
commit  f4c4723
info  🔄 Run: #16336 (attempt 1)

@github-actions
Copy link
Copy Markdown
Contributor

Visual Regression

16 screenshots compared. See report for details.
View full report

@khvn26 khvn26 merged commit 7145da4 into main Apr 27, 2026
36 checks passed
@khvn26 khvn26 deleted the fix/scope-feature-specific-segments-by-feature-segment branch April 27, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Env document: scope feature-specific segments by FeatureSegment reference

2 participants