The mutations journal was durable and coverage-symmetric, but several
correctness/robustness gaps remained. This addresses them.
seq is no longer AUTO_INCREMENT. AUTO_INCREMENT assigns at INSERT, not at
commit, so under concurrent transactions (the shared SQL server) commit-
visibility order can invert seq order and a consumer tailing WHERE seq > cursor
permanently skips a lower seq that commits after a higher one is visible;
rolled-back transactions also burn seqs. seq is now drawn from a single-row
counter table (bd_mutations_seq) incremented inside the mutation's own
transaction, at the ONE shared seam (issueops.insertMutationRow) both write
plumbings funnel through. The shared counter row makes concurrent allocators
conflict, so exactly one commit order survives; surviving seqs are gapless and
commit-ordered, and a rolled-back allocator burns no seq. The counter table is
dolt_ignore'd (same working-set locality as the journal) and seeded past the
journal high-water mark, so seq never resets across prune or restart.
Empirically verified in bd's actual deferred-commit model on BOTH concurrency
models: the Dolt SQL server resolves overlapping counter writers optimistically
and aborts the loser with a serialization error (retried by the write paths),
while the embedded engine serializes writers on the counter row. Two overlapping
transactions yield seq order == commit-visibility order with no gaps and no
duplicates; the guarantee holds even on dolt_ignore'd tables. The safety
property is unconditional: a committed seq=N implies its transaction read
counter=N-1, which required seq=N-1's transaction to have already committed.
Completeness guards are now STRUCTURAL, not name-based. They detect a mutator by
the DML it executes against a work-bead table (literal or templated table name),
not by a verb regex or a broad "Insert" coverage token, so a mutator named off-
pattern can no longer ship un-journaled. Shared static-analysis primitives live
in internal/storage/journalscan. Comment writes (a work-bead mutation) now
journal as an update on both seams, and the guards cover the comment receiver.
Phantom deletes fixed: the bulk delete paths (issueops.DeleteIssuesInTx and the
uow DeleteByIDs) journaled a delete for every requested id even when the id
removed no row (only the batch total was checked). They now journal a delete
only for ids that actually removed a row, matched by an in-transaction existence
read.
Docs: ts is documented as insert time stamped inside the committing transaction
(it always was); seq as counter-assigned/gapless/commit-ordered. The CLI help
now states that raw `bd sql` DML is not journaled, that the journal is per-branch
working-set state, and that prune retain floors are time/rows based rather than a
consumer watermark (a lagging consumer can be pruned past). The prune-floor
orchestration is consolidated into one helper (issueops.ComputeMutationsPruneWhere)
used by both the DBTX and proxied raw-SQL prune paths.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>