go-dynamo-anti-entropy-merkle-tree-range-repair-exactness
Solution complete and verified. Here's what was built.
~/ae/ — a self-contained Go module with:
- merkle.go — shape-independent Merkle tree
- planner.go — range diff, budget rounds, optimality certificate
- planner_test.go — 7 test functions (300 randomized trials)
- cmd/demo/main.go — end-to-end trace
- SOLUTION.md — the requested writeup (title, root-cause analysis, full code, verification)
| Failure mode | Mechanism |
|---|---|
| Replicas split ranges differently (rebalance moved leaves) | Digest is an XOR set hash over records, independent of tree shape; diff by token range + nearest boundary from either tree |
| Non-power-of-two splits | Leaves come from an explicit sorted boundary list; interior tree balances over the leaf list |
| Interior digest collisions | Ground-truth divergent set is an oracle: hashEqual && divergentInRange → refuse to prune, descend (collisionDescents) |
| Interior nodes rebuilt mid-epoch | Dirty flag + bottom-up ensure() recompute before any digest is trusted |
| Budget + optimality proof | Greedy round packing; certificate compares actual leaf batches to the union-partition lower bound |
PASS: TestBasicConvergence, TestNonPowerOfTwoSplits, TestRebalanceMovedLeaves,
TestInteriorCollisionStillConverges, TestDirtyInteriorRebuild,
TestBudgetRounds, TestRandomizedConvergence
ok ae 0.099s (go vet clean, gofmt clean)
certificate: divergent=3 keyTransfers=3 leafTransfers=3 leafOptimal=3 gap=0 withinOne=true
converged: true (|A|=5, |B|=5)
The certificate is tight: KeyTransfers = |divergent| (each key must move once) and LeafTransfers = LeafOptimal (a message covers at most one union-partition leaf), so the required "within one of optimal" bound holds with zero slack.
Run it yourself:
cd ~/ae && go test -v -count=1 ./... && go run ./cmd/demo
# Evidence - Problem class: go-dynamo-anti-entropy-merkle-tree-range-repair-exactness - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-30T10:06:54.211Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "In a Dynamo-style replicated store two replicas keep Merkle trees over the same token range with fixed-width digests, and a partial write has left the trees divergent with no record of which keys actually differ. Implement the anti-entropy repair planner: given both trees (including interior nodes whose children were rebuilt mid-epoch), the divergent key set and a per-round exchange budget, emit the exact sequence of subtree-hash comparisons and key transfers that provably converges both replicas, plus a certificate showing the number of leaf transfers is within one of optimal. Handle non-power-of-two range splits, interior digest collisions where distinct key sets hash alike, and a rebalance that moved leaves between sibling subtrees during the epoch.", "environment": "go1.26", "language": "go", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "go-dynamo-anti-entropy-merkle-tree-range-repair-exactness", "provider": "openrouter", "solved_at": "2026-09-30T10:06:54.211Z", "version": "1.26"}Solution complete and verified. Here's what was built.
~/ae/ — a self-contained Go module with:
- merkle.go — shape-independent Merkle tree
- planner.go — range diff, budget rounds, optimality certificate
- planner_test.go — 7 test functions (300 randomized trials)
- cmd/demo/main.go — end-to-end trace
- SOLUTION.md — the requested writeup (title, root-cause analysis, full code, verification)
| Failure mode | Mechanism |
|---|---|
| Replicas split ranges differently (rebalance moved leaves) | Digest is an XOR set hash over records, independent of tree shape; diff by token range + nearest boundary from either tree |
| Non-power-of-two splits | Leaves come from an explicit sorted boundary list; interior tree balances over the leaf list |
| Interior digest collisions | Ground-truth divergent set is an oracle: hashEqual && divergentInRange → refuse to prune, descend (collisionDescents) |
| Interior nodes rebuilt mid-epoch | Dirty flag + bottom-up ensure() recompute before any digest is trusted |
| Budget + optimality proof | Greedy round packing; certificate compares actual leaf batches to the union-partition lower bound |
PASS: TestBasicConvergence, TestNonPowerOfTwoSplits, TestRebalanceMovedLeaves,
TestInteriorCollisionStillConverges, TestDirtyInteriorRebuild,
TestBudgetRounds, TestRandomizedConvergence
ok ae 0.099s (go vet clean, gofmt clean)
certificate: divergent=3 keyTransfers=3 leafTransfers=3 leafOptimal=3 gap=0 withinOne=true
converged: true (|A|=5, |B|=5)
The certificate is tight: KeyTransfers = |divergent| (each key must move once) and LeafTransfers = LeafOptimal (a message covers at most one union-partition leaf), so the required "within one of optimal" bound holds with zero slack.
Run it yourself:
cd ~/ae && go test -v -count=1 ./... && go run ./cmd/demo
# Evidence - Problem class: go-dynamo-anti-entropy-merkle-tree-range-repair-exactness - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-30T10:06:54.211Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "In a Dynamo-style replicated store two replicas keep Merkle trees over the same token range with fixed-width digests, and a partial write has left the trees divergent with no record of which keys actually differ. Implement the anti-entropy repair planner: given both trees (including interior nodes whose children were rebuilt mid-epoch), the divergent key set and a per-round exchange budget, emit the exact sequence of subtree-hash comparisons and key transfers that provably converges both replicas, plus a certificate showing the number of leaf transfers is within one of optimal. Handle non-power-of-two range splits, interior digest collisions where distinct key sets hash alike, and a rebalance that moved leaves between sibling subtrees during the epoch.", "environment": "go1.26", "language": "go", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "go-dynamo-anti-entropy-merkle-tree-range-repair-exactness", "provider": "openrouter", "solved_at": "2026-09-30T10:06:54.211Z", "version": "1.26"}