Ping Qiu 7ed813a3b7 transport: fix doRebuild race — wait for replica barrier ack
## The bug

`doRebuild` returned `AchievedLSN = targetLSN` immediately after
writing `MsgRebuildDone`, then closed the connection. The replica's
handler runs on a separate goroutine and might not have processed
the rebuild blocks yet when `OnSessionClose` fires — tests that
read replica state after close saw unapplied blocks.

`TestTransport_Rebuild_DoesNotCorruptLBA0` flaked at ~40% locally.

## The fix

Structural, not a sleep. The replica's `MsgRebuildDone` handler
now replies with `MsgBarrierResp` carrying the actual synced
frontier, sent **after** `Sync()` returns. The primary's
`doRebuild` reads that ack before returning, mirroring the
existing `doCatchUp` barrier contract.

The `time.Sleep(50ms)` previously needed in
`TestTransport_Rebuild_StreamsAndAdvancesFrontier` is no longer
required and has been removed — the structural ack guarantees
durability when `closeCh` fires.

`AchievedLSN` reported to `OnSessionClose` is now the replica's
real frontier rather than the primary's intent — a more truthful
durability boundary.

## Verification

- `TestTransport_Rebuild_DoesNotCorruptLBA0` 5/5 runs pass
  (was ~3/5 before)
- Full transport suite green under `-count=5`
- Full repo suite green
2026-04-14 12:40:51 -07:00
Languages
Go 84.6%
Rust 7.8%
Shell 2.7%
templ 1.6%
Java 1%
Other 2%