Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

MemoryHealthCheck CHECK 9 reads the reviewer-runs directory instead of the .jsonl — EISDIR into a silent catch, so all four reviewer-streak findings are dead code

Open spazbg opened this issue 3 months ago • 2 comments

Version: 7.40.4 Platform: macOS (Darwin 25.6), Claude Code Impact: the reviewer-health half of MemoryHealthCheck.ts can never produce a finding; a week of failing curation runs passed with overall: ok

Summary

MemoryHealthCheck.ts defines one constant for two different things:

const REVIEWER_RUNS = join(OBS_DIR, "reviewer-runs");   // line 47

That path is the run-artifact directory (reviewer-runs/<runId>/dispatch.log). CHECK 5 uses it correctly:

readdirSync(REVIEWER_RUNS).filter(r => statSync(join(REVIEWER_RUNS, r)).isDirectory())

CHECK 9 uses the same constant as a file:

// CHECK 9: reviewer failures — recent runs that errored or hit EAT_CAP.
if (existsSync(REVIEWER_RUNS)) {
  try {
    const recent = readFileSync(REVIEWER_RUNS, "utf-8").trim().split("\n").slice(-5)
      …
  } catch { /* non-fatal */ }
}

existsSync passes because the directory exists, readFileSync throws EISDIR, and the exception lands in catch { /* non-fatal */ }. The intended source is reviewer-runs.jsonl, which is the file every other consumer reads — the string reviewer-runs.jsonl does not appear anywhere in MemoryHealthCheck.ts.

What this silences

Four findings, all unreachable:

  • reviewer-all-skips (warn)
  • reviewer-eat-cap (critical — "cap-jam actively losing memory")
  • reviewer-failing (warn)
  • reviewer-healthy (ok)

reviewer-eat-cap being unreachable is the sharp end: it is the check meant to catch the cap-jam dropping a real fact on the floor.

Reproduction

$ bun -e 'const {readFileSync}=require("fs");
  try{ readFileSync("<OBS_DIR>/reviewer-runs","utf-8") }catch(e){ console.log(e.code) }'
EISDIR

Then replay CHECK 9's own filter against the real JSONL:

const rows = readFileSync("<OBS_DIR>/reviewer-runs.jsonl","utf-8").trim().split("\n")
  .map(l => { try { return JSON.parse(l) } catch { return null } }).filter(Boolean);
// sliding window of 5, CHECK 9's predicate:
rows.filter(r => (r.ok === false || r.parse_ok === false) && r.skipped !== true)

On my install (92 runs): the failure count inside a 5-run window peaked at 4, i.e. reviewer-failing (threshold ≥ 3) should have been warning for days. It never fired once. MemoryHealthCheck.ts reported overall: ok throughout, and the only live reviewer signal was CortexHealth's separate last-row read of the JSONL — which itself clears the moment one run happens to have nothing to dispatch.

Why it matters beyond the typo

This is what let #1972 sit undetected. Every typed Cortex write was being refused at the system/user boundary and the reviewer was logging "error": "dispatch failed for N item(s)" on run after run, while the health tool that exists to surface exactly that stayed green. The failure only became visible when a run's last-row status happened to be read by a different check.

Fix

-const REVIEWER_RUNS = join(OBS_DIR, "reviewer-runs");
+const REVIEWER_RUNS_DIR  = join(OBS_DIR, "reviewer-runs");
+const REVIEWER_RUNS_LOG  = join(OBS_DIR, "reviewer-runs.jsonl");

CHECK 5 takes REVIEWER_RUNS_DIR, CHECK 9 takes REVIEWER_RUNS_LOG. Two adjacent suggestions:

  1. The bare catch { /* non-fatal */ } is what turned a wrong path into silence. Emitting a low-severity finding when a check cannot read its own evidence would have surfaced this immediately — a health tool that cannot run a check should say so rather than imply the check passed.
  2. Worth grepping for the same directory-vs-.jsonl conflation elsewhere; the two names differ by a suffix and both exist on disk, so existsSync guards give no protection anywhere this pattern repeats.

Filed separately from #1972 at the maintainer's discretion — happy to fold it back into that thread instead.

spazbg avatar Aug 27 '26 11:08 spazbg

Landed. CHECK 9 reads the .jsonl now, and both health checkers emit a warn finding when they cannot read their own evidence instead of swallowing it. This silence is why #1972 and #2005 sat undetected, so thanks: highest value per line on the whole list.

danielmiessler avatar Sep 03 '26 23:09 danielmiessler

This does not appear to be in main. Reporting from a fresh 7.40.4 install, where CHECK 9 is still dead.

On main right now (5e2f2e8, committed 2026-09-04T01:07:21Z, which is ~1h14m after the "Landed" comment above at 2026-09-03T23:53:20Z), LifeOS/install/LIFEOS/TOOLS/MemoryHealthCheck.ts reads:

 47:  const REVIEWER_RUNS = join(OBS_DIR, "reviewer-runs");
332:      const recent = readFileSync(REVIEWER_RUNS, "utf-8").trim().split("\n").slice(-5)

Fetched with gh api repos/danielmiessler/LifeOS/contents/LifeOS/install/LIFEOS/TOOLS/MemoryHealthCheck.ts, so it is not a stale local checkout.

There is still only one constant, and it is the directory. CHECK 6 at line 240 uses readdirSync on it correctly; CHECK 9 at line 332 passes the same constant to readFileSync.

Reproduced on 7.40.4 (latest release, v7.40.4, 2026-08-14):

$ bun LIFEOS/TOOLS/MemoryReviewer.ts review     # creates both artifacts
$ bun -e 'import{readFileSync}from"fs";readFileSync(".../OBSERVABILITY/reviewer-runs","utf-8")'
Error: EISDIR: illegal operation on a directory, read

$ bun LIFEOS/TOOLS/MemoryHealthCheck.ts
# ok_summary contains no `reviewer-healthy`; no CHECK 9 finding of any severity

The second half of the fix is not there either: I grepped CortexHealth.ts on main and found no warn finding for unreadable evidence.

Every other consumer already names the file correctly, so MemoryHealthCheck.ts is the lone outlier: CortexHealth.ts:116, MemoryStatus.ts:43, MemoryInsights.ts:112, MemoryReviewer.ts:61, PULSE/modules/menubar.ts:264.

Possibly the fix landed on a branch that was never merged, or was lost in a release-staging sync. Either way reviewer-eat-cap — the critical that fires when the reviewer drops a real fact on the 48-entry cap — is still dead code for anyone on 7.40.4.

Worth reopening.

mastromanolis avatar Sep 19 '26 12:09 mastromanolis