Commit Graph
5 Commits
Author SHA1 Message Date
pingqiu 2347ccb72d 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.
2026-04-27 00:30:45 -07:00
pingqiu 61f5ff62a8 G5-5A: master peer-set from observed supporting replicas
Architect ratification round 54 (2026-04-27): collectPeers may
synthesize peer descriptors for topology slot members observed by
heartbeat even when they don't have a bound authority publication.

Root cause from QA round 54: V3 controller only mints
AssignmentInfo for the BOUND replica (Publisher.apply path).
Supporting replicas have no published authority line, so
master.collectPeers' pub.LastPublished returns false for them,
peers list is empty, primary's ReplicationVolume has no peers,
fan-out/Sync barrier has no acks → iSCSI fsync I/O error.

Architect Option A (chosen): collectPeers falls back to
ObservationStore for slot members without published lines.
Topology membership is the allow-list (option R / arbitrary
observed nodes still rejected). Authority state stays clean —
Option B (mint presence records into pub.state) was rejected.

Implementation:

  core/authority/observation_store.go:
    + SlotFact(volumeID, replicaID) — returns latest-observation
      SlotFact across all servers; fail-closed on empty DataAddr.

  core/host/master/services.go:
    collectPeers signature changes from (volumeID, selfReplicaID
    string) to (volumeID string, selfInfo adapter.AssignmentInfo)
    so observation-derived peers can inherit subscriber's Epoch/EV.

    Body extracted to pure helper resolvePeers() for testability.

    Peer construction policy:
      Path 1: pub.LastPublished hits → use authority Epoch/EV/addrs
      Path 2: SlotFact hits → use heartbeat addrs + INHERIT
              SUBSCRIBER'S Epoch/EV (live ships carry primary's
              lineage; replica validates against it)
      Else:   skip fail-closed

    Inheriting subscriber's Epoch/EV is required because
    ReplicaPeer constructor (replication/peer.go:130) rejects
    zero values — the lineage stamps every outgoing live-ship
    frame, and primary's authority is what the supporting replica
    validates against.

Tests:
  core/authority/observation_store_slotfact_test.go: 5 tests
    (round trip, empty store, fail-closed empty addr,
    latest-wins across servers, vol/replica mismatch)
  core/host/master/services_g5_5a_test.go: 5 tests
    (headline r1-bound + r2-observed-only, both bound,
    neither bound nor observed, nil obs store, path-1 wins
    over path-2)

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

No engine/adapter behavior change — touches master/observation
peer-set construction only.

Refs: QA round 54 finding (cross-host fsync I/O error);
architect Option A ratification 2026-04-27.
2026-04-27 00:18:51 -07:00
wzcheng99 f6ae66254f T4a-6 follow-up: four QA spot-check fixes (install-or-refuse,
uint32 assertions, host-level tests, matrix honesty)

QA round-21 spot-check flagged four issues in the T4a-6 landing.
All four confirmed correct; this commit addresses them as one
reviewable unit per QA's recommended batch.

Finding #1 (HIGH) — install-or-refuse ordering in Host.streamOnce.
  Previous order was OnAssignment → UpdateReplicaSet, creating a
  window where the adapter's projection flipped Healthy before the
  peer set was installed. StorageBackend.lineageCheck would then
  pass and admit local-only writes with zero fan-out. V2 atomically
  set replicas before admitting writes; V3 had drifted. Fix:

    - Extract applyFact(fact) from streamOnce's inner loop so the
      handler logic is testable in isolation.
    - Invert order: if h.replication != nil, call UpdateReplicaSet
      FIRST. On failure, LOG and RETURN without calling OnAssignment.
      Adapter projection stays at its prior (not-Healthy until a
      fact fully installs) state; StorageBackend keeps writes
      blocked; master's stream replay redelivers the fact and
      natural convergence resumes on the next cycle.
    - Introduce narrow collaborator interfaces (assignmentConsumer,
      replicaSetUpdater) on Host so test doubles can drive applyFact
      without spinning up a real adapter + transport listener. The
      concrete adapter reference is retained as realAdpt for the
      existing Adapter() accessor.

Finding #2 (MEDIUM) — generation aliasing at the uint32 boundary.
  `(epoch << 32) | uint32(ev)` silently aliased distinct authority
  lines whenever either field exceeded 2^32. Fix:

    - Extract generationFitsUint32(epoch, ev) as a named package-
      level function with a descriptive reason string.
    - SubscribeAssignments calls generationFitsUint32 before minting
      the fact; on rejection, logs a structured diagnostic + skips
      the fact (master keeps running — this is a fail-fast on an
      invariant violation upstream, not a master-side error).
    - Pin with two adversarial tests: TestGenerationFitsUint32_
      MaxValidAccepted (epoch = 2^32-1, ev = 2^32-1 passes) and
      _OverflowRejected (epoch = 2^32 and ev = 2^32 each reject
      with reasons naming the offending field).

Finding #3 (MEDIUM) — T4a-5 host wire was uncovered by T4a-6. The
  L2 integration test bypassed Host.streamOnce entirely, so the
  "all T4a commits compose correctly" claim in commit 420a5a1 was
  stronger than what the test proved. Fix:

    - New apply_fact_test.go in core/host/volume with five pins:
      * TestHost_ApplyFact_Self_InstallsReplicaSetBeforeAssignment
        (ordering recorder proves UpdateReplicaSet before
        OnAssignment in the happy path).
      * TestHost_ApplyFact_Self_UpdateReplicaSetFailure_SkipsOnAssignment
        (fail-closed pin for finding #1).
      * TestHost_ApplyFact_Supersede_NeverCallsAdapterOrReplication
        (the supersede branch is unaffected by the reordering).
      * TestHost_ApplyFact_ObserverOnly_NoReplicationCallsOnAssignment
        (nil replication seam still flows to OnAssignment as before).
      * TestDecodeReplicaTargets_FieldCopy (auxiliary; catches
        decoder drift).
    - The commit message and batch-close story now honestly reflect
      that host ordering is covered. Full master → gRPC → host
      subprocess L2 integration deferred to T4b/T4c where the
      durability/recovery path makes it materially more valuable
      (per QA round-21 guidance).

Finding #4 (LOW) — matrix 'non-gating' fiction removed.
  The earlier runMatrix harness had walstore_nongating that
  claimed to demote subtest failures. Go's testing has no clean
  demote-subtest-failure API; the defer-based logic didn't
  actually demote. Replaced with honest naming: walstore is a
  second gating row (passes today under T4a best-effort paths;
  if it ever regresses under BUG-007 the test fails honestly
  and we invest in a real demotion harness then). File header
  comment updated to match.

Verification: full 21-package repo suite green including
core/host (122s integration run) and the 5 new host tests. No
regressions.
2026-04-23 17:30:53 -07:00
wzcheng99 db3be2e58c T4a-5: wire Host authority-callback to ReplicationVolume (P-refined)
Completes the T4a-5.0 §8C.3 Discovery Bridge resolution (Option
P-refined, landed per architect + QA round-19). Extends the
AssignmentFact wire with master-minted peer set + monotonic
generation, adds a separate host-only decode path that does NOT
touch AssignmentInfo (preserves the TestNoOtherAssignment
InfoConstruction AST fence), and wires Host.streamOnce to drive
ReplicationVolume.UpdateReplicaSet after every self-replica
AssignmentFact.

Guardrails (all four from round-19) honored:
  1. decodeAssignmentFact unchanged; AST fence stays green.
  2. decodeReplicaTargets is SEPARATE and produces replication.
     ReplicaTarget + generation, never AssignmentInfo. Adapter +
     engine packages: zero changes.
  3. Peer set is master-minted only. Host does NOT accumulate or
     derive from other-replica facts (option R rejected).
  4. peer_set_generation mandatory on the wire; monotonic guard in
     ReplicationVolume.UpdateReplicaSet.

Changes:

  core/rpc/proto/control.proto
    NEW message ReplicaDescriptor{replica_id, epoch, endpoint_
    version, data_addr, ctrl_addr}. AssignmentFact gains
    `repeated ReplicaDescriptor peers = 7` (excludes self) and
    `uint64 peer_set_generation = 8` (monotonic, master-minted).

  core/rpc/control/control.pb.go + control_grpc.pb.go
    Regenerated via scripts/genproto.sh.

  core/host/master/services.go
    SubscribeAssignments fills fact.Peers via new collectPeers
    helper (reads Publisher.LastPublished for each non-self slot
    in the volume's accepted topology). Generation derived as
    `(info.Epoch << 32) | info.EndpointVersion` — monotonic
    because publisher's lex-dedupe upstream guarantees strictly-
    increasing (Epoch, EV) pairs and Epoch/EV are durable authority
    facts (survives master restart).

  core/host/volume/subscribe.go
    NEW decodeReplicaTargets(fact) ([]replication.ReplicaTarget,
    uint64) — strict field-copy, same discipline as decode
    AssignmentFact. Produces a different output type so the
    AST fence TestNoOtherAssignmentInfoConstruction continues to
    pass.

  core/host/volume/host.go
    Config gains `ReplicationVolume *replication.ReplicationVolume`
    (nil = T0/observer-only; non-nil = T4a-5 production wire).
    streamOnce self-replica branch calls UpdateReplicaSet(gen,
    targets) AFTER adapter.OnAssignment. Non-blocking log on
    error (best-effort; failure does not stop the assignment
    stream).

  core/replication/volume.go
    UpdateReplicaSet signature break (QA option (a), no shim):
      Before: UpdateReplicaSet(targets []ReplicaTarget) error
      After:  UpdateReplicaSet(generation uint64, targets []ReplicaTarget) error

    Three-way generation rule (T4a-5.0 §9.4, QA corrected sw's
    original MaxUint64 sentinel which would have one-way-poisoned
    the monotonic guard):
      - gen == 0: unversioned apply; peer map mutated;
        lastAppliedGeneration NOT advanced. Test/fake-master only.
      - gen > 0 && gen > lastApplied: apply + advance.
      - gen > 0 && gen <= lastApplied: stale; peer map NOT mutated;
        replayedGens counter increments; debug log emits peer-ID-
        set delta (Q2 binding — IDs only, not full target structs).
        Returns nil (idempotent replay is success).

    Empty peer set (N → 0) flows through the same teardown path as
    any N → M-1 removal. No special branch (Q3 binding).

    New state: lastAppliedGeneration uint64 (mu-guarded);
    replayedGens atomic.Uint64 (stats counter, private; public
    Stats() deferred to T4-end observability pass).

    New helpers (internal): peerIDSet, targetIDSet,
    stringSetEqual, formatIDSet (deterministic brace-form
    rendering of peer-ID sets for log diffs).

  core/replication/volume_test.go
    All 8 existing tests migrated to new signature with gen=0
    (unversioned apply preserves previous functional semantics).
    3 new tests (Q1/Q2/Q3 pins):
      9.  UpdateReplicaSet_Generation_MonotonicGuard — advance
          through gens 1, 2, 3; stale replays at gen=2 and gen=3
          (equal is stale); verify replayedGens counter; forward
          progress at gen=4 works. Exercises Q2 differing-peers
          path via the gen=2 replay with original r1+r2 set.
      10. UpdateReplicaSet_GenerationZero_DoesNotAdvanceGuard —
          gen=5 applied, gen=0 applied (peers mutated, last
          Applied stays at 5), gen=3 rejected as stale. Pins the
          correctness of the gen=0 rule vs. the original
          MaxUint64 sentinel which would have failed this test.
      11. UpdateReplicaSet_EmptyPeerSet_AppliesWithTeardown — Q3
          binding three assertions: PeerCount=0 after empty
          apply, all former peers' executor sessions invalidated,
          next OnLocalWrite succeeds as zero-fanout no-op.

Verification: full 20-package repo suite green (core/host: 124s
including supersede_integration_test; core/host/volume: 31ms
confirming AST fence TestNoOtherAssignmentInfoConstruction still
passes; core/replication: all 17 tests green). G-2 tri-line godoc
on every new public surface.

Closes T4a-5.0 §8C.3 Discovery Bridge. Next: T4a-6 L2 subprocess
integration test.
2026-04-23 16:50:01 -07:00
wzcheng99 55793d49bc T0 closure: blockmaster/blockvolume hosting + D1-D5 tests
Product binaries (cmd/blockmaster, cmd/blockvolume) and
core/host wiring for volume-scoped assignment delivery,
durable authority with Windows rename retry, and the T0
closure test set (D1 L2 subprocess, D2 G1 adversarial,
D3 concurrent write-reload regression, D4 hosting-smoke
scenario + Go-native replay, D5 --topology flag).

Diagnostic surfaces: ObservationStore.SupersededCount
(PCDD-DELAYED-HB-001 evidence, not authority input) and
SetNowForTest clock seam on Store/Host, guarded by grep
test ensuring the identifier stays out of production files.
2026-04-21 02:02:52 -07:00