Repository navigation
fix(cron): long fenced deliveries no longer recorded as failed 'ownership lost' (#108341, #100401; salvage #106745) - #109310
Merged
kshitijk4poor merged 2 commits intoSep 12, 2026
Conversation
heartbeat_fire_claim only CAS-refreshes claim.at via _with_job; wrapping _under_fire_fence across save_jobs let a blocked .jobs.lock pin the fence and cause mark_job_run to fail closed on completed jobs.
Replace the POSIX-only jobs-flock contention test (skipped off-POSIX, ~120 LOC of monkeypatched flock plumbing) with a single invariant test that fails on pre-fix code in <1s: hold the per-job fire fence from a worker thread, assert the heartbeat still returns True on the calling thread, and that a takeover is still detected (False). The docstring on heartbeat_fire_claim now records WHY it is not under the fence, so the next refactor does not put it back. Co-authored-by: Oliver Heckmann <46627487+oheckmann74@users.noreply.github.com> Co-authored-by: salch-cred <141555468+salch-cred@users.noreply.github.com>
kshitijk4poor
enabled auto-merge (rebase)
September 12, 2026 17:23
This was referenced Sep 12, 2026
Closed
This was referenced Sep 12, 2026
This was referenced Sep 13, 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.
A cron run whose delivery or agent turn holds the per-job fire fence for longer than 30s is no longer recorded as
failed/ "Fire claim ownership lost" after it actually succeeded.Fixes #108341, fixes #100401. Salvage of #106745 by @KoNit-K (cherry-picked, authorship preserved); test shape from #100418 by @oheckmann74 and #108359 by @Sahilvishnaliya (Co-authored-by).
Root cause
The run thread holds
_fire_job_lock(a per-thread RLock + flock) across delivery. The 60scron-fire-claim-heartbeatthread renewed the claim through the same fence, blocked for_JOBS_LOCK_TIMEOUT_SECONDS(30s), failed closed toFalse, and the scheduler read that as a takeover:lost_ownershipset, run interrupted, ledger row writtenfailedwhile the message had already been delivered.Change
cron/jobs.pyheartbeat_fire_claim: refresh under_jobs_lockonly (same shape asheartbeat_run_claim)._refresh_claimstill compare-and-swaps onclaim["by"] == expected_owner, so a real takeover keeps returningFalse. Docstring records why the fence is deliberately not taken.tests/cron/test_claim_job_for_fire.py: one invariant test — worker thread holdsfire_claim_fence, heartbeat on the calling thread returnsTrue, heartbeat for a foreign owner returnsFalse. Fails on unfixedjobs.pyin ~2s.Validation
Falseafter timeoutTrue, ~0msclaim.bytakeoverFalseFalsescheduler._run_with_fire_claim_heartbeat, run holds fence 3s > heartbeat periodlost_ownershipset, "interrupting stale run"scripts/run_tests.sh tests/cron/test_ensure_hermes_home_sets_0700) reproduces on main, unrelatedLock ordering audited: every fence+jobs_lock site is fence→jobs_lock; the heartbeat now takes strictly fewer locks, no new ordering. Remaining
_under_fire_fenceusers (claim_job_for_fire,mark_job_run) mutatebyand run on the owner thread — correct.Related open PRs (same bug)
#95432 #97565 #100418 #100965 #102627 #104286 #105724 #106745 #107226 #107844 #108018 #108359 #108471 #109003 #109083 — this PR carries the smallest fix from that cluster; the tri-state/scheduler-side variants are unnecessary once the heartbeat no longer waits on the fence.