-
-
Notifications
You must be signed in to change notification settings - Fork 670
Description
Bug Description
After upgrading to claude-mem v8.5.2, the plugin created 13,000+ orphaned observer session files over 2 days (Dec 31 - Jan 2). Each file contains only the initialization message "Hello memory agent, you are continuing to observe..." with no actual observations.
This is likely a severe side effect of the startup-recovery mechanism reported in #510.
Impact
- Token consumption: Each observer session calls the LLM API even though no actual work is being observed
- Financial cost: Thousands of unnecessary API calls
- Storage waste: 13,000+ .jsonl files created
- UX degradation:
claude -rcommand shows thousands of useless sessions - Database integrity: Database shows normal session counts (~30/day) but filesystem has 13,000+ files
Statistics
File System Analysis (.jsonl session files)
| Date | Files Created |
|---|---|
| Dec 30, 2025 | ~30 (normal) |
| Dec 31, 2025 | 11,555 |
| Jan 1-2, 2026 | 1,770 |
| Total (abnormal) | ~13,325 files |
Database Analysis (sdk_sessions table)
| Date | Sessions in DB | Status |
|---|---|---|
| Dec 30, 2025 | 11 | All completed |
| Dec 31, 2025 | 13 | All completed |
| Jan 1, 2026 | 30 | All completed |
Key Finding: Database shows normal activity (~13-30 sessions/day), but filesystem has 13,000+ files. This indicates observer sessions are being created but not properly tracked in the database.
Session File Content
Each orphaned session file contains only:
{
"type": "queue-operation",
"operation": "dequeue",
"timestamp": "2026-01-01T16:30:42.480Z",
"sessionId": "[session-uuid]"
}
{
"parentUuid": null,
"type": "user",
"message": {
"role": "user",
"content": "Hello memory agent, you are continuing to observe the primary Claude session.\n\n<observed_from_primary_session>..."
},
"sessionId": "[session-uuid]"
}No actual tool executions or observations are recorded.
Environment
- claude-mem version: 8.5.2
- Claude Code version: 2.0.76
- OS: macOS (Darwin 25.2.0)
- Provider: Custom API endpoint (via
ANTHROPIC_BASE_URL) - Worker service: Running on port 37777
- Start date of issue: December 31, 2025
Root Cause Hypothesis
Based on Issue #510, the startup-recovery mechanism in worker-service.ts:748 always uses sdkAgent regardless of CLAUDE_MEM_PROVIDER setting:
session.generatorPromise = this.sdkAgent.startSession(session, this)Hypothesis: When worker restarts:
startSessionProcessor()is called for each pending session- Each call creates a NEW observer session file
- The observer session initializes with "Hello memory agent..." message
- But if there's no actual activity to observe, the session remains empty
- This creates a loop where every recovery attempt spawns more empty observer sessions
Logs Evidence
From claude-mem-2025-12-31.log:
[INFO ] [SYSTEM] Auto-recovered 4 sessions with pending work {totalPending=4, started=4, sessionIds=2833,2910,2916,2924}
Multiple recovery attempts may have created multiple observer sessions for the same pending work.
Steps to Reproduce
- Install claude-mem v8.5.2
- Use Claude Code normally for a few sessions
- Restart the worker service (either manually or due to version mismatch)
- Observe the creation of numerous
.jsonlfiles in~/.claude/projects/-[username]/ - Check database:
sqlite3 ~/.claude-mem/claude-mem.db "SELECT COUNT(*) FROM sdk_sessions WHERE status='active'" - Run
claude -rto see hundreds/thousands of "memory agent" sessions
Expected Behavior
- Startup-recovery should:
- Resume existing sessions, not create new ones
- Respect the
CLAUDE_MEM_PROVIDERsetting - Clean up failed recovery attempts
- Orphaned session files should not be created
- Database and filesystem should be in sync
Actual Behavior
- Startup-recovery creates thousands of observer session files
- Files exist in filesystem but not properly tracked in database
- Each observer session makes an LLM API call with the initialization prompt
- Sessions appear in
claude -rlist, cluttering the UI
Related Issues
- Startup-recovery ignores CLAUDE_MEM_PROVIDER setting, always uses Claude SDK #510: Startup-recovery ignores
CLAUDE_MEM_PROVIDERsetting (likely root cause) - 「Bug」During the execution of tasks using claude code, cmd pop-ups kept appearing and then closed after a while, and port 37777 became inaccessible during the process. #494: cmd pop-ups kept appearing, port 37777 became inaccessible (related symptom)
Temporary Workaround
Disabled auto-observation in ~/.claude-mem/settings.json:
{
"CLAUDE_MEM_CONTEXT_OBSERVATIONS": "0",
"CLAUDE_MEM_CONTEXT_FULL_COUNT": "0",
"CLAUDE_MEM_CONTEXT_SESSION_COUNT": "0",
"CLAUDE_MEM_DISABLED": "true"
}Then killed all worker processes:
pkill -f "claude-mem.*worker-service"
pkill -f "claude-mem.*mcp-server"Cleanup Commands
To remove orphaned session files (backup first!):
# Backup
mkdir -p ~/.claude/backup/$(date +%Y%m%d)
find ~/.claude/projects/-[username] -maxdepth 1 -name "*.jsonl" -newermt "2025-12-31" -exec mv {} ~/.claude/backup/$(date +%Y%m%d)/ \;
# Mark database sessions as completed
sqlite3 ~/.claude-mem/claude-mem.db "UPDATE sdk_sessions SET status='completed', completed_at=datetime('now') WHERE status='active';"Additional Notes
- Issue started after plugin update on Dec 31, 2025
- Previous version (before v8.5.2) did not have this problem
- The problem persists even after stopping/starting the worker
- Token consumption is significant: each observer session makes at least one API call
Severity
HIGH - This bug:
- Wastes API tokens/money
- Degrades user experience significantly
- Creates storage waste
- May affect all users who upgraded to v8.5.2
- Makes the
claude -rcommand unusable
Request
Please investigate the startup-recovery mechanism and fix the orphaned session creation bug. A hotfix would be greatly appreciated given the financial impact.