Skip to content

Preview experiment can lose user state transition due to race with kinto preview sync task #15618

@jaredlockhart

Description

@jaredlockhart

The nimbus_synchronize_preview_experiments_in_kinto celery task races against user state transitions on Preview experiments.

In Section A (experimenter/kinto/tasks.py#L498-L518), the task:

  1. Queries should_publish_experiments and hydrates each one in memory with status=PREVIEW, publish_status=IDLE.
  2. Calls kinto_client.create_record(data) (slow network I/O).
  3. Inside a transaction.atomic(), sets published_dto + published_date on the stale in-memory instance and calls experiment.save(), which writes all fields back.

If a user clicks "Request Launch" on the same Preview experiment between (1) and (3) — PreviewToReviewForm commits status=DRAFT, status_next=LIVE, publish_status=REVIEW — the task's experiment.save() overwrites those changes back to status=PREVIEW, publish_status=IDLE. The user sees the HTMX response render Review controls, then a hard refresh shows the experiment still in Preview.

Fix

In Section A, re-fetch the row with select_for_update() filtered on status=PREVIEW inside the transaction. If the experiment is no longer in Preview, skip the DB update — the next sync run reconciles Kinto via Section C. Also narrow the save() call with update_fields=["published_dto", "published_date"] so we don't write back fields we didn't intend to change.

Acceptance Criteria

  • A concurrent user transition out of Preview during the Kinto push is preserved (not reverted by the task).
  • Regression test in TestNimbusSynchronizePreviewExperimentsInKinto covers this case.

┆Issue is synchronized with this Jira Task

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions