Skip to content

feat(quic): build a twin only for a (source SA, destination) pair that has dialled — the matcher arm names the twin, on-demand CDS fetches it on first use, pairs persist in ObservedUpstreams (#1020) - #1032

Merged
bpalermo merged 2 commits into
mainfrom
feat/1020-demand-scoped-twins
Sep 28, 2026

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Why

The #1006 attribution found that on rev242 the fleet carried 118 quic: twins (59 local ServiceAccounts × 2 destinations), and only 2 of them ever carried a request (…@aether-test/default). An idle twin costs about 0 CPU. It does cost about 223 KiB of Envoy heap and about 52 stat series, and it is one more CDS resource to push, warm and keep in sync. It is also the surface of #1008. With unconditional QUIC (#979) the count would be about 650 twins, ~34k series and ~140 MiB of fixed heap fleet-wide. This PR builds a twin only for a (source ServiceAccount, destination) pair that has actually dialled. On today's fleet that is 118 → about 10.

Mechanism

A note on the title's wording: on_no_match is unchanged and still names the h2 cluster. What triggers ODCDS is the arm. The two designs sketched in the issue cannot be expressed in Envoy's config API:

  • The matcher cluster-specifier's action is ClusterAction { string cluster }, a static name and nothing else (matcher_cluster_specifier.cc). So on_no_match cannot format quic:%REQ(:authority)%@%FILTER_STATE(...)%.
  • cluster_header reads a request header at routing time, and nothing can copy filter state into a header before routing.

What does work:

The aether.source.sa stamp the issue suggested is not needed: the existing SPIFFE-ID stamp is the matcher key, and the arm carries the SA.

First-request cost and failure mode

  • Cost: one local ODCDS round trip. It was 23.6 ms (source A) and 17.2 ms (source B) against the pinned proxy, including the twin's EDS/SDS fetches and the QUIC handshake. A repeat request from the same pair took 1.1 ms.
  • Failure mode: a refused or timed-out fetch is 503 NC at the on_demand timeout. That timeout stays at 2 s (onDemandClusterTimeout, the catch-all's value). A fallback to h2 on ODCDS failure cannot be expressed in Envoy: there is no per-route fallback from an on-demand miss, and OnDemandCds has only the timeout. This is the same exposure the mesh catch-all has today, including an agent that is down while a new pair dials (demand-scoped TTL expires under continuous load and ODCDS re-discovery stalls ~5 min: 5-minute per-node outages on nodes with no local replica, invisible to soaks #682).
  • Observability: refusals are counted as aether.agent.quic.twin.refused{reason}. The proxy-side signal is envoy_cluster_manager_odcds_init_fetch_timeout_total. Both are in the runbook.

Pruning

There is no idle expiry, because nothing in xDS tells the agent that a twin stopped carrying traffic. A pair is pruned only on evidence that it is gone:

  • its source ServiceAccount has no pod left on the node. This applies only once the pod records are loaded (LoadListenersFromStorage), so a restore that runs first cannot prune everything;
  • its destination leaves the allow-list or the dependency set.

Pruning runs in the snapshot path, so a pruned pair's twin leaves in the same push. The persisted file is rewritten to match.

Gates, each seen red first

1. Cache unit tests (agent/internal/xds/cache/quic_demand_test.go, plus the three existing QUIC tests updated to observe their pairs):

  • (a) Three local SAs and no observed pairs: 0 twins, 0 twin CLAs. The arms name twins that are absent from CDS, and on_no_match is h2.
  • (b) ObserveQUICTwin(quic:…@demo/source-b) builds exactly that twin and its CLA in the same snapshot, with the arm present. A repeat request returns Known.
  • (c) The pair is persisted (quic_pairs), and a restarted cache builds the twin in its first snapshot.
  • (d) RemovePod of source-b drops its twin, CLA, arm and persisted pair. Delisting the destination drops the rest.
  • (e) A non-QUIC destination, a non-local SA, another namespace's SA, :port, a foreign domain, an extra segment or a missing source: all refused, nothing recorded, CDS unchanged.

Plus a restored pair that waits for the pod set before it is pruned, TestParseQUICClusterName, and an observer test in server.

Red: with twinsFor put back to the pre-#1020 rule (every local SA × allow-listed destination), (a)–(e) all fail. For example, (a) reads Should be empty, but was [quic:…@demo/source-a quic:…@demo/source-b quic:…@demo/source-c].

2. Live (//test/mtlspool quic_odcds_test.go, delta ADS, pinned proxy, a real HTTP/3 destination that requires and reports the client certificate; the harness's control-plane hook plays the agent's observer):

[odcds] CDS subscribe quic:echo.demo.aether.internal@demo/source-a (admit=true)
[odcds] published quic:echo.demo.aether.internal@demo/source-a (version 2)
source-a first request: status=200 san=".../sa/source-a" proto="HTTP/3.0" in 23.585212ms
[odcds] CDS subscribe quic:echo.demo.aether.internal@demo/source-b (admit=true)
[odcds] published quic:echo.demo.aether.internal@demo/source-b (version 3)
source-b first request: status=200 san=".../sa/source-b" proto="HTTP/3.0" in 17.22633ms
source-a second request: status=200 san=".../sa/source-a" proto="HTTP/3.0" in 1.087894ms   (no new CDS subscribe)
--- PASS: TestOnDemandQUICTwinPerPair (0.18s)
[odcds] CDS subscribe quic:echo.demo.aether.internal@demo/source-a (admit=false)
source-a first request with the twin refused: status=503 in 2.00143503s
--- PASS: TestOnDemandQUICTwinRefusedFails (2.12s)

TestOnDemandQUICTwinRefusedFails is the kept negative control. Red: with the on_demand filter removed from the source HCM, the green test fails with status=503 in 1.18ms. That shows the ODCDS path is what turns the arm into a 200.

3. //test/envoy_validate: the QUIC fixture now carries arms for sources a, b and c, twins only for the observed a and b, and production's on_demand filter ahead of the router. envoy --mode validate accepts it (quic_outbound_bootstrap.json ... OK). The pinned-TLS QUIC unwrap tests and the "no route to a quic: cluster sets early_data" assertion are unchanged and still pass. Red: building c's twin up front (the pre-#1020 shape) fails TestQUICOutboundFixtureCarriesTheSelection: twin "quic:echo.demo.mesh.local@demo/source-c" for an unobserved pair is built; it must be fetched on demand.

4. e2e/eastwest-quic.sh on kind:

  • E1 changes meaning: before any request, no twin may exist outside the pairs the suite drives. On a fresh cluster that is 0.
  • New E4c: the node's quic: cluster count must equal the pairs driven over a selecting route, and the set must match exactly.
  • E0–E5 are otherwise unchanged.

Result:

✓ 0 quic: twins before any request in this run (0 on a fresh cluster); none for a pair that never dialled; none for h2only
✓ E2: client-a -> quic-a: 10/10 x 200, XFCC URI=.../sa/client-a; own twin +10, other twin +0, h2 +0, dest h3 inbound +10   (x4)
✓ E3 ... ✓ E4 (weighted split stays h2, fetches no twin) ... ✓ E4b (x2)
✓ E4c: 6 quic: clusters = 6 driven pairs, exactly [quic:gamma-a…@…/client-a … quic:quic-b…@…/client-b]
✓ E5 (x4)
==> all east-west QUIC assertions passed

Agent log from the run: east-west QUIC fan-out quic_clusters=6 observed_pairs=6 local_identities=7 allow_listed_services=4. The pre-#1020 agent would have built 7 × 4 = 28 twins on that node. Red: EWQ_EXPECT_TWINS=28 e2e/eastwest-quic.sh verify fails E4c with 6 quic: clusters on the node, want 28. The EASTWEST_QUIC=off red now shows at E2 rather than E1; the header documents this. The kind cluster was torn down and kubectl config current-context was restored to talos-main.

Runs:

  • bazel test //agent/... //test/...: all pass.
  • --config=race //agent/internal/xds/...: clean.
  • --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/... //test/... //api/... //e2e/...: clean. This needed a gocognit split in resumeHeldClusters.
  • //:format and gazelle were run.

Docs

Charts: no change needed. agent.eastWestQuicServices keeps its meaning; only the cost it implies drops.

Closes #1020

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…t has dialled — on-demand CDS from the matcher's on_no_match, persisted in ObservedUpstreams (#1020)

The agent built one `quic:` twin per local ServiceAccount for every
allow-listed destination up front: 118 on rev242, 2 of which ever carried a
request (#1006). Unconditional QUIC (#979) would make that ~650.

Now the selection route keeps one arm per local ServiceAccount, but the twin
behind an arm is built only once that pair dials. The first request resolves
through the matcher cluster-specifier to the missing twin; the HCM's
on_demand filter asks for it by name over ODCDS; the agent's observer
validates it (destination QUIC-enabled and in the dependency set, source a
local ServiceAccount), records the pair in ObservedUpstreams.quic_pairs and
publishes the twin with its own load assignment in one snapshot (#1008's
rule, now load-bearing for every twin). A refused or timed-out fetch is 503
NC at the on_demand timeout (2 s); Envoy has no per-route fallback to h2
from an on-demand miss. Pairs have no idle TTL; they are pruned when the
source leaves the node or the destination leaves the allow-list or the
dependency set.

- proxy: ParseQUICClusterName / IsQUICClusterName; OnDemandHTTPFilter
  exported for the live harnesses.
- cache: quicPairs (depMu, persisted), ObserveQUICTwin / RestoreQUICTwin,
  armsFor (all local SAs) vs twinsFor (observed pairs), snapshot-time prune.
- server: the ODCDS observer routes quic: names to the cache, re-admits held
  twins on a fresh stream, counts refusals (aether.agent.quic.twin.refused).
- api: ObservedUpstreams.quic_pairs (edition 2024, implicit presence).
- tests: cache gates (a)-(e), mtlspool live ODCDS gate + negative control,
  envoy_validate fixture with an unbuilt arm + on_demand, e2e E4c pair count.
- docs: 038 Phase 4b + Selection, runbook, soak README.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo bpalermo changed the title feat(quic): build a twin only for a (source SA, destination) pair that has dialled — on-demand CDS from the matcher's on_no_match, persisted in ObservedUpstreams (#1020) feat(quic): build a twin only for a (source SA, destination) pair that has dialled — the matcher arm names the twin, on-demand CDS fetches it on first use, pairs persist in ObservedUpstreams (#1020) Sep 28, 2026
@bpalermo
bpalermo merged commit 5b1a74a into main Sep 28, 2026
24 checks passed
@bpalermo
bpalermo deleted the feat/1020-demand-scoped-twins branch September 28, 2026 00:57
bpalermo added a commit that referenced this pull request Sep 28, 2026
…set re-subscriptions are answered absent, and stale persisted pairs are pruned (#1033) (#1035)

rev245 (the first talos deploy of #1032) logged observed_pairs ==
local_identities x 2 on every node: the fresh agent admitted, and
persisted, every twin the running proxy re-stated on the new xDS stream,
i.e. the SAs x destinations fan-out the previous agent had built up front.

- agent/internal/xds/quicdemand: classifies a delta CDS request's quic:
  names as first use (named on a later request, not held), resubscribed
  (a live on-demand subscription re-stated on a fresh stream) or held-only
  (initial_resource_versions via the wildcard).
- Held-only twins admit nothing (RestoreQUICTwin is gone); an unpersisted
  one is answered absent in removed_resources and Envoy drops it; the next
  routed request is a real on-demand fetch.
- Re-subscribed twins are served (ResumeQUICSubscriptions): Envoy's ODCDS
  manager keeps one subscription per name for the process lifetime and
  skips every later request for it, so answering one absent strands the
  pair (503 NC at the on_demand timeout). Shown live by the mtlspool
  strand control.
- Post-start prune: a persisted pair with no on-demand fetch or
  re-subscription within --east-west-quic-pair-fetch-window (default 1h)
  of the agent starting is dropped with its twin; one log line per node.

Gates (each seen red): server delta test (24 held twins, empty persisted
set -> 0 admitted, 24 removed; red: admitted=24), cache prune test, live
mtlspool agent-restart tests.

Closes #1033


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

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
bpalermo added a commit that referenced this pull request Sep 28, 2026
…ormant while its source or destination is away, republished on return, pruned only when the subscription is gone (#1036) (#1038)

* fix(quic): a twin pair is admitted only on real first use — stream-reset re-subscriptions are answered absent, and stale persisted pairs are pruned (#1033)

rev245 (the first talos deploy of #1032) logged observed_pairs ==
local_identities x 2 on every node: the fresh agent admitted, and
persisted, every twin the running proxy re-stated on the new xDS stream,
i.e. the SAs x destinations fan-out the previous agent had built up front.

- agent/internal/xds/quicdemand: classifies a delta CDS request's quic:
  names as first use (named on a later request, not held), resubscribed
  (a live on-demand subscription re-stated on a fresh stream) or held-only
  (initial_resource_versions via the wildcard).
- Held-only twins admit nothing (RestoreQUICTwin is gone); an unpersisted
  one is answered absent in removed_resources and Envoy drops it; the next
  routed request is a real on-demand fetch.
- Re-subscribed twins are served (ResumeQUICSubscriptions): Envoy's ODCDS
  manager keeps one subscription per name for the process lifetime and
  skips every later request for it, so answering one absent strands the
  pair (503 NC at the on_demand timeout). Shown live by the mtlspool
  strand control.
- Post-start prune: a persisted pair with no on-demand fetch or
  re-subscription within --east-west-quic-pair-fetch-window (default 1h)
  of the agent starting is dropped with its twin; one log line per node.

Gates (each seen red): server delta test (24 held twins, empty persisted
set -> 0 admitted, 24 removed; red: admitted=24), cache prune test, live
mtlspool agent-restart tests.

Closes #1033

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

* fix(quic): a twin pair Envoy has subscribed to is never forgotten — dormant while its source or destination is away, republished on return, pruned only when the subscription is gone (#1036)

Envoy's ODCDS manager keeps one subscription per cluster name for the life
of the process. When the agent removed a twin the proxy had fetched on
demand (its source ServiceAccount's last pod left the node, or its
destination left the allow-list / dependency set), Envoy dropped the cluster
and kept the subscription; when a pod of that ServiceAccount came back, every
request to the twin was "already subscribed, skipping" -> 503 NC at the 2 s
on_demand timeout, until the proxy restarted.

quicdemand.Ledger records which twins the proxy holds an ODCDS subscription
for (first-use requests, refused or not, and fresh-stream re-subscriptions).
On removal evidence a subscribed pair goes dormant: its twin leaves the
snapshot, the pair is persisted in ObservedUpstreams.dormant_quic_pairs, and
the snapshot that sees it valid again republishes the twin with no request.
A dormant pair is pruned only when a fresh stream's first CDS request does
not re-subscribe it (agent restart against a proxy that no longer holds it,
or a hot-restart child). The fetch-window prune never touches a dormant or
subscribed pair.

Gates: //test/mtlspool TestOnDemandQUICDormantTwinRepublishedWhen{SourceReturns,
DestinationIsRelisted} (dormant: republished in 22 ms with no request, then
200/HTTP3 in 6.7 ms; forget_control: 503 in 2.000 s), cache/server/ledger
unit tests for the transitions, persistence and fresh-stream/generation prune.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

* test(cache): drain the debounced observed-set write before t.TempDir cleanup

TestQUICDormantOnlyForSubscribedPairs flaked 2/8 under --config=race with
"TempDir RemoveAll cleanup: directory not empty": a 1 ms debounced flush
landed after the test returned. newQUICDemandCacheWith now registers a
FlushObservedUpstreams cleanup, which runs before TempDir's (LIFO) and
serializes with any in-flight write.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
bpalermo added a commit that referenced this pull request Sep 29, 2026
Brings #979 up to date with 36 commits of main (demand-scoped twins #1020/#1032,
fresh-stream classifier #1033/#1035, dormant-pair ledger #1036/#1038, per-twin
EDS names #1012/#1029, the twin certificate gate #1051, the ODCDS always-answer
override, --east-west-quic-idle-timeout #1063, L4 stat keys #1043, access-log
timing #1048, the identity gate #1055, hot-restart knobs #1068 and the carried
Envoy patches) while keeping #979's intent: no allow-list, every destination in
the node's dependency set is QUIC-eligible.

Resolution:
- cache: quicServices / SetEastWestQUICServices removed. armsFor gives arms to
  every default, identity-ready, non-waypointed entry whose service is in the
  dependency set (the same rule recordQUICPair admits by, so no route names a
  twin the agent would refuse); twins stay demand-scoped. The
  destination_not_quic_enabled refusal/prune reason is gone.
- quicpairs: the dependency-set prune now waits for the pod set like the
  source prune does -- the allow-list used to force its destinations into the
  set, and without it the first snapshot after an agent restart dropped every
  restored pair (TestQUICDemandPairSurvivesAgentRestart was red).
- fan-out log: allow_listed_services dropped; observed_pairs and
  awaiting_client_cert kept.
- chart 1.0.12: eastWestQuicServices removed, eastWestQuicIdleTimeout and its
  parentShutdownTime check kept.
- e2e/eastwest-quic.sh: main's demand-scoped E1/E4c/E6 + #979's QUIC_DNS_SANS
  negative control; h2only/E3 removed; E6 dials quic-a and its idgate-* pairs
  are excluded from the driven-pair count. eastwest-quic-hotrestart.sh's h2
  control is now the weighted GAMMA split (the one h2-by-design path).
- tests, runbook, soak README, configuration.md, 038 rewritten for the
  unconditional state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo added a commit that referenced this pull request Sep 30, 2026
…holds — agent-only restarts no longer drop live twins an hour later (#1073) (#1076)

After a proxy restart every quic: twin reaches the new generation through
the wildcard, with no on-demand fetch and no subscription, and carries its
traffic that way. An agent-only roll then re-states those twins on the fresh
stream as held-only, and the fetch-window prune ("no on-demand fetch since
agent start") removed every one of them one window later: ~200 x 503 NC per
burst fleet-wide on the #979 proving soak, and an Envoy SIGBUS on one node
(#1074).

A pair is now kept on any evidence of use, ever: a live stream's on-demand
subscription (the ledger), or a confirmation -- fetched, re-subscribed, or
its twin re-stated as HELD on a fresh stream while the agent serves it
(ConfirmHeldQUICTwins). The confirmation is persisted
(ObservedQUICPair.demand_confirmed), so a node reboot, where the fresh proxy
uses twins it never fetches, does not prune them either. The window still
drains pairs no generation vouched for (the #1032 fan-out, pre-#1073 pairs
the proxy neither holds nor fetches).

Closes #1073


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

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

QUIC: build twins on observed demand only — 116 of 118 twins never carried traffic; ~223 KiB + ~52 series each; ~650 twins under unconditional QUIC

1 participant