@soulcraft/brainy 5.7.2 → 5.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/brainy.js +24 -1
- package/dist/import/ImportCoordinator.js +4 -0
- package/dist/storage/baseStorage.js +8 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [5.7.3](https://github.com/soulcraftlabs/brainy/compare/v5.7.2...v5.7.3) (2025-11-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### 🐛 Bug Fixes
|
|
9
|
+
|
|
10
|
+
* resolve REAL v5.7.x race condition - type cache layer (v5.7.3) ([ee17565](https://github.com/soulcraftlabs/brainy/commit/ee1756565ca01666e2aa3b31a80b62c6aa8046e8))
|
|
11
|
+
|
|
5
12
|
### [5.7.2](https://github.com/soulcraftlabs/brainy/compare/v5.7.1...v5.7.2) (2025-11-12)
|
|
6
13
|
|
|
7
14
|
|
package/dist/brainy.js
CHANGED
|
@@ -1613,6 +1613,21 @@ export class Brainy {
|
|
|
1613
1613
|
lastBatchTime = Date.now();
|
|
1614
1614
|
}
|
|
1615
1615
|
}
|
|
1616
|
+
// v5.7.3: Ensure nounTypeCache is populated for all successful entities
|
|
1617
|
+
// This prevents cache misses that trigger expensive 42-type searches
|
|
1618
|
+
// when entities are immediately queried (e.g., during brain.relate())
|
|
1619
|
+
const cacheWarmingNeeded = result.successful.filter(id => !this.storage.nounTypeCache?.has(id));
|
|
1620
|
+
if (cacheWarmingNeeded.length > 0) {
|
|
1621
|
+
// Warm the cache by fetching metadata for entities not in cache
|
|
1622
|
+
await Promise.all(cacheWarmingNeeded.map(async (id) => {
|
|
1623
|
+
try {
|
|
1624
|
+
await this.storage.getNounMetadata(id);
|
|
1625
|
+
}
|
|
1626
|
+
catch (error) {
|
|
1627
|
+
// Ignore errors during cache warming (entity may be invalid)
|
|
1628
|
+
}
|
|
1629
|
+
}));
|
|
1630
|
+
}
|
|
1616
1631
|
result.duration = Date.now() - startTime;
|
|
1617
1632
|
return result;
|
|
1618
1633
|
}
|
|
@@ -3079,7 +3094,15 @@ export class Brainy {
|
|
|
3079
3094
|
// 3. Flush graph adjacency index (relationship cache)
|
|
3080
3095
|
// Note: Graph structure is already persisted via storage.saveVerb() calls
|
|
3081
3096
|
// This just flushes the in-memory cache for performance
|
|
3082
|
-
this.graphIndex.flush()
|
|
3097
|
+
this.graphIndex.flush(),
|
|
3098
|
+
// 4. v5.7.3: Clear write-through cache after flush
|
|
3099
|
+
// Cache persists during batch operations for read-after-write consistency
|
|
3100
|
+
// Cleared here after all writes are guaranteed flushed to disk
|
|
3101
|
+
(async () => {
|
|
3102
|
+
if (this.storage && typeof this.storage.writeCache !== 'undefined') {
|
|
3103
|
+
this.storage.writeCache.clear();
|
|
3104
|
+
}
|
|
3105
|
+
})()
|
|
3083
3106
|
]);
|
|
3084
3107
|
const elapsed = Date.now() - startTime;
|
|
3085
3108
|
console.log(`✅ All indexes flushed to disk in ${elapsed}ms`);
|
|
@@ -643,6 +643,10 @@ export class ImportCoordinator {
|
|
|
643
643
|
if (addResult.failed.length > 0) {
|
|
644
644
|
console.warn(`⚠️ ${addResult.failed.length} entities failed to create`);
|
|
645
645
|
}
|
|
646
|
+
// v5.7.3: Ensure all writes are flushed before creating relationships
|
|
647
|
+
// Fixes "Source entity not found" error in v5.7.0/v5.7.1/v5.7.2
|
|
648
|
+
// Guarantees entities are fully persisted and queryable before brain.relate() is called
|
|
649
|
+
await this.brain.flush();
|
|
646
650
|
// Create provenance links in batch
|
|
647
651
|
if (documentEntityId && options.createProvenanceLinks !== false && entities.length > 0) {
|
|
648
652
|
const provenanceParams = entities.map((entity, idx) => {
|
|
@@ -75,10 +75,11 @@ export class BaseStorage extends BaseStorageAdapter {
|
|
|
75
75
|
this.isInitialized = false;
|
|
76
76
|
this.readOnly = false;
|
|
77
77
|
// v5.7.2: Write-through cache for read-after-write consistency
|
|
78
|
+
// v5.7.3: Extended lifetime - persists until explicit flush() call
|
|
78
79
|
// Guarantees that immediately after writeObjectToBranch(), readWithInheritance() returns the data
|
|
79
80
|
// Cache key: resolved branchPath (includes branch scope for COW isolation)
|
|
80
|
-
// Cache lifetime: write start →
|
|
81
|
-
// Memory footprint:
|
|
81
|
+
// Cache lifetime: write start → flush() call (provides safety net for batch operations)
|
|
82
|
+
// Memory footprint: Bounded by batch size (typically <1000 items during imports)
|
|
82
83
|
this.writeCache = new Map();
|
|
83
84
|
this.currentBranch = 'main';
|
|
84
85
|
this.cowEnabled = false;
|
|
@@ -360,16 +361,13 @@ export class BaseStorage extends BaseStorageAdapter {
|
|
|
360
361
|
async writeObjectToBranch(path, data, branch) {
|
|
361
362
|
const branchPath = this.resolveBranchPath(path, branch);
|
|
362
363
|
// v5.7.2: Add to write cache BEFORE async write (guarantees read-after-write consistency)
|
|
364
|
+
// v5.7.3: Cache persists until flush() is called (extended lifetime for batch operations)
|
|
363
365
|
// This ensures readWithInheritance() returns data immediately, fixing "Source entity not found" bug
|
|
364
366
|
this.writeCache.set(branchPath, data);
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
// v5.7.2: Remove from cache after write completes (success or failure)
|
|
370
|
-
// Small memory footprint: cache only holds in-flight writes (typically <10 items)
|
|
371
|
-
this.writeCache.delete(branchPath);
|
|
372
|
-
}
|
|
367
|
+
// Write to storage (async)
|
|
368
|
+
await this.writeObjectToPath(branchPath, data);
|
|
369
|
+
// v5.7.3: Cache is NOT cleared here anymore - persists until flush()
|
|
370
|
+
// This provides a safety net for immediate queries after batch writes
|
|
373
371
|
}
|
|
374
372
|
/**
|
|
375
373
|
* Read object with inheritance from parent branches (COW layer)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.3",
|
|
4
4
|
"description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. Stage 3 CANONICAL: 42 nouns × 127 verbs covering 96-97% of all human knowledge.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|