fix(delivery): ownership-token in-flight lock prevents stale finally double-delivery - #176
Open
donrami wants to merge 1 commit into
Open
fix(delivery): ownership-token in-flight lock prevents stale finally double-delivery#176donrami wants to merge 1 commit into
donrami wants to merge 1 commit into
Conversation
…double-delivery A failed send's .then released the lock and the generation-change retry re-acquired it for send 2; the original .finally then unconditionally deleted that new lock mid-flight, letting a third caller (another bind flush or complete event) start a duplicate workflow-result turn. The lock is now runId -> ownership token (Map<string, number>): release only if you own the token. Regression test covers the fail-overlap-rebind race. Also removes the scratch repro helper. Follow-up from QuintinShaw's QuintinShaw#169 approval comment.
This was referenced Aug 30, 2026
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.
Fixes #175.
deliverAndAck's in-flight lock (Set<runId>) could be released twice for one run: the failed send's.thenreleases it, the generation-change retry re-acquires it for the next send, and the original.finallydeletes it again — leaving the retry send unprotected so a third caller (bind flush / duplicatecomplete) can double-deliver the sameworkflow-resultturn.Change: the lock becomes
Map<runId, token>. Each deliver-and-ack captures its own token at acquisition; both.thenand.finallyrelease viarelease(), which deletes only if the stored token still matches. A superseded chain can no longer drop a newer send's lock.Verification:
a failed send overlapping a re-bind cannot double-deliver— fails on the oldSetlock (retry released mid-flight), passes with the token lock.workflow-authoring-skill,workflow-release-gate) fail on pristinemaintoo (pack-shape/environment, pre-existing).workflow-resultdelivered withpendingDeliverycleared, zero probe entries.