epoch-fenced-snapshot-merge
Done. The solution is written to ~/solution.md and the verified implementation lives in ~/epoch-fenced-snapshot-merge/.
Root causes (four distinct hazards, each needing its own metadata):
1. Stale writer clobbering newer data → needs a monotonic epoch fence
2. Deletes returning as values → needs versioned tombstones
3. Epoch/sequence confusion → needs epoch-dominant Version{Epoch,Seq}
4. Unsafe compaction → needs a global floor (min fence across shards)
Plus a real ordering bug my own tests caught: advancing the fence before applying entries raised the floor and discarded the snapshot's own older-epoch entries. Fixed by making fence-advance the last step (invariant I5).
The exact fix (merge.go):
- Reject snapshot.Epoch < fence[shard] before inspecting entries
- Per-key LWW with strict > (gives idempotency)
- Skip entries below floor = min(fence) (blocks post-compaction resurrection)
- Advance the fence only after entries are applied
- Compact() drops tombstones only when tombstone.Epoch < floor
Verification — go vet + go test -race -count=20 -shuffle=on ./... all pass:
- stale writer with huge seq rejected
- 100× retry idempotent
- out-of-order same-epoch delivery converges
- tombstone beats higher-seq/lower-epoch value
- compaction respects a lagging shard's watermark
- post-compaction delayed snapshot cannot resurrect
- 8 generations × 50 racing ops converge to the version max under -race
- all 4! delivery permutations yield identical state
The write-up includes the full source, the safety argument for compaction, coordinator epoch-assignment guidance, and a test-by-test property map.
# Evidence - Problem class: epoch-fenced-snapshot-merge - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-10-09T05:03:28.468Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Design a Go service that merges concurrently produced, partially overlapping snapshots from sharded key-value stores while rejecting stale writers using epoch fencing and preserving tombstone semantics. Specify the merge algorithm and metadata needed to remain idempotent under retries, tolerate out-of-order delivery, and compact history without resurrecting deleted keys; demonstrate correctness under adversarial interleavings.", "environment": "go1.26", "language": "go", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "epoch-fenced-snapshot-merge", "provider": "openrouter", "solved_at": "2026-10-09T05:03:28.469Z", "version": "1.26"}