Skip to content

fix(agent): exempt API-confirmed orphans from the prune circuit breaker (#670) - #672

Merged
bpalermo merged 1 commit into
mainfrom
fix/670-prune-breaker-orphans
Sep 3, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/670-prune-breaker-orphans

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Fixes #670.

Mechanism

classifyPruneCandidates builds one candidate set out of two classes that fail in completely different ways:

pruneStaleStoragePods then applied the breaker to the combined set and refused the whole pass on a trip. So a large number of legitimately-orphaned records — records Kubernetes confirms are garbage — tripped a breaker built to guard a different failure mode, and because they were never removed, the next pass saw the same fraction and refused again. The protection had become a deadlock, and a self-reinforcing one: the backlog could only grow.

An agent roll resets the counter but not the condition. The staleness lives in on-disk storage the fresh process re-reads, so the breaker re-arms within ~60s on the new process.

Live measurements (2026-09-03 soak, rev190/0.91.3-a14df22)

End of an 8h soak: 92 storage records for 39 live mesh-managed pods = 57.6% stale fleet-wide (worker-01: 36 records / 14 pods). Every node above pruneBreakerFraction = 0.30:

node aether_agent_storage_pods mesh-managed pods stale %
main-worker-01 35 12 66%
main-worker-05 17 9 47%
main-worker-04 12 5 58%
main-worker-02 15 9 40%
main-worker-03 13 8 38%

aether_agent_ghost_sweep_prune_breaker_tripped_total climbed +15 per 15 minutes on every node — exactly one refusal per sweep pass, every pass, perfectly linear for the full 170 minutes before an agent roll, then resumed the same cadence on the fresh pod.

The fix

Compute the breaker fraction over netns-derived candidates only, in both numerator and denominator, and prune API-confirmed orphans unconditionally (still subject to the existing per-pass rate limiting and the nodePodsOK guard). On a trip, only the netns-derived candidates are withheld; the pass is no longer refused wholesale.

Two small pure helpers keep classifyPruneCandidates untouched and pruneStaleStoragePods under the gocognit-15 threshold:

  • pruneCounts(pods, candidates) → (netnsCandidates, netnsEligible, orphanEntries). netnsEligible is every stored entry the API did not confirm orphaned, so the fraction is measured over the class at risk of netns misclassification. This is stricter than the old whole-storage denominator, not looser.
  • orphanCandidates(candidates) narrows the set to orphans when the breaker trips.

breakerTripped is still returned and still interlocks both self-heal eviction paths.

#566 protections preserved, and how each is proven

Protection Preserved Proven by
Netns hysteresis (ghostNetnsFailThreshold consecutive failures) Untouched — classifyPruneCandidates is unchanged TestSweepHysteresisTransientNetnsFailure, TestSweepPrunesStalePods (both unmodified)
API cross-check: a pod the API reports Running with an IP is never pruned regardless of netns (podRunningWithIP) Untouched TestSweepAPICrossCheckVetoesPrune (unmodified)
Breaker still trips and still prunes nothing under correlated netns-stat failure Yes — with no orphans to exempt, the carve-out cannot reach this incident new TestSweepBreakerStillRefusesCorrelatedNetnsFailure (10 pods, every stat fails, API confirms all 10 exist → 0 pruned, engaged gauge 1, trip counter positive); plus unmodified TestSweepMassBreakerRefusesPrune, TestSweepMassBreakerMetricAndInterlock
nodePodsOK == false → no pod-absence pruning at all Untouched — a failed List classifies no orphan, so the exemption has nothing to act on new TestSweepNoPodAbsencePruningWithoutNodePodList (0 pruned, 0 evicted, streaks dropped, stale_pods not even recorded)
#640 stale-while-Running eviction + shared per-pass eviction budget Untouched, still interlocked on breakerTripped TestSweepEvictsStaleRunningPodAfterThreshold, TestSweepStaleRunningEvictionRateLimitedAndBudgetShared, TestSweepStaleRunningInterlockedOnBreaker (all unmodified)
#650 superseded-entry path Untouched, and counted in the netns class (it is netns-derived) TestSweepPrunesSupersededEntry (unmodified)

New tests

  1. TestSweepPrunesMajorityOrphansDespiteBreaker — the regression test. 7 orphans + 3 live, netns pins all lingering (the talos signature): all 7 prune in one pass, breaker gauge reads 0.
  2. TestSweepBreakerStillRefusesCorrelatedNetnsFailure — the agent: ghost-sweep prune needs a mass-delete circuit breaker (power-blip incident 2026-07-19) #566 incident, must still block. It does.
  3. TestSweepMixedOrphansAndNetnsStale — 7 orphans + 4 netns-stale + 6 healthy: orphans prune, the 4 netns candidates stay withheld because they are 4/10 of their own class, above the fraction.
  4. TestSweepNoPodAbsencePruningWithoutNodePodList — the invariant.

Verified empirically that (1) and (3) fail against the pre-fix logic (should have 3 item(s), but has 10) while (2) and (4) pass on both — i.e. the new tests bracket exactly the behaviour change and nothing else. Every pre-existing test passes unmodified; none were weakened.

Instrumentation decision

The breaker was silent-by-log: it fired every 60s on every node for weeks and nobody noticed, because a counter with no alert reads as ordinary sweep activity and an ERROR line that never stops is indistinguishable from wallpaper. A counter is not a detection mechanism for a standing condition. Three changes:

  • aether.agent.ghost_sweep.prune_breaker_engaged (Int64Gauge, recorded every pass, zero included). Turns "the breaker is standing open" into a state an alert can match, rather than a slope someone has to notice. Recording zeros matters: the gauge falls back to 0 the moment the condition clears, so the alert self-resolves.
  • aether.agent.storage.stale_pods (Int64Gauge) — storage entries with no Kubernetes pod on this node, as detected, whether or not they were prunable. orphans_pruned reads zero both when there is no staleness and when cleanup is blocked; this gauge tells those two apart, which is exactly the signal that was missing. Not recorded when nodePodsOK is false, so a failed List is never reported as "zero stale".
  • The trip ERROR line is now rate-limited: loud on the transition into the tripped state (first_trip=true), then once every pruneBreakerRelogPasses = 30 passes (~30 min) while it stands, DEBUG in between — plus a new WARN on the tripped→clear transition so recovery is as visible as the trip.

The existing prune_breaker_tripped counter is kept unchanged.

Alert rules I would write (GitOps repo, not here):

- alert: AetherGhostSweepPruneBreakerStandingOpen
  expr: max_over_time(aether_agent_ghost_sweep_prune_breaker_engaged[15m]) == 1
  for: 30m
  labels: { severity: warning }
  annotations:
    summary: "Ghost-sweep prune breaker standing open on {{ $labels.k8s_node_name }}"
    description: "Stale storage cannot be cleaned on this node and will grow. Check for a correlated netns-stat failure; do not mass-delete."

- alert: AetherAgentStaleStorageBacklog
  expr: aether_agent_storage_stale_pods / clamp_min(aether_agent_storage_pods, 1) > 0.25
  for: 30m
  labels: { severity: warning }
  annotations:
    summary: "{{ $value | humanizePercentage }} of agent storage on {{ $labels.k8s_node_name }} has no live pod"

The second one is the load-bearing one — it would have caught this within half an hour of the backlog forming, independently of whether the breaker was the reason cleanup stalled.

Verifying on-cluster after deploy

  1. aether_agent_ghost_sweep_prune_breaker_tripped_total stops climbing on every node (it was exactly +1/pass).
  2. aether_agent_ghost_sweep_prune_breaker_engaged reads 0 steadily.
  3. aether_agent_storage_pods converges down toward each node's mesh-managed pod count — compare against count(kube_pod_info{node="..."} and on(pod,namespace) kube_pod_labels{label_aether_io_managed="true"}), or just kubectl get pods -A -l aether.io/managed=true --field-selector spec.nodeName=main-worker-01 | wc -l. Worker-01 should fall from ~35 toward ~12. Expect this within a few sweep passes: orphans are pruned per pass at whatever rate they classify, with no eviction involved.
  4. aether_agent_storage_stale_pods (new) drops to ~0 and stays low; aether_agent_ghost_sweep_orphans_pruned_total shows the one-time catch-up burst then settles to churn rate.
  5. Agent logs: a single prune circuit breaker CLEARED line per node, then silence.
  6. Nothing else should move — no lost_add_evictions / stale_running_evictions burst (the eviction paths are untouched and still interlocked), no unmeshed_pods change.

Note on #638

This plausibly removes the substrate of #638's H1, though not #638 itself. The chain is: stale storage record → the endpoint is never deregistered (etcd Put with no lease/TTL; deregistration is entirely agent-driven) → CNI IPAM recycles the dead pod's IP, during a roll overwhelmingly to a pod of the service being rolled → a client dials it, gets that pod's genuine SVID, and the SAN matcher rejects. Draining the stale-record backlog removes the ghost endpoints that recycled IP can collide with, and the correlation is suggestive: worker-01 carried by far the most stale records (23) and is the only node that has ever shown non-zero envoy_cluster_ssl_fail_verify_san_total.

Two caveats against calling #638 fixed here. First, #638's own separate defect — the ghost sweep matching ghosts to live pods by IP alone, ignoring the service — means a ghost whose IP has already been recycled stays un-reapable even with the breaker fixed; that needs its own change. Second, the 4.25s cross-wiring window observed at TRIPLE-cluster is short enough to be a genuine race rather than a standing-garbage effect. So: this should shrink #638's blast radius materially and is a prerequisite for testing H1 cleanly, but #638 should stay open and be re-measured on the next soak after this deploys.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…er (#670)

The #566 mass-delete breaker measured its fraction over the COMBINED
prune set: API-confirmed orphans (the node-scoped pod List says the pod
does not exist here) plus netns-derived candidates (the netns path has
been gone for N consecutive passes). Only the second class can be the
correlated-stat false positive the breaker exists to catch, but counting
the first made the guard self-reinforcing — once a node's orphan backlog
crossed 30% of storage every pass was refused, so the backlog could only
grow, and an agent roll reset the counter but not the condition because
the staleness lives in on-disk storage the fresh process re-reads.

Measured on talos-main during the 2026-09-03 soak: 92 storage records
for 39 live mesh-managed pods fleet-wide (57.6% stale; worker-01 at 36
records for 14 pods), with prune_breaker_tripped climbing +15 per 15
minutes on every node — exactly one refusal per sweep pass, every pass.

The fraction is now computed over the netns-derived class alone, in both
numerator and denominator, and a trip withholds only that class:
API-confirmed orphans prune regardless, still subject to the per-pass
rate limiting. The real protection against a bad API read is unchanged —
nodePodsOK is false when the List fails, which classifies no orphan at
all, so no pod-absence pruning happens in that pass.

Instrumentation: the breaker had been firing every minute on every node
for weeks unnoticed, so a counter alone is not a detection mechanism.
Adds aether.agent.ghost_sweep.prune_breaker_engaged (gauge, recorded
every pass) so a standing trip is a state an alert can match, and
aether.agent.storage.stale_pods (gauge) so the backlog is visible as
DETECTED rather than only as what was successfully pruned. The ERROR
line is now loud on the transition in and out of the tripped state and
rate-limited to once every 30 passes while it stands.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit cf68f1b into main Sep 3, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/670-prune-breaker-orphans branch September 3, 2026 15:54
bpalermo added a commit that referenced this pull request Sep 4, 2026
newCNIMetrics has been at cognitive complexity 16 against the lint limit of 15
since #672 (cf68f1b) added the prune_breaker_engaged and storage.stale_pods
gauges as its fifteenth and sixteenth sequential error-checked registrations.
That PR's CI test job passed, so the violation stayed dormant on main until any
PR that put //agent/internal/cni/server back in the bazel-diff impact set —
which is exactly what #676 (mesh-dns) and the #667 branch now do, and both go
red on it.

Pure mechanical extraction into registerSweepInstruments (ghost-sweep counters
and the prune-breaker gauge) and registerLifecycleInstruments (the unmeshed and
storage gauges, liveness instruments, identity-override counter). No metric
names, descriptions, units or registration order change.

Verified with fail_on_violation on //agent/internal/cni/server/... and the
package tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo added a commit that referenced this pull request Sep 4, 2026
newCNIMetrics is at cognitive complexity 16 against the lint limit of 15 on
main, and no PR ever failed CI for it. #671 (763f5b3) added the fifteenth
registration; #672 was branched before #671 merged, added two more to a file
it saw at 13, and its CI head (f5d540a) honestly measured 15 and passed. The
squash of #672 onto main produced the sixteenth. Nothing lints main after a
merge, so the violation surfaced only when #676 and the #667 branch put
//agent/internal/cni/server back into a PR's bazel-diff impact set.

Pure mechanical extraction into registerSweepInstruments (ghost-sweep counters
and the prune-breaker gauge) and registerLifecycleInstruments (the unmeshed and
storage gauges, liveness instruments, identity-override counter). No metric
names, descriptions, units or registration order change.

Verified with fail_on_violation on //agent/internal/cni/server/... and the
package tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo added a commit that referenced this pull request Sep 4, 2026
#678)

newCNIMetrics is at cognitive complexity 16 against the lint limit of 15 on
main, and no PR ever failed CI for it. #671 (763f5b3) added the fifteenth
registration; #672 was branched before #671 merged, added two more to a file
it saw at 13, and its CI head (f5d540a) honestly measured 15 and passed. The
squash of #672 onto main produced the sixteenth. Nothing lints main after a
merge, so the violation surfaced only when #676 and the #667 branch put
//agent/internal/cni/server back into a PR's bazel-diff impact set.

Pure mechanical extraction into registerSweepInstruments (ghost-sweep counters
and the prune-breaker gauge) and registerLifecycleInstruments (the unmeshed and
storage gauges, liveness instruments, identity-override counter). No metric
names, descriptions, units or registration order change.

Verified with fail_on_violation on //agent/internal/cni/server/... and the
package tests.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Fable 5.1 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 5, 2026
…efore merging (#679) (#685)

PR CI validates a PR head against that PR's merge-base, and nothing validated
main after a merge. Two PRs that each pass against their own base can combine
into a state neither was ever tested in — #671 and #672 each added CNI metric
registrations against a base without the other, and the second squash put
newCNIMetrics at gocognit 16/15 on main, surfacing days later on the unrelated
PRs #676/#677.

Add .github/workflows/main.yaml (`main-post-merge`): on every push to main it
runs the same build+lint+unit-test leg ci.yaml runs, with the bazel-diff impact
set computed as the merge commit vs its first parent (HEAD^), falling back to a
full //... build+test when bazel-diff cannot compute it. --config=ci implies
--config=remote, which pins TestRunner to the local strategy, so tests stay
local exactly as they are on the PR path. The pull_request path is untouched
and `ci` remains the only required status check.

ci-impacted-targets.sh never assumed a PR merge-base functionally, but its
docs did; retitle them for the two callers and add the new workflow to the
seed-file list so editing it forces a full run.

The preventive half — branch protection required_status_checks.strict — is a
repo settings change applied alongside this PR, not code.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Fable 5.1 <[email protected]>
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.

ghost-sweep prune breaker is permanently tripped on every node: API-confirmed orphans count toward the 30% fraction, so cleanup can never run

1 participant