Page MenuHomePhabricator

PHP + JS SDKs are not including correct contextual attributes with experiment events
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

Growth Team's revise tone experiment is not including expected values for performer.id and performer.edit_count as contextual attributes that are included in the custom stream (mediawiki.product_metrics.contributors.experiments) for the experiment.

What happens?:

SELECT count(*)
FROM event.mediawiki_product_metrics_contributors_experiments 
WHERE experiment.enrolled = 'growthexperiments-revise-tone'
  AND year = 2026 AND month = 2 AND day >= 10
  AND performer.id IS NOT NULL;

returns 0 rows

but before 2/10:

SELECT count(*)
FROM event.mediawiki_product_metrics_contributors_experiments 
WHERE experiment.enrolled = 'growthexperiments-revise-tone'
  AND year = 2026 AND month = 2 AND day < 10
  AND performer.id IS NOT NULL;

returns 970086 rows

What should have happened instead?:

Queries for 2/10 (when the experiment was restarted) should include values for performer.id and performer.edit_count

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Relevant patches that were recently merged:

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/GrowthExperiments/+/1218398

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/TestKitchen/+/1227747

Event Timeline

cjming triaged this task as Unbreak Now! priority.Feb 10 2026, 10:36 PM
cjming updated the task description. (Show Details)

Change #1238478 had a related patch set uploaded (by Clare Ming; author: Clare Ming):

[operations/mediawiki-config@master] Add `mediawiki.product_metrics.contributors.experiments` to `wgTestKitchenExperimentStreamNames`

https://gerrit.wikimedia.org/r/1238478

After wrestling with my local dev and trying to figure out how to get the experiment to send events on my local, I'm looking at Experiment.metricsClient.streamConfigs on both my local and on enwiki prod and not seeing the expected stream mediawiki.product_metrics.contributors.experiments - it's defaulting to product_metrics.web_base which doesn't have the performer_id and performer_edit_count which I think explains why we're not seeing those values in the event table.

enwiki:

Screenshot 2026-02-10 at 8.47.47 PM.png (2,782×1,584 px, 682 KB)

local:

Screenshot 2026-02-10 at 9.04.51 PM.png (2,788×1,482 px, 657 KB)

I think we need to add mediawiki.product_metrics.contributors.experiments to the $wgTestKitchenExperimentStreamNames variable
https://gerrit.wikimedia.org/r/c/operations/mediawiki-config/+/1238478

After I did that on my local, I could send the event with the performer values and see the validated event in my local EventGate:

Screenshot 2026-02-10 at 9.33.07 PM.png (1,362×896 px, 234 KB)

{F71807389}

Now I see mediawiki.product_metrics.contributors.experiments in the list of streamConfigs on my local:

Screenshot 2026-02-10 at 9.40.04 PM.png (1,384×1,288 px, 343 KB)

I don't know if the fix to this is as simple as adding the custom stream name to that config var -- I'm testing the PHP SDK and I think there is also a bug there:

In ReviseToneExperimentInteractionLogger::log, the following sequence of methods are called:

...
$experimentConfig = $experiment->getExperimentConfig();
...
$experiment->setStream( self::EXPERIMENT_STREAM );
$experiment->send(
	$action,
	$interactionData
);

I was having a hard time getting the config for GE set up to test the actual log function so I tried a simple PageVisit experiment on my local that does basically the same thing (i.e. gets the experiment by name from the ExperimentManager, sets a new stream on the experiment, then sends the event from the Experiment object).

As I step debug through the code, it looks like $experimentConfig['contextual_attributes'] never gets updated after calling send:

Screenshot 2026-02-10 at 11.00.32 PM.png (2,410×1,680 px, 572 KB)

In my local config, I have:

$wgEventStreams = [
	'mediawiki.product_metrics.contributors.experiments' => [
		'schema_title' => 'analytics/product_metrics/web/base',
		'destination_event_service' => 'eventgate-analytics-external',
		'producers' => [
			'metrics_platform_client' => [
				'provide_values' => [
					"performer_is_logged_in",
					"performer_is_temp",
					"performer_is_bot",
					"performer_pageview_id",
					"performer_active_browsing_session_token",
					"mediawiki_skin",
					"mediawiki_database",
					"performer_id",
					"performer_edit_count"
				],
			],
		],
		'eventgate' => [
			'enrich_fields_from_http_headers' => [
				'http.request_headers.user-agent' => false,
			],
			'use_edge_uniques' => true,
		]
	]
]

Which is not what is in $experimentConfig['contextual_attributes'] by the time the eventSubmitter gets all the data.

The ExperimentManager's constructor sets $staticStreamConfigs via StreamConfigs:: getContextualAttributesForStream( $streamName)

Would the solution here be to reset the contextual attributes inside Experiment::setStream()? Or call a new function that resets contextual attributes for the stream after Experiment::setStream() is called to update $experimentConfig?

Only ExperimentManager knows about StreamConfigs - maybe client code has to reset contextual attributes on the ExperimentManager after setting a new stream name on the Experiment object?

Client code could then do something like:

$experiment = $this->experimentManager->getExperiment( self::EXPERIMENT_NAME );
$experiment->setStream( self::STREAM_NAME );
$experiment->setContextualAttributesByStreamName(
     self::STREAM_NAME,
     $this->experimentManager->getStreamConfigs()
);
$experiment->send( $action, $interactionData );

Change #1238610 had a related patch set uploaded (by Clare Ming; author: Clare Ming):

[mediawiki/extensions/TestKitchen@master] Update Experiment and ExperimentManager

https://gerrit.wikimedia.org/r/1238610

Change #1238478 merged by jenkins-bot:

[operations/mediawiki-config@master] Add `mediawiki.product_metrics.contributors.experiments` to `wgTestKitchenExperimentStreamNames`

https://gerrit.wikimedia.org/r/1238478

Mentioned in SAL (#wikimedia-operations) [2026-02-11T08:06:25Z] <cjming@deploy2002> Started scap sync-world: Backport for [[gerrit:1238478|Add mediawiki.product_metrics.contributors.experiments to wgTestKitchenExperimentStreamNames (T417091)]]

Mentioned in SAL (#wikimedia-operations) [2026-02-11T08:08:45Z] <cjming@deploy2002> cjming: Backport for [[gerrit:1238478|Add mediawiki.product_metrics.contributors.experiments to wgTestKitchenExperimentStreamNames (T417091)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-02-11T08:15:34Z] <cjming@deploy2002> Finished scap sync-world: Backport for [[gerrit:1238478|Add mediawiki.product_metrics.contributors.experiments to wgTestKitchenExperimentStreamNames (T417091)]] (duration: 09m 09s)

As I step debug through the code, it looks like $experimentConfig['contextual_attributes'] never gets updated after calling send:

<snip />

Would the solution here be to reset the contextual attributes inside Experiment::setStream()? Or call a new function that resets contextual attributes for the stream after Experiment::setStream() is called to update $experimentConfig?

Nice catch!

Even though Experiment#setStream() is a stop-gap measure until we've finished T408186: Configure experiments with stream, schema and contextual attributes (by the end of this sprint, hopefully), I think it's worth putting in a little effort and making sure it's ergonomic.

What about making ExperimentManager inject StreamConfigs into the Experiment instance so that Experiment#setStream() can update them as necessary? That way, the developer only has to write:

$e = $experimentManager->getExperiment( 'my-awesome-experiment' );
$e->setStream( 'my-awesome-stream' );

Change #1238610 merged by jenkins-bot:

[mediawiki/extensions/TestKitchen@master] Fix contextual attributes when stream is set

https://gerrit.wikimedia.org/r/1238610

Change #1238799 had a related patch set uploaded (by Clare Ming; author: Clare Ming):

[mediawiki/extensions/TestKitchen@wmf/1.46.0-wmf.15] Fix contextual attributes when stream is set

https://gerrit.wikimedia.org/r/1238799

Change #1238799 merged by jenkins-bot:

[mediawiki/extensions/TestKitchen@wmf/1.46.0-wmf.15] Fix contextual attributes when stream is set

https://gerrit.wikimedia.org/r/1238799

Mentioned in SAL (#wikimedia-operations) [2026-02-11T22:01:16Z] <cjming@deploy2002> Started scap sync-world: Backport for [[gerrit:1238799|Fix contextual attributes when stream is set (T417091)]]

Mentioned in SAL (#wikimedia-operations) [2026-02-11T22:03:26Z] <cjming@deploy2002> cjming: Backport for [[gerrit:1238799|Fix contextual attributes when stream is set (T417091)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-02-11T22:07:57Z] <cjming@deploy2002> Finished scap sync-world: Backport for [[gerrit:1238799|Fix contextual attributes when stream is set (T417091)]] (duration: 06m 41s)

need to dig further -- so far we are still seeing events with the wrong contextual attributes almost an hour after we backported fix to wmf.15

realizing that Group 2 wikis which is what the experiment is running on doesn't get wmf.15 until tomorrow -- so we will check data as soon as it rolls out

Santi and I confirmed that the contributors experiments events are now decorated with the correct contextual attributes.

Thank you for swiftly resolving this, Clare!