Skip to content

fix(scheduler): record fire events under the session lease - #2426

Merged
rdimitrov merged 1 commit into
mainfrom
rdimitrov/efficacious-visage-24f58015
Oct 22, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
rdimitrov/efficacious-visage-24f58015

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

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.fired or schedule.failed event. With a lease backend, appendEvent then rejected the write ("session is leased by another process"), so no fire on mecak8s ever had this event in its durable log. EmitScheduleEvent now holds the session lease for the append and releases it afterwards. It uses reaffirmLease (no drain gate), so a fire settled during shutdown still records its outcome. The acquire-and-release-if-new pattern is pulled into acquireScopedLease, 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 GetSession fail during run admission. GetSession reports every load failure as not found, so the fire record said session not found and FireNow returned NotFound for a schedule that exists. The fire still counts as failed (the run never started, as TestFireProvisionalAdmissionDeadlineKeepsPendingUntilRecovery requires), 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

  • TestScheduleEventLogContainsEvScheduleFired now runs with and without a session lease. The lease case failed before the fix and asserts every acquired lease is released.
  • TestFireDeadlineDuringRunAdmissionNamesDeadline uses a store whose Load honors cancellation, like Redis. It failed before the fix with session not found.
  • Local Kind (mecatl-dev, 2 replicas, Redis, mock provider): fire streams now end with schedule.fired or schedule.failed, with no append warnings and no leftover fire-session leases. A 1ms fire_timeout fire records the deadline message, and FireNow returns Internal with that message.
  • golangci-lint is clean on every module except one pre-existing finding in the macOS-only environment/microvm/launch_ownership_darwin.go, which this PR doesn't touch.
  • Scheduler, schedule-server and lease tests pass with -race. On macOS, task test:race hits pre-existing environmental failures (/var vs /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/mecademo shows the tool call, permission ask and approval, and the result.

API compatibility

  • Assessment: compatible bug fix, no major bump, no new feature identifier.
  • Event log: lease-backed deployments now record the schedule.fired and schedule.failed events that the contract already promises and single-process deployments already record. Clients reading the durable log see the documented events; none needs to change.
  • FireNow error: when a fire's deadline lapses before its run starts, FireNow now returns Internal with a deadline message instead of NotFound. NotFound falsely claimed the schedule or session did not exist. The fire's stop reason is unchanged (error). A client that treated NotFound as "schedule deleted" no longer gets a false positive in this case.
  • Upgrade implications: none. No stored-data or Go API changes outside internal/.

🤖 Generated with Claude Code

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
rdimitrov force-pushed the rdimitrov/efficacious-visage-24f58015 branch from c6b2534 to 43d06e0 Compare October 22, 2026 12:20
@rdimitrov
rdimitrov merged commit bf5ad22 into main Oct 22, 2026
44 checks passed
@rdimitrov
rdimitrov deleted the rdimitrov/efficacious-visage-24f58015 branch October 22, 2026 13:43
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 23, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working kubernetes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant