Commit ae23f0d673d for woocommerce

commit ae23f0d673da4f271c476ffe6c3612afb64e08c0
Author: AnnaMag <AnnaMag@users.noreply.github.com>
Date:   Fri Dec 4 12:34:05 2026 +0100

    Start the first AI shopping health check on page visit, and start requested checks right away (#71805)

    * Start a requested AI shopping health check without waiting for the queue runner.

    Check your store was waiting up to a minute for Action Scheduler's next run. A newly queued scan now starts that runner immediately.

    * Start the queue runner for a requested scan only when the loopback can run.

    Use Action Scheduler's 60-second async runner lock, so a click right after an admin page load does not start a second runner. Send the loopback only for a user logged in by cookie, as its nonce is checked against the request's cookies; requests over application passwords or OAuth still wait for WP-Cron. Skip it when the scan was not queued, and drop the duplicate ajax handler the new runner instance hooks.

    * Start a requested scan when an idle admin page holds the queue lock.

    Action Scheduler sets that lock before it looks for due actions, so a normal admin page leaves it held without a runner. A queue already at its batch limit still does not get another loopback.

    * Start the first AI shopping health check when a merchant opens the page.

    On a store never checked, opening AI shopping health or Settings > AI tools
    queues the first check once, and both show it running with a line on how long
    the first check takes.

    * Name the view route in the README and don't autoload the first-check option.

    * Don't mark the first AI shopping health check as done when it wasn't queued.

    * Decide whether the first check was queued from the scheduling result.

    * Keep Check your store on the button while the first AI shopping health check runs.

    * Drop the Action Scheduler class check from the queue runner start.

diff --git a/plugins/woocommerce/changelog/fix-ai-shopping-health-start-now b/plugins/woocommerce/changelog/fix-ai-shopping-health-start-now
new file mode 100644
index 00000000000..91cd1977aa8
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-ai-shopping-health-start-now
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Check the store as soon as AI shopping health is first opened, and start a requested check right away instead of after a minute.
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/components/checked-card.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/components/checked-card.tsx
index b88ac998303..8d37fbfe0f1 100644
--- a/plugins/woocommerce/client/admin/client/sales-readiness/components/checked-card.tsx
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/components/checked-card.tsx
@@ -4,7 +4,7 @@
 /* eslint-disable @wordpress/use-recommended-components -- The design asks for these @wordpress/ui components; this chunk bundles the package. */
 import { Button, Card, Link, Text } from '@wordpress/ui';
 /* eslint-enable @wordpress/use-recommended-components */
-import { Spinner, ToggleControl } from '@wordpress/components';
+import { ToggleControl } from '@wordpress/components';
 import { createInterpolateElement } from '@wordpress/element';
 import { __ } from '@wordpress/i18n';

@@ -44,15 +44,20 @@ export const CheckedCard = ( {
 			<Card.Content>
 				<div className="wc-sales-readiness-checked">
 					{ checking ? (
-						<div
-							className="wc-sales-readiness-checked__running"
-							role="status"
-						>
-							<Spinner />
-							<Text variant="body-md">
-								{ view.run.message ||
-									__( 'Checking your store', 'woocommerce' ) }
-							</Text>
+						<div>
+							<RunStatus
+								run={ {
+									...view.run,
+									pending: true,
+									stalled: false,
+									message:
+										view.run.message ||
+										__(
+											'Checking your store',
+											'woocommerce'
+										),
+								} }
+							/>
 						</div>
 					) : (
 						<div>
@@ -100,9 +105,7 @@ export const CheckedCard = ( {
 						disabled={ view.run.pending || running }
 						onClick={ onRun }
 					>
-						{ checking
-							? __( 'Check again', 'woocommerce' )
-							: view.run.label }
+						{ view.run.label }
 					</Button>
 				</div>
 				{ ! checking && <RunStatus run={ view.run } /> }
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/components/run-status.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/components/run-status.tsx
index 993a8f377f1..1ce786067eb 100644
--- a/plugins/woocommerce/client/admin/client/sales-readiness/components/run-status.tsx
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/components/run-status.tsx
@@ -1,7 +1,8 @@
 /**
  * External dependencies
  */
-import { Text, VisuallyHidden } from '@wordpress/ui';
+import { Text } from '@wordpress/ui';
+import { Spinner } from '@wordpress/components';

 /**
  * Internal dependencies
@@ -10,16 +11,30 @@ import type { ReadinessView } from '../types';
 import { RowLink } from './check-row';

 /**
- * The check's status under Run check: while it runs, a message for screen readers only (the
- * disabled button shows it's running), and the message itself when the check is stuck, with a
- * button to Scheduled Actions.
+ * The check's status before the first results: a spinner and the message while it runs, with how
+ * long the first check takes, and the message itself when the check is stuck, with a button to
+ * Scheduled Actions.
  */
 export const RunStatus = ( { run }: { run: ReadinessView[ 'run' ] } ) => {
 	if ( run.pending && ! run.stalled ) {
 		return (
-			<div role="status">
-				<VisuallyHidden>{ run.message }</VisuallyHidden>
-			</div>
+			<>
+				<div
+					className="wc-sales-readiness-checked__running"
+					role="status"
+				>
+					<Spinner />
+					<Text variant="body-md">{ run.message }</Text>
+				</div>
+				{ run.note && (
+					<Text
+						variant="body-sm"
+						className="wc-sales-readiness__muted"
+					>
+						{ run.note }
+					</Text>
+				) }
+			</>
 		);
 	}
 	if ( ! run.message ) {
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/overview.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/overview.tsx
index ecd231e88ee..80dd29d0ac7 100644
--- a/plugins/woocommerce/client/admin/client/sales-readiness/overview.tsx
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/overview.tsx
@@ -127,12 +127,14 @@ export default function SalesReadinessOverview( {
 					</Text>
 					{ ! view.checked ? (
 						<>
-							<Text
-								variant="body-sm"
-								className="wc-sales-readiness__muted"
-							>
-								{ view.last_checked }
-							</Text>
+							{ ! ( view.run.pending && ! view.run.stalled ) && (
+								<Text
+									variant="body-sm"
+									className="wc-sales-readiness__muted"
+								>
+									{ view.last_checked }
+								</Text>
+							) }
 							<RunStatus run={ view.run } />
 							<div className="wc-sales-readiness-card__actions">
 								<Button
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/sales-readiness.scss b/plugins/woocommerce/client/admin/client/sales-readiness/sales-readiness.scss
index 779f48948d1..b78cec2aafe 100644
--- a/plugins/woocommerce/client/admin/client/sales-readiness/sales-readiness.scss
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/sales-readiness.scss
@@ -436,22 +436,22 @@ body:has(.wc-sales-readiness) {
 		gap: 2px;
 	}

-	> .wc-sales-readiness-checked__running {
-		flex-direction: row;
-		align-items: center;
-		gap: var(--wpds-dimension-gap-md);
-
-		.components-spinner {
-			margin: 0;
-		}
-	}
-
 	> button {
 		flex-shrink: 0;
 		white-space: nowrap;
 	}
 }

+.wc-sales-readiness-checked__running {
+	display: flex;
+	align-items: center;
+	gap: var(--wpds-dimension-gap-md);
+
+	.components-spinner {
+		margin: 0;
+	}
+}
+
 .wc-sales-readiness-checked__daily {
 	margin-block-start: var(--wpds-dimension-gap-lg);
 	padding-block-start: var(--wpds-dimension-gap-lg);
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/test/checked-card.test.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/test/checked-card.test.tsx
index 64d7e9c0692..6634bb612dc 100644
--- a/plugins/woocommerce/client/admin/client/sales-readiness/test/checked-card.test.tsx
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/test/checked-card.test.tsx
@@ -42,7 +42,32 @@ describe( 'CheckedCard', () => {
 		).toBeNull();
 	} );

-	it( 'shows a spinner, Checking your store and a turned-off Check again while a check runs', () => {
+	it( 'says how long to wait under the spinner while the first check runs', () => {
+		const note =
+			'Your first check can take a few minutes. You can leave this page, and the results show here when it’s done.';
+		render(
+			<CheckedCard
+				view={ {
+					...firstVisit,
+					run: {
+						...firstVisit.run,
+						pending: true,
+						message: 'Checking your store',
+						note,
+					},
+				} }
+				running={ false }
+				onRun={ jest.fn() }
+				onDownloadError={ jest.fn() }
+			/>
+		);
+		expect( screen.getByRole( 'status' ) ).toHaveTextContent(
+			'Checking your store'
+		);
+		expect( screen.getByText( note ) ).toBeInTheDocument();
+	} );
+
+	it( 'shows a spinner, Checking your store and a turned-off Check your store while the first check runs', () => {
 		const running = {
 			...firstVisit,
 			run: {
@@ -67,6 +92,28 @@ describe( 'CheckedCard', () => {
 		);
 		expect( screen.queryByText( 'Not checked yet' ) ).toBeNull();
 		// Turned off but still focusable, so focus stays on it after the click.
+		expect(
+			screen.getByRole( 'button', { name: 'Check your store' } )
+		).toHaveAttribute( 'aria-disabled', 'true' );
+	} );
+
+	it( 'keeps Check again, turned off, while a later check runs', () => {
+		render(
+			<CheckedCard
+				view={ {
+					...firstVisit,
+					run: {
+						...firstVisit.run,
+						label: 'Check again',
+						pending: true,
+						message: 'Checking your store',
+					},
+				} }
+				running={ false }
+				onRun={ jest.fn() }
+				onDownloadError={ jest.fn() }
+			/>
+		);
 		expect(
 			screen.getByRole( 'button', { name: 'Check again' } )
 		).toHaveAttribute( 'aria-disabled', 'true' );
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/test/use-readiness-view.test.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/test/use-readiness-view.test.tsx
index dd1cd627f60..97e626b4317 100644
--- a/plugins/woocommerce/client/admin/client/sales-readiness/test/use-readiness-view.test.tsx
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/test/use-readiness-view.test.tsx
@@ -287,17 +287,24 @@ describe( 'RunStatus', () => {
 		link: null,
 	} );

-	it( 'shows no spinner while a check runs, only its message for screen readers', () => {
+	it( 'shows a spinner and the message while a check runs, with how long the first one takes', () => {
 		const { container } = render(
-			<RunStatus run={ run( true, false, 'Checking your store' ) } />
+			<RunStatus
+				run={ {
+					...run( true, false, 'Checking your store' ),
+					note: 'Your first check can take a few minutes.',
+				} }
+			/>
 		);
-		expect( container.querySelector( '.components-spinner' ) ).toBeNull();
+		expect(
+			container.querySelector( '.components-spinner' )
+		).not.toBeNull();
 		expect( screen.getByRole( 'status' ) ).toHaveTextContent(
 			'Checking your store'
 		);
 		expect(
-			container.querySelector( '.wc-sales-readiness__muted' )
-		).toBeNull();
+			screen.getByText( 'Your first check can take a few minutes.' )
+		).toBeVisible();
 	} );

 	it( 'shows the message once the check is stuck', () => {
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/types.ts b/plugins/woocommerce/client/admin/client/sales-readiness/types.ts
index cc198f46a3e..9ce03079ca9 100644
--- a/plugins/woocommerce/client/admin/client/sales-readiness/types.ts
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/types.ts
@@ -121,6 +121,8 @@ export interface ReadinessView {
 		pending: boolean;
 		stalled: boolean;
 		message: string;
+		/** While the first check runs, how long to wait. Empty otherwise. */
+		note?: string;
 		/** Scheduled Actions, when the check can't start. */
 		link: ViewLink | null;
 	};
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/README.md b/plugins/woocommerce/src/Internal/AgentReadiness/README.md
index beb3833ccf3..180eddbf600 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/README.md
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/README.md
@@ -186,7 +186,7 @@ Per check, `channels` maps a channel id to the feed field and the effect, the sa

 ## Background scan and REST

-"Check your store" on WooCommerce > Sales readiness, or `POST wc/v3/agent-readiness/scan`, queues the scan in Action Scheduler (`ScheduledScan`). The report is stored in the `woocommerce_agent_readiness_report` option (not autoloaded). When daily checks are on, each run schedules the next one for the coming night before scanning (`ScheduledScan::next_daily_run()`: a minute between 1:00 and 5:00 on the store's clock, fixed per store by its address), so a failed scan doesn't stop the daily refresh and a run that starts late doesn't move the next one. A slot less than 6 hours away is left for the night after. "Automatically run checks daily" on the page (`POST wc/v3/agent-readiness/daily-checks`, option `woocommerce_agent_readiness_daily_scan`) turns the daily run off: its action is removed, runs schedule no next one, and checks only run on request. Cancelling the scheduled actions under Tools > Scheduled Actions stops the chain until the next manual check. If a queued scan still hasn't started 10 minutes after it was due and no other scheduled action has finished, failed or started in that time (Action Scheduler isn't running), the Sales readiness page says so and the scan stays queued. The scan never runs in a page or REST request.
+"Check your store" on WooCommerce > Sales readiness, or `POST wc/v3/agent-readiness/scan`, queues the scan in Action Scheduler (`ScheduledScan`). On a store that was never checked, opening AI shopping health or Settings > AI tools queues the first scan without a click (`ScheduledScan::queue_first()`, called from `ReadinessCheckPage::view()`, so `GET wc/v3/agent-readiness/view` does too). The page shows it running, with a line on how long the first check takes. This happens once per store (the `woocommerce_agent_readiness_first_scan` option), so a first scan that gives up without a report isn't queued again on every visit; Check your store still runs one. A newly queued scan requested by a merchant logged in to wp-admin starts Action Scheduler's async queue runner right away (`maybe_dispatch()`), so it doesn't wait up to a minute for WP-Cron or the next admin page load. It takes Action Scheduler's 60-second `async-request-runner` lock when that lock is free, so two requests don't each send a loopback. A lock left by an idle admin page, which sets it before checking for due actions, does not block the scan. A queue already at its batch limit is not sent another loopback. A scan already waiting doesn't send another loopback request. A scan requested without a login cookie (application passwords, OAuth, WP-CLI, cron) still waits for WP-Cron: the loopback request's nonce is checked against the request's cookies. The report is stored in the `woocommerce_agent_readiness_report` option (not autoloaded). When daily checks are on, each run schedules the next one for the coming night before scanning (`ScheduledScan::next_daily_run()`: a minute between 1:00 and 5:00 on the store's clock, fixed per store by its address), so a failed scan doesn't stop the daily refresh and a run that starts late doesn't move the next one. A slot less than 6 hours away is left for the night after. "Automatically run checks daily" on the page (`POST wc/v3/agent-readiness/daily-checks`, option `woocommerce_agent_readiness_daily_scan`) turns the daily run off: its action is removed, runs schedule no next one, and checks only run on request. Cancelling the scheduled actions under Tools > Scheduled Actions stops the chain until the next manual check. If a queued scan still hasn't started 10 minutes after it was due and no other scheduled action has finished, failed or started in that time (Action Scheduler isn't running), the Sales readiness page says so and the scan stays queued. The scan never runs in a page or REST request.

 A scan runs as a chain of actions (`NEXT_HOOK`, with the scan's id), so no action tests more than one batch of products. The first lists the products to test, newest change first (on a catalog over 5,000 products with sales to rank by, best sellers of the last 90 days first, skipping any the scan does not check and reading the next sellers until the limit is filled or the sales run out, then newest change), and stores that list with the totals in the `woocommerce_agent_readiness_scan` option (not autoloaded). Starting reads the store's 90-day totals once (`ProductSales::last_days()`). When those totals say the scan can rank, it then reads the best seller ids, summed in SQL and limited to published products, so memory doesn't grow with the number of products sold. A page of sellers the scan cannot check is followed by the next page, up to ten pages. Each later batch reads only its own products' sales, so the whole store's sales map is never loaded. Each action tests the next batch of 200, saves the totals and queues the next; the last builds the report, with the store output checks, and stores it. Before testing, an action queues a retry RETRY_AFTER (10 minutes) later, which it removes when it finishes, so a batch that ends early, as on a timeout, is tried again from the last finished batch. After MAX_ATTEMPTS (3) tries of the same batch, the scan stops and the last report stays. Giving up, cancelling, or replacing a scan removes failure rows it wrote for products the last report never covered, so the Products list stays aligned with that report. A new request (or the daily run) replaces a scan in progress and starts over; the replaced scan's actions change nothing. `refresh_report()` runs the same steps in one request.

diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
index 97424520705..3fb451be562 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
@@ -292,9 +292,10 @@ class ReadinessCheckPage implements RegisterHooksInterface {
 	 */
 	public function view(): array {
 		self::$failing_ids = array();
+		$queued            = $this->scheduled_scan->queue_first();
 		// Pending on either side of the report read: a scan that finishes during the read must not
 		// pair an old report with pending false, and a scan queued during the read must not be hidden.
-		$pending  = $this->scheduled_scan->is_pending();
+		$pending  = $queued || $this->scheduled_scan->is_pending();
 		$report   = $this->agent_readiness->get_cached_report();
 		$pending  = $pending || $this->scheduled_scan->is_pending();
 		$stalled  = $pending && $this->scheduled_scan->is_stalled();
@@ -334,6 +335,8 @@ class ReadinessCheckPage implements RegisterHooksInterface {
 				'pending' => $pending,
 				'stalled' => $stalled,
 				'message' => $message,
+				// The first check has no results to show yet, so say how long to wait.
+				'note'    => $pending && ! $stalled && null === $report ? __( 'Your first check can take a few minutes. You can leave this page, and the results show here when it’s done.', 'woocommerce' ) : '',
 				'link'    => $stalled ? array(
 					'href' => admin_url( 'admin.php?page=wc-status&tab=action-scheduler&status=pending' ),
 					'text' => __( 'View Scheduled Actions', 'woocommerce' ),
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php b/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php
index fb86340fc19..3489b914598 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ScheduledScan.php
@@ -16,7 +16,8 @@ defined( 'ABSPATH' ) || exit;
  * (next_daily_run()), unless the merchant turned daily checks off (DAILY_OPTION),
  * so nothing is queued until a
  * merchant or the REST API asks for the first scan, and no request pays for a
- * scheduling check. The next run is scheduled before the scan, so a scan that
+ * scheduling check. A scan requested by a merchant logged in to wp-admin starts the
+ * queue runner at once, so it doesn't wait for the next WP-Cron run. The next run is scheduled before the scan, so a scan that
  * fails or times out does not end the chain. Cancelling the scheduled actions
  * under Tools > Scheduled Actions stops the chain until the next manual check.
  *
@@ -52,6 +53,11 @@ class ScheduledScan implements RegisterHooksInterface {
 	 */
 	public const DAILY_OPTION = 'woocommerce_agent_readiness_daily_scan';

+	/**
+	 * Set once a page visit queued the first scan, so a first scan that gives up without a report isn't queued again on every visit.
+	 */
+	public const FIRST_SCAN_OPTION = 'woocommerce_agent_readiness_first_scan';
+
 	/**
 	 * Hours of the night, on the store's clock, between which the daily scan is scheduled.
 	 */
@@ -114,12 +120,79 @@ class ScheduledScan implements RegisterHooksInterface {
 	 * Queue a scan unless one is already waiting or running.
 	 */
 	public function queue(): void {
+		$this->queue_now();
+	}
+
+	/**
+	 * Queue a scan unless one is already starting.
+	 *
+	 * @return bool Whether this request queued a scan.
+	 */
+	private function queue_now(): bool {
 		// A scan already testing batches is replaced: the new one starts over with the current catalog.
-		if ( ! $this->is_starting() ) {
-			// A single action due now rather than an async one, which has no date to tell a stalled scan by.
-			// Unique, so two requests that both found nothing pending still queue one scan.
-			as_schedule_single_action( time(), self::RUN_NOW_HOOK, array(), self::GROUP, true );
+		if ( $this->is_starting() ) {
+			return false;
+		}
+		// A single action due now rather than an async one, which has no date to tell a stalled scan by.
+		// Unique, so two requests that both found nothing pending still queue one scan.
+		// Only for a scan this request queued: a waiting one already started the runner, and repeat clicks must not each send a loopback.
+		if ( ! as_schedule_single_action( time(), self::RUN_NOW_HOOK, array(), self::GROUP, true ) ) {
+			return false;
+		}
+		self::start_queue_runner();
+		return true;
+	}
+
+	/**
+	 * Queue the first scan when a merchant opens AI shopping health or AI tools on a store that was never checked,
+	 * so the page shows the check running instead of asking for a click. Once per store.
+	 *
+	 * @since 11.5.0
+	 *
+	 * @return bool Whether it queued the scan. The caller counts it as pending: the queue runner may finish it
+	 *              before the caller reads, and this request has already cached the report as missing.
+	 */
+	public function queue_first(): bool {
+		if ( false !== get_option( self::FIRST_SCAN_OPTION ) ) {
+			return false;
+		}
+		// A missing Action Scheduler must not take the page down. Not marked as done, so a later visit still queues it.
+		if ( ! ActionSchedulerUtil::is_ready() ) {
+			return false;
+		}
+		$queue = ! $this->is_pending() && null === $this->agent_readiness->get_cached_report();
+		// Action Scheduler can refuse the action. Then nothing is marked, so a later visit tries again.
+		// Decided from the scheduling result, not a later read: the queue runner can finish the scan before that read.
+		if ( $queue && ! $this->queue_now() ) {
+			return false;
+		}
+		// Set even when nothing was queued: a scan that gives up isn't retried on every visit. Check your store still queues one.
+		update_option( self::FIRST_SCAN_OPTION, 'yes', false );
+		return $queue;
+	}
+
+	/**
+	 * Run the queue now instead of on the next WP-Cron run or admin page load, which can be a minute away.
+	 * Takes Action Scheduler's async runner lock when it is free: its maybe_dispatch_async_request() only runs in admin pages, not REST,
+	 * and it sets that lock before it looks for due actions, so an idle admin page holds the lock with no runner.
+	 * A queue already at its batch limit is refused by maybe_dispatch(), which also applies the runner filter.
+	 * Only for a user logged in by cookie, as the loopback request's nonce is checked against this request's cookies.
+	 * Otherwise, or if the loopback fails, WP-Cron runs the scan as before.
+	 */
+	private static function start_queue_runner(): void {
+		if ( wp_validate_auth_cookie( '', 'logged_in' ) !== get_current_user_id() ) {
+			return;
+		}
+		$lock = \ActionScheduler::lock();
+		// An idle admin page leaves this lock set. Only a lost race for a free lock bails; a running queue is refused below.
+		if ( ! $lock->is_locked( 'async-request-runner' ) && ! $lock->set( 'async-request-runner' ) ) {
+			return;
 		}
+		$runner = new \ActionScheduler_AsyncRequest_QueueRunner( \ActionScheduler::store() );
+		// Its constructor hooks a second handler for the loopback; Action Scheduler's own instance handles it.
+		remove_action( 'wp_ajax_as_async_request_queue_runner', array( $runner, 'maybe_handle' ) );
+		remove_action( 'wp_ajax_nopriv_as_async_request_queue_runner', array( $runner, 'maybe_handle' ) );
+		$runner->maybe_dispatch();
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
index 78cde18ed70..77f8beb765c 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
@@ -55,6 +55,8 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
 			grant_super_admin( get_current_user_id() );
 		}
 		delete_option( 'woocommerce_feature_ucp_enabled' );
+		// Reading the view queues the first check on a store never checked; only the tests about that clear this.
+		update_option( ScheduledScan::FIRST_SCAN_OPTION, 'yes', false );
 		$this->sut = wc_get_container()->get( AgenticCommerceSettings::class );
 	}

@@ -2252,6 +2254,32 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
 		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
 	}

+	/**
+	 * @testdox The first visit to a store never checked starts the check: the page shows it running with a line on how long to wait, and later visits queue nothing more.
+	 */
+	public function test_first_visit_starts_the_first_check(): void {
+		delete_option( AgentReadiness::REPORT_OPTION );
+		delete_option( ScheduledScan::FIRST_SCAN_OPTION );
+		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
+
+		$run = $this->view()['run'];
+		$this->assertTrue( $run['pending'], 'The visit queued the first check' );
+		$this->assertSame( 'Checking your store', $run['message'] );
+		$this->assertSame( 'Your first check can take a few minutes. You can leave this page, and the results show here when it’s done.', $run['note'] );
+		$this->assertNotFalse( as_next_scheduled_action( ScheduledScan::RUN_NOW_HOOK, array(), ScheduledScan::GROUP ) );
+
+		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
+		$run = $this->view()['run'];
+		$this->assertFalse( $run['pending'], 'A first check that gave up is not queued again on every visit' );
+		$this->assertSame( '', $run['note'] );
+		$this->assertSame( 'Check your store', $run['label'], 'The merchant can still start one' );
+
+		wc_get_container()->get( ScheduledScan::class )->queue();
+		update_option( AgentReadiness::REPORT_OPTION, array( 'store_checks' => array() ), false );
+		$this->assertSame( '', $this->view()['run']['note'], 'A check after the first one has results to show, so no wait line' );
+		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
+	}
+
 	/**
 	 * Date every finished action an hour back, so only what the test does next
 	 * counts as recent queue activity.
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCheckPageTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCheckPageTest.php
index 371348d4dc8..19126a8e0ff 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCheckPageTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCheckPageTest.php
@@ -30,6 +30,8 @@ class ReadinessCheckPageTest extends WC_Unit_Test_Case {
 		parent::setUp();
 		StoreOutputChecksTest::block_requests();
 		delete_option( AgentReadiness::REPORT_OPTION );
+		// Reading the view queues the first check on a store never checked; only the tests about that clear this.
+		update_option( ScheduledScan::FIRST_SCAN_OPTION, 'yes', false );
 		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
 		$this->sut = wc_get_container()->get( ReadinessCheckPage::class );
 	}
@@ -46,9 +48,10 @@ class ReadinessCheckPageTest extends WC_Unit_Test_Case {
 	 * A scan whose is_pending answers come from a list, one per call.
 	 *
 	 * @param array<int, bool> $answers Pending answers in call order.
+	 * @param bool             $queued  What queue_first() answers: whether it queued the first scan.
 	 * @return ScheduledScan
 	 */
-	private function scan_with_pending_answers( array $answers ): ScheduledScan {
+	private function scan_with_pending_answers( array $answers, bool $queued = false ): ScheduledScan {
 		$scan          = new class() extends ScheduledScan {
 			/**
 			 * Pending answers left to return.
@@ -70,8 +73,23 @@ class ReadinessCheckPageTest extends WC_Unit_Test_Case {
 			public function is_stalled(): bool {
 				return false;
 			}
+
+			/**
+			 * Whether queue_first() says it queued the first scan.
+			 *
+			 * @var bool
+			 */
+			public bool $queued = false;
+
+			/**
+			 * Queues nothing, so the answers stay the test's.
+			 */
+			public function queue_first(): bool {
+				return $this->queued;
+			}
 		};
 		$scan->answers = $answers;
+		$scan->queued  = $queued;
 		return $scan;
 	}

@@ -120,6 +138,20 @@ class ReadinessCheckPageTest extends WC_Unit_Test_Case {
 		$this->assertSame( 'https://woocommerce.com/my-account/create-a-ticket/?utm_medium=product', $this->sut->view()['support_url'] );
 	}

+	/**
+	 * @testdox A first scan queued by this view counts as pending even if it finished before the reads, so the page polls and shows the results.
+	 */
+	public function test_view_is_pending_when_it_queued_the_first_scan(): void {
+		$this->sut->init(
+			wc_get_container()->get( FeaturesController::class ),
+			wc_get_container()->get( StoreConditions::class ),
+			wc_get_container()->get( AgentReadiness::class ),
+			$this->scan_with_pending_answers( array( false, false ), true )
+		);
+
+		$this->assertTrue( $this->sut->view()['run']['pending'] );
+	}
+
 	/**
 	 * @testdox With no scan before or after the report read, the view is not pending.
 	 */
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php
index e617d926163..8ed44d8a8f2 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php
@@ -31,6 +31,8 @@ class ReadinessRestControllerTest extends WC_REST_Unit_Test_Case {
 		// Report tests stay offline: store output checks would load the test site's pages.
 		StoreOutputChecksTest::block_requests();
 		delete_option( AgentReadiness::REPORT_OPTION );
+		// Reading the view queues the first check on a store never checked; only the tests about that clear this.
+		update_option( ScheduledScan::FIRST_SCAN_OPTION, 'yes', false );
 		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
 		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
 	}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php
index 463292b3c35..0afb765758b 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTest.php
@@ -32,6 +32,89 @@ class ScheduledScanTest extends ScheduledScanTestCase {
 		);
 	}

+	/**
+	 * Waiting first-scan actions.
+	 *
+	 * @return array<int, int>
+	 */
+	private function waiting_scans(): array {
+		return as_get_scheduled_actions(
+			array(
+				'hook'   => ScheduledScan::RUN_NOW_HOOK,
+				'status' => \ActionScheduler_Store::STATUS_PENDING,
+			),
+			'ids'
+		);
+	}
+
+	/**
+	 * @testdox A first scan Action Scheduler refused is not reported as queued or marked as done, so the next visit queues it.
+	 */
+	public function test_queue_first_retries_when_the_scan_was_not_queued(): void {
+		delete_option( AgentReadiness::REPORT_OPTION );
+		$not_queued = static function ( $pre, $timestamp, $hook ) {
+			unset( $timestamp ); // Avoid parameter not used PHPCS errors.
+			return ScheduledScan::RUN_NOW_HOOK === $hook ? 0 : $pre;
+		};
+		add_filter( 'pre_as_schedule_single_action', $not_queued, 10, 3 );
+		try {
+			$this->assertFalse( $this->sut->queue_first() );
+		} finally {
+			remove_filter( 'pre_as_schedule_single_action', $not_queued, 10 );
+		}
+		$this->assertFalse( get_option( ScheduledScan::FIRST_SCAN_OPTION ) );
+
+		$this->assertTrue( $this->sut->queue_first() );
+		$this->assertCount( 1, $this->waiting_scans() );
+	}
+
+	/**
+	 * @testdox A first scan the queue runner finishes before queue_first() returns still counts as queued, so one that gave up is not queued again on the next visit.
+	 */
+	public function test_queue_first_counts_a_scan_that_finished_at_once(): void {
+		delete_option( AgentReadiness::REPORT_OPTION );
+		$finish = static function ( $action_id ) {
+			\ActionScheduler::store()->mark_complete( $action_id );
+		};
+		add_action( 'action_scheduler_stored_action', $finish );
+		try {
+			$this->assertTrue( $this->sut->queue_first() );
+		} finally {
+			remove_action( 'action_scheduler_stored_action', $finish );
+		}
+		$this->assertSame( 'yes', get_option( ScheduledScan::FIRST_SCAN_OPTION ) );
+
+		$this->assertFalse( $this->sut->queue_first() );
+		$this->assertSame( array(), $this->waiting_scans() );
+	}
+
+	/**
+	 * @testdox The first scan is queued once on a store never checked, not again after one gave up, and not on a store already checked or with a scan waiting.
+	 */
+	public function test_queue_first_only_before_the_first_report(): void {
+		delete_option( AgentReadiness::REPORT_OPTION );
+
+		$this->assertTrue( $this->sut->queue_first() );
+		$this->assertFalse( $this->sut->queue_first() );
+		$this->assertCount( 1, $this->waiting_scans(), 'One first scan, however often the page is opened' );
+		$this->assertSame( 'yes', get_option( ScheduledScan::FIRST_SCAN_OPTION ) );
+
+		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
+		$this->assertFalse( $this->sut->queue_first() );
+		$this->assertSame( array(), $this->waiting_scans(), 'A first scan that gave up without a report is not queued again on every visit' );
+
+		delete_option( ScheduledScan::FIRST_SCAN_OPTION );
+		$this->sut->queue();
+		$this->assertFalse( $this->sut->queue_first(), 'A scan already waiting is not queued twice' );
+		$this->assertCount( 1, $this->waiting_scans() );
+
+		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
+		delete_option( ScheduledScan::FIRST_SCAN_OPTION );
+		update_option( AgentReadiness::REPORT_OPTION, array( 'store_checks' => array() ), false );
+		$this->assertFalse( $this->sut->queue_first(), 'A checked store waits for the daily run or a manual check' );
+		$this->assertSame( array(), $this->waiting_scans() );
+	}
+
 	/**
 	 * @testdox Queueing twice before the scan runs leaves one pending scan.
 	 */
@@ -45,6 +128,166 @@ class ScheduledScanTest extends ScheduledScanTestCase {
 		$this->assertCount( 1, $this->pending( ScheduledScan::RUN_NOW_HOOK ) );
 	}

+	/**
+	 * @testdox A scan requested by a merchant logged in by cookie starts Action Scheduler's async queue runner at once, and a second click sends no loopback.
+	 */
+	public function test_queue_starts_the_queue_runner(): void {
+		global $wp_filter;
+		$this->log_in_by_cookie();
+		$handlers = count( $wp_filter['wp_ajax_as_async_request_queue_runner']->callbacks[10] ?? array() );
+
+		$dispatched = $this->dispatches_while(
+			function () {
+				$this->sut->queue();
+				$this->sut->queue();
+			}
+		);
+
+		$this->assertSame( array( false ), $dispatched, 'One loopback request, which the click does not wait for, and none for a second click' );
+		$this->assertCount( $handlers, $wp_filter['wp_ajax_as_async_request_queue_runner']->callbacks[10] ?? array(), 'Adds no second handler for the loopback request' );
+		$this->assertTrue( \ActionScheduler::lock()->is_locked( 'async-request-runner' ), 'Sets the lock Action Scheduler checks before it starts another runner' );
+	}
+
+	/**
+	 * @testdox A scan requested just after an idle admin page still starts the queue runner.
+	 *
+	 * Action Scheduler sets the async runner lock on admin shutdown before it looks for due actions,
+	 * so a page with nothing to run leaves the lock held and sends no loopback.
+	 */
+	public function test_queue_starts_after_an_idle_admin_page(): void {
+		$this->log_in_by_cookie();
+		$screen = get_current_screen();
+		set_current_screen( 'dashboard' );
+		// The same early return as an idle queue: the lock is taken, then allow() declines.
+		add_filter( 'action_scheduler_allow_async_request_runner', '__return_false' );
+		try {
+			$during_page_load = $this->dispatches_while(
+				static function () {
+					\ActionScheduler_QueueRunner::instance()->maybe_dispatch_async_request();
+				},
+				false
+			);
+		} finally {
+			remove_filter( 'action_scheduler_allow_async_request_runner', '__return_false' );
+			set_current_screen( $screen ? $screen->id : 'front' );
+		}
+
+		$this->assertSame( array(), $during_page_load, 'An idle admin page does not start a runner' );
+		$this->assertTrue( \ActionScheduler::lock()->is_locked( 'async-request-runner' ), 'It still leaves the throttle lock set' );
+
+		$dispatched = $this->dispatches_while( array( $this->sut, 'queue' ) );
+
+		$this->assertSame( array( false ), $dispatched, 'The scan starts even though that lock is held' );
+		$this->assertCount( 1, $this->pending( ScheduledScan::RUN_NOW_HOOK ) );
+	}
+
+	/**
+	 * @testdox A requested scan sends no loopback while the queue is already at its batch limit, and stays queued.
+	 */
+	public function test_queue_sends_no_loopback_at_the_batch_limit(): void {
+		$this->log_in_by_cookie();
+		add_filter( 'action_scheduler_queue_runner_concurrent_batches', '__return_zero' );
+		try {
+			$this->assertTrue( \ActionScheduler::runner()->has_maximum_concurrent_batches() );
+			$dispatched = $this->dispatches_while( array( $this->sut, 'queue' ), false );
+		} finally {
+			remove_filter( 'action_scheduler_queue_runner_concurrent_batches', '__return_zero' );
+		}
+
+		$this->assertSame( array(), $dispatched );
+		$this->assertCount( 1, $this->pending( ScheduledScan::RUN_NOW_HOOK ) );
+	}
+
+	/**
+	 * @testdox A requested scan sends no loopback when Action Scheduler's runner filter disallows it.
+	 */
+	public function test_queue_sends_no_loopback_when_the_runner_is_disallowed(): void {
+		$this->log_in_by_cookie();
+		add_filter( 'action_scheduler_allow_async_request_runner', '__return_false', 11 );
+		try {
+			$dispatched = $this->dispatches_while( array( $this->sut, 'queue' ) );
+		} finally {
+			remove_filter( 'action_scheduler_allow_async_request_runner', '__return_false', 11 );
+		}
+
+		$this->assertSame( array(), $dispatched );
+		$this->assertCount( 1, $this->pending( ScheduledScan::RUN_NOW_HOOK ) );
+	}
+
+	/**
+	 * @testdox A scan requested without a login cookie, as over an application password, sends no loopback its nonce check would reject.
+	 */
+	public function test_queue_without_login_cookie_sends_no_loopback(): void {
+		wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+
+		$dispatched = $this->dispatches_while( array( $this->sut, 'queue' ) );
+
+		$this->assertSame( array(), $dispatched );
+		$this->assertCount( 1, $this->pending( ScheduledScan::RUN_NOW_HOOK ) );
+	}
+
+	/**
+	 * @testdox A request whose scan Action Scheduler did not queue, as when another request queued the same unique scan first, sends no loopback.
+	 */
+	public function test_queue_sends_no_loopback_when_nothing_was_queued(): void {
+		$this->log_in_by_cookie();
+		$not_queued = static function ( $pre, $timestamp, $hook ) {
+			unset( $timestamp ); // Avoid parameter not used PHPCS errors.
+			return ScheduledScan::RUN_NOW_HOOK === $hook ? 0 : $pre;
+		};
+		add_filter( 'pre_as_schedule_single_action', $not_queued, 10, 3 );
+		try {
+			$dispatched = $this->dispatches_while( array( $this->sut, 'queue' ) );
+		} finally {
+			remove_filter( 'pre_as_schedule_single_action', $not_queued, 10 );
+		}
+
+		$this->assertSame( array(), $dispatched );
+	}
+
+	/**
+	 * Log in an administrator with a logged-in cookie, as in wp-admin.
+	 */
+	private function log_in_by_cookie(): void {
+		$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+		wp_set_current_user( $user_id );
+		$_COOKIE[ LOGGED_IN_COOKIE ] = wp_generate_auth_cookie( $user_id, time() + HOUR_IN_SECONDS, 'logged_in' );
+	}
+
+	/**
+	 * Run a callback and record the loopback requests it sends.
+	 *
+	 * @param callable $callback     What to run.
+	 * @param bool     $allow_runner Whether to let the runner filter allow a loopback. Tests of that filter pass false.
+	 * @return array The blocking argument of each loopback request.
+	 */
+	private function dispatches_while( callable $callback, bool $allow_runner = true ): array {
+		$dispatched = array();
+		$record     = static function ( $preempt, $args, $url ) use ( &$dispatched ) {
+			if ( is_string( $url ) && str_contains( $url, 'as_async_request_queue_runner' ) ) {
+				$dispatched[] = $args['blocking'] ?? null;
+				return array(
+					'response' => array( 'code' => 200 ),
+					'body'     => '',
+				);
+			}
+			return $preempt;
+		};
+		add_filter( 'pre_http_request', $record, 10, 3 );
+		if ( $allow_runner ) {
+			add_filter( 'action_scheduler_allow_async_request_runner', '__return_true' );
+		}
+		try {
+			$callback();
+		} finally {
+			remove_filter( 'pre_http_request', $record, 10 );
+			if ( $allow_runner ) {
+				remove_filter( 'action_scheduler_allow_async_request_runner', '__return_true' );
+			}
+		}
+		return $dispatched;
+	}
+
 	/**
 	 * @testdox Two requests that both see no pending scan, as when they run at the same time, still queue one scan.
 	 */
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTestCase.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTestCase.php
index 75c36ee59b8..d4364429768 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTestCase.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ScheduledScanTestCase.php
@@ -32,6 +32,8 @@ abstract class ScheduledScanTestCase extends WC_Unit_Test_Case {
 		as_unschedule_all_actions( ScheduledScan::DAILY_HOOK );
 		as_unschedule_all_actions( ScheduledScan::NEXT_HOOK );
 		delete_option( AgentReadiness::SCAN_OPTION );
+		delete_option( 'action_scheduler_lock_async-request-runner' );
+		wp_cache_delete( 'action_scheduler_lock_async-request-runner', 'action_scheduler_locks' );
 		$this->sut = wc_get_container()->get( ScheduledScan::class );
 	}

@@ -39,6 +41,7 @@ abstract class ScheduledScanTestCase extends WC_Unit_Test_Case {
 	 * Tear down test fixtures.
 	 */
 	public function tearDown(): void {
+		unset( $_COOKIE[ LOGGED_IN_COOKIE ] );
 		as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
 		as_unschedule_all_actions( ScheduledScan::DAILY_HOOK );
 		as_unschedule_all_actions( ScheduledScan::NEXT_HOOK );