Repository navigation
fix(scheduler): record fire events under the session lease - #2426
Merged
Merged
Conversation
On a lease-backed deployment (mecak8s), the fire function closes its session, releasing the lease, before the scheduler emits schedule.fired or schedule.failed, so appendEvent rejected every lifecycle event. EmitScheduleEvent now holds the session lease for the append via reaffirmLease, so a fire settled during drain still records its outcome. The acquire-and-release-if-new pattern moves into acquireScopedLease, shared with the two mutation-lease helpers. A fire deadline that lapsed during run admission surfaced as "session not found" (GetSession reports any load failure as absent), and FireNow returned NotFound for a schedule that exists. The fire stays a failed fire, but its error now names the deadline; the original admission error is logged. Also ignore the mecak8s Kind fixture's generated kubeconfig. Co-Authored-By: Claude Opus 5.5 <[email protected]>
rdimitrov
force-pushed
the
rdimitrov/efficacious-visage-24f58015
branch
from
October 22, 2026 12:20
c6b2534 to
43d06e0
Compare
Merged
2 tasks
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
Fixes two scheduled-task bugs found while validating scheduled tasks on Kubernetes. Both only show up with a session lease backend, so local single-process runs never hit them.
Fired/failed events were dropped on Kubernetes. The fire function closes its session, releasing the session lease, before the scheduler writes the
schedule.firedorschedule.failedevent. With a lease backend,appendEventthen rejected the write ("session is leased by another process"), so no fire on mecak8s ever had this event in its durable log.EmitScheduleEventnow holds the session lease for the append and releases it afterwards. It usesreaffirmLease(no drain gate), so a fire settled during shutdown still records its outcome. The acquire-and-release-if-new pattern is pulled intoacquireScopedLease, which the two existing mutation-lease helpers now share.A deadline that lapsed before the run started reported "session not found". With a context-aware store (Redis), the expired fire context made
GetSessionfail during run admission.GetSessionreports every load failure as not found, so the fire record saidsession not foundandFireNowreturnedNotFoundfor a schedule that exists. The fire still counts as failed (the run never started, asTestFireProvisionalAdmissionDeadlineKeepsPendingUntilRecoveryrequires), but its error now names the deadline:scheduled fire wall-clock deadline of 1ms lapsed before the run started. The rewrite applies only when the fire's own deadline is the one that expired, not an earlier caller deadline, and the original admission error is logged as a warning.Also ignores the mecak8s Kind fixture's generated kubeconfig, which held a client key and was not ignored.
Related follow-ups, not in this PR: #2423 (FireNow fails on non-leader replicas) and #2424 (stop schedules of deactivated owners).
Testing
TestScheduleEventLogContainsEvScheduleFirednow runs with and without a session lease. The lease case failed before the fix and asserts every acquired lease is released.TestFireDeadlineDuringRunAdmissionNamesDeadlineuses a store whoseLoadhonors cancellation, like Redis. It failed before the fix withsession not found.mecatl-dev, 2 replicas, Redis, mock provider): fire streams now end withschedule.firedorschedule.failed, with no append warnings and no leftover fire-session leases. A 1msfire_timeoutfire records the deadline message, andFireNowreturnsInternalwith that message.golangci-lintis clean on every module except one pre-existing finding in the macOS-onlyenvironment/microvm/launch_ownership_darwin.go, which this PR doesn't touch.-race. On macOS,task test:racehits pre-existing environmental failures (/varvs/private/var, git worktree, microVM); they fail identically on a clean checkout of the base commit. CI on Linux is the authoritative run.go run ./cmd/mecademoshows the tool call, permission ask and approval, and the result.API compatibility
schedule.firedandschedule.failedevents that the contract already promises and single-process deployments already record. Clients reading the durable log see the documented events; none needs to change.FireNownow returnsInternalwith a deadline message instead ofNotFound.NotFoundfalsely claimed the schedule or session did not exist. The fire's stop reason is unchanged (error). A client that treatedNotFoundas "schedule deleted" no longer gets a false positive in this case.internal/.🤖 Generated with Claude Code