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 |
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
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.🤖 Generated with Claude Code
https://claude.ai/code/session_01MSS7QWGFC7BR6zTBswFw7x