mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[GH-ISSUE #401] scheduler: self-invalidating leader gate (single-goroutine elect loop) #102
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#102
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @NickNYU on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/kvcache-ai/AgentENV/issues/401
Affected component
Gateway / scheduler
Problem statement
The scheduler's leader gate reads only the local acquisition flag, which lags the real Lease holder by up to
renew_deadline. In #341 this is made safe by the validated timing inequality (lease_duration > renew_deadline): client-go stops the old leader withinrenew_deadlineof its last successful renew, while a standby can only acquire afterlease_duration— so no two replicas serve concurrently.But the safety argument rests on client-go's callback timing rather than on anything self-evident in the scheduler's own code, and a partitioned old leader keeps serving for up to
renew_deadline— legal single-writer, but longer than necessary.Use case
HA scheduler deployment (see
deploy/k8s/overlays/ha): the leader pod is partitioned from the API server but stays alive and keeps receiving traffic on its (soon-to-be-removed) endpoint.Current behavior and workarounds
renew_deadline, not anything the scheduler controls directly.Desired behavior
lease_duration/2, read directly from the leadership snapshot — self-invalidating reads, no watcher goroutine.Proposed approach
Already implemented on
NickNYU/AgentENVbranchfeat/scheduler-elect-loop(commit 59d9ce6, stacked on #341):leadershipSnapshot.expiresAt= last successful acquire/renew +lease_duration/2(sofa-registry-style duration/2 safety margin); the gate isleader && now < expiresAt.electLoopreplaces client-go'sleaderelection.Runcallbacks; standby acquire keeps client-go semantics (observe the unexpired record, then resourceVersion CAS;AcquireTime/LeaderTransitionsbookkeeping preserved).renew_deadlineconfig field removed; validation becomeslease_duration >= 4 * retry_periodso the serving margin spans at least two election ticks.Compatibility and operational impact
API/config changes: removes
scheduler.leader_election.renew_deadline(leader election is new in #341 and unreleased, so no migration).Snapshot or storage format changes: none.
New host/runtime requirements: none.
Upgrade and rollback considerations: behavior change on partition — the old leader stops serving at
lease_duration/2instead ofrenew_deadline; strictly faster fail-closed.Alternatives considered
Pre-submission checklist