G5-5A round 54 follow-ups: freshness gate + lineage rule + comment

Architect review round 54 findings (3 items, all addressed):

HIGH 1 — SlotFact ignores freshness:
  ObservationStore explicitly says expired observations stay
  visible but are 'semantically ineligible for supported snapshot
  synthesis'. SlotFact was scanning the full observation map
  without checking ExpiresAt. For peer-set construction this is
  wrong: a stale heartbeat addr is unsafe to dial.
  Fix: SlotFact now skips observations where now > obs.ExpiresAt.
  New test TestObservationStore_SlotFact_ExpiredObservation_FailsClosed
  verifies the boundary (ok=true within FreshnessWindow,
  ok=false past expiry).

HIGH 2 — path 1 mis-stamps live-ship lineage:
  resolvePeers path 1 was using the peer's OWN LastPublished
  Epoch/EV. If LastPublished(v1, r2) returns r2's retained
  historical authority line (e.g., r2 was previously bound at
  Epoch=N before reassignment to r1 at Epoch=N+1), primary r1
  would stamp live-ship frames under r2's old N — breaks the
  apply gate at the replica which expects current authority.
  Fix: BOTH paths now stamp peer.Epoch/EV with subscriber's
  lineage. Authority/observation supplies addresses only;
  subscriber stamps lineage. Updated TestResolvePeers_BothBound
  to pin this (peer's old 4/1 must NOT win over subscriber's
  5/2). path-1-preferred test still passes — it's about which
  ADDR wins, not lineage.

LOW 3 — stale comment:
  collectPeers godoc still claimed observation-derived peers
  'carry Epoch=0 + EndpointVersion=0 to mark observation-derived'.
  Out of date since round-54 inheritance fix. Rewrote comment
  block to reflect current rule: both paths stamp subscriber's
  lineage; authority/observation supplies addresses only.

All G5-5A tests still pass (10/10); cmd/blockvolume G5-4
integration test PASS; full V3 suite green.

Refs: architect round 54 review of 61f5ff6.
This commit is contained in:
pingqiu committed 2026-04-27 00:30:45 -07:00
1 parent 61f5ff62a8
commit 2347ccb72d
4 files changed
+128 -55

No files matched your search

@@ -78,7 +78,10 @@ func (s *ObservationStore) SupersededCount() uint64 {
// - no observation has reported any slot for this (volumeID, replicaID), OR
// - observations exist but the matching slot has empty DataAddr
// (caller-side fail-closed: skip the peer rather than synthesize
// a descriptor with an unusable addr)
// a descriptor with an unusable addr), OR
// - all matching observations are EXPIRED (now > obs.ExpiresAt) per
// architect round 54 finding-1: "expired heartbeat addr should
// fail closed" — same discipline as snapshot synthesis.
//
// NOT authority input. Read-only; safe to call concurrently.
func (s *ObservationStore) SlotFact(volumeID, replicaID string) (SlotFact, bool) {
@@ -87,12 +90,21 @@ func (s *ObservationStore) SlotFact(volumeID, replicaID string) (SlotFact, bool)
}
s.mu.Lock()
defer s.mu.Unlock()
now := s.now()
var (
best SlotFact
bestObsAt time.Time
found bool
best SlotFact
bestObsAt time.Time
found bool
)
for _, obs := range s.observations {
// Fail-closed on stale heartbeats (architect round 54
// finding-1). An expired observation's DataAddr cannot be
// trusted for primary→replica dial; skip and let caller
// surface the slot as "no observation" until the next
// fresh heartbeat lands.
if !obs.ExpiresAt.IsZero() && now.After(obs.ExpiresAt) {
continue
}
for _, slot := range obs.Slots {
if slot.VolumeID != volumeID || slot.ReplicaID != replicaID {
continue
@@ -100,8 +112,7 @@ func (s *ObservationStore) SlotFact(volumeID, replicaID string) (SlotFact, bool)
if slot.DataAddr == "" {
// Fail-closed: an observation that names the slot but
// without a usable DataAddr is unusable for primary
// fan-out. Skip; let the caller's topology check
// surface as "no observation" if this is the only one.
// fan-out.
continue
}
if !found || obs.ObservedAt.After(bestObsAt) {
@@ -82,6 +82,39 @@ func TestObservationStore_SlotFact_LatestObservationWins(t *testing.T) {
}
}
// TestObservationStore_SlotFact_ExpiredObservation_FailsClosed pins
// architect round 54 finding-1: expired heartbeat addrs MUST NOT be
// used for live replication peer construction. Observation stays
// visible in the store (other diagnostic surfaces use it), but
// SlotFact's narrow contract is "give me an addr safe to dial NOW".
func TestObservationStore_SlotFact_ExpiredObservation_FailsClosed(t *testing.T) {
t0 := time.Date(2026, 4, 27, 10, 0, 0, 0, time.UTC)
now := t0
clock := func() time.Time { return now }
s := NewObservationStore(FreshnessConfig{FreshnessWindow: 10 * time.Second}, clock)
// Ingest at t0 (ExpiresAt = t0+10s).
if err := s.Ingest(Observation{
ServerID: "src",
ObservedAt: t0,
Slots: []SlotFact{{VolumeID: "v1", ReplicaID: "r2", DataAddr: "192.168.1.184:9221"}},
}); err != nil {
t.Fatal(err)
}
// Within freshness window: ok=true.
now = t0.Add(5 * time.Second)
if _, ok := s.SlotFact("v1", "r2"); !ok {
t.Fatal("within freshness window: ok=false; want true")
}
// Past freshness window: must fail closed.
now = t0.Add(11 * time.Second)
if got, ok := s.SlotFact("v1", "r2"); ok {
t.Fatalf("after expiry: ok=true got %+v; want false (fail-closed on expired heartbeat)", got)
}
}
func TestObservationStore_SlotFact_VolumeOrReplicaMismatch_ReturnsFalse(t *testing.T) {
now := time.Date(2026, 4, 27, 10, 0, 0, 0, time.UTC)
s := NewObservationStore(FreshnessConfig{FreshnessWindow: 30 * time.Second}, func() time.Time { return now })
+52 -37
View File
@@ -315,30 +315,38 @@ func generationFitsUint32(epoch, endpointVersion uint64) (reason string, ok bool
// discovery doc §9.5: never accumulate from arbitrary observed
// nodes).
//
// Per-slot resolution (G5-5A architect ratification 2026-04-27):
// Per-slot resolution (G5-5A architect ratification 2026-04-27,
// refined at round-54 review):
//
// 1. PRIMARY path: for slots whose authority is published (the
// 1. AUTHORITY path: for slots whose authority is published (the
// bound replica + any historically-bound replicas with retained
// records), use the publisher's `LastPublished` lineage —
// authoritative Epoch / EndpointVersion / DataAddr / CtrlAddr.
// records), pull DataAddr/CtrlAddr from `LastPublished` (this
// is the freshest authoritative addr — refreshed via
// IntentRefreshEndpoint).
//
// 2. SUPPORTING path: for slots that ARE declared in topology
// 2. OBSERVATION path: for slots that ARE declared in topology
// but have NO published authority line (the common case for
// supporting replicas — Publisher.apply only mints for the
// bound replica), fall back to the observation store's last
// heartbeat-reported SlotFact for that (volumeID, replicaID).
// This is OBSERVATION TRUTH, not authority truth. The synthesized
// ReplicaDescriptor carries Epoch=0 + EndpointVersion=0 to mark
// it explicitly as observation-derived; only the addresses are
// load-bearing for primary fan-out.
// bound replica), pull DataAddr/CtrlAddr from the observation
// store's freshest non-expired heartbeat. pub.state stays
// authority-only — architect option (B) "mint presence
// records" REJECTED.
//
// pub.state stays authority-only. Architect option (B) — minting
// "presence" records into pub.state — was REJECTED at round 54.
// Both paths stamp peer.Epoch / peer.EndpointVersion with the
// SUBSCRIBING PRIMARY's lineage, NOT the peer's own. Rationale:
// the descriptor's Epoch/EV become the live-ship lineage downstream
// at ReplicaPeer construction; live ships travel under primary's
// authority. Using a retained historical LastPublished epoch/EV
// for the peer would mis-stamp frames against the current
// authority and break the replica's apply gate.
//
// Fail-closed cases (slot is skipped, NOT silently substituted):
// - slot is the self replica (primary doesn't ship to itself)
// - slot has no published line AND no observation store record
// - observation exists but reports empty DataAddr (unusable for dial)
// - slot has no published line AND no fresh observation
// - observation exists but reports empty DataAddr (unusable)
// - observation exists but is expired (now > ExpiresAt) —
// architect round-54 finding 1: stale heartbeat addrs are
// unsafe for live dial
//
// Without this fallback, a cross-host replicated write would hang at
// fsync barrier because primary's peers list is empty and nothing
@@ -371,42 +379,48 @@ type peerObservation interface {
}
// resolvePeers implements the G5-5A peer-set construction policy
// (architect ratification 2026-04-27). Pure function; testable
// without constructing a full Host.
// (architect ratification 2026-04-27, refined round-54).
// Pure function; testable without constructing a full Host.
//
// Observation-derived peers (path 2) inherit the SUBSCRIBING
// primary's (Epoch, EndpointVersion). Rationale: in V3, supporting
// replicas have no authority line of their own; live-ship frames
// from primary→replica carry the PRIMARY's lineage, which is what
// the replica validates against. The peer descriptor's Epoch/EV
// fields are interpreted by the primary's ReplicaPeer constructor
// as "lineage to stamp on outgoing frames", so primary's own
// Epoch/EV is the architecturally-correct value. Stamping zero
// would correctly mark the descriptor as observation-derived but
// would break the downstream ReplicaPeer constructor's nonzero
// invariant (replication/peer.go:130).
// LINEAGE RULE (architect round 54 finding 2): peer descriptor
// Epoch/EndpointVersion ALWAYS comes from the subscribing primary's
// own line, regardless of whether the peer's address came from
// authority publication (path 1) or observation (path 2).
// Rationale: the peer descriptor is consumed by the primary's
// ReplicaPeer constructor to stamp live-ship frames; live-ship is
// always under PRIMARY's lineage. A retained historical
// LastPublished line for the peer (e.g., r2 was previously bound
// before reassignment to r1) carries r2's old Epoch/EV — using
// those as the live-ship lineage would mis-stamp frames against
// the current authority and the replica's apply gate would reject.
// Authority/observation supplies ADDRESSES; subscriber lineage
// stamps EPOCH/EV.
//
// PATH RULE: path 1 (authority) is preferred over path 2
// (observation) when both have data, because authority has the
// live-current DataAddr/CtrlAddr (refreshed via IntentRefreshEndpoint),
// whereas observation may show a stale address from before a
// re-bind.
func resolvePeers(slots []string, selfInfo adapter.AssignmentInfo, volumeID string, pub peerLookup, obsStore peerObservation) []*control.ReplicaDescriptor {
peers := make([]*control.ReplicaDescriptor, 0, len(slots))
for _, rid := range slots {
if rid == selfInfo.ReplicaID {
continue
}
// Path 1: published authority line (bound replica or
// retained record after IntentReassign).
// Path 1: published authority line — use authority addrs,
// stamp subscriber lineage.
if info, ok := pub.LastPublished(volumeID, rid); ok {
peers = append(peers, &control.ReplicaDescriptor{
ReplicaId: info.ReplicaID,
Epoch: info.Epoch,
EndpointVersion: info.EndpointVersion,
Epoch: selfInfo.Epoch,
EndpointVersion: selfInfo.EndpointVersion,
DataAddr: info.DataAddr,
CtrlAddr: info.CtrlAddr,
})
continue
}
// Path 2: observation-only (supporting replica; topology
// membership confirmed by the slots loop above; addr from
// last heartbeat). Inherit subscriber's Epoch/EV so the
// downstream ReplicaPeer ships under primary's lineage.
// Path 2: observation-only — use heartbeat addrs, stamp
// subscriber lineage. Same rationale as path 1.
if obsStore != nil {
if slot, ok := obsStore.SlotFact(volumeID, rid); ok {
peers = append(peers, &control.ReplicaDescriptor{
@@ -422,7 +436,8 @@ func resolvePeers(slots []string, selfInfo adapter.AssignmentInfo, volumeID stri
// Else: fail-closed skip. Slot is declared in topology but
// neither authority nor observation has a usable address yet
// (cold-start before heartbeat lands, or replica down). The
// next emission (after r2 heartbeats in) will include it.
// next emission (after the supporting replica heartbeats in)
// will include it.
}
return peers
}
@@ -78,20 +78,33 @@ func TestResolvePeers_R1Bound_R2ObservedOnly_R2InPeersWithHeartbeatAddr(t *testi
}
// TestResolvePeers_BothBound — both slots have published authority
// lines; both contribute via path 1 with their authoritative
// epoch/EV/addrs. Confirms path-1 still works (no regression).
// lines. r2 contributes via path 1 with its address from authority
// state, but its lineage is STAMPED with the subscribing primary's
// Epoch/EV (architect round 54 finding 2: lineage is always
// subscriber's, even on path 1, because live-ship frames travel
// under primary's authority — using r2's old/historical authority
// values would break the apply gate at the replica).
func TestResolvePeers_BothBound(t *testing.T) {
pub := &stubPub{state: map[[2]string]adapter.AssignmentInfo{
{"v1", "r1"}: {VolumeID: "v1", ReplicaID: "r1", Epoch: 5, EndpointVersion: 2, DataAddr: "10.0.0.1:9220"},
{"v1", "r2"}: {VolumeID: "v1", ReplicaID: "r2", Epoch: 4, EndpointVersion: 1, DataAddr: "10.0.0.2:9221"},
}}
obs := &stubObs{state: map[[2]string]authority.SlotFact{}}
peers := resolvePeers([]string{"r1", "r2"}, adapter.AssignmentInfo{ReplicaID: "r1", Epoch: 1, EndpointVersion: 1}, "v1", pub, obs)
subscriber := adapter.AssignmentInfo{ReplicaID: "r1", Epoch: 5, EndpointVersion: 2}
peers := resolvePeers([]string{"r1", "r2"}, subscriber, "v1", pub, obs)
if len(peers) != 1 {
t.Fatalf("expected 1 peer (r2, self r1 excluded); got %d", len(peers))
}
if peers[0].ReplicaId != "r2" || peers[0].Epoch != 4 || peers[0].EndpointVersion != 1 {
t.Errorf("path-1 record: got %+v want {r2, Epoch=4, EV=1}", peers[0])
got := peers[0]
if got.ReplicaId != "r2" {
t.Errorf("ReplicaId: got %q want r2", got.ReplicaId)
}
if got.DataAddr != "10.0.0.2:9221" {
t.Errorf("DataAddr: got %q want 10.0.0.2:9221 (path-1 authority addr)", got.DataAddr)
}
if got.Epoch != 5 || got.EndpointVersion != 2 {
t.Errorf("Epoch/EV: got %d/%d want 5/2 (subscriber's lineage, NOT peer's old 4/1)",
got.Epoch, got.EndpointVersion)
}
}
@@ -124,24 +137,25 @@ func TestResolvePeers_NilObservationStore(t *testing.T) {
// TestResolvePeers_PathOnePreferredOverPathTwo — when the same slot
// has BOTH a published line AND an observation, path-1 (authority)
// must win. The slot is the bound replica; observation is a stale
// heartbeat from before the bind.
// addr wins. The peer.Epoch/EV is still subscriber's lineage.
func TestResolvePeers_PathOnePreferredOverPathTwo(t *testing.T) {
pub := &stubPub{state: map[[2]string]adapter.AssignmentInfo{
{"v1", "r1"}: {VolumeID: "v1", ReplicaID: "r1", Epoch: 7, EndpointVersion: 3, DataAddr: "AUTH:1"},
{"v1", "r2"}: {VolumeID: "v1", ReplicaID: "r2", Epoch: 7, EndpointVersion: 3, DataAddr: "AUTH:2"},
{"v1", "r2"}: {VolumeID: "v1", ReplicaID: "r2", Epoch: 4, EndpointVersion: 1, DataAddr: "AUTH:2"},
}}
obs := &stubObs{state: map[[2]string]authority.SlotFact{
{"v1", "r2"}: {VolumeID: "v1", ReplicaID: "r2", DataAddr: "OBS:2"},
}}
peers := resolvePeers([]string{"r1", "r2"}, adapter.AssignmentInfo{ReplicaID: "r1", Epoch: 7, EndpointVersion: 3}, "v1", pub, obs)
subscriber := adapter.AssignmentInfo{ReplicaID: "r1", Epoch: 7, EndpointVersion: 3}
peers := resolvePeers([]string{"r1", "r2"}, subscriber, "v1", pub, obs)
if len(peers) != 1 {
t.Fatalf("expected 1 peer; got %d", len(peers))
}
if peers[0].DataAddr != "AUTH:2" {
t.Errorf("DataAddr: got %q want AUTH:2 (path-1 must win over path-2)", peers[0].DataAddr)
t.Errorf("DataAddr: got %q want AUTH:2 (path-1 addr must win over path-2)", peers[0].DataAddr)
}
if peers[0].Epoch != 7 {
t.Errorf("Epoch: got %d want 7 (authority value)", peers[0].Epoch)
if peers[0].Epoch != 7 || peers[0].EndpointVersion != 3 {
t.Errorf("Epoch/EV: got %d/%d want 7/3 (subscriber's lineage even on path 1)",
peers[0].Epoch, peers[0].EndpointVersion)
}
}