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
Languages
Go 84.5%
Rust 7.9%
Shell 2.7%
templ 1.6%
Java 1%
Other 2%