You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cron): out-of-order overlapping slot completion can regress schedule and duplicate execution #962
at internal/cli/cron_run.go:206-220. The per-job lock makes each mutation atomic but does not make values derived from an earlier slot current.
Depending on completion order, slot N's completion can move NextRunAt from N+2 back to N+1, allowing another scheduler to claim N+1 again. Both completions can also persist FireCount == 1 rather than 2.
The existing concurrent claim test (internal/cli/cron_claim_test.go:12-41) covers two schedulers racing for the same slot, not adjacent slots completing out of order.
Expected behavior
Each scheduled slot is claimed at most once.
NextRunAt advances monotonically and never moves backward when older work completes.
FireCount reflects every completed fire.
Actual behavior
Completion of an older slot can overwrite newer schedule/accounting state, exposing an already-claimed slot as due and causing duplicate automated actions and lost fire counts.
Recommended fix
Persist a claimed slot/run identity. At completion:
increment current.FireCount rather than assigning a stale count;
update schedule state with a slot-aware CAS or monotonic guard;
never move NextRunAt backward;
add adjacent-slot/out-of-order completion tests across independent stores/process locks.
PierrunoYT prepared and independently validated a focused fix locally while awaiting maintainer triage; no branch or PR has been published because this issue does not yet have issue-approved.
Regression proof on exact base 6fe0d1edcdbadea6d566800fbcca739c1cd54ea1, with only the new test applied:
go test ./internal/cli -run '^TestFireJobOutOfOrderAdjacentSlotsDoesNotRegress$' -count=1
FireCount=1 NextRunAt=2026-06-09 09:01:00 +0000 UTC; want FireCount=2 NextRunAt=2026-06-09 09:02:00 +0000 UTC
The focused change makes the claimed next-run value a completion CAS token, increments the current lock-protected fire count, and prevents an older completion from overwriting a newer adjacent-slot claim. The regression passes with the fix.
Validation completed successfully:
make fmt-check
go vet ./...
go test ./...
make test (full race suite)
go run ./cmd/zero-release build
go run ./cmd/zero-release smoke
make lint-static (0 issues.)
make vulncheck (No vulnerabilities found.)
git diff HEAD --check
If maintainers approve the issue for outside contribution, the focused commit is ready to publish as a PR.
Reopening this, and applying issue-approved so it is not blocked on the label again.
@PierrunoYT you closed your own report on 2026-08-26 with an empty comment, after saying upthread that you were holding the branch back because this issue had no issue-approved label. The defect you described is still on main verbatim:
Both assignments happen inside store.Mutate with no slot identity, no compare-and-swap and no monotonic guard, so a slot that finishes out of order still writes its stale view over a newer one. internal/cli/cron_claim_test.go covers same-slot racing through TestFireJobClaimPreventsDoubleFire and nothing covers the overlapping out-of-order case.
Closing a live defect because the process gate had not been applied is the wrong outcome, and the gate was mine to apply. It is applied now, so a PR implementing this can merge on review. If you still have that branch, please open it; if you would rather not, say so and it goes in the pool with the label already on it.
Found in a coverage audit that was looking for issues whose linked PR had closed, which this one would have escaped: it has no PR at all.
@PierrunoYT two weeks since the label went on. If the branch you validated is still around, open it as it is and I'll review it. If not, or if you'd rather not, I'll write the fix from Monday, Sep 29, so it doesn't sit any longer. Either is fine, just say which here.
Activity
PierrunoYT commentedon Aug 25, 2026
PierrunoYT prepared and independently validated a focused fix locally while awaiting maintainer triage; no branch or PR has been published because this issue does not yet have
issue-approved.Regression proof on exact base
6fe0d1edcdbadea6d566800fbcca739c1cd54ea1, with only the new test applied:The focused change makes the claimed next-run value a completion CAS token, increments the current lock-protected fire count, and prevents an older completion from overwriting a newer adjacent-slot claim. The regression passes with the fix.
Validation completed successfully:
make fmt-checkgo vet ./...go test ./...make test(full race suite)go run ./cmd/zero-release buildgo run ./cmd/zero-release smokemake lint-static(0 issues.)make vulncheck(No vulnerabilities found.)git diff HEAD --checkIf maintainers approve the issue for outside contribution, the focused commit is ready to publish as a PR.
Vasanthdev2004 commentedon Sep 12, 2026
Reopening this, and applying
issue-approvedso it is not blocked on the label again.@PierrunoYT you closed your own report on 2026-08-26 with an empty comment, after saying upthread that you were holding the branch back because this issue had no
issue-approvedlabel. The defect you described is still on main verbatim:Both assignments happen inside
store.Mutatewith no slot identity, no compare-and-swap and no monotonic guard, so a slot that finishes out of order still writes its stale view over a newer one.internal/cli/cron_claim_test.gocovers same-slot racing throughTestFireJobClaimPreventsDoubleFireand nothing covers the overlapping out-of-order case.Closing a live defect because the process gate had not been applied is the wrong outcome, and the gate was mine to apply. It is applied now, so a PR implementing this can merge on review. If you still have that branch, please open it; if you would rather not, say so and it goes in the pool with the label already on it.
Found in a coverage audit that was looking for issues whose linked PR had closed, which this one would have escaped: it has no PR at all.
Vasanthdev2004 commentedon Sep 26, 2026
@PierrunoYT two weeks since the label went on. If the branch you validated is still around, open it as it is and I'll review it. If not, or if you'd rather not, I'll write the fix from Monday, Sep 29, so it doesn't sit any longer. Either is fine, just say which here.
PierrunoYT commentedon Sep 26, 2026
Workin on it!
fix(cron): preserve newer claims when overlapping runs complete (Twig…