diff --git a/src/brainy.ts b/src/brainy.ts index 25a7669a..ad05e702 100644 --- a/src/brainy.ts +++ b/src/brainy.ts @@ -912,6 +912,19 @@ export class Brainy implements BrainyInterface { 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 } + 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() diff --git a/src/plugin.ts b/src/plugin.ts index 6ba52b74..2f66a2bb 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -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 + * source→target 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 + /** * @description Entity ints reachable from `id` (1 hop), deduped. * @param id - The entity's interned int (from the shared idMapper).