Skip to content

fix(stats): distinguish configured scopes from observed DB scopes#468

Open
Garyko0730 wants to merge 1 commit intoCortexReach:masterfrom
Garyko0730:fix/scope-stats-observed-vs-configured
Open

fix(stats): distinguish configured scopes from observed DB scopes#468
Garyko0730 wants to merge 1 commit intoCortexReach:masterfrom
Garyko0730:fix/scope-stats-observed-vs-configured

Conversation

@Garyko0730
Copy link
Copy Markdown

Summary

This PR fixes a confusing scope stats mismatch in memory-pro stats / memory stats tool output.

Previously, the plugin mixed two different scope views:

  • configured scopes from ScopeManager.getStats()
  • observed scopes in DB from store.stats().scopeCounts

This could produce misleading output such as:

  • memory.scopeCounts.agent:main = 225
  • but scopes.totalScopes = 1

which looks like a broken memory system even when the database is healthy.

What changed

1. Separate configured vs observed scope stats

  • added summarizeScopesByType(scopes: string[]) in src/scopes.ts
  • kept ScopeManager.getStats() focused on configured scopes
  • derived observed scope stats from Object.keys(stats.scopeCounts)

2. Improve CLI stats output

Updated memory-pro stats to show:

  • configured scopes
  • observed scopes in DB
  • observed scopes by type
  • configured scopes by type
  • memories by scope
  • memories by category

3. Improve tool/API stats output

Updated memory stats tool output/details to expose both:

  • configured
  • observed

while preserving top-level compatibility fields.

4. Add regression coverage

Added:

  • test/scope-stats-regression.test.mjs

Updated:

  • test/cli-smoke.mjs

Why this matters

Users can now distinguish:

  • what scopes are declared in config
  • what scopes are actually present in LanceDB

This makes debugging much easier after migrations, imports, or historical scope writes.

Validation

Ran locally:

  • node --test test/scope-stats-regression.test.mjs
  • node test/cli-smoke.mjs

Both passed.

Notes

This PR intentionally does not include local memory data cleanup.
Only reusable plugin code + regression tests are included.

Copy link
Copy Markdown
Collaborator

@AliceLJY AliceLJY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configured-vs-observed scope split is the right fix here. I re-ran node --test test/scope-stats-regression.test.mjs and node test/cli-smoke.mjs on the PR branch; both passed.

@rwmjhb
Copy link
Copy Markdown
Collaborator

rwmjhb commented Apr 3, 2026

LGTM on the code. This PR currently has merge conflicts, so please rebase onto master and resolve them before merge.

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.

3 participants