MemoryRetriever: write the memory-retrievals.jsonl audit stream CortexHealth already checks - #2094
MemoryRetriever: write the memory-retrievals.jsonl audit stream CortexHealth already checks#2094dth0m wants to merge 1 commit into
Conversation
…xHealth already checks
The per-turn retrieval audit stream was designed in ISC-107..112 and
documented in MemorySystem.md and ObservabilitySystem.md as "written by
MemoryRetriever", with the note "not yet populated as of 2026-05-23;
infrastructure ready". The writer never landed. Release 7.40.4 then added
CortexHealth.ts, which WARNs when the latest row is missing or older than
24h, so every install has shown a permanent amber memory-health line
regardless of how well retrieval works. No test referenced the stream,
so nothing could catch a check shipping without its producer.
This adds the writer to getRelevantContext(): every uncached exit funnels
through one finish() closure that appends a row shaped exactly as
CortexHealth.validRetrievalRow requires — {ts, query_hash, returned_count,
duration_ms} plus optional top_score. Empty-result paths are recorded too
(an empty retrieval is still evidence the retriever ran); cache hits are
not (they do no ranking work). The query is stored as a 16-hex sha256
prefix, never raw, since it is the principal's prompt. Writes are
best-effort and swallowed: the retriever is on every turn's critical path
and must not fail because a log did.
Adds `bun MemoryRetriever.ts test`, following the self-test convention
MemoryReviewer and seven other TOOLS already use: runs the real hot-path
entry point in a child process against a throwaway corpus, then validates
the produced rows with the real collectCortexEvidence/assessCortexEvidence.
12 assertions, PASS.
Doc line in ObservabilitySystem.md updated from "not yet populated" to
the landed behavior.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MSS7QWGFC7BR6zTBswFw7x
|
Reproduced on a fresh 7.40.4 install (macOS, Claude Code in the Claude desktop app) before finding this PR: Applied this diff to that install: 🤖 Generated with Claude Code |
|
Thanks @pai-scaffolde, that's a second machine and a second OS confirming it, which is more than I could do from here. Good call on the cache note; I've added a "Validating by hand" line to the PR body so nobody trips on a repeated prompt writing no row. |
Closes #2093
Summary
CortexHealth.ts(added in 7.40.4) WARNs whenMEMORY/OBSERVABILITY/memory-retrievals.jsonlis missing or older than 24h, but nothing has ever written that file.ObservabilitySystem.md:55still says "not yet populated as of 2026-05-23; infrastructure ready". Every install therefore shows a permanent amber memory-health line regardless of how well retrieval works.This adds the writer to
getRelevantContext()and a hermetictestsubcommand so the check and its producer can't drift apart again.Changes
LIFEOS/TOOLS/MemoryRetriever.tsrecordRetrieval()appends one row per uncached BM25 run, shaped exactly asCortexHealth.validRetrievalRowrequires:{ts, query_hash, returned_count, duration_ms}plus optionaltop_score.getRelevantContext()funnel through a singlefinish()closure, so empty-result paths are recorded too (an empty retrieval is still evidence the retriever ran). Cache hits are not recorded; they do no ranking work.bun MemoryRetriever.ts test: follows the self-test conventionMemoryReviewerand seven other TOOLS use. Spawns the real hot path against a throwaway corpus, validates the rows with the realcollectCortexEvidence/assessCortexEvidence. 12 assertions.LIFEOS/DOCUMENTATION/Observability/ObservabilitySystem.md: line 55 updated from "not yet populated" to the landed behavior.Verification
Validating by hand: a repeated prompt is served from
relevantCache(60s TTL) and writes no row by design, so probe with a fresh query each time. Cache hits do no ranking work and are deliberately not recorded.On a live 7.40.4 install,
MemoryHealthCheck.tswent fromwarn {critical:0, warn:1, ok:25}took {critical:0, warn:0, ok:26}. Existing CLI behavior (--help, positional query, corpus-missing error) is unchanged.Independent verification: thanks to @pai-scaffolde for reproducing the warning on a fresh 7.40.4 macOS install, applying this diff, and confirming both the 12/12 self-test and the cleared
retrieval-missingfinding on a second machine. The hand-validation note above is theirs.🤖 Generated with Claude Code
https://claude.ai/code/session_01MSS7QWGFC7BR6zTBswFw7x