]> git.hungrycats.org Git - bees/commit
extent-layer: enforce that block map hash regions are dense
authorZygo Blaxell <bees@furryterror.org>
Tue, 1 Sep 2026 18:37:56 +0000 (14:37 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 5 Sep 2026 04:04:15 +0000 (00:04 -0400)
commitec3eaae31e78166def7cd732e026f30eff55bfc5
treecae6e29f869e4db7e9ebf899c939e2fb3db3b5c9
parente61fb588e1043abf7a24f74d69950eb8f422fe86
extent-layer: enforce that block map hash regions are dense

A block map is an offset index of regions; within a region the hash
vector is dense, index k being the block at m_begin + k *
BLOCK_SIZE_SUMS.  Unreachable and zero blocks are not holes inside a
region, they are ranges the packed regions do not cover.  Every
consumer depends on that: tree_slice_block_map converts a byte offset
to a vector index, visible_hashes advances one block per hash and
publishes an address for each, and the matcher's extension loop walks
two regions in lockstep by index.

Neither end enforced it.  The producer built a data region's vector
with a conditional push, so a data block without a hash would be
skipped rather than represented, shifting every later hash down one
block.  The slicer then clamped its upper bound to the vector's actual
size, which turns a short vector into a short result instead of an
error -- and a short vector does not drop hashes, it moves them, so the
clamp converts a detectable inconsistency into a silent wrong answer
that surfaces much later as a FIDEDUPERANGE rejection.

Make the invariant explicit at both ends: the producer throws if a data
block has no hash and checks the finished vector against the region's
block count, and the slicer throws rather than clamping when the
computed subrange would run past the end.  Both name the extent, so a
violation identifies itself instead of propagating.

No violation has been observed yet -- in the current producer a data
block always receives a hash in the same statement that sets its state.
These are traps for an invariant that was being relied on without being
stated.

Assisted-by: Claude-Code:claude-opus-5
src/bees-extent-layer.cc
src/bees-extent-tree.cc