Repository navigation
[Bug]: Resumed map or parallel can omit recorded terminal item outcomes #835
Description
Reference implementation
Merged JavaScript fix: aws/aws-durable-execution-sdk-js#1091 — keep recorded item outcomes when a batch resumes
The JavaScript PR fixes the equivalent defect and includes reconciliation tests for recorded successes, recorded failures, bounded concurrency, unfinished items, and custom completion predicates. Its required behavior and regression cases are the parity reference for this issue. The Python implementation can use a different internal design, but it should produce the same observable result for recorded terminal items.
Expected Behavior
A map or parallel operation can resume while its parent CONTEXT operation is still STARTED. Some nested item or branch contexts can already have terminal SUCCEEDED or FAILED records.
The resumed batch must incorporate every existing terminal child-context outcome before it makes a new completion decision.
For this state:
| Operation | Recorded status |
|---|---|
| Batch parent | STARTED |
| Item 0 | SUCCEEDED |
| Item 1 | SUCCEEDED |
| Item 2 | FAILED |
| Item 3 | STARTED |
with:
MapConfig(
max_concurrency=2,
completion_config=CompletionConfig(min_successful=2),
)the resumed BatchResult must satisfy:
[item.status for item in result.all] == [
BatchItemStatus.SUCCEEDED,
BatchItemStatus.SUCCEEDED,
BatchItemStatus.FAILED,
]
result.success_count == 2
result.failure_count == 1
result.has_failure is True
result.status is BatchItemStatus.FAILED
result.completion_reason is CompletionReason.MIN_SUCCESSFUL_REACHEDresult.throw_if_error() must raise the recorded item failure.
Item 3 does not need to remain in the result. A previously STARTED item is not a terminal outcome.
Actual Behavior
When the batch parent is STARTED, map_handler() and parallel_handler() call ConcurrentExecutor.execute().
execute() initializes every branch as pending. It does not first identify child contexts that already have terminal records.
The recorded child contexts replay on worker threads. Their events reach the coordinator in thread-completion order. That order can differ from their original completion order and their item-index order.
In the state above:
- Items 0 and 1 replay their recorded successes.
- The first success frees a concurrency slot, so item 2 is submitted.
- The second success reaches
min_successful=2. - The coordinator completes the batch before item 2's worker reports its already-recorded failure.
- The final nonblocking event drain does not wait for that event.
The resulting value can be:
[item.status for item in result.all] == [
BatchItemStatus.SUCCEEDED,
BatchItemStatus.SUCCEEDED,
BatchItemStatus.STARTED,
]
result.failure_count == 0
result.has_failure is False
result.status is BatchItemStatus.SUCCEEDEDThe execution history still contains item 2's FAILED child-context record.
The resumed parent then checkpoints this incomplete BatchResult. Subsequent replay preserves the incorrect result.
Steps to Reproduce
-
Configure a four-item nested map with:
MapConfig( max_concurrency=2, completion_config=CompletionConfig(min_successful=2), nesting_type=NestingType.NESTED, )
-
Produce this first-invocation order:
- Items 0 and 1 start.
- Item 1 succeeds, which starts item 2.
- Item 2 fails and records its terminal child-context failure.
- Item 3 starts.
- Item 0 succeeds, which reaches
min_successful=2. - End the invocation before the batch parent records its terminal checkpoint.
-
Resume with the batch parent still
STARTEDand child records:item 0: SUCCEEDED item 1: SUCCEEDED item 2: FAILED item 3: STARTED -
In a deterministic unit test:
- Allow item 0's cached success event to reach the coordinator.
- Confirm that the coordinator submits item 2.
- Hold item 2 after it observes the recorded failure but before its worker posts the
FAILEDevent. - Allow item 1's cached success event to reach the coordinator.
- Observe that the coordinator returns after reaching two successes.
-
Assert that item 2 is reported as
STARTED,failure_countis zero, andhas_failureis false despite its recordedFAILEDcontext.
The same coordinator code is used by parallel().
SDK Version
Reproduced in:
aws-durable-execution-sdk-python2.1.0aws-durable-execution-sdk-python3.0.0 on currentmain
The relevant executor, map handler, and parallel handler are unchanged between these versions.
Python Version
3.14
Is this a regression?
No.
Additional Context
Relevant Python code:
concurrency/executor.py- Evaluates completion after each worker event.
- Stops once the current counts meet the completion policy.
- Performs one nonblocking event drain after that decision.
- Does not identify terminal child records before scheduling.
operation/map.py- Calls
replay()only for a terminal parent. - Calls
execute()when the parent remainsSTARTED.
- Calls
operation/parallel.py- Uses the same distinction.
concurrency/models.py- Calculates
has_failure, status, and errors only from items included in the returnedBatchResult.
- Calculates
Success criteria
-
Recorded outcomes are retained
- Every existing terminal
SUCCEEDEDorFAILEDnested child-context record appears with that terminal status in the resumedBatchResult. - A terminal record cannot become
STARTEDor disappear because of worker-event ordering.
- Every existing terminal
-
Completion waits for reconciliation
- The resumed batch does not resolve until all child contexts that were terminal at invocation start have been incorporated.
- The order in which their worker events arrive does not change which recorded outcomes appear.
-
Completion policies use the reconciled state
min_successful, fail-fast, failure-count tolerance, and failure-percentage tolerance are evaluated against all recorded terminal outcomes before later items are admitted.- A supported monotonic
should_completepredicate cannot cause a recorded terminal outcome to be omitted.
-
No unnecessary new work starts
- If the reconciled terminal records already satisfy a completion rule, no item beyond the recorded range starts.
- Existing operation-ID ordering and
max_concurrencyguarantees remain intact.
-
Existing replay behavior remains valid
- A parent that is already terminal continues replaying its serialized
BatchResultorCompletionRecord. - Existing normal-payload and
ReplayChildrenhistories require no migration. - Existing in-flight
STARTEDexecutions remain readable without a checkpoint-format change.
- A parent that is already terminal continues replaying its serialized
-
Tests cover both APIs
- Add the exact
SUCCEEDED,SUCCEEDED,FAILEDreproduction formap(). - Add equivalent coverage for
parallel(). - Cover fail-fast and failure-tolerance decisions.
- Cover delayed deserialization or delayed worker-event delivery.
- Assert that
has_failure,failure_count,status, andthrow_if_error()reflect the recorded failure. - Assert that terminal branch bodies follow their existing replay behavior.
- Assert that later item bodies do not run once the reconciled state has completed the batch.
- Add the exact
-
Documentation distinguishes two cases
- A
STARTEDparent must reconcile terminal child records before completing. - After the parent itself has checkpointed its
BatchResult, that result remains authoritative on replay. A child can still appear terminal in history while the recorded batch item remainsSTARTED, as documented for JavaScript by aws/aws-durable-execution-sdk-js#1092.
- A
Out of scope
- Changing
NestingType.FLAT, which has no per-item child-context record to reconcile. - Changing the accepted result/history mismatch after the batch parent has recorded its result.
- Rejecting new operations under orphaned branches, tracked by #641.
- Invocation deadlines and unbounded branch cleanup, tracked by #741.
- Changing any public method signature or checkpoint payload format.
Activity