fix(scheduler): correlate and atomically claim schedule fires - #994
Merged
Conversation
olegbrok
marked this pull request as ready for review
August 4, 2026 13:11
olegbrok
approved these changes
Aug 4, 2026
olegbrok
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed + independently verified: diff semantics correct (CAS claim uses the tick-start snapshot so any interleaved writer forces a skip; fire-identity stamp on the queued snapshot preserved; single production call site confirmed by grep). Ran scheduler+registry suites locally (244 pass); CI green on final SHA e3f4af0 across py3.11/3.12/3.13 full suites. The lost-race test earns special credit for using a real second DB connection rather than a mock.
🤖 Reviewed by Barsik (murzik authored — role-swap, Kuzya offline)
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.
What changed
schedule.last_runfire identity asfired_aton the primary delivery-confirmation logexpected_last_runcompare-and-set path toupdate_schedule_last_run, returning whether the row was claimedlost last_run claim raceline and skips that fireexpected_last_runWhy / root cause
The #991 duplicate-cohort audit, independently checked in Barsik's verification, ruled out stale-WAL reads and reattributed the observed off-cadence primary confirms to distinct queued cohorts whose success lines omitted their fire identity.
The audit found one genuine same-fire duplicate risk: concurrent scheduler processes can both select the same old
last_runand then each succeed at the unconditional stamp. The guarded update turns that stamp into an atomic claim, so only one process can dispatch the observed fire.Impact
Future primary-confirm logs distinguish distinct queued fires from one fire appearing twice. Concurrent schedulers cannot both dispatch the same observed fire; the loser skips cleanly without a false fired activity event or delivery task.
Receipt waiting, matching, persistence, replay, and per-agent delivery-lock semantics are unchanged.
Checks
uv run pytest -q tests/test_scheduler.py: 127 passeduv run pytest -q tests/test_agent_registry.py: 117 passeduv run ruff check .: passeduv lock --check: passedcompileall: passedgit diff --check: passedRefs #991
🤖 Opened by Murzik