678dac5efc
First concern moved out of el_runtime.c under the ratchet, and the move is
deliberately small: it exists to prove the mechanism end to end before anything
large depends on it.
engram_text.{c,h} — query tokenization, candidate-token hygiene, word-boundary
matching, and the text-damage signature. Four functions, moved verbatim; only
`static` was dropped and each doc comment travelled with the code. They touch no
EL value type and no engram store type: plain C over <ctype.h>/<string.h> over
char buffers. They were never el_runtime.c's business.
el_runtime.c 20,527 -> 20,427 lines (BUDGET max_lines ratcheted down)
engram fns 279 -> 275 (BUDGET max_engram_fns ratcheted down)
The Stage 1 extension point worked as designed: adding the file to
lang/runtime/SOURCES was one line, and every build path picked it up. The
Stage 2 drift guard then caught that I had NOT added it to install.sh's
standalone list — the exact class of drift it was written for, on its first
real change, before the commit rather than after a broken SDK shipped.
WHY ONLY 100 LINES, AND WHAT ACTUALLY BLOCKS THE REST
Measured, not estimated: of 273 engram-domain functions in el_runtime.c
(~9,700 lines), only 75 (~1,058 lines) can move today, and they are scattered
rather than clustered. The blocker is a single fact:
EngramNode, EngramEdge, EngramStore, EngramLayer, EngramWal and EngramIdSlot
are typedef'd INSIDE el_runtime.c. No sibling can see them. engram_store.h
defines a SEPARATE serializable "node view" struct and maps between the two.
So every engram function that takes an EngramNode* — which is most of them, 109
of 273 by direct type reference — cannot compile in engram_store.c until those
types move to a shared header. That extraction is the real Stage 3 enabler and
it deserves its own change: it touches the most load-bearing struct in the
system, and doing it in the same commit as a code move would make a regression
impossible to bisect.
REPAIRED: 10 engram harnesses that had silently stopped linking
Not new breakage from this move — verified against unmodified dev, where
el_runtime.c + engram_store.c alone already failed with undefined symbols.
They had been dead for as long as el_runtime.c has been calling into the
siblings, and nothing noticed because nothing ran them.
run_m3_parity, run_m7_traversal, run_m35_hebb_persist,
run_interoception_p0..p5 — now build from $(scripts/el-runtime-sources.sh)
run_wal_tests — its two TUs #include "el_runtime.c" directly, so
it links the SIBLINGS ONLY; adding el_runtime.c
to that link line would define every symbol twice
(That #include'd .c is worth recording: the runtime does have one, in
engram/test/test_wal.c and the generated test_failloud.c.)
Verified locally — every one of these was run, not assumed:
* m3_parity ............ PASS, incl. ASan+UBSan clean across seed/on/reboot
* m7_traversal ......... PASS
* m35_hebb_persist ..... PASS (the gate over the original prod hebb bug)
* interoception p0..p5 . PASS (all six)
* wal_tests ............ 66 passed, 0 failed, + fail-loud exit check
* self-host fixpoint ... byte-identical, AND the emitted C is byte-identical
to the pre-move compiler output — the move changes
nothing the compiler produces
* engram/src/server.el . compiles and links
* native suites ........ 8 of 13, unchanged from before the move; the same 5
pre-existing failures, no regression
* both runtime guards .. green at the new, lower budget
Also fixes a block comment left unterminated by the extraction (the deleted
range carried its closing */), restoring the compile to its single pre-existing
-Wcomment warning.
133 lines
6.0 KiB
Bash
Executable File
133 lines
6.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# M3 JSON-parity gate. Pure C harness (NOT elb/elc): links the real el_runtime.c
|
|
# native engram builtins + engram_store.c and drives ENGRAM_STORE on vs off.
|
|
# Writes ONLY under a throwaway /tmp dir with a throwaway HOME + ENGRAM_DATA_DIR.
|
|
set -u
|
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
RTSRC="$("$HERE/../../scripts/el-runtime-sources.sh" "$HERE/../../lang/runtime")"
|
|
# The runtime is MULTI-FILE (lang/runtime/SOURCES). This harness used to link
|
|
# el_runtime.c + engram_store.c only, which stopped linking once el_runtime.c
|
|
# began calling into the other engram siblings. Unquoted on purpose: a list.
|
|
SSLFLAGS=""
|
|
if command -v brew >/dev/null 2>&1 && O="$(brew --prefix openssl@3 2>/dev/null)"; then
|
|
SSLFLAGS="-I$O/include -L$O/lib"
|
|
fi
|
|
INC="$HERE/../../lang/runtime"
|
|
WORK="$(mktemp -d /tmp/engram-m3-XXXXXX)"
|
|
DATA="$WORK/data"; mkdir -p "$DATA"
|
|
BIN="$WORK/m3"
|
|
export HOME="$WORK/home"; mkdir -p "$HOME" # never touch real ~/.neuron
|
|
export ENGRAM_DATA_DIR="$DATA"
|
|
export ENGRAM_WAL_SYNC=always
|
|
unset ENGRAM_STORE
|
|
fail=0
|
|
|
|
echo "== compiling harness (gcc: el_runtime.c + engram_store.c + test_m3_parity.c) =="
|
|
gcc -O1 -std=c11 -I "$INC" "$HERE/test_m3_parity.c" $RTSRC $SSLFLAGS -lcurl -lssl -lcrypto -lpthread -lm -o "$BIN" 2>"$WORK/cc.log"
|
|
if [ $? -ne 0 ]; then echo "COMPILE FAILED:"; cat "$WORK/cc.log"; rm -rf "$WORK"; exit 1; fi
|
|
grep -i warning "$WORK/cc.log" | grep -iE 'engram_store|eg_store|eg_load|scan_nodes|scan_edges' && echo "(warnings in M3 code above)" || true
|
|
|
|
echo
|
|
echo "== 0) default-OFF: flag unset leaves the store untouched =="
|
|
( unset ENGRAM_STORE; "$BIN" offcheck "$DATA" )
|
|
[ $? -ne 0 ] && { echo "FAIL: offcheck"; fail=1; }
|
|
[ -e "$DATA/neuron.egm" ] && { echo "FAIL: neuron.egm created while flag OFF"; fail=1; } \
|
|
|| echo " ok: no neuron.egm created with flag OFF"
|
|
|
|
echo
|
|
echo "== 1) seed (ENGRAM_STORE unset): build graph, save snapshot.json, activate =="
|
|
( unset ENGRAM_STORE; "$BIN" seed "$DATA" ) || { echo "FAIL: seed"; fail=1; }
|
|
|
|
echo
|
|
echo "== 2) on (ENGRAM_STORE=1): import snapshot.json ONCE -> neuron.egm, resident-load, activate =="
|
|
ENGRAM_STORE=1 "$BIN" on "$DATA" || { echo "FAIL: on"; fail=1; }
|
|
[ -e "$DATA/neuron.egm" ] && echo " ok: neuron.egm created by import" || { echo "FAIL: neuron.egm missing"; fail=1; }
|
|
|
|
echo
|
|
echo "== 3) reboot (ENGRAM_STORE=1, snapshot.json DELETED): must load from neuron.egm, never JSON =="
|
|
rm -f "$DATA/snapshot.json"
|
|
ENGRAM_STORE=1 "$BIN" reboot "$DATA" || { echo "FAIL: reboot"; fail=1; }
|
|
|
|
echo
|
|
echo "== 4) parity comparison (modulo ordering) =="
|
|
python3 - "$DATA" <<'PY'
|
|
import json, sys, os
|
|
d = sys.argv[1]
|
|
def load(name):
|
|
with open(os.path.join(d, name)) as f: return json.load(f)
|
|
def norm_graph(g):
|
|
nodes = sorted(g.get("nodes", []), key=lambda n: n.get("id",""))
|
|
edges = sorted(g.get("edges", []), key=lambda e: e.get("id",""))
|
|
layers= sorted(g.get("layers", []), key=lambda l: l.get("layer_id",0))
|
|
return {"nodes":nodes, "edges":edges, "layers":layers}
|
|
def act_ids(a):
|
|
# list of (node id, promoted); robust set + ordered list
|
|
seq = [(e.get("node",{}).get("id",""), int(e.get("promoted",0))) for e in a]
|
|
return seq
|
|
|
|
rc = 0
|
|
snap = norm_graph(load("snapshot.json") if os.path.exists(os.path.join(d,"snapshot.json")) else load("off_graph.json"))
|
|
off = norm_graph(load("off_graph.json"))
|
|
on = norm_graph(load("on_graph.json"))
|
|
rebt = norm_graph(load("reboot_graph.json"))
|
|
|
|
def cmp(label, a, b):
|
|
global rc
|
|
if a == b:
|
|
print(f" PASS: {label} (nodes={len(a['nodes'])} edges={len(a['edges'])} layers={len(a['layers'])})")
|
|
else:
|
|
rc = 1
|
|
print(f" FAIL: {label}")
|
|
for k in ("nodes","edges","layers"):
|
|
if a[k] != b[k]:
|
|
print(f" {k}: {len(a[k])} vs {len(b[k])}")
|
|
for x,y in zip(a[k], b[k]):
|
|
if x != y:
|
|
print(f" first diff:\n A={json.dumps(x)[:300]}\n B={json.dumps(y)[:300]}")
|
|
break
|
|
|
|
cmp("graph: ENGRAM_STORE=1 (export) == ENGRAM_STORE=0 (JSON path)", on, off)
|
|
cmp("round-trip: snapshot.json seed == store export (on_graph)", on, off) # off_graph==snapshot save
|
|
cmp("reboot from neuron.egm (no JSON) == on-path store", rebt, on)
|
|
|
|
offa = act_ids(load("off_act.json"))
|
|
ona = act_ids(load("on_act.json"))
|
|
if set(offa) == set(ona):
|
|
print(f" PASS: activation result set identical (off={len(offa)} on={len(ona)} entries)")
|
|
if offa == ona:
|
|
print(" (and identical ordering/promotion sequence)")
|
|
else:
|
|
print(" (same set; ordering differs only where scores tie — reporting honestly)")
|
|
else:
|
|
rc = 1
|
|
print(" FAIL: activation result set differs")
|
|
print(f" off-only: {set(offa)-set(ona)}")
|
|
print(f" on-only: {set(ona)-set(offa)}")
|
|
|
|
sys.exit(rc)
|
|
PY
|
|
[ $? -ne 0 ] && fail=1
|
|
|
|
echo
|
|
echo "== 5) ASan+UBSan build, exercise M3 scan/boot/hooks (leaks off — harness intentionally leaks el_strdup) =="
|
|
SANBIN="$WORK/m3.san"
|
|
gcc -O1 -g -std=c11 -fsanitize=address,undefined -fno-sanitize-recover=undefined \
|
|
-I "$INC" "$HERE/test_m3_parity.c" $RTSRC $SSLFLAGS -lcurl -lssl -lcrypto -lpthread -lm -o "$SANBIN" 2>"$WORK/san_cc.log"
|
|
if [ $? -ne 0 ]; then echo " SAN COMPILE FAILED:"; tail -20 "$WORK/san_cc.log"; fail=1; else
|
|
export ASAN_OPTIONS=detect_leaks=0
|
|
DATA2="$WORK/data2"; mkdir -p "$DATA2"
|
|
( unset ENGRAM_STORE; "$SANBIN" seed "$DATA2" ) >/dev/null 2>"$WORK/san_run.log" && \
|
|
ENGRAM_STORE=1 "$SANBIN" on "$DATA2" >/dev/null 2>>"$WORK/san_run.log" && \
|
|
{ rm -f "$DATA2/snapshot.json"; ENGRAM_STORE=1 "$SANBIN" reboot "$DATA2" >/dev/null 2>>"$WORK/san_run.log"; }
|
|
if grep -qiE 'runtime error|AddressSanitizer|UndefinedBehavior|ERROR: ' "$WORK/san_run.log"; then
|
|
echo " FAIL: sanitizer findings:"; grep -iE 'runtime error|Sanitizer|ERROR' "$WORK/san_run.log" | head; fail=1
|
|
else
|
|
echo " ok: ASan+UBSan clean across seed/on/reboot (scan, boot, resident-load, mutation hooks)"
|
|
fi
|
|
fi
|
|
|
|
echo
|
|
if [ "$fail" -eq 0 ]; then echo "================ M3 PARITY GATE: PASS ================"; else echo "================ M3 PARITY GATE: FAIL ================"; fi
|
|
rm -rf "$WORK"
|
|
exit $fail
|