mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 06:06:02 +09:00
* fix(#2677): doctor memory — add integrity + content + embedding-coverage checks Closes half of #2677 (@stuinfla's proposed checks 1–3; check 4 recall probe deferred to a follow-up since it needs end-to-end write+search+delete). ## Problem Before: `ruflo doctor --component memory` was existsSync + statSync — literally CANNOT fail on any file that exists. Reported PASS on a 99.97%-empty and even a SQLite-malformed DB (both from stuinfla's 81-store fleet report). "A check that cannot fail protects nothing." ## Fix — 3 new checks stacked on the existing existence probe Ordered so the earliest chain-break is always the first red the user sees: 1. **Memory Integrity** — opens via sql.js, runs `PRAGMA integrity_check`. Two failure modes handled distinctly: - Open fails / query refused: WARN (encrypted DB or corrupt — doctor can't distinguish from outside) - Open succeeds but pragma != 'ok': FAIL (definite corruption) 2. **Memory Content** — counts rows in `memory_entries` where `content` is non-empty. FAIL if ratio < 95%. Message includes the actual ratio ("content 3/11133 (0.03%)") per stuinfla's "Print the measurement, not a checkmark" rule. 3. **Memory Embedding Coverage** — counts rows with a vector on populated-content rows. FAIL if ratio < 95%. Schema-shape discovery handles the two known variants (inline `embedding`/`vector` column, or a paired `embeddings`/`vector_indexes` table). ## Design rules honored (from #2677) - **A check that cannot fail protects nothing** — every check has a demonstrable red state, verified live against this repo's DB (which happens to be broken enough to WARN on all three). - **UNKNOWN is never PASS** — encrypted / unreadable / schema-mismatch cases return warn or fail, never a reassuring pass. Encrypted-DB case gets an operator-actionable "DB refused query: … (encrypted DB or corruption)" message that names what the user needs to know. - **Print the measurement** — ratios in-line ("content 3/11133 (0.03%)"), not just checkmarks. - **Exit non-zero on failing dimension** — inherits from the existing doctor exit-code aggregation. ## componentMap now supports arrays `--component memory` runs the whole memory-health suite instead of a single check. Type of map values widened to `(() => Promise<HealthCheck>) | Array<() => Promise<HealthCheck>>`; `checksToRun` uses `Array.isArray()` at expansion time. No behavior change for the other 24 components — all still single functions. ## Verified live on this repo Before: `✓ Memory Database: 0.00 MB — 1 passed. All checks passed! System is healthy.` After: `✓ Memory Database` + 3 × ⚠ (integrity refused / content unknowable / embedding unknowable) with the diagnostic message on each. ## Deferred to follow-up - Check 4 (recall probe): needs actual write+search+delete round-trip through the CLI's memory pipeline. Slower + higher-blast-radius than read-only SQL. Its own PR. - Checks 5–8 (distillation, reflexion, skills, continuity) + the underlying distill→reflexion write-path fix stuinfla identified. Bigger change; his own PR proposal per issue thread. Closes half of #2677. Full closure requires stuinfla's second PR. Co-Authored-By: RuFlo <ruv@ruv.net> * ci(env-audit): allowlist RUFLO_AI_BUDGET_{DIR,DISABLE} + RUFLO_METAHARNESS_SKIP_LOCAL These env vars ship in main from PR #2663 (repo-supervisor + AI-cost fuse) and the metaharness invoke shim, but were never added to KNOWN_ESCAPE_HATCHES — so the env-var-precedence audit fails on every PR that touches related files. Drive-by fix while adding the doctor memory checks in PR #2681. Each entry follows the existing allowlist convention: rationale comment naming the file + why it's intentionally env-only (background service / plugin script — no CLI-flag surface to attach to). (Local audit surfaces ~12 more missing entries but the CI flagged only these 3 for this PR — the rest are pre-existing debt on main and warrant their own cleanup pass.) Co-Authored-By: RuFlo <ruv@ruv.net> * ci(env-audit): also allowlist RUFLO_HELPERS_LOCKED (v3.30.0 .LOCKED escape hatch) The env-audit's fail-level 'x' now surfaces our own new escape hatch from PR #2676 (.LOCKED marker + env opt-out for the concurrent-session helper clobber fix). Adding to KNOWN_ESCAPE_HATCHES with rationale. Follows the same pattern as the other 'runs from a hook, no CLI surface' entries above — helper-refresh is invoked from a session-restore hook, not a user-typed command, so there's no argv position for a --helpers- locked flag to attach to. Co-Authored-By: RuFlo <ruv@ruv.net>