Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Iamadig
Copy link
Contributor

@Iamadig Iamadig commented Jan 30, 2026

Problem

The memory index dirty flag was showing a false positive after a clean sync. When running clawdbot memory status, it would always report Dirty: yes even after a successful clawdbot memory sync, causing confusion about whether the index actually needed reindexing.

Root Cause

Each clawdbot memory command creates a fresh MemoryIndexManager instance. The issue occurred because:

  1. Constructor unconditionally set this.dirty = this.sources.has("memory") (line 248)
  2. sync() would set this.dirty = false after successful indexing
  3. close() removes the manager from cache
  4. Next command creates a new instance -> dirty resets to true again

The actual indexing logic was working correctly (using file hashes to skip unchanged files), but the dirty flag was purely a UX issue showing incorrect state.

Solution

Persist the dirty flag to the database metadata so it survives across manager instances:

  1. Extended MemoryIndexMeta type to include optional dirty?: boolean field
  2. Modified constructor to restore dirty state from metadata: this.dirty = meta?.dirty ?? this.sources.has("memory")
  3. Added persistDirtyState() helper that updates the dirty flag in metadata
  4. Persist after sync completes (when setting dirty = false)
  5. Persist when watcher detects changes (when setting dirty = true)

Testing

Added comprehensive test suite in manager-dirty-flag.test.ts that verifies:

  • After sync, dirty is set to false and persisted
  • New manager instances restore the dirty state from metadata
  • The flag doesn't incorrectly reset to true on each new instance

Impact

  • User-facing: Status now accurately reflects whether the index needs reindexing
  • Backward compatible: Existing indexes without the dirty field default to true (safe fallback)
  • No data changes: Only affects the status reporting, not the actual indexing logic

The dirty flag was unconditionally set to true in the constructor whenever
the 'memory' source was present, even after a successful sync. This caused
status to always show 'Dirty: yes' on subsequent commands, even though the
index was fully synced.

Root cause:
- Each clawdbot memory command creates a fresh MemoryIndexManager instance
- Constructor set dirty = sources.has('memory') unconditionally (line 248)
- sync() would set dirty = false after indexing
- close() removes manager from cache
- Next command creates new instance → dirty resets to true

Solution:
- Added 'dirty' field to MemoryIndexMeta type
- Constructor now restores dirty state from metadata if available
- persistDirtyState() helper persists dirty flag to metadata
- Called after sync completes and when watcher marks files dirty

This ensures the dirty flag accurately reflects the index state across
manager instances, eliminating the false positive UX issue.

Fixes the issue where status incorrectly reports 'Dirty: yes' after
a clean sync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant