Page MenuHomePhabricator

xLab: Allow user re-enrollment at specific times
Closed, ResolvedPublic

Description

Background
Growth team is working on the adoption of xLab for experimentation. The feature we want to experiment with is Leveling up notifications. These notifications are sent to users 48h after they register with some engaging messages that vary according to the number of edits the user has done by that time.

In order to send these notifications, GrowthExperiments uses the LocalUserCreated hook to schedule a job with a release timestamp of +48h (see source). GrowthExperiments needs to know if the user is enrolled in the experiment and in which group by this time so it can decide to send different messaging for group A and group B or even send an extra notification for the treatment group.

The only point of enrollment xLab has built in now is BeforeInitialize, which is called early in the request lifecycle. Earlier than LocalUserCreated in an authentication flow. By the time xLab requests enrollment the user object in context is non-registered, so xLab skips enrollment for active logged in experiments (see source), returning a null assignment.

In order to circumvent this problem GrowthExperiments is requesting re-enrollment to xLab before scheduling its notifications so XLab's experiment manager knows about the logged in experiments and is able to enroll users into the experiment and assign some group. To do so, we're re-doing the same steps xLab does with a guaranteed registered user:

  1. Fetch configs
  2. Enroll user
  3. Initialize manager with enrollment result
  4. Decorate output with xLab client JS config vars and body CSS classes

Feature summary (what you would like to be able to do and where):
Ideally GrowthExperiments should do nothing for getting a user enrolled in logged in experiments on account creation. However if that's a non standard use-case it would be sufficient that xLab provides a mechanism to allow re-enrollment at specific places.

Another use cases for Growth that has come up is the retrieval of an assigned group within an action API or rest request.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

  • Experiment assigned group retrieval on account creation
  • Experiment assigned group retrieval on API calls
  • Experiment assigned group retrieval on maintenance scripts
  • ...

Benefits (why should this be implemented?):
Adoption of xLab for more complex features that do not only change web UI but more broad behaviors of the system.

Questions

  • The retrieval of a central ID right after account creation (LocalUserCreated) has been problematic in the past. Are there any better alternatives to subscribe to an account creation and ensure relevant data is there, even at the cost of some delay? Would Domain events be suitable for this?
  • What points of enrollment should xLab support? BeforeInitialize seems only covering a subset of valid use cases, specially for logged in experiments.

Event Timeline

JVanderhoop-WMF moved this task from Incoming to READY TO GROOM on the Test Kitchen board.

This has invited some thinking around generalizing the enrollment authority - our first step is to spike T408133: [Spike] Explore Generalizing Enrollment Authorities

We'll keep this task as a record of the challenges here. T409965: Enable experiment enrollment in the MediaWiki Action API is addressing the use case of Experiment assigned group retrieval on API calls, and we will create a new task to target Experiment assigned group retrieval on account creation.

We'll keep this task as a record of the challenges here. T409965: Enable experiment enrollment in the MediaWiki Action API is addressing the use case of Experiment assigned group retrieval on API calls, and we will create a new task to target Experiment assigned group retrieval on account creation.

That's good to know, ty! We have some hacky code running for solving the account creation use-case. On our last conversation with @phuedx we thought we could remove that code from GrowthExperiments at the end of the Leveling up notifications experiment (which we're planning to turn off today). However I'm realizing that we also have had a long lived metric tracked via statsd and shown in Grafana rather than with analytics instruments (see screenshot). It is kind of a "newcomer experiment exposure" metric. Unless this is a big burden, we'd like to keep these charts because they are part of our current product health monitoring process which is all stats/grafana driven.

Screenshot 2025-11-28 at 13.58.04.png (1×3 px, 669 KB)

Experiment newcomer exposure note: the drop on variant assignation from the last 24h is due to our new notifications feature train deployment to all wikis (including those which were in the experiment).

It would be great if we can reference a phab task for the account creation issue in a docstring alongside our hackish code, and also for monitoring the task and react accordingly.

@Sgs: In T410896: Expose Experiment Enrollment Sampling method, we introduced MediaWiki\Extension\MetricsPlatform\XLab\Coordinator#getAssignmentForUser( string $identifier, string $experimentName ). Could your custom code in GrowthExperiments be rewritten using that?

@Sgs: In T410896: Expose Experiment Enrollment Sampling method, we introduced MediaWiki\Extension\MetricsPlatform\XLab\Coordinator#getAssignmentForUser( string $identifier, string $experimentName ). Could your custom code in GrowthExperiments be rewritten using that?

I can look into it, I have some questions around T410896.