Skip to content

feat(#44): store self-metrics — row bytes, rows/day, capture lag p50/p95, dead weight - #99

Merged
abogartz merged 3 commits into
mainfrom
feat/status-self-metrics
Oct 25, 2026
Merged

abogartz merged 3 commits into
mainfrom
feat/status-self-metrics

Conversation

@abogartz

Copy link
Copy Markdown
Owner

Closes #44

Part of #84. Depends on: the stack merges in order — #96 → #97 → #98 → this PR → #45. Base is feat/hits-log because the dead-weight number this PR renders is produced by #42's ledger.

What this does

Makes the store able to describe itself. memory_status and the /memory panel now carry, next to the row counts that were already there:

STORE
  41 active · 12 superseded · 4 open · 6 scopes
  retrieved 33 rows in the last 30d; never retrieved 8 (20%) — reported, not acted on
  24.1 KB total · 604 B per row · 1.3 rows/day (30d) · capture lag p50 42 s / p95 6 min
number how it is computed why it is computed that way
bytes total / per row rendered row bytes summed over active rows the number that matters is what retrieval has to carry, not what stat() says about a file
rows/day (30d) rows inside the window ÷ distinct days that saw activity dividing by 30 always made an idle store report a gentle trend; two writes on one day is 2/day, not 0.07
capture lag p50 / p95 new capture_lag evidence line: newest transcript message → the instant the capture model was asked an idle session produces an hour-old capture. Before this, nothing distinguished a fresh capture from a stale one
dead weight active rows the #42 ledger has never credited, as count + share stated, not deleted (see below)

Nothing here acts. Retirement, decay and consolidation stay explicit decisions; a metric that quietly deleted rows would be the worst possible thing in this PR.

The lag semantics

lagSince() takes the newest timestamp it can find in a session context (time.updated, createdAt, created, timestamp; numbers or ISO strings). A capture with no parseable message time records no lag at all rather than lag=0: inventing zero would pull p50 toward "instant" and hide exactly the staleness the ticket asks about. The percentile is nearest-rank over the trailing 30 days, and lines outside the window are ignored.

Tests

  • test/metrics.test.ts — percentile is nearest-rank and returns no answer for empty input; rowsPerDay counts active days (3 rows over 2 days = 1.5), ignores rows outside the window, and says "no evidence" rather than 0 for an idle store; captureLag filters by window and by event; lagSince tolerates missing/garbage timestamps — "yesterday" must not become 0 ms.
  • test/metrics-tool.test.ts — the shipped memory_status tool renders all four numbers together against a real store: bytes and per-row average present, rows/day (30d) present, capture lag p50 4.2 s / p95 4.2 s from one evidence row, never retrieved 2 (100%) before anything has been recalled.
  • Full suite on this branch: 430 pass / 5 skip / 0 fail; tsc clean; Biome clean at error level.

Review focus

  1. Window edges. rowsPerDay and captureLag both use ISO string comparison against a 30-day cutoff, and rowsPerDay groups by ts.slice(0, 10) (UTC day). Correct for us, but a store with clock-skewed rows across the boundary is doing string math — worth a look.
  2. never retrieved is a claim about the ledger's lifetime, not the store's. A row created before the ledger started, or before the last rotation, can look dead when it is merely old. The report shows the number without that qualifier (the since bound exists in readLedger()); if you want the qualifier surfaced, say so and I'll add it rather than soften the number.
  3. Rendering cost. memory_status now sums rendered bytes over active rows and reads up to 30 evidence files per call. Fine at current store sizes; it is an O(store) read on a tool call.
  4. Nothing is pruned from these numbers. Dead weight is reported with an explicit "not acted on". If the review wants a follow-up ticket that turns the number into a proposal (a list, not a deletion), that belongs in P3: Consolidation promotion pass (dry-run via memory_merge_review) — gated on #42 usage data #45's consolidation PR, not here.

…d weight

A store that cannot describe itself cannot be maintained. memory_status and the
/memory panel now answer four questions nobody could answer before:

- what a row costs: total store bytes and per-row average, measured over the
  rendered row (the number that matters is what retrieval has to carry).
- how fast it grows: rows/day over the trailing 30d, per ACTIVE day, so a store
  idle for three weeks does not report "0.1 rows/day" as if it were a trend.
- how stale a capture is: capture_lag evidence (lag from the newest transcript
  message to the moment the capture model was asked) rendered as p50/p95.
  A capture with no observed message time contributes no lag rather than an
  invented 0 ms — that would make every session look instant.
- how much of the store never gets used (the #42 ledger's dead-weight number,
  carried into the same STORE section as the count and share).

Everything here is reported, never acted on. Retirement, decay and consolidation
remain explicit decisions.

Test: test/metrics.test.ts (percentile nearest-rank; rowsPerDay active-day math
and window edges; capture_lag window filter; lagSince timestamp tolerance —
"yesterday" must not become 0 ms), test/metrics-tool.test.ts (the shipped
memory_status tool renders bytes, rows/day, lag and dead weight together).
ticket: #44
@abogartz
abogartz force-pushed the feat/status-self-metrics branch from 0c5786e to 6d1858b Compare October 25, 2026 20:00
@abogartz
abogartz changed the base branch from feat/hits-log to main October 25, 2026 20:08
@abogartz
abogartz merged commit 7d1bdcc into main Oct 25, 2026
3 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P3: memory_status self-metrics — write-to-readable lag, bytes/memory, growth, dead weight

1 participant