Skip to content

fix(supervisor): anchor the successor's ready gate to its first LIVE and keep holding readiness while the admin is busy, so the old pod is never deleted mid-handoff (#991) - #1026

Merged
bpalermo merged 4 commits into
mainfrom
fix/991-handoff-readiness-timing
Sep 27, 2026

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Problem (#991)

On the rev242 soak (0.95.3, cb79180) the old aether-proxy pod was deleted mid-handoff on 22 of 30 node-rolls: its supervisor logged termination requested mid-handoff and recorded shutdown_branch{branch="handoff"}. The data plane stayed clean because every case took the handoff arm. But the #132/#795 invariant (the old pod stays until the successor has taken over) was broken. A successor that wedges before going LIVE would have left the node on the 155 s drain_fallback rather than on an old pod that is still Ready.

Nothing in the supervisor or the chart changed between rev239 and rev242. What changed is the successor Envoy's fork → starting workers time under load: 2.2–3.5 s on rev239, 3.2–6.0 s on rev242 (one outlier at 31 s). That broke two assumptions:

  • Group A: 13 of 30, SIGTERM at +18.9–19.8 s. successorReadyGate() made the successor Ready at fork + 15 s + 3 s = fork + 18.0 s. Envoy arms its parent-shutdown timer in startWorkers(), not at the fork: shutting down parent after drain − starting workers measured 14.93–15.00 s on every roll. So the predecessor died at 18.2–21.0 s, after the gate, and the DaemonSet deleted the old pod about 1 s after the new one went Ready.
  • Group B: 9 of 30, SIGTERM at +6.0–11.3 s. onNotLiveEpoch held the old pod's readiness only while ready && reachable && anyChildTracked() (fix(supervisor): hold readiness while serving as hot-restart parent #132). During the handoff the admin port belongs to the successor, whose main thread is busy loading its first listener batch (13 inbound_*_h3 listeners on w05). One /server_info probe over its 1 s timeout cleared the marker. Three failed exec probes at 2 s later the pod went NotReady, and with a surge pod already present the DaemonSet deleted it at once. pod not ready came 5.0–6.3 s before each early SIGTERM.

Fix (both in agent/internal/proxy/hotrestart)

  1. The ready gate is anchored on the successor's first observed LIVE (liveAnchoredReadyGate, called from onLiveEpoch on the gated epoch's first LIVE):
    readyGate = max(fork + ParentShutdownTime + 3s, firstLiveObserved + ParentShutdownTime + 2s)
    • ParentShutdownTime is cfg.ParentShutdownTime, the same value buildEnvoyCmd passes as --parent-shutdown-time-s, not a literal.
    • The gate only ever moves later, and only for the epoch initStartEpoch armed. In-pod hot restarts and fresh epoch-0 starts are unaffected.
    • Why 2 s: the parent exits by LIVE + PST + 0.9 s (measured), and the observed LIVE is never earlier than the real one.
    • Logged as successor ready gate anchored anchor=fork|live sinceFork=… readyGateIn=… readyGateAfterFork=…. The fork gate is now also logged on live predecessor confirmed (readyGateIn, readyGateAnchor=fork).
  2. The parent hold survives an unreachable admin, up to the existing admin watchdog's bound:
    hold := ready && anyChildTracked() && (reachable || now − unreachableSince < adminUnresponsiveDeadline())
    • The bound is the existing adminUnresponsiveDeadline() (--admin-unresponsive-deadline, 30 s default). No new constant.
    • A genuinely wedged admin still ends the hold on the same tick that checkWedgeWatchdogs restarts the container.
    • With no Envoy of ours tracked, the hold never applies.
    • Logged once per unreachable streak as holding readiness through unreachable admin: successor likely initializing … holdBound=30s.

To make the state machine testable, the supervisor gets an injectable clock (Supervisor.now, time.Now outside tests). It is used by the gate, the hold and the two wedge watchdogs.

Gates, each seen RED

New file agent/internal/proxy/hotrestart/handoffgate_test.go drives onLiveEpoch / onNotLiveEpoch / checkWedgeWatchdogs on a fake clock.

test pre-fix rules this PR
(A) TestSuccessorReadyGateAnchorsOnFirstLive: LIVE at fork + 5 s. Not Ready at fork + 18 s, nor 1 ms before LIVE + 15 s + 2 s; Ready at that point FAIL (Ready at fork + 18 s) PASS
(B) TestReadinessHeldThroughBusySuccessorAdmin: admin unreachable for 1, 2, 3 s and then 29 s with a child tracked. The marker is held FAIL (marker cleared on the first unreachable tick) PASS
(B bound) TestReadinessHoldThroughUnreachableAdminIsBounded: unreachable past 30 s. The marker is cleared, the admin watchdog fires on the same tick, and with no child tracked there is never a hold PASS PASS
TestSuccessorReadyGateKeepsForkFloorOnFastLive (control: LIVE at +0.5 s keeps fork + 18 s) PASS PASS
TestLiveAnchorIgnoresUngatedEpochs (in-pod epoch and epoch-0 are never gated) PASS PASS

How red was shown: the clock plumbing was kept, and only the two decision rules were reverted to today's code (adminAnswering := reachable, and liveAnchoredReadyGate returning early). With that, --- FAIL: TestSuccessorReadyGateAnchorsOnFirstLive and --- FAIL: TestReadinessHeldThroughBusySuccessorAdmin, and every other test passed. With the fix restored, all pass.

The existing tests are unchanged and green: #132 hold, S16 TestInitStartEpochPublishesEpochAndGateTogether (the fork gate is still armed atomically with the epoch), S17, #795 / successor_wait, and the #729 lame duck. The only edit to them is the new unreachableSince argument in the two onNotLiveEpoch calls in epoch_test.go.

No integration harness runs a real Envoy for the supervisor under test/ or e2e/, so the unit gates plus the next soak are the validation.

Verification

  • bazel test //agent/internal/proxy/... //agent/cmd/proxy-supervisor/...: 3/3 pass. That includes //agent/cmd/proxy-supervisor:deps_test; the supervisor binary gains no dependencies (stdlib only).
  • --config=race //agent/internal/proxy/hotrestart:all: pass.
  • build --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/...: clean.
  • run //:format: no diff.

Expected cost

Successor Ready moves from fork + 18.0 s to roughly fork + 19.5–23 s under load, which is 1.5–5 s per node-roll. An unloaded successor that is LIVE within about 1 s keeps the fork gate (anchor=fork), so the cost there is 0. No chart change is needed.

Fleet gate for the next soak

  • sum by (k8s_node_name) (increase(aether_supervisor_shutdown_branch_total{branch="handoff"}[<roll window>])) should be ≈ 0 per roll. On a healthy roll the old pod's Envoy is terminated by the successor's parent-shutdown before the successor goes Ready. The old pod then turns NotReady on its own (nothing of its own is left running) and logs no termination requested. A non-zero count is again a finding. It was 1 per node on 22 of 30 rolls on rev242.
  • termination requested mid-handoff lines should be 0. A line 5–6 s after the same pod's pod not ready means rule 2 failed. A line at about fork + 19 s, after the successor's pod ready, means rule 1 failed.
  • Expect successor ready gate anchored anchor=live on loaded rolls, with readyGateAfterFork ≈ fork→LIVE + 17 s.

Docs

The new docs/runbook.md section "How a proxy roll hands the node over" covers both rules, their bounds, the log lines to grep and the fleet gate. The branch-PromQL comment in the SIGTERM section now says that handoff during a rolling upgrade is a finding. e2e/soak/README.md does not state the +18 s number, and no separate supervisor metrics doc exists, so neither needed changes.

Closes #991

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 4 commits September 27, 2026 18:45
…and keep holding readiness while the admin is busy (#991)

Under soak load the successor Envoy's fork -> "starting workers" grew from
2.2-3.5s (rev239) to 3.2-6.0s (rev242), and the old aether-proxy pod was
deleted mid-handoff on 22 of 30 rolls:

- Group A (13/30): the ready gate was fork + ParentShutdownTime + 3s, but
  Envoy arms parent shutdown in startWorkers(). The gate now is
  max(fork + PST + 3s, firstLiveObserved + PST + 2s), with PST the value
  passed to envoy as --parent-shutdown-time-s. Logged as
  "successor ready gate anchored" with its anchor (fork|live).
- Group B (9/30): the parent's readiness hold dropped on one unreachable
  /server_info tick while the successor's main thread was busy loading its
  first listener batch. The hold now survives an unreachable admin for the
  existing admin watchdog bound (adminUnresponsiveDeadline, 30s default),
  logged once per streak as "holding readiness through unreachable admin".

The supervisor gets an injectable clock so the coordination state machine
is tested on a fake clock; both new gates were seen red with the two rules
reverted. Runbook documents both rules, their bounds, the log lines and
the fleet gate (shutdown_branch{branch="handoff"} ~0 per roll).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 88312db into main Sep 27, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/991-handoff-readiness-timing branch September 27, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

supervisor: on rev242 the old proxy pod gets SIGTERM mid-handoff (6–11 s after the fork, before the successor's readiness gate) in 7 of 15 handoffs

1 participant