Skip to content

Memory daemon never auto-starts: ensure_memory_daemon() is dead code #156

@udhaya10

Description

@udhaya10

Bug

The memory daemon (memory_daemon.py) is never auto-started on session start. The ensure_memory_daemon() function exists in the Python version of the session start hook but the TypeScript/MJS version (which is actually registered and runs) has no memory daemon logic.

Result

  • archival_memory table stays empty — no learnings are ever auto-extracted from ended sessions
  • Users have no visibility into this unless they manually check ~/.claude/memory-daemon.pid

Root Cause

Two parallel implementations of the session start hook diverged:

File Has ensure_memory_daemon()? Registered in settings.json?
session_start_continuity.py (Python) Yes (line 197, called at line 659) No — never referenced anywhere
session-start-continuity.mjs (TypeScript) No — 0 references to "memory" or "daemon" Yesnode $HOME/.claude/hooks/dist/session-start-continuity.mjs

This has been the case since the initial release (f8d7173). The Python file has always had the function, the MJS file has never had it, and settings.json has always pointed to the MJS file.

Verification

# MJS has zero memory/daemon references:
grep -c -i "memory\|daemon" .claude/hooks/dist/session-start-continuity.mjs
# → 0

# TS source also has zero:
grep -c -i "memory\|daemon" .claude/hooks/src/session-start-continuity.ts
# → 0

# Only MJS is registered:
grep "session.start.continuity" .claude/settings.json
# → "command": "node $HOME/.claude/hooks/dist/session-start-continuity.mjs"

# Python file is never referenced:
grep -rn "session_start_continuity.py" .claude/settings.json .claude/hooks/
# → (empty)

# But Python has the logic:
grep -n "ensure_memory_daemon" .claude/hooks/session_start_continuity.py
# → 197:def ensure_memory_daemon() -> str | None:
# → 659:    memory_status = ensure_memory_daemon()

Secondary Issues (in ensure_memory_daemon() itself)

Even once wired up, the function has observability gaps:

  1. stderr=subprocess.DEVNULL (line 245) — daemon startup errors are swallowed
  2. Returns "Started" even if daemon crashes immediately (line 248) — fire-and-forget Popen
  3. Script-not-found is silent (line 250) — return None with no log or warning
  4. No PEP 723 metadata in memory_daemon.pyfrom dotenv import load_dotenv may fail under uv run

Suggested Fix

Port ensure_memory_daemon() to the TypeScript version (session-start-continuity.ts):

function ensureMemoryDaemon(): string | null {
  const pidFile = path.join(os.homedir(), '.claude', 'memory-daemon.pid');
  // Check if already running via PID file + kill -0
  // If not, spawn: uv run <daemon_script> start
  // Return status string for additionalContext
}

Alternatives:

  • Register the Python file as a second SessionStart hook
  • Consolidate both hooks into one language

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions