Skip to content

Split outstanding into active + outstanding; fix finalization race - #28

Open
thatch wants to merge 1 commit into
mainfrom
thatch/last-call
Open

Split outstanding into active + outstanding; fix finalization race#28
thatch wants to merge 1 commit into
mainfrom
thatch/last-call

Conversation

@thatch

@thatch thatch commented Apr 25, 2026

Copy link
Copy Markdown
Member

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.

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
thatch marked this pull request as ready for review April 29, 2026 19:03
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