fix: resolve clear() not deleting COW data and counters
Fixes critical bug where brain.clear() did not fully clear storage:
Root causes:
1. _cow/ directory contents deleted but directory not removed
2. In-memory counters (totalNounCount, totalVerbCount) not reset
3. COW could auto-reinitialize on next operation
Fixes applied:
- FileSystemStorage: Delete entire _cow/ directory with fs.rm()
- OPFSStorage: Delete _cow/ with removeEntry({recursive: true})
- S3CompatibleStorage: Reset counters after clear
- BaseStorage: Guard initializeCOW() against reinit when cowEnabled=false
- All adapters: Reset totalNounCount and totalVerbCount to 0
Impact: Resolves Workshop bug report - storage now properly clears from
103MB to 0 bytes, entity counts correctly return to 0.
GCSStorage, R2Storage, AzureBlobStorage already had correct implementations.
This commit is contained in:
parent
ef7bf1b04c
commit
e6cc12b64e
8 changed files with 141 additions and 4 deletions
|
|
@ -481,9 +481,35 @@ export class OPFSStorage extends BaseStorage {
|
|||
// Remove all files in the index directory
|
||||
await removeDirectoryContents(this.indexDir!)
|
||||
|
||||
// v5.6.1: Remove COW (copy-on-write) version control data
|
||||
// This directory stores all git-like versioning data (commits, trees, blobs, refs)
|
||||
// Must be deleted to fully clear all data including version history
|
||||
try {
|
||||
// Delete the entire _cow/ directory (not just contents)
|
||||
await this.rootDir!.removeEntry('_cow', { recursive: true })
|
||||
|
||||
// CRITICAL: Reset COW state to prevent automatic reinitialization
|
||||
// When COW data is cleared, we must also clear the COW managers
|
||||
// Otherwise initializeCOW() will auto-recreate initial commit on next operation
|
||||
this.refManager = undefined
|
||||
this.blobStorage = undefined
|
||||
this.commitLog = undefined
|
||||
this.cowEnabled = false
|
||||
} catch (error: any) {
|
||||
// Ignore if _cow directory doesn't exist (not all instances use COW)
|
||||
if (error.name !== 'NotFoundError') {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the statistics cache
|
||||
this.statisticsCache = null
|
||||
this.statisticsModified = false
|
||||
|
||||
// v5.6.1: Reset entity counters (inherited from BaseStorageAdapter)
|
||||
// These in-memory counters must be reset to 0 after clearing all data
|
||||
;(this as any).totalNounCount = 0
|
||||
;(this as any).totalVerbCount = 0
|
||||
} catch (error) {
|
||||
console.error('Error clearing storage:', error)
|
||||
throw error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue