Skip to content

fix(agent,registrar): close the agent-roll 404 gaps - #142

Merged
bpalermo merged 1 commit into
mainfrom
fix/agent-roll-404-gaps
Jun 11, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/agent-roll-404-gaps

Conversation

@bpalermo

@bpalermo bpalermo commented Jun 11, 2026 •

Copy link
Copy Markdown
Owner

Fixes the ~3.8k-failure 404 window from the rev-66 roll. Root-cause investigation reconstructed a per-second timeline; two gaps share one flaw — config derived from whatever the registry returns at a single instant — plus a co-roll amplifier.

Mechanism correction (post-review, verified from registrar logs): the original Gap 1 attribution ("helm termination wave unregistered endpoints") was imprecise — the helm upgrade only rolled aether-system, and there are zero UnregisterEndpoint RPCs in the 13:13–13:15 window. What actually emptied services was partial world views: the co-rolled registrar restarted with an empty snapshot, agents reconnected/fell back to it mid-warm and faithfully replaced good 8-service caches with partial ones (the RegisterEndpoint storm at 13:13:54+ is the agents' ghost-sweep re-registering real, running pods the partial view said didn't exist). That mechanism is killed by layer 3 below. The retention grace (layer 0) remains essential for the legitimate transient-emptying path: deletionTimestamp early-dereg during fast svc rolls can briefly drive a real service to 0 registered endpoints.

Gap 1 — vhost loss on healthy nodes (~36s, the bulk of the damage)

Services that transiently vanish from the registry listing dropped out of LoadClustersFromRegistry's wholesale rebuild → live proxies received route configs with 2 of 8 vhosts → 404s. A route-table miss is a lie: the service exists.

Fix: disappeared services are retained with their cluster + vhost and an empty endpoint set for a 90s grace (outlasting observed churn), then pruned. During the grace clients get the honest, retriable no-healthy-upstream 503 and recover the instant endpoints reappear. (Deliberately chose retention over the investigated count-based hold-down: a count heuristic both masks real deletions and misses same-count swaps.)

Gap 2 — fresh agent serving vhosts=0 (~170ms, guaranteed hit)

RegistrarRegistry.Initialize starts its watch loop async and returns; PreListen derived the initial snapshot from an empty cache and opened the xDS socket — the reconnecting Envoy landed exactly in that window.

Fix, three layers:

  1. Protocol: new EVENT_TYPE_SNAPSHOT_COMPLETE marks the end of the initial snapshot stream (sent even when the client is up-to-date). Backward-compatible: old clients no-op on unknown event types.
  2. Client: WaitReady (registry.ReadyWaiter capability) blocks until the first marker; PreListen waits up to 15s before deriving the initial snapshot, then proceeds degraded (the existing local-only fallback and background retry are untouched — a dead registrar still cannot crash-loop the node).
  3. Registrar: snapshot-serving RPCs (WatchEndpoints, ListAllEndpoints) gate on the syncer's first completed cycle. This kills the actual rev-66 mechanism — without it, a freshly rolled registrar serves a complete-but-empty/partial snapshot to every reconnecting agent while still warming from Cloud Map, and the marker alone would bless garbage.

Testing

  • TestLoadClustersFromRegistry_RetainsDisappearedServices: retain-empty → reappear-restore → prune-after-grace; existing prune test updated to the graced semantics.
  • TestSnapshotCompleteClosesReady: through processStream — marker closes ready, advances the resume token, mutates nothing, idempotent on reconnect markers.
  • TestWatchEndpointsSendsSnapshotComplete, TestWatchEndpointsGatedOnFirstSync, TestListAllEndpointsGatedOnFirstSync.
  • Full suite 38/38.

Post-deploy validation: repeat the full-chart co-roll; expect the 404 class gone (fails back to the ~7–14 connection-churn baseline, any residue 503/000-shaped).

🤖 Generated with Claude Code

The rev-66 helm roll cost ~3.8k loadgen failures, all code=404: proxies
were serving with listeners up but route tables missing service vhosts.
Root cause analysis found two gaps sharing one flaw — config derived from
whatever the registry returns at one instant — plus an amplifier:

Gap 1 (~36s, hit HEALTHY nodes that were not even rolling): the helm
termination wave floods ENDPOINT_REMOVED events; services whose endpoints
all vanish mid-churn dropped out of LoadClustersFromRegistry's wholesale
rebuild, and the snapshot pushed route configs with 2 of 8 vhosts to live
proxies. Requests to the missing services 404'd — a route-table miss is a
lie; the service exists and its pods were coming right back.

Fix: services that disappear from the registry listing are retained with
their cluster and vhost and an EMPTY endpoint set for a 90s grace
(outlasting observed churn windows), then pruned. During the grace,
clients get the honest, retriable no-healthy-upstream 503 and recover the
instant endpoints reappear.

Gap 2 (~170ms but guaranteed): RegistrarRegistry.Initialize starts its
watch loop async and returns; the agent's PreListen then derived the
initial snapshot from an empty cache and opened the xDS socket serving
vhosts=0 — the reconnecting Envoy landed exactly in that window.

Fix, in three layers:
- protocol: new EVENT_TYPE_SNAPSHOT_COMPLETE marks the end of the initial
  snapshot stream (sent even when the client is up-to-date), so the
  client knows its cache holds a complete world view;
- client: WaitReady (registry.ReadyWaiter capability) blocks until the
  first marker; PreListen waits up to 15s before deriving the initial
  snapshot, then proceeds degraded (existing local-only fallback intact);
- registrar: snapshot-serving RPCs (WatchEndpoints, ListAllEndpoints)
  gate on the syncer's first completed cycle — the co-roll amplifier:
  without this, a freshly rolled registrar happily serves a complete-but-
  EMPTY snapshot to every reconnecting agent while still warming from the
  external registry.

The existing rebuild-prunes-stale test is updated to the new graced
semantics (retain-empty during grace, prune after); new regression tests
cover retention/reappearance/pruning, the client ready machinery through
processStream, and the server-side sync gate + marker.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@bpalermo
bpalermo merged commit 809f58a into main Jun 11, 2026
10 checks passed
@bpalermo
bpalermo deleted the fix/agent-roll-404-gaps branch June 11, 2026 15:32
bpalermo added a commit that referenced this pull request Jun 11, 2026
…p-drain gap (#143)

Instrumented two controlled svc rolls (2026-06-11) and pinned the residual
~3-7 fails per pod delete: the drain pipeline itself is fast and correct
(deletionTimestamp -> EDS mark on every client in <800ms, zero fails in
the propagation window), but Envoy's DRAINING health keeps established H2
pool connections OPEN. They sit idle through preStop and die at the app's
shutdown GOAWAY — and streams the server had claimed but not yet answered
at that instant fail non-retriably (upstream_rq_rx_reset=0 across all
nodes: the app never broke a response; retry_success == retry_total:
every retry that could fire succeeded; the fails were the GOAWAY
last_stream_id race plus two retry_overflow rejections).

Fix: report draining endpoints as UNHEALTHY instead of DRAINING and set
close_connections_on_host_health_failure on the service clusters. Pools
now close at drain-mark time (~t0+0.8s) while the app is healthy and the
pools are idle; anything caught mid-transmit resets pre-request and
retries successfully onto a live endpoint. The app-side preStop window is
unchanged and still covers genuinely in-progress responses.

Supporting changes on the service clusters:
- healthy_panic_threshold: 0 — with drainers now counting as unhealthy, a
  heavy simultaneous roll could cross Envoy's default 50% panic threshold
  and spray traffic at known-unhealthy hosts; deterministic exclusion +
  per-request retries + the registry health pipeline are the mesh's
  answer, not panic spraying.
- max_retries circuit breaker 3 -> 16 — the drain-time pool close briefly
  produces a burst of pre-request resets; the default breaker rejected
  retries under exactly that burst (retry_overflow observed).

Validation plan: re-run the instrumented single-svc roll; expect 0 fails
(first-pod-deleted rolls already showed 0 — the fix makes every pod look
like the first). Also re-confirmed during instrumentation: zero 404s
under churn (the #142 retention guard holding).

Co-authored-by: Claude Opus 4.8 <[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.

1 participant