Repository navigation
feat(agent): node-ownership lock and standby mode for a surge roll of the agent (proposal 041) - #1155
Merged
Merged
Conversation
This was referenced Oct 3, 2026
… the agent (proposal 041) A node agent now claims its node with an exclusive flock on /run/aether/agent.lock, tried once at process start before local storage is read. A free lock is today's behaviour: the agent owns the node as the manager starts. A taken lock makes it a standby that builds everything a first serve needs (identity, registry watch, listeners from storage, capture projection, client certificates) but binds neither xds.sock nor cni.sock and writes no node file until the kernel releases the lock. Takeover steps, between the lock and ownership: merge the observed upstreams and QUIC pairs the old agent persisted (its final flush included), then diff local storage against the standby's load and apply the overlap's CNI ADD/DEL (storage.Reloader; a DEL now removes listeners and the SVID subscription). Then the sockets bind (bind gate in common/xds), and the liveness loop, termination watch, ghost sweep, observed-set flush, mesh-DNS snapshot, conflist repair, taint remover and metrics server start. - common/xds: SetBindGate; SetUnlinkOnClose(false) plus an inode check, so a server exiting never unlinks a successor's socket. - readiness: a "standby" check passes once the first snapshot is complete, and always once the node is owned. - registrar: WatchEndpointsRequest.instance (the pod name) keys the watch, so two agents on one node no longer replace each other's stream. - a lock-free node with a live server on its sockets (an agent predating the lock) is also treated as owned by someone else until nothing answers. Refs #1123 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo
force-pushed
the
feat/041-agent-standby
branch
from
October 3, 2026 17:57
933d5ab to
18b4c85
Compare
…es passed, not timed out (proposal 041 review) FirstServeReady also closes when the registry gate (15 s, local-only start) or the capture gate (10 s) times out: right for a node nobody else serves, wrong for a surge standby. Its Ready lets the DaemonSet delete a healthy old agent, and the takeover would then publish local-only CDS/EDS over the proxy's working config, the #740 clobber. A registrar + agent upgrade makes that a real scenario. - AgentXdsServer.StandbyComplete closes once the first snapshot is built, the registry actually loaded (initially or by the background retry), and the capture projection landed. The "standby" readiness check waits on it, so a standby that cannot reach the registrar stalls the roll (maxUnavailable 0) instead. The client-certificate gate stays lenient. - The post-takeover certificate wait covers only pods the takeover added: a takeover step notes the backlog before the reconcile (MarkTakeoverBaseline), and the bind waits (<= 1 s) only while the backlog is above it. One pod whose SVID never comes no longer adds 1 s to every takeover. - Proposal: both recorded, plus the in-flight-ADD-at-SIGTERM gap cost and the liveServer note. Refs #1123 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Owner
Author
|
Review fixes pushed (b0b6d39):
Re-validated on kind with surge on: 20 rolls under load, gap median 0.080 s / p99 0.169 s, 0 non-200 of 18,107, gate 1.0 s green. The overlap ADD+DEL e2e is green again. 🤖 Generated with Claude Code |
bpalermo
marked this pull request as ready for review
October 3, 2026 18:36
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.
Refs #1123. Part 1 of 4 of proposal 041 (the standby agent). Stack: this PR ← agent-ready probe ← chart ← e2e gate (
Fixes #1123).Nothing changes for a delete-then-create roll or a plain restart: the lock is free when the agent starts, so it owns the node as the manager starts and no takeover step runs. The surge strategy is turned on by the chart PR.
What it does
Node ownership (
agent/internal/ownership).flockon/run/aether/agent.lock(--node-lock) once, at process start, before local storage is read.xds.sock/cni.sock. This covers an agent that predates the lock: the first surge roll onto this version.Standby builds everything a first serve needs: identity, registry watch, listeners from storage, capture projection, client certificates. It holds back:
xds.sockandcni.sock. There is a newSetBindGateincommon/xds, called between PreListen and bind.SnapshotCache.SetNodeWriteGate);Reasserter.Owned; it still observes, because readiness reads it).TaintRemover.Owned) and the metrics port.EADDRINUSEfor up to 30 s, never fatally. The kernel can hand over the flock while the old process is still closing its listening socket.Takeover steps (only on a contended start):
SnapshotCache.ReloadNodeState:CNIServer.ReconcileStorage(open question 1).storage.Reloader(CachedLocalStorage.Reload) returns added/updated/removed records against the standby's view:RemovePod+ SVID unsubscribe;AddPod+ SVID subscribe;AddPod.It waits for the xDS server's own load from storage, which is the view the diff is taken against. It runs before either socket binds.
Then
xds.sockbinds, after a ≤1 s wait for certificates of pods added by the takeover. Thencni.sockbinds and the writers start.Readiness. A
standbycheck passes once the xDS first snapshot is complete (FirstServeReady: every #1085/#1099/#1118 gate passed). It always passes once the node is owned. This is what a surge roll waits on.Socket ownership.
SetUnlinkOnClose(false), plus an inode check before the server unlinks its own socket on shutdown.Registrar watch keyed per agent. Found in implementation, not in the proposal:
WatchEndpointsstreams bycluster/node. With two agents on one node, eachSubscribecloses the other's stream with DataLoss and forces a full resync, and they ping-pong for the whole overlap.WatchEndpointsRequest.instance(field 5, additive) carries the pod name and is now part of the key. When it is empty, the old key is kept.Hazard table (proposal 041 § "What the overlap must not break")
EADDRINUSEretried (this PR);ports:dropped and exec probes over a pod socket (PRs 2, 3)TestOwnedRunnable*SetUnlinkOnClose(false)+ inode check; live-server wait for a lock-less predecessorTestBindGate_*,TestShutdownLeavesASuccessorsSocketAlone,TestAServerWithoutTheLockStillHoldsTheNode,TestAStaleSocketIsNotAServercni.sock; takeover diff incl. DELTestReconcileStorage_AppliesTheOverlap(ADD + DEL + rewrite over a real shared dir),…ADDThenDELInsideTheOverlapLeavesNothing; e2e in PR 4TestNodeWriteGate_*,TestReloadNodeState_*,TestStandbyObservesButDoesNotRepairTestSurgeAgentsOnOneNodeKeepBothWatches,TestWatcherIDOfTestReconcileStandbyLeavesTheTaintstandbycheckTestStandbyReadiness,TestPreListen_SignalsTheStandbyMilestones,TestSetOwnership_BindsOnlyOnceOwnedapi/aether/cni) is untouched by this stackAlso argued, not gated: the GAMMA/L4 reconcilers write route
status. Every agent on every node already writes the same deterministic status (only on change), and a standby is one more identical writer.Lock/handoff state machine tests (
agent/internal/ownership):--node-lock="".Checks
bazel test --test_tag_filters=-integration //agent/... //common/xds:all //registrar/... //registry/...: all pass.--config=raceon ownership, storage, common/xds, cni/server, xds/cache, xds/server, node, cniconflist, registrar/server and cmd: all pass.bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violationon the touched trees: clean. gocognit pushedReconcileStorage,runAgentandReasserter.Startinto helpers.make gazelle,make format. No go.mod change.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr