Split outstanding into active + outstanding; fix finalization race - #28
Open
thatch wants to merge 1 commit into
Open
Split outstanding into active + outstanding; fix finalization race#28thatch wants to merge 1 commit into
thatch wants to merge 1 commit into
Conversation
The old single `outstanding` counter was overloaded: it covered both batches with `process()` in flight and results sitting in `output_notifications` waiting to be forwarded. That ambiguity let `_check_for_final` see `outstanding == 0` and mark a step final while results were still queued, causing dropped notifications under concurrency. This change splits it into `active` (process() in flight) and `outstanding` (items in output_notifications not yet forwarded). `_check_for_final` now acquires `state_lock` once to read all three counters as a consistent snapshot. `_GuardedList` and a `__setattr__` override enforce the locking discipline statically. `unprocessed_notifications` appends remain intentionally unlocked — they only occur before the finalization window opens for a given step. Also adds `last_call()`, a hook called exactly once when a step's inputs are exhausted and all batches have drained, so subclasses can emit trailing work without fighting the finalizer.
thatch
marked this pull request as ready for review
April 29, 2026 19:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The old single
outstandingcounter was overloaded: it covered bothbatches with
process()in flight and results sitting inoutput_notificationswaiting to be forwarded. That ambiguity let_check_for_finalseeoutstanding == 0and mark a step final whileresults were still queued, causing dropped notifications under
concurrency.
This change splits it into
active(process() in flight) andoutstanding(items in output_notifications not yet forwarded)._check_for_finalnow acquiresstate_lockonce to read all threecounters as a consistent snapshot.
_GuardedListand a__setattr__override enforce the locking discipline statically.
unprocessed_notificationsappends remain intentionally unlocked — theyonly occur before the finalization window opens for a given step.
Also adds
last_call(), a hook called exactly once when a step's inputsare exhausted and all batches have drained, so subclasses can emit
trailing work without fighting the finalizer.