Page MenuHomePhabricator

refreshLinkRecommendations.php does not run when link-recommendation task type is disabled
Closed, ResolvedPublic

Description

As part of working on T370802: Add a link (Structured task): Release as "turned off" to English Wikipedia, I discovered that the refreshLinkRecommendations.php script does not run when Add Link is disabled via CommunityConfiguration. This is incorrect – the refreshing script is a part of the backend, and as long as the backend flag (GENewcomerTasksLinkRecommendationsEnabled) is enabled, the script should continue running (the CommunityConfiguration flag should affect the frontend only, not the backend). Doing so will enable us to enable Add Link silently, in a way that needs only a community Administrator to enable Add Link via CommunityConfiguration.

Since https://en.wikipedia.org/w/index.php?title=MediaWiki:GrowthExperimentsSuggestedEdits.json&diff=prev&oldid=1237412036, refreshLinkRecommendations.php results in the following at en.wikipedia:

[urbanecm@mwmaint1002 ~]$ mwscript extensions/GrowthExperiments/maintenance/refreshLinkRecommendations.php --wiki=enwiki --verbose
'link-recommendation' is not a link recommendation task type
[urbanecm@mwmaint1002 ~]$

Interestingly, revalidateLinkRecommendations.php works just fine, even though Add Link is disabled via CommunityConfiguration, see T370802#10025055.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Bummer. Thanks for documenting this issue. Is this small enough that we should pull it into the current sprint?

🤨

This error seems to come from:

refreshLinkRecommendations.php
	protected function initConfig(): void {
		$taskTypes = $this->configurationLoader->getTaskTypes();
		$taskType = $taskTypes[LinkRecommendationTaskTypeHandler::TASK_TYPE_ID] ?? null;
		if ( !$taskType || !$taskType instanceof LinkRecommendationTaskType ) {
			$this->fatalError( sprintf( "'%s' is not a link recommendation task type",
				LinkRecommendationTaskTypeHandler::TASK_TYPE_ID ) );
		} else {
			$this->recommendationTaskType = $taskType;
		}
		$this->searchUser = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
	}

Did this ever work?

Anyway. LinkRecommendationUpdater also loads the disabled tasks types to get the config, we may want to do something similar:

LinkRecommendationUpdater.php
	private function getLinkRecommendationTaskType(): LinkRecommendationTaskType {
		if ( !$this->linkRecommendationTaskType ) {
			$taskTypes = $this->configurationLoader->loadTaskTypes();
			if ( $taskTypes instanceof StatusValue ) {
				throw new WikiConfigException( 'Could not load task types: ' .
					Status::wrap( $taskTypes )->getWikiText( false, false, 'en' ) );
			}
			$taskTypes = $this->configurationLoader->getTaskTypes() +
				$this->configurationLoader->getDisabledTaskTypes();
			$taskType = $taskTypes[LinkRecommendationTaskTypeHandler::TASK_TYPE_ID] ?? null;
			if ( !( $taskType instanceof LinkRecommendationTaskType ) ) {
				throw new WikiConfigException( 'Could not load link recommendation task type' );
			}
			$this->linkRecommendationTaskType = $taskType;
		}
		return $this->linkRecommendationTaskType;
	}

I looked into this, and the task is relatively straightforward. Moving to sprint.

Change #1058091 had a related patch set uploaded (by Urbanecm; author: Urbanecm):

[mediawiki/extensions/GrowthExperiments@master] refreshLinkRecommendations: Work even when link-recommendation is disabled

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

Change #1058116 had a related patch set uploaded (by Urbanecm; author: Urbanecm):

[mediawiki/extensions/GrowthExperiments@wmf/1.43.0-wmf.15] refreshLinkRecommendations: Work even when link-recommendation is disabled

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

Change #1058117 had a related patch set uploaded (by Urbanecm; author: Urbanecm):

[mediawiki/extensions/GrowthExperiments@wmf/1.43.0-wmf.16] refreshLinkRecommendations: Work even when link-recommendation is disabled

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

Change #1058091 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@master] refreshLinkRecommendations: Work even when link-recommendation is disabled

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

Change #1058117 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@wmf/1.43.0-wmf.16] refreshLinkRecommendations: Work even when link-recommendation is disabled

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

Change #1058116 merged by jenkins-bot:

[mediawiki/extensions/GrowthExperiments@wmf/1.43.0-wmf.15] refreshLinkRecommendations: Work even when link-recommendation is disabled

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

Mentioned in SAL (#wikimedia-operations) [2024-07-30T12:02:33Z] <urbanecm@deploy1003> Started scap sync-world: Backport for [[gerrit:1057970|[Growth] hywwiki: Disable Add link backend (T370558)]], [[gerrit:1058117|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]], [[gerrit:rODNS10581164f3e4|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]]

Mentioned in SAL (#wikimedia-operations) [2024-07-30T12:16:43Z] <urbanecm@deploy1003> sync-world aborted: Backport for [[gerrit:1057970|[Growth] hywwiki: Disable Add link backend (T370558)]], [[gerrit:1058117|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]], [[gerrit:rODNS10581164f3e4|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]] (duration: 14m 10s)

Mentioned in SAL (#wikimedia-operations) [2024-07-30T12:17:06Z] <urbanecm@deploy1003> Started scap sync-world: Backport for [[gerrit:1057970|[Growth] hywwiki: Disable Add link backend (T370558)]], [[gerrit:1058117|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]], [[gerrit:rODNS10581164f3e4|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]]

Mentioned in SAL (#wikimedia-operations) [2024-07-30T12:58:42Z] <urbanecm@deploy1003> Started scap sync-world: Backport for [[gerrit:1057970|[Growth] hywwiki: Disable Add link backend (T370558)]], [[gerrit:1058117|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]], [[gerrit:rODNS10581164f3e4|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]]

Mentioned in SAL (#wikimedia-operations) [2024-07-30T13:21:13Z] <urbanecm@deploy1003> Finished scap: Backport for [[gerrit:1057970|[Growth] hywwiki: Disable Add link backend (T370558)]], [[gerrit:1058117|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]], [[gerrit:rODNS10581164f3e4|refreshLinkRecommendations: Work even when link-recommendation is disabled (T371316)]] (duration: 22m 31s)

Did this ever work?

It very likely never did. That's why I mentioned we need to check this in EngSync, as I recalled we had to enable the task in CC before working with the task pool.

Anyway, it does work now:

[urbanecm@mwmaint1002 ~]$ mwscript extensions/GrowthExperiments/maintenance/refreshLinkRecommendations.php --wiki=enwiki
Refreshing link recommendations...
  processing topic biography...
    no new tasks needed
  processing topic women...
    no new tasks needed
  processing topic food-and-drink...
    no new tasks needed
  processing topic internet-culture...
    no new tasks needed
  processing topic linguistics...
    no new tasks needed
  processing topic literature...
    no new tasks needed
  processing topic books...
    no new tasks needed
  processing topic entertainment...
    no new tasks needed
  processing topic films...
    no new tasks needed
  processing topic media...
    no new tasks needed
  processing topic music...
    no new tasks needed
  processing topic radio...
    no new tasks needed
  processing topic software...
    no new tasks needed
  processing topic television...
    no new tasks needed
  processing topic video-games...
    no new tasks needed
  processing topic performing-arts...
    no new tasks needed
  processing topic philosophy-and-religion...
    no new tasks needed
  processing topic sports...
^C
[urbanecm@mwmaint1002 ~]$

So, all good now.