fix(flush): clear() and repairIndex() set the dirty witness themselves
Some checks are pending
CI / Node 22 (push) Waiting to run
CI / Node 24 (push) Waiting to run
CI / Integration + conformance (Node 22) (push) Waiting to run
CI / Bun (latest) (push) Waiting to run

Both mutate durable state outside the two commit paths, so neither was seen by
the flush witness added with the idle-flush law. A clear() followed by a
flush() would have found the brain "clean" and skipped the entity-tree stamp,
leaving a stamp describing the population the clear had just removed — a false
divergence warning at the next open. Closing the gap where it is, rather than
widening the witness to guess.
This commit is contained in:
David Snelling 2026-08-28 11:06:06 -07:00
parent bc1555feb8
commit 0304350a41

View file

@ -8523,6 +8523,11 @@ export class Brainy<T = any> implements BrainyInterface<T> {
*/
async clear(): Promise<void> {
await this.ensureInitialized()
// A clear mutates durable state without going through a commit path, so
// it must set the dirty witness itself — otherwise a `clear()` followed by
// `flush()` would find the brain "clean" and skip the entity-tree stamp,
// leaving a stamp that describes the population this call just removed.
this._dirtySinceLastFlush = true
// Clear storage
await this.storage.clear()
@ -18394,6 +18399,10 @@ export class Brainy<T = any> implements BrainyInterface<T> {
*/
async repairIndex(options?: { rebuild?: Array<'metadata' | 'graph' | 'vector'> | 'all' }): Promise<RepairReport> {
await this.ensureInitialized()
// A repair recounts, prunes and rebuilds outside the commit paths; the
// dirty witness is set so a caller's flush after a repair does its normal
// work rather than finding the brain "clean".
this._dirtySinceLastFlush = true
const startedAt = Date.now()
const families: RepairFamilyReport[] = []