Skip to content

fix(experimentation): suspend rollout split while an experiment is paused - #9215

Open
zaidrain06 wants to merge 2 commits into
Flagsmith:mainfrom
zaidrain06:fix/experimentation-pause-suspend-rollout
Open

zaidrain06 wants to merge 2 commits into
Flagsmith:mainfrom
zaidrain06:fix/experimentation-pause-suspend-rollout

Conversation

@zaidrain06

Copy link
Copy Markdown

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

When an experiment transitions to ExperimentStatus.PAUSED, transition_experiment_status previously updated only experiment.status, leaving its rollout segment's PERCENTAGE_SPLIT condition active so identities kept being split across control and treatment variants.

Note that setting FeatureState.enabled = False on a segment override would evaluate matched identities with the flag disabled (enabled: false) rather than falling back to the environment default (control). Instead, this PR suspends and restores the rollout segment's live Condition(operator=PERCENTAGE_SPLIT) value while preserving the configured rollout percentage on segment.rules_data:

  • On RUNNING -> PAUSED (and if apply_experiment_rollout is called while PAUSED), set the rollout segment's PERCENTAGE_SPLIT condition to "0.0" and invalidate the project's environment segments cache (clear_environments_cache()) so identities fall back cleanly to the environment default (control).
  • On PAUSED -> RUNNING, restore the PERCENTAGE_SPLIT condition from segment.rules_data and invalidate the segments cache so the configured rollout split resumes seamlessly.
  • Read the configured rollout_percentage from segment.rules_data in get_experiment_rollout (with fallback to the Condition row) so the API/UI continues displaying the configured rollout percentage while paused.
  • Update docs/docs/experimentation/analyse-an-experiment.md under Pausing the experiment to document the pause/resume behaviour.

How did you test this code?

  • Added unit tests in api/tests/unit/experimentation/test_services.py covering RUNNING -> PAUSED -> RUNNING transitions across both legacy and v2 feature versioning environments, rollout updates while paused, and edge cases without a rollout or with legacy empty rules_data.
  • Verified uv run ruff check, uv run ruff format --check, uv run mypy, python manage.py makemigrations --dry-run --check, pytest (46 passed), and diff-cover (100% across all 32 changed lines).

…used

Set the rollout segment percentage split condition to 0 while paused so identities fall back to the environment default, and restore the configured percentage from segment.rules_data on resume.

Closes Flagsmith#9186

Signed-off-by: Ömer <[email protected]>
@zaidrain06
zaidrain06 requested review from a team as code owners December 2, 2026 11:08
@zaidrain06
zaidrain06 requested review from Holmus and khvn26 and removed request for a team December 2, 2026 11:08
@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates labels Dec 2, 2026

@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

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

Re-trigger cubic

Comment thread api/experimentation/services.py Resolved

@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 docs Documentation updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pausing an experiment only changes its status: the rollout override keeps serving the split

1 participant