v2/docs/BUG_REPORT_MEMORY_STATS.md
memory stats Command Returns Zero for ReasoningBank DataThe memory stats command always returns zero entries/namespaces/size, even when ReasoningBank contains data. This is caused by the command exclusively reading from the legacy JSON file (./memory/memory-store.json) instead of querying the active ReasoningBank SQLite database.
npx claude-flow@alpha memory stats# Command returns zeros
$ npx claude-flow@alpha memory stats
✅ Memory Bank Statistics:
Total Entries: 0
Namespaces: 0
Size: 0.00 KB
# But ReasoningBank list shows 10+ entries
$ npx claude-flow@alpha memory list --reasoningbank
✅ ReasoningBank memories (10 shown):
📌 test-key
📌 test-sqlite
📌 api-design
[... 16 more entries]
# Direct SQL query confirms 19 entries exist
$ sqlite3 .swarm/memory.db "SELECT COUNT(*) FROM patterns WHERE type = 'reasoning_memory';"
19
# ReasoningBank status confirms data exists
$ npx claude-flow@alpha memory status --reasoningbank
✅ 📊 ReasoningBank Status:
Total memories: 19
Average confidence: 80.0%
Embeddings: 19
Trajectories: 0
Problem Location: Lines 217-244
async function showMemoryStats(loadMemory) {
try {
const data = await loadMemory(); // ❌ Only reads JSON file
let totalEntries = 0;
const namespaceStats = {};
for (const [namespace, entries] of Object.entries(data)) {
namespaceStats[namespace] = entries.length;
totalEntries += entries.length;
}
printSuccess('Memory Bank Statistics:');
console.log(` Total Entries: ${totalEntries}`);
console.log(` Namespaces: ${Object.keys(data).length}`);
console.log(` Size: ${(new TextEncoder().encode(JSON.stringify(data)).length / 1024).toFixed(2)} KB`);
// ...
}
}
The loadMemory() function (line 26-33):
async function loadMemory() {
try {
const content = await fs.readFile(memoryStore, 'utf8'); // hardcoded JSON path
return JSON.parse(content);
} catch {
return {};
}
}
Where memoryStore = './memory/memory-store.json' (line 14)
showMemoryStats() only reads from ./memory/memory-store.jsonstore, query, list), stats doesn't call detectMemoryMode() (line 23)stats directly to showMemoryStats() without checking if ReasoningBank is activestore, query, and list all support --reasoningbank flag via handleReasoningBankCommand(), but stats doesn't// ✅ These commands properly detect mode and support ReasoningBank
case 'store':
await storeMemory(subArgs, loadMemory, saveMemory, namespace, enableRedaction);
break;
case 'query':
await queryMemory(subArgs, loadMemory, namespace, enableRedaction);
break;
case 'list':
await listNamespaces(loadMemory);
break;
// ❌ This command ignores mode detection
case 'stats':
await showMemoryStats(loadMemory); // Never checks ReasoningBank!
break;
The memory stats command should:
--reasoningbank flag to force ReasoningBank stats# Auto mode (should detect ReasoningBank if initialized)
$ npx claude-flow@alpha memory stats
✅ Memory Bank Statistics:
Storage Backend: ReasoningBank (SQLite)
Total Entries: 19
Namespaces: 3
Size: 9.14 MB
📁 Namespace Breakdown:
default: 12 entries
test-namespace: 5 entries
api: 2 entries
💡 Use 'memory stats --basic' for JSON statistics
# Force ReasoningBank mode
$ npx claude-flow@alpha memory stats --reasoningbank
✅ ReasoningBank Statistics:
Database: .swarm/memory.db
Total Memories: 19
Total Embeddings: 19
Average Confidence: 80.0%
Trajectories: 0
Links: 0
Database Size: 9.14 MB
# Force basic mode
$ npx claude-flow@alpha memory stats --basic
✅ JSON Memory Statistics:
Total Entries: 0
Namespaces: 0
Size: 0.00 KB
⚠️ Consider migrating to ReasoningBank for better performance
Modify src/cli/simple-commands/memory.js:
// Line 65-67: Add mode detection to stats case
case 'stats':
if (mode === 'reasoningbank') {
await handleReasoningBankStats(getStatus);
} else {
await showMemoryStats(loadMemory);
}
break;
// Add new handler function (around line 718)
async function handleReasoningBankStats(getStatus) {
try {
const stats = await getStatus();
printSuccess('ReasoningBank Statistics:');
console.log(` Database: ${stats.database_path || '.swarm/memory.db'}`);
console.log(` Total Memories: ${stats.total_memories}`);
console.log(` Total Categories: ${stats.total_categories}`);
console.log(` Average Confidence: ${(stats.avg_confidence * 100).toFixed(1)}%`);
console.log(` Embeddings: ${stats.total_embeddings}`);
console.log(` Trajectories: ${stats.total_trajectories}`);
console.log(` Links: ${stats.total_links || 0}`);
console.log(` Storage Backend: ${stats.storage_backend}`);
if (stats.database_path) {
const dbSize = await getFileSize(stats.database_path);
console.log(` Database Size: ${(dbSize / 1024 / 1024).toFixed(2)} MB`);
}
} catch (error) {
printError(`Failed to get ReasoningBank stats: ${error.message}`);
}
}
// Helper function
async function getFileSize(path) {
try {
const stats = await fs.stat(path);
return stats.size;
} catch {
return 0;
}
}
Show both JSON and ReasoningBank statistics in one output:
async function showMemoryStats(loadMemory, mode) {
const rbInitialized = await isReasoningBankInitialized();
printSuccess('Memory Bank Statistics:\n');
// Show JSON stats
const jsonData = await loadMemory();
let totalEntries = Object.values(jsonData).reduce((sum, arr) => sum + arr.length, 0);
console.log('📁 JSON Storage (./memory/memory-store.json):');
console.log(` Total Entries: ${totalEntries}`);
console.log(` Namespaces: ${Object.keys(jsonData).length}`);
console.log(` Size: ${(new TextEncoder().encode(JSON.stringify(jsonData)).length / 1024).toFixed(2)} KB`);
// Show ReasoningBank stats if initialized
if (rbInitialized) {
const { getStatus } = await import('../../reasoningbank/reasoningbank-adapter.js');
const rbStats = await getStatus();
console.log('\n🧠 ReasoningBank Storage (.swarm/memory.db):');
console.log(` Total Memories: ${rbStats.total_memories}`);
console.log(` Categories: ${rbStats.total_categories}`);
console.log(` Average Confidence: ${(rbStats.avg_confidence * 100).toFixed(1)}%`);
console.log(` Embeddings: ${rbStats.total_embeddings}`);
console.log('\n💡 Active Mode: ReasoningBank (auto-selected)');
} else {
console.log('\n⚠️ ReasoningBank not initialized (using JSON storage)');
console.log(' Run "memory init --reasoningbank" to enable AI features');
}
}
Test with empty JSON, empty ReasoningBank
rm -rf memory/ .swarm/
npx claude-flow@alpha memory stats
# Expected: Show zeros for both backends
Test with data in ReasoningBank only
npx claude-flow@alpha memory store "test" "value" --reasoningbank
npx claude-flow@alpha memory stats
# Expected: Show ReasoningBank stats with 1 entry
Test with data in JSON only
npx claude-flow@alpha memory store "test" "value" --basic
npx claude-flow@alpha memory stats
# Expected: Show JSON stats with 1 entry
Test with data in both backends
npx claude-flow@alpha memory store "json-key" "json-value" --basic
npx claude-flow@alpha memory store "rb-key" "rb-value" --reasoningbank
npx claude-flow@alpha memory stats
# Expected: Show stats for both backends
Test with flags
npx claude-flow@alpha memory stats --reasoningbank
npx claude-flow@alpha memory stats --basic
npx claude-flow@alpha memory stats --auto
# Expected: Respect mode flags
memory stats are seeing incorrect informationUsers can check ReasoningBank data using:
memory status --reasoningbank - Shows basic statsmemory list --reasoningbank - Lists all entriessqlite3 .swarm/memory.db "SELECT COUNT(*) FROM patterns;"store, query, list commandsstatus --reasoningbank command works and shows accurate statisticsstats command (without flags)stats caseshowMemoryStats() to support ReasoningBankhandleReasoningBankStats() function (around line 718)✅ No breaking changes - existing JSON-based stats will continue to work
✅ New flag --reasoningbank is optional
✅ Auto mode will fall back to JSON if ReasoningBank not initialized
Priority: High - This is a user-facing bug that makes a primary feature (statistics) non-functional for ReasoningBank users.
Suggested for: v2.7.31 hotfix
.swarm/memory.dbnpx claude-flow@alpha memory init --reasoningbanknpx claude-flow@alpha memory store test-key "test value" --reasoningbanknpx claude-flow@alpha memory list --reasoningbank (shows data)npx claude-flow@alpha memory stats (shows zeros ❌)/workspaces/claude-code-flow/src/cli/simple-commands/memory.js (main bug location)/workspaces/claude-code-flow/src/reasoningbank/reasoningbank-adapter.js (working getStatus() function).swarm/memory.db (SQLite database with 19 entries)./memory/memory-store.json (empty JSON file)