Skip to content

fix(api): report the cache that requests actually use in /api/cache/stats - #10769

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.50from
maxmad64bis:fix/cache-stats-real-cache
Aug 20, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.50from
maxmad64bis:fix/cache-stats-real-cache

Conversation

@maxmad64bis

Copy link
Copy Markdown
Contributor

⚠️ base-red inherited: #9985

Summary

/api/cache/stats calls getPromptCache(), an in-memory LRU with no caller anywhere else in the
codebase. The cache actually wired into the request path is semanticCache.ts (semantic_cache
table) — with 31 entries on a live instance, the endpoint still answered 0 hit / 0 miss, size 0,
and both /dashboard/health and /dashboard/usage rendered that as fact.

The route now reports the semantic cache's in-memory entries, using the same LRUCache.getStats()
shape, so no dashboard code changes. DELETE clears the in-memory entries only — wiring it to the
full clearCache() would also delete persisted rows, a separate decision from a stats-reporting
fix.

Same fix @Poid-ZA already wrote and had accepted in principle in #9446 ("the change itself is
wanted!") before it was closed for an unrelated reason: that branch carried +12,055/-1,259 across
dozens of unrelated files from a stale base and conflicted broadly. This rebuilds just the
targeted change — two files — on a fresh branch.

Related Issues

Validation

  • Change type: routing / caching (API)
  • Focused tests: node --test tests/unit/cache-stats-reports-semantic-cache.test.ts (3/3),
    npm run test:vitest (368/368)
  • npm run lint
  • Reconciled with release/v3.8.50
  • Production-code changes include a new automated test in this PR

Tests Added Or Updated

  • tests/unit/cache-stats-reports-semantic-cache.test.ts (new)

Coverage Notes

Touches src/app/api/cache/stats/route.ts and src/lib/semanticCache.ts. The new test covers the
GET stats shape and the DELETE memory-clear path directly.

Reviewer Notes

DELETE is memory-only by design — see Summary.

…tats

/api/cache/stats read getPromptCache() — an LRU no request path writes to. It
answered 0 hit / 0 miss with size 0 no matter how much traffic the semantic
cache served, and the Health and Usage dashboards rendered that as fact.

It now reports the semantic cache's in-memory entries. Same LRUCache shape, so
the response keys and their types are unchanged and no dashboard code moves.
DELETE clears the in-memory entries only: wiring it to clearCache() would turn a
stats fix into a delete of persisted rows, which is a separate decision.

Co-authored-by: Poid-ZA <Poid-ZA@users.noreply.github.com>
@diegosouzapw
diegosouzapw merged commit 7d2efdf into diegosouzapw:release/v3.8.50 Aug 20, 2026
5 checks passed
@maxmad64bis
maxmad64bis deleted the fix/cache-stats-real-cache branch September 24, 2026 21:12
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…tats (diegosouzapw#10769)

Merged via merge-train (release/v3.8.50, batch1 2026-08-20) — static gates (typecheck/file-size/complexity/cognitive/changelog) green on the combined tree; test:unit reds observed in the boarded run were verified pre-existing on the pure release tip (unrelated flake), not caused by this PR. Thanks for the contribution!
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.

2 participants