fix(substrate): correctness & performance hardening (Tranche A)#16
Merged
CodeWithJuber merged 1 commit intoJul 6, 2026
Merged
Conversation
Bug-fixes from the full code+whitepaper review; behaviour gets more correct, nothing new to opt into. Off-by-default paths unchanged. - SECRET_RE: the bare-word arm (secret|password|api key) silently gutted the LLM proposer and refused to persist lessons for any auth-related task. It now needs a value-shaped assignment; credential formats stay refused. Unblocks a whole class of legitimate work. - Resilience: one malformed lesson file / JSONL line no longer throws out of lessons_store.load / readEpisodes / cortex_hook.readSession (which had taken down retrieval, routing, and the pre-edit advisory). - Honest writes: recordMistake reports "refused" (not "created") when save is rejected; applyDistillation / recordContradiction return the real save result. - Atlas correctness: emit inherits edges (extends / Python bases) — the weight was dead, so base-class changes never showed in blast radius. - Atlas incremental + staleness: build() reuses per-file extraction by content hash; isStale() lets verify rebuild instead of running hallucination detection on a stale graph; capped graph degrades to "uncertain" not "absent". - Perf: resolveEdges O(E) (was O(E·N)); impact() memoizes one reverse-adjacency map across the up-to-8 calls per substrate run. - substrate computes preflight once and threads the gap into routing, removing a duplicate pass and a redundant assumption model call under FORGE_LLM. 204 tests pass (+12), typecheck + Biome clean, zero new runtime deps. Verified on this repo: 5 inherits edges emitted, incremental rebuild 60ms→25ms. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HGZUYFdUb4EViXV5tRid19
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.
What & why
First of four tranches from a full code + whitepaper review. Tranche A — pure correctness &
performance bug-fixes. No new behaviour to opt into; every off-by-default path is unchanged.
Correctness
SECRET_REno longer guts auth work. The bare-word arm (secret/password/api key)matched any prose, so a task or lesson mentioning those words was silently refused —
disabling the LLM proposer (
adjudicate) and blocking memory persistence (recall/lessons)for exactly the high-risk code you most want help on. The word arm now requires a value-shaped
assignment (
password = "…",SECRET_KEY: …); credential formats (sk-…,ghp_…, JWTs)stay refused.
src/recall.js.lessons_store.load/readEpisodesandcortex_hook.readSessionskip a corrupt lesson file / JSONL line instead of throwing (whichhad broken retrieval, routing, and the pre-edit advisory everywhere
loadis called).recordMistakereturnsrefused(notcreated) when a save is rejected,so the Stop hook never distills a phantom lesson;
applyDistillation/recordContradictionsurface the real write result.
inheritsedges (class X extends Y; Pythonclass X(Base)) — the edgeweight was defined but never produced, so base-class changes were invisible to blast-radius.
isStale()letsverifyrebuild when the cached graph is out of date —post-edit hallucination detection was running on a stale atlas. A capped graph now degrades
to "uncertain" rather than raising false "unknown symbol" / "not found in the code".
Performance
resolveEdgesis O(E) (was O(E·N) — a full node scan per edge).impact()memoizes one reverse-adjacency map across the up-to-8 calls persubstraterun.instead of re-parsing the whole repo (verified 60ms → 25ms on this repo).
substratecomputes preflight once and threads the gap into routing — removes a duplicatepass and a redundant assumption model call under
FORGE_LLM=1.Checklist
npm testpasses (Node 18/20/22) — 204 tests (+12)npm run checkpasses (Biome lint + format)isStale, inherits edges, incremental, resilience, refused-save)fix:)CHANGELOG.mdupdated under## [Unreleased]Risk & rollback
(secrets, resilience, staleness). The atlas cache is a gitignored sidecar.
.forge/atlas.cache.jsonisself-healing (ignored on hash mismatch).
Extra checks
npm run typecheckpassesVerification
Full suite + typecheck + Biome green. Manual on this repo:
atlas.buildemits 5 inheritsedges (was 0), incremental rebuild 60ms→25ms,
isStalecorrect;routeTaskwithFORGE_LLM=1now fires exactly one model call (asserted in a test).Next: Tranche B (whitepaper fidelity — M5 footprint, doom-loop breaker, consequence-sim classes).
🤖 Generated with Claude Code
https://claude.ai/code/session_01HGZUYFdUb4EViXV5tRid19
Generated by Claude Code