Repository navigation
v0.0.5 — the checkpoint codec is declared, and initialization belongs to the generation
Two fixes, both for defects that were silent by construction: each had a failure
mode that produced no error and no failing test.
THE CHECKPOINT CODEC (#11). SaveCheckpointRequest gained an Encoding field
(EncodingV1 / EncodingV2), Checkpoint carries it back, and two sentinels were
added: ErrEncodingRequired and ErrUnsupportedEncoding. EncodingUnspecified is
never valid.
Why it could not stay optional: a decoder handed bytes in the wrong codec returns
an EMPTY document with NO error, in both directions. That is measured, not
assumed. A store that infers the codec therefore cannot distinguish "wrong codec"
from "empty document", so the data-loss path and the ordinary path look the same
from the inside. The writer now declares the encoding and the reader never
guesses.
INITIALIZATION LIFETIME (#12). Registry.Acquire ran the OpenFunc on the creating
caller's goroutine under the creating caller's context, which made an arbitrary
participant the owner of work everyone else depended on: coalesce a 2s caller and
a 60s caller, and if the 2s caller wins the race the 60s caller's load dies at 2s
for reasons it cannot see. Initialization now belongs to the generation, on its
own goroutine under a context this registry owns.
The generation context is WithCancel(WithoutCancel(callerCtx)). It keeps the
winning caller's VALUES — tenant scope, credentials, trace context, which the
OpenFunc was written against — and drops only its lifetime. It is cancelled when
the last waiter leaves, on Invalidate, and on Close.
CONTRACT CHANGE FOR CONSUMERS. OpenFunc no longer inherits the acquirer's
deadline. Anything relying on that must impose its own bound, derived from the
given context so the values survive. Note the part that is easy to miss: new
arrivals RENEW the last-waiter condition, so a document under load can hold the
waiter count above zero indefinitely and a wedged store is then never bounded by
this context at all — which is precisely the case where it is wedged.
Three further defects were found while reviewing that change, all reachable:
- A cancelled generation stayed joinable, so the next caller attached to an
initialization that could no longer succeed. - A failed open closed its completion channel twice and panicked. Caught by
this registry's own conformance suite, not by the new tests. - A waiter could be handed a document Evict or Close had already destroyed —
two callers then mutating different documents under one ID.
Invalidate now also waits for an abandoned initialization of the same document,
so after it returns no load of that document is in flight, including one no
caller is waiting for.
Every one of the eleven new registry tests is verified against a planted defect.
Two first-draft tests were hollow and only injection revealed it; one was a race
dressed as a barrier and is now genuinely ordered.