Skip to content

feat: add should_complete to CompletionConfig - #605

Open
ayushiahjolia wants to merge 2 commits into
mainfrom
feat/custom-completion-predicate
Open

feat: add should_complete to CompletionConfig#605
ayushiahjolia wants to merge 2 commits into
mainfrom
feat/custom-completion-predicate

Conversation

@ayushiahjolia

@ayushiahjolia ayushiahjolia commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: #519

Description of changes:
Adds a should_complete predicate to CompletionConfig for map and parallel operations, giving full control over when a batch completes early.

from aws_durable_execution_sdk_python import complete_batch, continue_batch

config = CompletionConfig(
    should_complete=lambda status: (
        complete_batch() if status.success_count >= 2
        else continue_batch()
    )
)

The predicate receives a CompletionStatus snapshot (counts + per-item statuses) and returns a CompletionDecision - either continue_batch() or complete_batch(outcome). The outcome determines whether CUSTOM_COMPLETION_SUCCEEDED or CUSTOM_COMPLETION_FAILED is reported.

Key design decisions -

  • Cannot be combined with threshold fields (raises ValidationError)
  • Predicate must be deterministic and side-effect-free
  • Replay uses the checkpointed decision, never re-invokes the predicate
  • On resumed invocations, deferred until prior checkpoints replay

Testing -

  • Unit tests, integration tests and examples

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ayushiahjolia
ayushiahjolia force-pushed the feat/custom-completion-predicate branch from 862e017 to c72785b Compare July 31, 2026 05:22
@ayushiahjolia ayushiahjolia changed the title feat: custom completion predicate feat: add should_complete to CompletionConfig Jul 31, 2026
@ayushiahjolia
ayushiahjolia temporarily deployed to ai-pr-review-runtime July 31, 2026 05:36 — with GitHub Actions Inactive
@ayushiahjolia
ayushiahjolia temporarily deployed to ai-pr-review-runtime July 31, 2026 05:36 — with GitHub Actions Inactive
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ayushiahjolia
ayushiahjolia force-pushed the feat/custom-completion-predicate branch from c72785b to 306c81c Compare July 31, 2026 19:22
@ayushiahjolia
ayushiahjolia had a problem deploying to ai-pr-review-runtime July 31, 2026 19:39 — with GitHub Actions Failure
@ayushiahjolia
ayushiahjolia had a problem deploying to ai-pr-review-runtime July 31, 2026 19:39 — with GitHub Actions Failure
@ayushiahjolia
ayushiahjolia force-pushed the feat/custom-completion-predicate branch from 306c81c to 5483a62 Compare July 31, 2026 19:44
@ayushiahjolia
ayushiahjolia temporarily deployed to ai-pr-review-runtime July 31, 2026 20:13 — with GitHub Actions Inactive
@ayushiahjolia
ayushiahjolia temporarily deployed to ai-pr-review-runtime July 31, 2026 20:13 — with GitHub Actions Inactive
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ayushiahjolia
ayushiahjolia force-pushed the feat/custom-completion-predicate branch from 5483a62 to fffee6d Compare July 31, 2026 21:17
@ayushiahjolia
ayushiahjolia temporarily deployed to ai-pr-review-runtime July 31, 2026 21:18 — with GitHub Actions Inactive
@ayushiahjolia
ayushiahjolia temporarily deployed to ai-pr-review-runtime July 31, 2026 21:18 — with GitHub Actions Inactive
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ayushiahjolia
ayushiahjolia force-pushed the feat/custom-completion-predicate branch from fffee6d to 7ad4242 Compare July 31, 2026 21:55
@ayushiahjolia
ayushiahjolia force-pushed the feat/custom-completion-predicate branch from 7ad4242 to 302330d Compare July 31, 2026 21:56
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

if self.policy.should_complete is not None
else ()
)
decision = self.policy.evaluate(succeeded, failed, items_snapshot)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex AI review

[P1] Restore prior terminal state before evaluating the predicate

On a resumed incomplete batch, prior child checkpoints replay asynchronously while these counters start at zero. Evaluating after whichever replay event arrives first can make a deterministic status predicate choose a different outcome than before suspension, potentially checkpointing a different result and skipping work. Determine the terminal branches present at invocation start and defer predicate evaluation until all of that state has been restored, including equivalent handling for FLAT nesting.

submit(pending.popleft())
in_flight += 1
running += 1
needs_snapshot_rebuild = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex AI review

[P2] Evaluate the new STARTED snapshot before blocking

This flag is set after submission, but execution proceeds directly to events.get() rather than returning to the loop. Consequently, the predicate is not called for the PENDING to STARTED transition; with max_concurrency=1, it may never observe STARTED before the branch becomes terminal. Predicates based on scheduling state can therefore fail to complete early or block indefinitely. Continue the outer loop after any submissions, or evaluate the rebuilt snapshot immediately before waiting for events.

@github-actions

Copy link
Copy Markdown
Contributor

Codex AI review

Two correctness issues affect replay determinism and STARTED-state predicates. Existing tests do not cover these event-order cases.

Reviewed commit 04483d54ad90899c9ac25a59186f685c31f88354. Workflow run

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.

3 participants