Repository navigation
fix(routines): persist schedule records for zero-I/O declarations, single-flight scheduling, and duplicate-chain collapse (#582) - #588
Merged
Conversation
…ngle-flight scheduling, and duplicate-chain collapse (#582)
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Routines are re-declared in memory on every request, and every declaration synced to Action Scheduler: one as_get_scheduled_actions() query plus one fetch_action() per pending action per request (~720 queries per page view at Data Machine's scale), with no lock around check-then-schedule and no collapse of duplicate chains. The bridge now keeps one persisted record of what it last scheduled (routine id → trigger signature + action id in a single option), so an unchanged declaration returns with zero scheduler I/O, and only a missing or changed signature reaches the store under a short single-flight per-routine lock. Any call that does reach Action Scheduler — declarations and reconcile's new authoritative repair() path alike — collapses duplicate matching chains to the one live chain the watermark model considers current and cancels the rest by id, while reconcile still repairs drift the record cannot see (including an action deleted out-of-band).
What changed
How to test
composer install -q --no-interaction && for f in tests/routine-smoke.php tests/routines-durability-smoke.php tests/routine-ability-target-smoke.php tests/routines-backend-contract-smoke.php; do php "$f" || exit 1; done && composer smoke && composer phpstan; expect passes as recorded by Cook's deterministic gate.Compatibility
Additive except one named break: the WP_Agent_Routine_Backend contract now requires repair(), so third-party backend implementations must add it. The agents_routine_schedules record option, the per-routine lock options, and the removed matching_action_id() helper are internal to the default bridge; unregister/pause/resume/run-now semantics and the generation/watermark fence are unchanged.
Evidence
composer install -q --no-interaction && for f in tests/routine-smoke.php tests/routines-durability-smoke.php tests/routine-ability-target-smoke.php tests/routines-backend-contract-smoke.php; do php "$f" || exit 1; done && composer smoke && composer phpstan: status=succeeded; candidate commit1b61042f7b4af6f4c010682891979fd9b5aa2623, tree47aae49b5477c397df1595319ad302c413f72fed, fingerprint3fdcf1fb2fd0fa66949454a6d5aa407b38f742731aff35ee051e6e45689de735; durable gategate-1AI assistance
Source relationships