v2/docs/FIX_VERIFICATION_MEMORY_STATS.md
GitHub Issue #865: memory stats command returns zero for ReasoningBank data
Successfully fixed the memory stats command to properly detect and display ReasoningBank SQLite data alongside JSON storage statistics.
File: src/cli/simple-commands/memory.js
Modified showMemoryStats() function (lines 221-315):
mode parameter to detect active storage backendUpdated stats case in switch statement (lines 66-70):
showMemoryStats(loadMemory)mode parameter: showMemoryStats(loadMemory, mode)Added comment in mode delegation (line 52):
stats command is handled in switch statement for unified outputhandleReasoningBankCommandCommand: memory stats (default, no flags)
Output:
✅ Memory Bank Statistics:
📁 JSON Storage (./memory/memory-store.json):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
Namespace Breakdown:
default: 1 entries
🧠 ReasoningBank Storage (.swarm/memory.db):
Total Memories: 19
Categories: 2
Average Confidence: 80.0%
Embeddings: 19
Trajectories: 0
Database Size: 9.58 MB
💡 Active Mode: ReasoningBank (auto-selected)
Use --basic flag to force JSON-only statistics
Result: ✅ PASS - Shows both storage backends with complete statistics
Command: memory stats --basic
Output:
✅ Memory Bank Statistics (JSON Mode):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
📁 Namespace Breakdown:
default: 1 entries
💡 Tip: Initialize ReasoningBank for AI-powered memory
Run: memory init --reasoningbank
Result: ✅ PASS - Shows only JSON storage with helpful tip
Command: memory stats --reasoningbank
Output:
✅ Memory Bank Statistics:
📁 JSON Storage (./memory/memory-store.json):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
Namespace Breakdown:
default: 1 entries
🧠 ReasoningBank Storage (.swarm/memory.db):
Total Memories: 19
Categories: 2
Average Confidence: 80.0%
Embeddings: 19
Trajectories: 0
Database Size: 9.58 MB
💡 Active Mode: ReasoningBank (auto-selected)
Use --basic flag to force JSON-only statistics
Result: ✅ PASS - Shows unified statistics (same as auto mode)
Direct SQL Query:
$ sqlite3 .swarm/memory.db "SELECT COUNT(*) FROM patterns WHERE type = 'reasoning_memory';"
19
ReasoningBank List:
$ memory list --reasoningbank
✅ ReasoningBank memories (10 shown):
📌 test-key
📌 test-sqlite
📌 api-design
[... 16 more entries]
Result: ✅ PASS - Statistics match actual database content
$ memory stats
✅ Memory Bank Statistics:
Total Entries: 0 # ❌ Wrong - ReasoningBank has 19 entries
Namespaces: 0 # ❌ Wrong - ReasoningBank has 2 categories
Size: 0.00 KB # ❌ Wrong - Database is 9.58 MB
$ memory stats
✅ Memory Bank Statistics:
📁 JSON Storage (./memory/memory-store.json):
Total Entries: 1
Namespaces: 1
Size: 0.11 KB
🧠 ReasoningBank Storage (.swarm/memory.db):
Total Memories: 19 # ✅ Correct
Categories: 2 # ✅ Correct
Database Size: 9.58 MB # ✅ Correct
async function showMemoryStats(loadMemory, mode) {
const rbInitialized = await isReasoningBankInitialized();
// Auto mode: show unified stats if ReasoningBank exists
if (mode === 'reasoningbank' || (rbInitialized && mode !== 'basic')) {
// Show both JSON and ReasoningBank statistics
// ... unified output ...
} else {
// Basic mode: JSON only
// ... JSON-only output ...
}
}
.swarm/memory.db exists--basic and --reasoningbank flagsfs.stat() to get accurate database size✅ No Breaking Changes
memory stats behavior preserved for JSON-only mode--basic, --reasoningbank, --auto) work correctlygetStatus() function from ReasoningBank adapterAll memory commands now properly support both backends:
| Command | JSON Mode | ReasoningBank Mode | Unified Output |
|---|---|---|---|
store | ✅ | ✅ | N/A |
query | ✅ | ✅ | N/A |
list | ✅ | ✅ | N/A |
stats | ✅ | ✅ | ✅ (NEW) |
status | N/A | ✅ | N/A |
Potential improvements for future versions:
The fix successfully resolves the bug where memory stats returned zeros for ReasoningBank data. The command now provides comprehensive statistics for both storage backends with intelligent mode detection and helpful user guidance.
Status: ✅ VERIFIED AND WORKING
Files Modified:
src/cli/simple-commands/memory.js (3 changes, ~100 lines added)Tests Passed: 4/4 ✅
Build Status: ✅ Successful (warnings are expected from pkg binary compilation)
Ready for: v2.7.32 release