fix: clear() wipes the full native/derived footprint, not a subset

clear() removed entities, indexes, system and _cas but left three top-level
trees on disk: _blobs (raw HNSW/LSM segment bytes and the native dkann index),
_id_mapper (the native shared mmap id-mapper), and _column_index (column-store
manifests). A cleared brain therefore re-read stale native state.

Worse, the column store splits its state across two of those trees — manifests
under _column_index/ and their segment bytes under _blobs/_column_index/ — so
removing one without the other stranded a manifest listing segments that no
longer exist, which the hardened segment-load path now (correctly) refuses with
ColumnSegmentLoadError. The three trees now fall together as a set, exactly as
_cas already does. locks/ is deliberately preserved: it is live coordination
state, not data.
This commit is contained in:
David Snelling 2026-07-13 09:18:36 -07:00
parent af5d2f389b
commit d8301f8d08
2 changed files with 92 additions and 0 deletions

View file

@ -1349,6 +1349,24 @@ export class FileSystemStorage extends BaseStorage {
await fs.promises.rm(casDir, { recursive: true, force: true })
}
// Remove the raw-blob + native-shared + column-index footprint. These
// top-level trees were NOT wiped before, so a cleared brain re-read stale
// native blobs (HNSW/LSM segments, the native dkann index), a stale native
// id-mapper, and — worst — orphaned column manifests. `_column_index` holds
// the column-store MANIFEST.json files while their segment bytes live under
// `_blobs/_column_index/...`; removing one without the other would strand a
// manifest listing segments that no longer exist, which the load path now
// (correctly) refuses with ColumnSegmentLoadError. They must fall together,
// as a set, exactly as `_cas` does — the complete derived footprint, not a
// subset. (`locks/` is deliberately left: it is live coordination state,
// not data.)
for (const nativeDir of ['_blobs', '_id_mapper', '_column_index']) {
const dir = path.join(this.rootDir, nativeDir)
if (await this.directoryExists(dir)) {
await fs.promises.rm(dir, { recursive: true, force: true })
}
}
// Reset ALL shared derived state via the same path restore uses: the
// write-through cache, id→type/subtype caches, per-type/subtype count
// rollups, statistics cache, graph-index singleton, and the BlobStorage