Skip to content

refactor(registrar): shared snapshot-version parser; give the in-flight-publication watch test teeth - #1274

Merged
bpalermo merged 2 commits into
mainfrom
fix/1271-1272-snapshot-version-shared
Oct 5, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/1271-1272-snapshot-version-shared

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Closes #1272
Closes #1271

Test and refactor only. No behaviour change, no proto change. Based on main after #1266/#1267.

#1272: one parser for agent and server

New leaf package common/snapshotversion (stdlib only: strconv, strings). It now holds the version format documentation (moved out of registrar/internal/server/snapshot.go), plus:

  • Format(revision, dirty, hash): was the server's formatVersion.
  • ContentHash(version): was versionContentHash, which existed on both sides.
  • Compare(token, current) Relation: returns Same (identical), Renamed (same embedded hash) or Different. Empty tokens get no special meaning here; each caller keeps its own "no token means resend" check.
  • HashLen (was contentHashLen) and the separator constants.

Both sides now classify with the same function:

  • Server, Snapshot.resumeLocked: Compare(token, s.version). This is equivalent to the old hash(token) == s.contentHash check because s.version is always rendered from s.contentHash (NewSnapshot / refreshLocked).
  • Agent, emptyResend: Compare(lastVersion, marker.Version) == Different. This is the old version equal → false; else !ok || !markerOK || hashes differ logic.

Table tests cover every form: <rev>.<hash>, <rev>+<hash>, hash:<hash>, a legacy counter, empty, empty hash parts, and garbage. The garbage cases pin today's "everything after the first separator" behaviour, so a stricter parser has to be a deliberate change made on both sides. Other tests:

  • a Format→ContentHash round trip;
  • the mixed-form comparisons: older revision, clean vs dirty, fallback vs revisioned, rebuilt etcd (all Renamed); different hash, legacy counter, empty (all Different); identical (Same).

Existing tests of both packages pass unchanged. The only edit is in publish_order_test.go, which follows the helper to its new name.

Dependency footprint: bazel query --noimplicit_deps 'kind(go_library, deps(//common/snapshotversion))' returns only the package itself. Its reverse deps are //registrar/internal/server and //registry/internal/registrar. The agent already links the second through registry/registrarclient. somepath from every guarded binary (agent-ready, identity-ready, mesh-dns, mesh-dns-ready, proxy-ready, proxy-supervisor, uds-csi, cni, plus prober and controller) to the package is empty.

#1271: TestWatchEndpoints_PreSnapshotBatchCannotRegressTheToken has teeth again

Problem. Since publications are serialized, batch C cannot overtake an in-flight batch B. If SubscribeWith stopped excluding publications, the watch would still receive B twice: once in its snapshot and once on its channel after the marker. But that duplicate now carries the snapshot's own version, so the old token and cache assertions could not see it.

Fix. The test keeps its scenario: B is applied but not yet broadcast, C is queued behind it, and a watch starts in between. It keeps the token and cache assertions and adds the rule SubscribeWith enforces: each batch is in the watch's snapshot or on its channel, never both. B's and C's endpoints must reach the stream exactly once (new helper: endpointDeliveries). The doc comment now says what the test proves and why the exactly-once assertion is the one that matters.

Mutation evidence. I removed b.publishMu.Lock()/Unlock() from SubscribeWith locally (not committed) and ran --runs_per_test=10:

I re-ran this on the post-merge main basis with the same result. TestWatchEndpoints_ChangeDuringInitialExchangeIsDelivered covers the lost-batch rule but not the duplicate, so this test is not redundant.

Proof

  • bazel test passes for //common/snapshotversion:all, //registrar/internal/server:all, //registry/internal/registrar:all, //agent/internal/cmd:all, //registrar/internal/cmd:all, //registrar/internal/services:all, and all 8 deps_test guards.
  • bazel test --config=race --runs_per_test=5 passes for snapshotversion_test, server_test and registrar_test.
  • make gazelle leaves the tree clean, and make format-check passes.
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //... passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits October 5, 2026 13:59
…#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
#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
@bpalermo
bpalermo merged commit df3a113 into main Oct 5, 2026
24 checks passed
@bpalermo
bpalermo deleted the fix/1271-1272-snapshot-version-shared branch October 5, 2026 17:38
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