Repository navigation
Conversation
…etes Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
yaythomas
left a comment
There was a problem hiding this comment.
The repository's commit-message check rejects the current 73-character subject because subjects are limited to 50 characters. Can the squash/merge subject use a shorter form, such as fix(sdk): reconcile recorded batch outcomes?
| @@ -342,6 +356,7 @@ def submit(branch: Branch[CallableType, ResultType]) -> None: | |||
| pending | |||
| and in_flight < max_in_flight | |||
| and self.policy.should_continue(failed) | |||
There was a problem hiding this comment.
The coordinator postpones completion while recorded_unsettled is non-empty, but should_continue(failed) can stop admission before every recorded terminal branch is reached. Once the running branches drain, the coordinator raises SuspendExecution, and the same history repeats on the next invocation. Can the reconciling path continue through last_recorded independently of the normal stop rule, while omitting any unrecorded gap whose outcome is already known?
I reproduced this with the reachable history [FAILED, SUCCEEDED, SUCCEEDED, STARTED, SUCCEEDED], max_concurrency=3, and fail-fast behavior. Indices 0–2 start, index 0's cached failure arrives first, index 4 is never admitted, and execute() raises SuspendExecution. The JavaScript reference continues reconciliation and skips gap items. Can this include the equivalent fail-fast and failure-tolerance regression case from Python SDK #835: resumed batches can omit recorded terminal outcomes?
| @@ -330,10 +341,13 @@ def submit(branch: Branch[CallableType, ResultType]) -> None: | |||
| ) | |||
| decision = self.policy.evaluate(succeeded, failed, items_snapshot) | |||
There was a problem hiding this comment.
decision is recomputed and overwritten whenever a recorded item settles. A supported predicate can remain complete while changing its outcome, so resume returns the last outcome rather than the first completion decision that live execution used. Can this retain the first complete CompletionDecision during reconciliation and use it when calculating the completion reason?
I reproduced this with a recorded success followed by a delayed recorded failure. The predicate continues at zero progress, then always completes, first with SUCCEEDED and later with FAILED. This head returns CUSTOM_COMPLETION_FAILED instead of retaining CUSTOM_COMPLETION_SUCCEEDED. The predicate satisfies the documented monotonic contract, and the JavaScript parity implementation latches its first decision.
| assert binding.get() == "empty" | ||
|
|
||
|
|
||
| def test_resumed_batch_settles_recorded_terminal_items_before_completing(): |
There was a problem hiding this comment.
The test function and its executor override are untyped, so mypy does not check their bodies. My type-check run passed but emitted annotation-unchecked for this test. Can these signatures be fully annotated as required by CONTRIBUTING.md's typing rule, including -> None, the executor's generic arguments, and the override parameters and return type?
There was a problem hiding this comment.
Good catch on the unchecked bodies. 237016f fully annotates the test: -> None, the ConcurrentExecutor[Callable[[], str], str] generic arguments, and the parameters and return type of the _execute_item_in_child_context override. It also annotates the evaluate wrapper and the local variables. mypy on tests/concurrency_test.py now reports no issues and no annotation-unchecked notes for this test. The test still fails on the base executor, and tests/concurrency_test.py passes (211 passed).
| def _execute_item_in_child_context(self, executor_context, executable): | ||
| started.append(executable.index) | ||
| if executable.index == 2: | ||
| time.sleep(0.2) # replays its recorded failure after items 0, 1 |
There was a problem hiding this comment.
The 200 ms delay makes the intended event order likely rather than guaranteed under a loaded test host. Can this use threading.Event or a barrier to hold and release item 2 at an observed point in the coordinator sequence?
There was a problem hiding this comment.
Fixed in 237016f. The 200 ms sleep is gone. Item 2 now waits on a threading.Event (5 s timeout). The event is set when the coordinator's evaluate first sees two successes. So item 2's recorded failure arrives after both successes are applied, which is the order that broke the base code.
The test fails on the base executor (index 2 is STARTED, not FAILED) and passes with the fix. tests/concurrency_test.py passes (211 passed) and ruff is clean. I haven't run the full suite or the hatch lanes. The executor.py threads on admission past last_recorded and on latching the first CompletionDecision are still open.
Annotate the regression test and its executor override so mypy checks their bodies, and replace the fixed 200 ms delay with an event that releases the failing item only after the coordinator has applied both recorded successes. The test still fails on the base executor.
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
This is a small change to when a resumed map or parallel decides it is complete, so please check that waiting for the recorded items matches how you want replay to behave.
Thanks for the precise write-up of the
[SUCCEEDED, SUCCEEDED, STARTED]case; it made the failing test easy to build.Issue #, if available
Fixes #835
Description of changes
On resume, a map or parallel batch can contain child contexts that already recorded a terminal outcome. Their replays reach the coordinator in thread completion order, so the batch could decide it was complete before every recorded item had been settled, which left a recorded FAILED item reported as STARTED.
ConcurrentExecutornow reads which NESTED child contexts already have a terminal record (_recorded_terminal_indexes), defers the completion decision until each of those has settled, and starts no new item past the last recorded index while any are unsettled. FLAT branches never checkpoint themselves, so they have no record and are unaffected.Design
recorded_unsettledis empty andlast_recordedis -1).executor.py, no public API members.Assumptions
Decisions not covered by the issue or the design note
Checklist
pending[0].index <= last_recordedcondition, or the FLAT early return, makes tests fail.test_resumed_batch_settles_recorded_terminal_items_before_completing) gave[SUCCEEDED, SUCCEEDED, STARTED]instead of[..., FAILED]on the baseexecutor.pywhen I ran it separately. I can split it into two commits if you want that.How I checked: the full core suite gives 2284 passed with the fix (it needs the testing package installed), and
ruffandmypyon the core source are clean. Not run:hatch run test:all, the CI checks script, commit-message lint, and the examples and wheel lanes. While running the suite repeatedly I sawparallel_test::test_parallel_item_deserializefail about twice in 30 runs, and a different test once in 15 runs on main; both looked timing related and I did not chase them.