Skip to content

fix: do not retry unit of work after it has committed - #47

Merged
lindyhopchris merged 1 commit into
developfrom
fix/unit-of-work-retry-after-commit
Nov 14, 2026
Merged

lindyhopchris merged 1 commit into
developfrom
fix/unit-of-work-retry-after-commit

Conversation

@lindyhopchris

Copy link
Copy Markdown
Member

Closes #46

Problem

UnitOfWorkManager::retry() caught exceptions thrown by after commit callbacks, which run after the unit of work has committed. This caused already-committed work to be re-executed, discarded or re-ran after commit callbacks, and hid the original exception behind the last attempt's failure.

Changes

  • After commit callbacks now execute outside the retry scope, so only failures before the commit are re-attempted. A failed attempt still forgets the callbacks it registered, so a retry starts clean.
  • After commit callbacks are expected to be independent of each other (no reliance on execution order), so a failing callback no longer prevents the remaining ones from executing:
    • exactly one failure: its exception is rethrown as-is (unchanged behaviour for the single-failure case);
    • more than one failure: a new AfterCommitCallbacksFailed exception is thrown. It implements the ApplicationException contract, exposes exceptions() (in the order thrown) and uses the first exception as its previous exception.
  • After commit exceptions are not reported via the ExceptionReporter, as they are not swallowed; they are thrown to the caller.
  • Changelog and the units of work guide are updated.

Tests

Failing tests were added first, then the fix was applied:

  • it_does_not_retry_when_after_commit_callback_fails
  • it_executes_all_after_commit_callbacks_when_several_fail (including callbacks registered by a failing callback)
  • it_does_not_retry_after_commit_following_a_failed_attempt
  • it_flushes_callbacks_when_after_commit_callback_fails
  • AfterCommitCallbacksFailedTest

composer all passes.

🤖 Generated with Claude Code

After commit callbacks are now executed outside the retry scope, so a
failing callback no longer causes the committed unit of work to be
re-attempted. All after commit callbacks are executed even if one fails;
a single failure is rethrown, multiple failures are wrapped in the new
AfterCommitCallbacksFailed exception.

Closes #46

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lindyhopchris lindyhopchris self-assigned this Nov 14, 2026
@lindyhopchris
lindyhopchris merged commit 3aea66f into develop Nov 14, 2026
2 checks passed
@lindyhopchris
lindyhopchris deleted the fix/unit-of-work-retry-after-commit branch November 16, 2026 10:27
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.

UnitOfWorkManager::retry() retries after the unit of work has committed

1 participant