a refused delete
v0.6.0-alpha.4 is three small fixes. one of them is a bug that sat in zat's MST through the interop fixtures and every hand-written test, and turned out to be in Atmos too. nobody read their way to it. a machine generated operation histories until one of them broke.
the bug
an MST can be loaded with blocks missing. that is the normal case for a
firehose commit: the CAR carries the nodes on the path to what changed,
and the rest of the tree is stubs — a CID where a node would be. an
operation that has to cross a stub it cannot resolve returns
error.PartialTree. fine. the caller asked for something the tree can't
do, and the tree said so.
the unstated half of that contract is that a refusal changes nothing.
deleteReturn did not keep it. it removed the entry first and trimmed
the root afterwards. deleting the root's only entry hands the root to
whatever sits beneath it, and the trim has to load that node to find out
whether it holds an entry. on a partial tree that load is where
error.PartialTree came from — after the entry was already gone. the
caller got an error and a tree whose root had no entries and a rootCid
belonging to no tree.
the minimal case is two keys: one at layer 3, one at layer 1, loaded from a CAR holding only the root block. delete the layer-3 key.
how it was found
Inanna Malick's Property Testing with Agent Swarms makes an argument I wanted to test on something I own: writing the reference model, the generators and the assertions for a stateful property test is tedious, mechanical work, which makes it delegable to an agent, and once it exists it checks millions of cases without spending a token on any of them.
so the MST got one. the engine is libhegel, the property-testing core behind Hegel: it generates cases, shrinks failures, and replays them. it has a C API, so the zig side is a thin driver — hegel-zig, which exists for this harness and is only as wide as it needs.
the model is a map from key to value. after any history, a tree must hold exactly what the model holds, and its root CID must equal the root CID of a tree built fresh from those contents. the second check is the one with teeth: an MST is canonical, so any path to the same contents has to land on the same bytes.
histories draw from sixteen keys spread across five layers, small enough
that overwrites and delete-then-reinsert are common, spread enough that
they hit splits, merges and the bridging nodes between layers. mutation
is mixed with everything that touches the dirty-flag cache or the
stub/loaded distinction: rootCid reads, collectBlocks, copies mutated
on either side, and reloads of the committed tree — eager, lazy, partial
with a block reader, partial without. that last one is allowed to refuse
an operation, and must then be left as it was.
before trusting a clean run, the harness had to prove it could see something. planting a dirty-flag bug by hand and running 100 cases caught it in 9 or 10 runs out of 10. a test that passes on broken code is the default outcome of writing tests, and the only way to rule it out is to break the code.
then it ran. about 12.2 million histories against zat's MST, the last 1.44 million of them (82.8 million operations, across twelve key pools) under libhegel's own state machine with swarm testing. one finding. the dirty-flag cache, the copies, the lazy loads, the reload paths — the parts I was actually worried about — held.
I'd like to say that's the surprising part, but it is the ordinary shape of this kind of result. the bug was not in the clever code. it was in an error path nobody had written down a rule for.
the fix
deleteReturn now resolves the next root before it removes anything. if
the root keeps an entry, it stays the root and nothing below has to load
after the removal. if the delete takes the root's only entry, the merged
subtree beneath it is found and trimmed first, and adopted only once the
delete can no longer fail. a refused delete leaves entries, root layer
and rootCid where they were.
two regression tests pin it: the two-key case on a partial tree with no reader, and the same tree loaded lazily through a reader that serves only the root block.
the same bug, in go
zat's MST hot path was aligned with Atmos's back in
devlog 012, so the obvious next question was
whether the two deletes shared this too. they did: Tree.Remove edited
the root in place and then loaded the node beneath it.
atmos#14 is the report,
with a two-key repro; as far as I could tell the commit verifier drops
the tree on the first error, so this was about Remove's error contract,
not about anything trusting a bad root.
atmos#15 is the fix, and it
merged better than I sent it. my half was two commits: the same
resolve-before-remove change, and a second one because a loaded empty
node looked the same as a stub and was fetched again after the removal.
then @calabro.io pushed three more
on top, among them a model-based test of Remove on partial stores
(wired up as a fuzz target too) and a fix for a different bug, where a block that failed validation partway
left a half-built node behind for every later operation to trust. it
merged and shipped as
v0.7.1 the same
evening.
devlog 014 said zat should learn from Atmos's refusals. it is nice when the debt runs the other way for a day.
the other two
both are cancellation bugs, and both come from the same fact about
std.Io: a cancel request is delivered once, to the next cancellation
point. swallow it and it is gone.
JetstreamClient.subscribe treated every error out of its read loop as a
dropped connection, error.Canceled included. it reported the error,
slept the backoff and reconnected, while the canceller's blocking
cancel() waited forever. it returns error.Canceled now.
HandleResolver renamed every transport error to a resolution failure
and fell back to DNS on most of them. a cancel that landed in the
well-known fetch was answered with a full DNS-over-HTTPS request.
error.Canceled and error.OutOfMemory pass through now, with no
fallback. the DNS arm has a regression test against a loopback endpoint;
the well-known arm does not, because the identity host check rejects
loopback, which is the check doing its job.
what stays
the harness is not in the release. it lives on a discovery branch, opt-in
behind a build flag, so zig build test needs neither libhegel nor the
driver. what crossed over to main is what the post says should: a
fix and the smallest tests that pin it.
twelve million histories and one bug is a good ratio for a tree that people's repos hang off. it is also one more bug than I knew about before the machine started.