Skip to content

fix(cli): status uses /memories?count=true instead of /export#667

Open
Taeyoung96 wants to merge 1 commit into
rohitg00:mainfrom
Taeyoung96:fix/status-count-endpoint
Open

fix(cli): status uses /memories?count=true instead of /export#667
Taeyoung96 wants to merge 1 commit into
rohitg00:mainfrom
Taeyoung96:fix/status-count-endpoint

Conversation

@Taeyoung96
Copy link
Copy Markdown

@Taeyoung96 Taeyoung96 commented May 27, 2026

Summary

`agentmemory status` calls `/export` to derive the observation and memory
counts shown in the status footer. `/export` is unbounded — it serialises
every observation and memory in one iii invocation that hits the 30 s
engine timeout on any installation that has grown past the demo stage.
Result: the footer always shows `0 obs / 0 memories` for real users while
`memory_diagnose` returns all-green and the server is fully healthy.

`#648` added `/memories?count=true` exactly to fix this class of problem for
the viewer (`#544`). `runStatus()` was never updated to use it.

Fix

  • Replace the `/export` fetch in `runStatus()` with `/memories?count=true`.
  • Sum `observationCount` from the already-fetched `/sessions` response
    instead of the export payload — no extra round-trip needed.
  • Extract `countMemories()` and `countSessionObservations()` into
    `src/cli/status-metrics.ts`: two pure functions that normalise the
    count-endpoint response and the sessions array, guarding against
    non-finite / negative / NaN values so the display is always a
    well-defined non-negative integer.

Diff

  • `src/cli/status-metrics.ts` — new, +35 (pure helpers)
  • `src/cli.ts` — +18 / −4 (`runStatus` wired to new endpoint + helpers)
  • `test/status-metrics.test.ts` — new, +60 (8 unit tests covering
    normal path, missing fields, NaN, negative, non-array input)

Validation

  • `npm test -- --exclude="**/status-metrics*"` → 1172/1172 pass (108 files), no regressions against current main
  • `npm test` → all pass including new status-metrics suite
  • `npm run build` → bundle clean
  • Smoke: `agentmemory status` on a live server with >500 observations
    previously showed `0 obs`; now returns correct totals in <200 ms

Relation to prior work

Follow-up to #648 (#544). That PR added the count endpoint and updated
the viewer; this PR closes the same gap in the CLI status command.

Summary by CodeRabbit

  • Refactor

    • Improved accuracy of observation and memory metrics in the status command.
  • Tests

    • Added comprehensive test coverage for metrics calculation functions.

Review Change Stack

Signed-off-by: Taeyoung96 <tyoung96@naver.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

@Taeyoung96 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6bbc97e3-0ea6-42ad-9819-4a762f5aa406

📥 Commits

Reviewing files that changed from the base of the PR and between 6939d4a and af727a6.

📒 Files selected for processing (3)
  • src/cli.ts
  • src/cli/status-metrics.ts
  • test/status-metrics.test.ts

📝 Walkthrough

Walkthrough

The PR introduces two reusable metrics helper functions for validating and aggregating observation and memory counts from API responses, then integrates them into the CLI status command to replace direct array-length calculations and switches the API endpoint from /export to /memories?count=true.

Changes

Metrics Helpers and CLI Status Integration

Layer / File(s) Summary
Metrics counting helpers with validation
src/cli/status-metrics.ts, test/status-metrics.test.ts
countSessionObservations sums valid observationCount values across sessions with fallback to 0, flooring each count and skipping invalid entries. countMemories prefers a total field when valid, falls back to memories array length, and returns 0 for missing/invalid inputs. Comprehensive test coverage validates edge cases including NaN, negative values, and type mismatches.
CLI status integration and API endpoint update
src/cli.ts
The CLI status command imports the new helper functions, adjusts the REST fetch list to request /memories?count=true instead of /export, and refactors metrics computation to use countSessionObservations(sessionItems) and countMemories(memoriesRes) instead of direct array-length calculations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • #666: Directly implements the recommendation to stop relying on the /agentmemory/export call for CLI status counts by switching to the /memories?count=true endpoint and deriving observation counts from session data using the new helper functions.

Poem

🐰 Counting observations, tallying with care,
New helpers validate each metric so fair,
The CLI now fetches a count-aware endpoint,
Where observations sum from each session spent,
Robust and tested—no edge cases bare! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing the /export endpoint with /memories?count=true in the status command, which directly addresses the performance issue outlined in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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