Repository navigation
fix(registrar): resume the agent watch across dependency-set changes (#1239) - #1266
Merged
Merged
Conversation
bpalermo
marked this pull request as ready for review
October 5, 2026 14:30
bpalermo
force-pushed
the
fix/1239-watch-filter-resume
branch
from
October 5, 2026 14:51
6949a67 to
c026e4f
Compare
This was referenced Oct 5, 2026
bpalermo
force-pushed
the
fix/1239-watch-filter-resume
branch
2 times, most recently
from
October 5, 2026 15:52
c026e4f to
2ecfd24
Compare
…1239) Every dependency-set change re-opened the agent's WatchEndpoints stream with an empty resume token: watchLoop cleared lastVersion whenever the filter generation moved, shrink or growth alike, so the registrar could only answer with a full (filtered) resend. A TCP service appearing or disappearing changes every node's set, so each such change resent every agent's snapshot. The agent now tracks which services its cache holds at the resume token (held) and presents the token accordingly: - filter shrank or is unchanged: last_version as on any reconnect. The version names the registrar's whole snapshot, so a current token is current for any subset of the services it was earned on. - filter grew: the token goes in the new partial_resume {version, services} with last_version empty. A registrar that knows the field sends only the added services' endpoints (ENDPOINT_ADDED) when the version names its current contents and marks the SNAPSHOT_COMPLETE extended; a stale token is resent in full. An older registrar sees no token and resends: skew-safe both ways. The cache only admits endpoint events for the current filter (a stream still carrying the old filter can no longer refill a purged service), the purge on a switch from the full watch now drops everything outside the new filter, and a tokenless resend with nothing in the filter now clears the cache at the marker. New resume label value: aether_registrar_watch_starts_total{resume="extended"}. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
F1. completeStart held the stream's whole filter. A service the filter dropped while the initial exchange was still arriving was purged, and the stream kept delivering after the cancellation; if the service came back before the marker it was held partial (or empty) under a token the registrar answers "current". The agent now tracks streamComplete (the stream's filter at the open, narrowed by every later filter change) and holds only that. F2. Broadcaster.Publish held publishMu only for reading, so two publications interleaved mutate and broadcast: on one endpoint a watcher could receive REMOVED x (v2) then ADDED x (v1) and keep x, or get one batch's unversioned events after another's versioned last event (#1203). Publications are now serialized; lock order is publishMu, then Snapshot.mu or the broadcaster's mu, never both. P2. A stream that presented last_version could not tell an empty resend from a renamed resume, so a stale token resent for a filter with no endpoints left stale entries held under the new token. The marker now decides: a content hash different from the presented token's is a resend, and the cache is cleared (renamed always has an equal hash). Regression tests are adapted from the reviewer's failing ones. TestWatchEndpoints_PreSnapshotBatchCannotRegressTheToken now publishes its batch C from a goroutine, because C waits for B. Its assertions are unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
#1239) TestPublish_ConcurrentPublicationsKeepEveryVersionHonest failed on a slow CI runner: the watcher's 256-event buffer overflowed (the designed force-resync) before the recorder drained it, and the "kept up" precondition failed. Each publisher now waits for headroom of publishers x 3 events (3 is the most one publication emits) before it publishes. All eight at once still cannot fill the buffer, whatever the scheduler does, and the publications still run concurrently. The test also asserts that it verified at least 400 versioned events, so it cannot pass vacuously (it verifies about 1200). With Publish back on a read lock it still fails 20/20 runs, and 10/10 under race. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
bpalermo
force-pushed
the
fix/1239-watch-filter-resume
branch
from
October 5, 2026 16:42
2ecfd24 to
3162a2e
Compare
bpalermo
added a commit
that referenced
this pull request
Oct 5, 2026
…ht-publication watch test teeth (#1274) * refactor(registrar): one snapshot-version parser for agent and server (#1272) The agent's versionContentHash (registry/internal/registrar) duplicated the registrar server's parser (registrar/internal/server/snapshot.go), and #1266's emptyResend cache-clear depends on the two agreeing on "renamed". Move the version format -- its documentation, Format, ContentHash and a Compare (Same / Renamed / Different) -- into common/snapshotversion, a stdlib-only leaf package, and use it on both sides: the server's resumeLocked and the agent's emptyResend now classify with the same function. Table tests cover every form (<rev>.<hash>, <rev>+<hash>, hash:<hash>, legacy counter, empty, garbage) and the mixed-form comparisons both sides make. Pure refactor: s.version is always rendered from s.contentHash, so comparing a token to the version's hash is comparing it to the content hash. Existing tests pass unchanged (publish_order_test only follows the helper's new name). Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr * test(registrar): give the in-flight-publication watch test teeth again (#1271) Since publications are serialized (#1266), batch C can no longer overtake an in-flight batch B, so TestWatchEndpoints_PreSnapshotBatchCannotRegressTheToken passed even with SubscribeWith no longer excluding publications: B's duplicate broadcast now carries the snapshot's own version, so the token and cache assertions cannot see it. Assert the rule SubscribeWith actually enforces: each batch is in the watch's snapshot or on its channel, never both -- B's and C's endpoints reach the stream exactly once. With publishMu dropped from SubscribeWith (local mutation, not committed) the test fails 10/10 on B delivered twice; the original assertions pass under the same mutation. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
registry/internal/registrar/registrar.gowatchLoop(main at 65e473a, lines 590-594) cleared the resume token whenever the filter generation moved:SetServiceFilterbumpsfilterGenand cancels the live stream on every dependency-set change (a server-streaming RPC cannot change its filter in place). So every change re-openedWatchEndpointswithlast_version = "", whichSnapshot.resumeLockedcan only classifyresent, shrink or growth alike. The registrar was not rejecting a good token: it never got one. Every TCP mesh service is always in every node's dependency set (agent/internal/xds/cache/cache.go), so a TCP service appearing or disappearing changes every node's set. That matches the soak:resentsteps lined up with fleet-wideservice left dependency set, andcurrentnever fired.Clearing the token on a growth is necessary, because a growth needs content the agent lacks. On a shrink it was not.
Fix
The agent now tracks
held: the services whose cached endpoints are exactly what its resume token names. It is narrowed by every filter change (their entries are purged), set to the stream's filter atSNAPSHOT_COMPLETE, and emptied when a resend clears the cache. At each (re)open,resumeFordecides:last_versionas on any reconnect. The version names the registrar's whole snapshot, so a token that is current is current for any subset of the services it was earned on. The response iscurrentorrenamed.last_versionwould be wrongly answeredcurrentwhile the added services are missing. It stays empty, and the token goes in the newpartial_resume {version, services: held ∩ filter}. A registrar that knows the field sends only the missing services' endpoints, as unversionedENDPOINT_ADDEDevents (notFULL_SNAPSHOT, which clears the agent cache). It does this only when the token names its current contents, and setsextended: trueon the marker. A stale token is resent in full.Hardening in the same code:
scope, updated in the same critical section as the purge). Before this, a stream still carrying the old filter could re-insert a service the purge had just dropped.extended. If such a resend has nothing in the filter it sends noFULL_SNAPSHOT, so the cache is now cleared at the marker.aether_registrar_watch_starts_total{resume="extended"}, plus a debug logWatchEndpoints resolvedwith the outcome.Wire compatibility (one-release skew)
current/renamedextended(orresentif stale)current/renamed(same claim a token always made)partial_resume, sees no token,resent; agent sees noextendedand treats it as a resendresent(unchanged)resent(unchanged)The proto adds fields only (
WatchEndpointsRequest.partial_resume = 6,PartialResume,WatchEndpointsResponse.extended = 6), on edition 2023.Tests
registry/internal/registrar/watch_resume_test.go:TestWatchLoop_DependencySetChangeKeepsTheTokendrives the real watch loop through narrow, shrink and grow. It fails on main's logic (the shrink request carrieslast_version "") and passes with the fix. There are unit tests forresumeFor(including the negative: a service that left and re-entered within one stream is not held), the scope guard, extended, cut-extended and resend starts, and the empty-resend clear.registrar/internal/server/partial_resume_test.go: shrunk filter resumes; partial resume current and renamed; stale token is resent, never extended; empty partial version;last_versionbeatspartial_resume; full-watch partial; metric labels.bazel testandbazel test --config=raceon//registrar/internal/server:server_testand//registry/internal/registrar:registrar_test, plus the dependentcmd/servicestests. Lint withfail_on_violationandmake format-checkare clean.e2e/eastwest-quic.sh up, kubernetes backend, this stack's images): scalingquic-b1→0 (service left dependency set) loggedresume=current events=0. Scaling 0→1 loggedresume=extended events=1, and client-a → quic-b answered 200 ×5 afterwards.Runbook: the "Reconnect outcomes" list in docs/runbook.md now covers
extendedand dependency-set changes.Review findings fixed
An independent adversarial review found three lost updates, one bug of #1266 and two older holes it widened. All three are fixed in this PR. Each fix is proven by a regression test that fails on the pre-fix code; I reverted each fix temporarily to confirm. The tests are adapted from the reviewer's.
completeStartsetheld = filter ∩ scope. That undid the narrowingSetServiceFilterapplied while the exchange was still arriving: a purged service that came back before the marker was held partial or empty, and the next reconnect was answeredcurrent. The fix tracksstreamComplete: the stream's filter at open, narrowed by every later filter change.completeStartholds onlystreamComplete ∩ scope. Tests inwatch_flap_test.go, one per way a stream can start (resend, plain current resume, extension):TestConsumeStream_FlapDuringInitialResendIsNotHeldTestConsumeStream_FlapDuringCurrentResumeIsNotHeldTestConsumeStream_FlapDuringExtensionIsNotHeldBroadcaster.PublishheldpublishMuonly for reading, so two publications could interleave their mutate and broadcast steps. On one endpoint a watcher received REMOVED x (v2) then ADDED x (v1) and kept x. One batch's unversioned events could also land after another's versioned last event, breaking the registrar/agent: the watch version is stamped on every event, so a stream truncated mid-snapshot or mid-batch leaves the agent with last_version = V and partial state — a reconnect that matches V skips the resend #1203 rule. Publications are now serialized:publishMuis async.Mutex. Lock order ispublishMu, thenSnapshot.muor the broadcaster'smu, never both at once, soSubscribeWithandMarkVersioncannot deadlock. Tests inpublish_order_test.go:TestPublish_SameKeyPublicationsAreOrderedTestPublish_ConcurrentPublicationsKeepEveryVersionHonest: 8 goroutines × 200 registers and multi-IP unregisters on shared keys. At every versioned event the watcher's cache must hash to that version. Without the fix it fails 3/3 runs with hundreds of violations.TestWatchEndpoints_PreSnapshotBatchCannotRegressTheTokenrelied on the old concurrency: batch C published while batch B was open. C now goes through a goroutine because it waits for B. Its assertions are unchanged.renamedanswer always has an equal hash. Tests:TestConsumeStream_EmptyResendAfterPresentedTokenClearsTestConsumeStream_RenamedResumeKeepsTheCache(the negative)TestEmptyResend: a table over<rev>.<h>,<rev>+<h>,hash:<h>, pre-registrar: every sync poll bumps the snapshot version even when nothing changed, so a reconnecting agent with last_version never matches and always gets the full snapshot #1193 counters, no token, and extended.TestWatchLoop_DependencySetChangeCacheContentsruns the real watch loop against a fake that answers like the registrar (current, extended or resent). Through narrow, shrink, grow and grow it asserts both the outcomes (resentonce, thencurrent,current,extended,extended) and the exact cache contents after each step.Closes #1239
🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr