feat(8.0): eager graphIndex.init() before the isReady() rebuild gate

A native graph provider cold-loads its source->target adjacency lazily, so
isReady() would report false at the rebuild gate on a cold open and force a
spurious rebuild (failing the §7.1 rebuild()==0 acceptance). Add an OPTIONAL
GraphIndexProvider.init() (mirrors MetadataIndexProvider.init) and call it during
init, AFTER metadataIndex.init() (id-mapper hydrated first, so a native int
adjacency resolves endpoints through it) and BEFORE rebuildIndexesIfNeeded. The JS
graph index omits init() and self-loads on demand, so the JS path is unchanged.
This commit is contained in:
David Snelling 2026-06-30 09:55:19 -07:00
parent fc7f110479
commit 8f4787bb10
2 changed files with 25 additions and 0 deletions

View file

@ -912,6 +912,19 @@ export class Brainy<T = any> implements BrainyInterface<T> {
this.graphIndex = graphIndex
}
// Eager graph cold-load (cor contract). The native graph provider lazily
// defers loading its source→target adjacency, so isReady() would report
// false at the rebuild gate below and force a spurious rebuild (failing the
// §7.1 rebuild()==0 acceptance). Trigger the eager cold-load now — AFTER
// metadataIndex.init() above (the id-mapper is hydrated, so a native int
// adjacency resolves endpoints through it: the CTX-BR-RESTORE-REBUILD order)
// and BEFORE rebuildIndexesIfNeeded. Optional: the JS graph has no init()
// and self-loads its adjacency on demand.
const graphWithInit = this.graphIndex as { init?: () => Promise<void> }
if (typeof graphWithInit.init === 'function') {
await graphWithInit.init()
}
// 8.0 u64 contract: thread the shared UUID ↔ int resolver into the JS
// graph index and the storage layer's verb read paths.
this.wireGraphIdResolver()

View file

@ -264,6 +264,18 @@ export interface GraphIndexProvider {
*/
isReady?(): boolean
/**
* @description OPTIONAL eager cold-load. Called once during brain init AFTER
* the metadata provider's `init()` (so the id-mapper is hydrated; a native int
* adjacency resolves endpoints through it the id-mapper-before-adjacency
* order) and BEFORE the rebuild gate so a native provider loads its
* sourcetarget adjacency from storage and reports `isReady() === true` at the
* gate, with no spurious rebuild (the §7.1 `rebuild()==0` acceptance). Mirrors
* {@link MetadataIndexProvider.init}. The JS graph index omits it and
* self-loads its adjacency on demand.
*/
init?(): Promise<void>
/**
* @description Entity ints reachable from `id` (1 hop), deduped.
* @param id - The entity's interned int (from the shared idMapper).