fix: metadata-only update() never rewrites the noun record — the unconditional whole-vector save turned per-entity stat touches into full rewrites+fsync, amplifying read-heavy sweeps into disk saturation on a production deployment
All checks were successful
CI / Node 22 (push) Successful in 2m53s
CI / Node 24 (push) Successful in 2m46s
CI / Bun (latest) (push) Successful in 3m0s

Also: idle PathResolver stats tick no longer logs NaN% every minute (logs
only on new traffic, via prodLog); graph-lsm-* key family recognized as
system resources (kills the per-boot unknown-key warning on provider-backed
brains). Four regression pins in tests/integration/update-write-granularity.
This commit is contained in:
David Snelling 2026-07-29 10:42:50 -07:00
parent 64049631bc
commit cb717be275
4 changed files with 155 additions and 15 deletions

View file

@ -3161,18 +3161,23 @@ export class Brainy<T = any> implements BrainyInterface<T> {
new UpdateNounMetadataOperation(this.storage, params.id, updatedMetadata)
)
// Operation 2: Update vector data (will use updated type cache)
tx.addOperation(
new SaveNounOperation(this.storage, {
id: params.id,
vector,
connections: new Map(),
level: 0
})
)
// Operation 3-4: Update HNSW index (remove and re-add if reindexing needed)
// Operations 2-4: vector-record write + HNSW reindex — ONLY when the
// vector side actually changed (new data/vector/type). A metadata-only
// update must never rewrite the noun record: the record carries the
// full vector, so an unconditional save turned every metadata touch
// into a whole-vector rewrite + fsync — under a read-heavy consumer
// sweep that bumps per-entity stats, this amplified into disk
// saturation on a production deployment (SELF-ENGINE-RESTART-GRIND,
// 2026-07-29: 5.8GB written in 40min from ~50 recalls/min).
if (needsReindexing) {
tx.addOperation(
new SaveNounOperation(this.storage, {
id: params.id,
vector,
connections: new Map(),
level: 0
})
)
tx.addOperation(
new RemoveFromVectorIndexOperation(this.index, params.id, existing.vector)
)