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
|
|
@ -1032,8 +1032,10 @@ export class R2Storage extends BaseStorage {
|
|||
|
||||
prodLog.info('🧹 R2: Clearing all data from bucket...')
|
||||
|
||||
// Clear all prefixes
|
||||
for (const prefix of [this.nounPrefix, this.verbPrefix, this.metadataPrefix, this.verbMetadataPrefix, this.systemPrefix]) {
|
||||
// Clear all prefixes (v5.6.1: includes _cow/ for version control data)
|
||||
// _cow/ stores all git-like versioning data (commits, trees, blobs, refs)
|
||||
// Must be deleted to fully clear all data including version history
|
||||
for (const prefix of [this.nounPrefix, this.verbPrefix, this.metadataPrefix, this.verbMetadataPrefix, this.systemPrefix, '_cow/']) {
|
||||
const objects = await this.listObjectsUnderPath(prefix)
|
||||
|
||||
for (const key of objects) {
|
||||
|
|
@ -1041,6 +1043,14 @@ export class R2Storage extends BaseStorage {
|
|||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
this.nounCacheManager.clear()
|
||||
this.verbCacheManager.clear()
|
||||
|
||||
|
|
|
|||
Reference in a new issue