Skip to content

[Bulk transition] PR-1881: Conflict handling & automatic per-subset retry - #575

Open
stevetrinh wants to merge 1 commit into
PR-1880from
PR-1881
Open

stevetrinh wants to merge 1 commit into
PR-1880from
PR-1881

Conversation

@stevetrinh

Copy link
Copy Markdown

This pull request adds configurable retry and failure handling options to bulk state transitions in Statesman, making ActiveRecord adapter behavior more robust and flexible in the face of persistent insert conflicts. The main changes introduce new on_failure and conflict_retry_attempts options, allow callers to control how many times a bulk insert is retried after a conflict, and determine whether to raise or collect failures after retries are exhausted. These options are threaded through all relevant code paths and validated for correctness. Comprehensive tests are added to ensure the new behaviors work as intended.

Bulk transition retry and failure handling improvements:

  • Added on_failure: and conflict_retry_attempts: options to BulkTransition.call and bulk_create methods, allowing callers to specify how many times to retry bulk inserts after a conflict and whether to raise or collect failures when retries are exhausted. [1] [2] [3] [4] [5]
  • Updated the BulkCreate logic to respect the new options: after exhausting retries, it either raises a new BulkTransitionConflictError (wrapping the original RecordNotUnique) or collects all conflicted items as failures, depending on on_failure.

API and interface consistency:

  • Ensured the in-memory adapter (Adapters::Memory) accepts the new options for interface parity, even though they have no effect in that context.
  • Threaded the new options through all call paths and constructors, updating method signatures and internal state accordingly. [1] [2] [3]

Validation and error handling:

  • Added validation to ensure conflict_retry_attempts is a positive integer, raising an ArgumentError otherwise.

Testing improvements:

  • Added and updated tests to cover the new options, including scenarios for persistent conflicts, custom retry counts, and both :collect and :raise failure modes. [1] [2] [3]

@stevetrinh
stevetrinh added this pull request to stack #569 October 5, 2026 09:20
@stevetrinh stevetrinh changed the title PR-1881: WU5 - Conflict handling & automatic per-subset retry [Bulk transition] PR-1881: WU5 - Conflict handling & automatic per-subset retry Oct 5, 2026
@stevetrinh stevetrinh changed the title [Bulk transition] PR-1881: WU5 - Conflict handling & automatic per-subset retry [Bulk transition] PR-1881: Conflict handling & automatic per-subset retry Oct 5, 2026
Thread on_failure: and a new conflict_retry_attempts: option through
BulkTransition.call -> #persist -> the adapter's bulk_create ->
BulkCreate.call. On exhausting BulkCreate's internal RecordNotUnique
retry, on_failure: :collect (default) now surfaces the remaining
survivors as :conflict failures instead of raising the raw AR error;
on_failure: :raise raises Statesman::BulkTransitionConflictError,
wrapping the original RecordNotUnique as #cause. The retry bound
itself is now caller-configurable instead of a hardcoded constant.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant