Skip to content

fix(experimentation): keep draft experiment rollout at 0% until started - #9222

Open
saudademjj wants to merge 5 commits into
Flagsmith:mainfrom
saudademjj:fix/draft-experiment-rollout-9177
Open

saudademjj wants to merge 5 commits into
Flagsmith:mainfrom
saudademjj:fix/draft-experiment-rollout-9177

Conversation

@saudademjj

@saudademjj saudademjj commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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 #9177

Draft experiments (ExperimentStatus.CREATED) previously wrote their configured PERCENTAGE_SPLIT directly to live segment Condition rows, causing flag_engine to match identities and serve experiment variants before the experiment was started.

  • Keep segment.rules_data storing the configured rollout percentage, while writing 0.0 to the live ORM Condition rules whenever apply_experiment_rollout runs on a CREATED experiment.
  • Read the configured percentage from Segment.rules_data in get_experiment_rollout (via Segment.objects.all_with_deleted()) so draft rollout reads and no-op checks continue to reflect the configured percentage.
  • Activate the rollout segment on first start (CREATED -> RUNNING) in transition_experiment_status by calling write_segment_rules(segment, segment.rules_data) (relying on Experiment.rebuild_environment_document for the environment document rebuild).
  • Add data migration 0021_zero_draft_rollout_splits (RunPython) to zero live PERCENTAGE_SPLIT conditions on existing CREATED draft experiments while leaving RUNNING experiments untouched.

How did you test this code?

  • Added unit tests covering draft evaluation (enabled=True and enabled=False), environment document activation on first start (CREATED -> RUNNING), and the 0021_zero_draft_rollout_splits data migration; updated existing draft rollout unit tests to assert live 0.0 vs configured rules_data.
  • Ran uv run ruff format --check, uv run ruff check, uv run mypy, uv run python manage.py makemigrations --dry-run --check, and uv run pytest tests/unit/experimentation/ --create-db (1009 passed).

@saudademjj
saudademjj requested a review from a team as a code owner December 2, 2026 17:30
@saudademjj
saudademjj requested review from khvn26 and removed request for a team December 2, 2026 17:30
@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@saudademjj is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@github-actions github-actions Bot added the api Issue related to the REST API label Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.11%. Comparing base (139faae) to head (3d41fdf).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9222      +/-   ##
==========================================
- Coverage   98.96%   98.11%   -0.86%     
==========================================
  Files        1724     1725       +1     
  Lines       73879    73971      +92     
==========================================
- Hits        73113    72574     -539     
- Misses        766     1397     +631     

☔ View full report in Codecov by Harness.
📢 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.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

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

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experimentation: a draft experiment (status created) serves its variants when its rollout is above 0%

1 participant