Skip to content

Session memory indexing skips historical sessions on first startup #3558

@Aaryan-Kapoor

Description

@Aaryan-Kapoor

Bug Description

When memorySearch.experimental.sessionMemory is enabled with sources: ["memory", "sessions"], historical sessions in ~/.clawdbot/agents/*/sessions/*.jsonl are not indexed on first startup. Only the active session gets indexed.

Expected: All 42 session files indexed
Actual: Only memory files (5) indexed, sessions (0)

Root Cause

Two issues in src/memory/manager.ts:

Issue 1: Missing sessionsDirty initialization (constructor, line ~144)

// Current:
this.dirty = this.sources.has("memory");
// Missing:
this.sessionsDirty = this.sources.has("sessions");

Without this, sessionsDirty stays false on startup and historical sessions are never marked for indexing.

Issue 2: Incorrect condition order in shouldSyncSessions() (lines ~759-765)

// Current (broken):
const reason = params?.reason;
if (reason === "session-start" || reason === "watch")
    return false;  // ← Short-circuits before needsFullReindex!
if (needsFullReindex)
    return true;

// Fixed:
if (needsFullReindex)
    return true;  // ← Check this FIRST
const reason = params?.reason;
if (reason === "session-start" || reason === "watch")
    return false;

On first startup with empty/missing DB, needsFullReindex=true but the session-start reason returns false before it's evaluated.

Proposed Fix

Change 1: Add to constructor after this.dirty = ...:

this.sessionsDirty = this.sources.has("sessions");

Change 2: In shouldSyncSessions(), move needsFullReindex check before reason check.

Testing

After fix:

SELECT source, COUNT(*) FROM files GROUP BY source;
-- memory|5
-- sessions|42  ✅

Environment

  • Clawdbot: 2026.1.24-3
  • Node: v22.22.0
  • OS: Ubuntu 24.04 LTS

Review

Fix reviewed and approved by:

  • Claude Opus 4.5 (2 independent reviews)
  • Gemini 3 Pro

All confirmed: minimal, correct, no side effects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions