Repository navigation
fix(routines): hourly WP-Cron reconcile repair and one atomic shared option lock - #589
Merged
Merged
Conversation
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
Follow-up to #582/#588 (Extra-Chill/data-machine#3495): since declarations started trusting the persisted schedule record, a routine chain lost out of band (cancelled in the Action Scheduler admin UI, pruned or restored table) stayed lost because nothing ran reconcile() on a schedule, and the bridge's stale schedule-lock takeover let two observing processes both proceed. Agents API now declares one hourly WP-Cron event (wp_agent_routines_reconcile) on init, guarded by wp_next_scheduled(), whose callback runs the lock-protected WP_Agent_Routine_Registry::reconcile() and fires wp_agent_routines_reconcile_completed with the report, so a lost chain is restored within one hour. The atomic stale-lock takeover is extracted into one shared helper under src/Routines/ used by both the reconcile lock and the bridge's per-routine schedule lock, so exactly one acquirer wins a stale lock.
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. The only behavior change is the schedule lock's storage (options API → $wpdb row): leftover agents_routine_schedule_lock_<id> option rows from prior versions are simply ignored and inert, and lock names, TTLs, and hook contracts are otherwise 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 commite881986e6ad4272ac5be62b51fb4b1d06751f855, treecd54bcd7b1a3a4393e9137c4a17a1459f23bd397, fingerprint45e9cc1dca9da0b9ebd2230b13d601ea295e24b55d1d5dc229a2076c0e2fe9b5; durable gategate-1AI assistance
Source relationships