fix: fence stale job recovery transitions - #209
Merged
GiovaniGuizzo merged 2 commits intoAug 26, 2026
Conversation
GiovaniGuizzo
approved these changes
Aug 26, 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.
Summary
JobTransitionerwrite, closing both stale-sweep and old-executor overwrite races;LazyBackend; andCloses #208
Why this is needed
releaseStaleJobs()currently operates on snapshots returned byBackend.staleJobs(). Before recovery writes its transition, a live executor or another worker can complete, re-claim, or start a newer attempt of the same job. The existing update is matched only by jobid, so recovery can overwrite that newer state.A state-only condition is not sufficient: a stale snapshot and a newer attempt can both be
running. This change compares the lifecycle fields that identify the execution on which the transition was based:The backend performs the comparison and update atomically. If the fingerprint no longer matches,
JobTransitionerraisesJobTransitionConflictError. Stale recovery catches only that conflict and skips the obsolete snapshot; other backend failures continue to propagate.Why all lifecycle transitions are fenced
Fencing only
releaseStaleJobs()closes one direction of the race but leaves the inverse:Using the same compare-and-update precondition in
JobTransitionerprevents an old executor from completing, failing, retrying, snoozing, or canceling an execution it no longer owns.Backend behavior
UPDATE ... RETURNING.findOneAndUpdate()withidplus the execution fingerprint in the filter.LazyBackenddelegates the new method.The MySQL conformance test includes a matching update that changes no values, ensuring a match is not misclassified as a conflict.
No database schema migration is required.
Compatibility note
Backend.updateJobIfCurrent()is intentionally required rather than optional. This is a source-level compatibility change for custom backend implementations, but making it optional would allow a backend to compile while silently omitting the safety guarantee. The custom-backend documentation and example are updated.If maintainers prefer a persisted revision/fencing-token column, the same tests can validate that implementation. The submitted fingerprint approach keeps this fix focused and avoids a schema migration.
Tests added
LazyBackenddelegates the conditional update; andBefore the fix, the two primary stale-sweep regression tests fail deterministically on v1.16.2: a completed job becomes
waiting, and a newerrunningattempt 2 owned byworker-bis replaced by the stale attempt 1 snapshot owned byworker-a.Validation
yarn build— 13/13 tasks passedyarn format:check— passedyarn lint— passedyarn test:all:ci— 8/8 tasks passedyarn test:integration:ci— 3 files, 76/76 tests passedyarn test:all:cigit diff --check— passedPull request checklist
yarn test:all:ciandyarn test:integration:ci)