fix(close): a read-only brain writes no clean-shutdown evidence — the marker is the writer's word about itself
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
Delta Gate / Delta gate — candidate vs control (push) Waiting to run

This commit is contained in:
David Snelling 2026-09-02 10:56:32 -07:00
parent a79db434ac
commit 367ca721a5
3 changed files with 280 additions and 4 deletions

View file

@ -20486,9 +20486,22 @@ export class Brainy<T = any> implements BrainyInterface<T> {
await this._aggregationIndex.flush()
}
})(),
// 8.0 MVCC: detach the generation-bump hook and persist the counter
// 8.0 MVCC: detach the generation-bump hook and persist the counter.
// READ-ONLY GUARD: a reader's open() never sets the bump hook, never
// buffers pending single-ops, and — since generationStore.open() also
// leaves the clean-shutdown marker untouched for a reader — never
// consumes it either, so there is nothing of a writer's to persist or
// release here. Calling close() anyway would still WRITE: it
// unconditionally re-stamps `_system/clean-shutdown.json` (and can
// advance the fold checkpoint / counter files) at the generation this
// session merely observed — a reader vouching for a commit it never
// made. The marker is the writer's own evidence about the writer's own
// process; a read-only brain must leave `_system/` exactly as it found
// it. (Mirrors the same guard already applied to every other Phase-1
// step below, and to the signal-path shutdown in
// registerShutdownHooks().)
(async () => {
if (this.generationStore) {
if (this.generationStore && !this.isReadOnly) {
await this.generationStore.close()
}
})()