Skip to content

[good first issue]🎯 fix(data): checkpoint counters never decrease — drift from actual data after cleanup #157

@MuBeiGe

Description

@MuBeiGe

Summary

total_memories_extracted and l0_conversations_count in recall_checkpoint.json only increment. After any cleanup (deleting test pipeline states, running memory-cleaner, or manual JSONL pruning), the counters permanently overstate reality.

Root Cause

CheckpointManager (bundled in dist/index.mjs L8339, L8375):

cp.total_memories_extracted += memoriesExtracted;  // L8339
cp.l0_conversations_count += 1;                     // L8375

No code path decrements these counters. memory-cleaner deletes records from JSONL and SQLite, but never updates the checkpoint.

Reproduction

  1. Run gateway for a few days, accumulate ~45 L1 records
  2. Clean up test data: remove 8 pipeline_states entries from recall_checkpoint.json and delete corresponding JSONL lines
  3. Observe: total_memories_extracted=50 while actual JSONL has 42 records
  4. Counter will never self-correct

Actual Impact

The drifted counters cause:

  • Incorrect status reporting ("50 memories extracted" when only 42 exist)
  • The counter is used by L2/L3 pipeline logic for persona generation thresholds (cp.total_processed, cp.memories_since_last_persona), which may trigger prematurely or never trigger

Suggested Fix

Add a recalibrate() method to CheckpointManager that recounts from actual data:

async recalibrate(): Promise<void> {
  await this.mutate((cp) => {
    // Count actual JSONL records
    const actualExtracted = /* count lines across all .jsonl files */;
    cp.total_memories_extracted = actualExtracted;
    // Count actual L0 conversations from DB
    cp.l0_conversations_count = /* SELECT COUNT(*) FROM l0_conversations */;
  });
}

Call once on gateway startup. ~20 lines.

Metadata

Metadata

Assignees

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