Skip to content

fix(events): prevent callbacks after failed transitions - #523

Open
sjinks wants to merge 2 commits into
mainfrom
pltfrm-2760-prevent-callback-execution-after-event-transition
Open

fix(events): prevent callbacks after failed transitions#523
sjinks wants to merge 2 commits into
mainfrom
pltfrm-2760-prevent-callback-execution-after-event-transition

Conversation

@sjinks

@sjinks sjinks commented Aug 27, 2026

Copy link
Copy Markdown
Member

Summary

  • prevent event callbacks from running when completing or rescheduling the event fails
  • release non-forced event locks on transition failure
  • cover one-time, recurring, and internal event failure paths

Testing

  • php -l includes/class-events.php
  • php -l __tests__/unit-tests/test-events.php
  • php -l __tests__/unit-tests/fixtures/class-transition-failure-events.php
  • ./vendor/bin/phpcs --standard=phpcs.xml includes/class-events.php __tests__/unit-tests/test-events.php __tests__/unit-tests/fixtures/class-transition-failure-events.php
  • git diff --check
  • ./vendor/bin/phpunit __tests__/unit-tests/test-events.php (blocked locally: WordPress test bootstrap at /tmp/wordpress-tests-lib and its MariaDB database are unavailable)

Fixes PLTFRM-2760.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 27, 2026 20:57
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens event execution by ensuring an event’s state transition (complete/reschedule) succeeds before running its callback, and by cleaning up acquired locks when that transition fails. It also adds unit coverage for one-time, recurring, and internal-event transition failure paths.

Changes:

  • Add a transition_event() hook point and early-return behavior to prevent callbacks after failed transitions.
  • Centralize lock cleanup via release_event_locks() and invoke it on both transition failure and normal completion paths.
  • Add unit tests plus a fixture Events subclass to simulate transition failures.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
includes/class-events.php Moves complete/reschedule into a transition step and ensures locks are released when that step fails.
tests/unit-tests/test-events.php Adds tests asserting callbacks don’t run and locks are handled correctly when transitions fail.
tests/unit-tests/fixtures/class-transition-failure-events.php Introduces a test-only Events subclass that forces transition failures for deterministic testing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread includes/class-events.php
@@ -256,10 +256,11 @@ public function run_event( $timestamp, $action, $instance, $force = false ) {
}

// Core reschedules/conpletes an event before running it, so we respect that.
Comment on lines +129 to +136
Lock::prime_lock( Events::LOCK );

$result = $events->run_event( $event->get_timestamp(), md5( $event->get_action() ), $event->get_instance() );

$this->assertSame( $error, $result );
$this->assertSame( 0, $called );
$this->assertSame( $event->is_internal() ? 1 : 0, Lock::get_lock_value( Events::LOCK ) );
$this->assertSame( 0, Lock::get_lock_value( $events->get_lock_key_for_event_action( $event ) ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants