Skip to content

Avoid Action Scheduler next-action checks before AS datastore initializes during wp-phpunit install #1812

@chubes4

Description

@chubes4

Problem

The Playground proof for Extra-Chill/homeboy-extensions#422 is now green through Stage 3, and Data Machine Code's pre-install schema option warnings were fixed by Extra-Chill/data-machine-code#273 / PR #274.

The only remaining noisy bootstrap output in Stage 1/2 is this Action Scheduler notice:

NOTICE:USER_NOTICE: Function as_next_scheduled_action was called incorrectly. as_next_scheduled_action() was called before the Action Scheduler data store was initialized Please see https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/ for more information. (This message was added in version 3.1.6.) at /wordpress/wp-includes/functions.php:6131 context=stage=load_component hook=wp_loaded wp_installing=true

Stage 3 is clean, and all stages pass, so this is non-blocking noise. It is still a real lifecycle mismatch worth cleaning up upstream.

Likely path

The likely route is activation-time flow re-scheduling:

  • data-machine.phpdatamachine_activate_plugin()
  • datamachine_activate_scheduled_flows() at data-machine.php:716
  • inc/migrations/flows.php delegates non-manual flows to DataMachine\Api\Flows\FlowScheduling::handle_scheduling_update()
  • FlowScheduling delegates to DataMachine\Engine\Tasks\RecurringScheduler::ensureSchedule()
  • RecurringScheduler::ensureSchedule() schedules and then verifies persistence with RecurringScheduler::isScheduled()
  • RecurringScheduler::isScheduled() calls as_next_scheduled_action() when the function exists, but in wp-phpunit's install bootstrap Action Scheduler's function exists before its datastore is initialized.

Relevant code today:

public static function isScheduled( string $hook, array $args, string $group = self::GROUP ): bool {
    if ( ! function_exists( 'as_next_scheduled_action' ) ) {
        return false;
    }
    return false !== as_next_scheduled_action( $hook, $args, $group );
}

Repro

Use the current proof branch and upstream dependencies:

cd /Users/chubes/Developer/wc-store-blueprints@feat-playground-ci-proof-stage3
bash tests/playground-ci/scripts/run-stage-1.sh
bash tests/playground-ci/scripts/run-stage-2.sh

Both pass but print the notice above. run-stage-3.sh passes cleanly.

Expected

No Action Scheduler "called before the Action Scheduler data store was initialized" notice during wp-phpunit/Playground boot.

Suggested fix shape

Smallest reasonable options:

  1. In RecurringScheduler::isScheduled(), also guard for AS datastore readiness before calling as_next_scheduled_action(). If the datastore is not ready, return false or a typed "unavailable" result that callers can handle without triggering _doing_it_wrong().
  2. Or, skip activation-time re-scheduling while wp_installing() is true, similar to DMC's schema-upgrade guard. This may be broader than needed; prefer the scheduler-level guard if it keeps production behavior intact.

Do not change the Playground proof branch or homeboy-extensions to suppress the notice. The scheduler should avoid calling AS read helpers before AS is ready.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions