feat(agent-memory): Phase 9 — observability#257
Open
jamby77 wants to merge 2 commits into
Open
Conversation
eea7699 to
ee647cc
Compare
339567e to
312772a
Compare
14b6e7c to
9412e5a
Compare
312772a to
22b6f78
Compare
9412e5a to
37c7a4b
Compare
22b6f78 to
b160dd0
Compare
37c7a4b to
06b56f6
Compare
b29dd7e to
4ea754e
Compare
7d0fa87 to
90ac526
Compare
4ea754e to
8711302
Compare
90ac526 to
f325dee
Compare
8711302 to
41e8dfe
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 41e8dfe. Configure here.
f325dee to
94e4101
Compare
a97fc05 to
ef0538d
Compare
KIvanow
approved these changes
Jun 19, 2026
94e4101 to
ff2e1f1
Compare
ef0538d to
6bdf7dc
Compare
- Add createMemoryTelemetry: prom-client metrics (items gauge, recall total/hits/empty, recall latency histogram, embedding calls, evictions, consolidations) with a configurable prefix, plus an OTel tracer - Emit spans for remember/recall/consolidate via a traced() helper with OK/ERROR status, recording k/candidate-count/result-count and candidate/created/deleted attributes - Wire metrics through remember/recall/consolidate/forget/forgetByScope/ embed and the capacity-eviction path - Telemetry option (tracerName/metricsPrefix/registry); no-op tracer and default registry when unset, mirroring agent-cache - Add @opentelemetry/api + prom-client deps and the OTel SDK dev dep
…trics enforceCapacity bumped the evictions stat/counter and decremented the items gauge by evictKeys.length without reading the DEL reply, so a stale index (keys already gone) drifted Prometheus. Use the actual removal count, guarded > 0, matching forget/forgetByScope/consolidate.
ff2e1f1 to
0efd8ba
Compare
6bdf7dc to
9f72079
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Stacked on #256 (Phase 8 — self-optimization config reads).
What
Phase 9 of
@betterdb/agent-memory: OpenTelemetry spans + Prometheus metrics, mirroring the agent-cache/semantic-cache telemetry pattern.createMemoryTelemetry({ tracerName?, metricsPrefix?, registry? })builds a prom-client metric set + an OTel tracer. Metrics (prefix configurable, defaultagent_memory):agent_memory_items(gauge)agent_memory_recall_total/agent_memory_recall_hits_total/agent_memory_recall_empty_totalagent_memory_recall_latency_seconds(histogram)agent_memory_embedding_calls_totalagent_memory_evictions_totalagent_memory_consolidations_totalSpans via a
traced()helper (OK/ERROR status, alwaysend()):agent_memory.remember—memory.importance,memory.ttlagent_memory.recall—recall.k,recall.candidate_count,recall.result_countagent_memory.consolidate—consolidate.candidates,consolidate.created,consolidate.deletedMetrics are wired through remember/recall/consolidate/forget/forgetByScope/embed and the capacity-eviction path. All
store_name-labelled.Design / review notes
.call-sequence unit tests are unaffected.itemsgauge is an in-process net delta (documented as approximate). Eviction/forget/consolidate decrement it; remember increments it.Deps
Adds
@opentelemetry/api,prom-client(deps, matching agent-cache) and@opentelemetry/sdk-trace-base(devDep, for the in-memory span exporter used in tests). Lockfile updated.Tests
MemoryStore.telemetry.test.ts(6): embedding+items on remember · recall hit (+latency count) · empty recall · evictions · consolidations · configurable prefix — all read a real promRegistry.MemoryStore.spans.test.ts(3): remember/recall/consolidate spans + attributes, asserted via anInMemorySpanExporter.86/86 package tests green ·
tscclean · prettier clean.Note
Low Risk
Observability is additive and optional; the eviction counting fix only makes metrics/stats more accurate when the search index is stale.
Overview
Adds Phase 9 observability to
@betterdb/agent-memory: optionaltelemetryonMemoryStore(and exportedcreateMemoryTelemetry) following the same pattern as agent-cache—no-op OTel until a provider is registered, prom-client metrics on the default or a passedRegistry.remember,recall, andconsolidaterun inside atraced()helper that emitsagent_memory.*spans with operation-specific attributes and OK/ERROR status. Recall also records totals, hit/empty counters, and a latency histogram; writes/deletes adjust an in-processitemsgauge; embed, eviction, and consolidation paths increment their counters (all labelled bystore_name).Capacity eviction now increments
__mem_statsevictions and Prometheus using theDELreply count, not the number of keys requested—so stale index entries do not inflate stats (new eviction test covers this).Reviewed by Cursor Bugbot for commit 9f72079. Bugbot is set up for automated code reviews on this repo. Configure here.