Skip to content

fix(quic): track twin subscriptions per proxy generation so overlapping ADS streams after an agent restart can't leave phantom dormant pairs (#1052) - #1071

Merged
bpalermo merged 2 commits into
mainfrom
fix/1052-dormant-pairs-per-generation
Sep 29, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/1052-dormant-pairs-per-generation

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Mechanism

quicdemand.Ledger kept one process-wide set of on-demand (ODCDS) twin subscriptions, and every fresh xDS stream's first CDS request replaced it (Restate). A dormant pair the new set did not name was pruned; a re-subscribed, unservable pair was parked dormant (recordQUICPair → Park).

After an agent restart that lands mid proxy hot restart, two proxy generations reconnect, each on its own fresh stream. On rev248 main-worker-03:

  1. 15:39:16Z the child's stream named nothing. Restate(∅) pruned the persisted dormant pairs.
  2. 15:39:27Z the draining parent's stream re-subscribed them. They were parked dormant again.
  3. The parent exited. Nothing ever removed the pairs, so the ledger held dormant pairs that no live generation subscribed to.

That breaks the premise of the republish-on-return path (#1038: "the proxy still holds their on-demand subscriptions, so the twin is pushed with no request"). #979 (QUIC unconditional) multiplies pairs, so this has to be right before the proving soak.

Generation identity: the xDS stream ID

  • Envoy's Node does not tell two generations apart. Both get the same --service-node/--service-cluster/--service-zone and the same bootstrap. --restart-epoch is not visible over xDS. Node metadata carries no epoch.
  • One Envoy process speaks exactly one ADS stream at a time. So go-control-plane's per-stream streamID (given to OnStreamDeltaRequest and OnDeltaStreamClosed) is the proxy generation as the agent sees it.
  • Two CDS-carrying streams are live at once exactly across a hot restart.
  • Using the stream ID needs no chart, supervisor or bootstrap change, and still works if the old generation reconnects after the new one.

Fix

quicdemand.Ledger now holds subscriptions per stream (streams map[int64]set), plus an orphaned set:

Cache:

  • ObserveQUICTwin, RestateQUICSubscriptions, ResumeQUICSubscriptions and recordQUICPair take the stream ID.
  • New CloseQUICStream(ctx, streamID) marks the persisted set dirty and logs pruned dormant east-west QUIC pairs: the proxy generation that held their on-demand subscriptions ended its stream while a newer one is live stream=… count=….

Observer: passes streamID through, and onDeltaStreamClosed calls CloseQUICStream.

Invariants kept:

Tests

  • quicdemand/ledger_test.go:
    • TestLedgerOverlappingGenerationsAfterAgentRestart: persisted dormant pairs reloaded, then two overlapping streams new→old (the rev248 order) and old→new, then the old stream ends. Also a case where the child's own later subscription survives the parent's exit.
    • TestLedgerLastStreamEndOrphansUntilRestate
    • TestLedgerStreamResetWhileAnotherGenerationIsLive
  • cache/quic_generation_test.go:
    • TestQUICDormantPairsOverlappingGenerationsNewThenOld and …OldThenNew: an agent restart with a persisted-ledger reload, both stream orders, and the parent's stream end. They assert no phantom dormant pair in memory or in observed-upstreams.json, and no republish on the source's return.
    • TestQUICDormantPairRepublishedForTheGenerationThatHoldsIt
    • TestQUICLastStreamEndKeepsDormantUntilTheNextRestate
  • server/quic_generation_test.go:
    • TestOnDemandObserver_OverlappingProxyGenerationsAfterAgentRestart: the real observer callbacks and a real cache, both orders. Agent 1 persists the pairs, agent 2 reloads them, two fresh streams arrive, the parent's stream closes, and agent 3 reloads the store and finds no phantom.
    • TestOnDemandObserver_ChildFirstUseSurvivesParentExit
  • Existing tests: none deleted.
    • Call sites gained a stream ID (testQUICStream).
    • Three tests that modeled a generation change as "a new stream re-states nothing" now also end the old generation's stream. Each asserts the pair stays dormant while the parent lives and is pruned when it ends:
      • TestLedger
      • TestQUICDormantPairsPrunedOnProxyGenerationChange
      • TestOnDemandObserver_FreshStreamRestatesSubscriptionsForDormantPairs
    • //test/mtlspool uses the new Restate/Subscribe signatures.

Run locally, all green:

  • bazel test //agent/internal/xds/... (8/8)
  • bazel test --config=race //agent/internal/xds/cache:all //agent/internal/xds/server:all //agent/internal/xds/quicdemand:all
  • bazel test //test/mtlspool:mtlspool_test (real Envoy)
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...
  • make format-check

Docs

docs/runbook.md, east-west QUIC "Pruning": pairs are held per stream, the two prune log lines, and the #1052 failure shape.

No charts/ change.

Closes #1052

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 29, 2026 16:41
…ng ADS streams after an agent restart can't leave phantom dormant pairs (#1052)

The QUIC twin ledger kept one process-wide subscription set that every fresh
xDS stream replaced. After an agent restart that lands mid hot restart, two
proxy generations reconnect: on rev248 w03 the child's stream (naming nothing)
pruned the dormant pairs, and the draining parent's stream 11 s later
re-subscribed them and they were parked dormant again, outliving the parent.

quicdemand.Ledger now holds subscriptions per xDS stream (the stream is the
proxy generation: one Envoy process speaks one ADS stream and the Node carries
no restart epoch). A dormant pair is kept only while a live stream holds it:
Restate records a fresh stream's re-statement for that stream alone, and the
new Close drops an ended stream's holdings when another stream is live
(pruning dormant pairs nobody holds). The last live stream ending orphans its
holdings until the next re-statement, as before. The observer passes the
stream ID through ObserveQUICTwin / RestateQUICSubscriptions /
ResumeQUICSubscriptions and calls the new CloseQUICStream on stream close.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 9ca975c into main Sep 29, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1052-dormant-pairs-per-generation branch September 29, 2026 20:12
bpalermo added a commit that referenced this pull request Sep 29, 2026
… ledger, #1072)

odcds.go: main's stream-scoped observeQUICTwin(streamID, name) with #979's
dependency-set wording. The new server/quic_generation_test.go fixture puts
demo/echo in the dependency set (RestoreDependency) instead of allow-listing
it; the soak new-SA step's wording notes both destinations are QUIC-eligible
since #979.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant