89e45ed689
Kills the engram-clobber loop at its source. engram_save did a bare fopen("wb")
that truncates snapshot.json to 0 bytes before the 47MB write — a booting soul's
engram_load could read that empty window -> genesis -> nodes=1 -> a 63-node save
overwrote the populated file. Two guards:
1. Atomic write: serialize to <path>.tmp, fflush+fsync, rename() over target
(atomic on POSIX) — no reader ever sees a truncated/0-byte snapshot.
2. Sparse-write floor: refuse to overwrite a >200KB snapshot with one < 1/16 its
size — a partial load can never clobber a healthy graph, whatever the cause.
Validated in isolation: standalone clang harness 11/11; rebuilt the darwin soul
(scripts/build-soul-darwin.sh) and booted it on an isolated port against a golden
copy — loaded 5113 nodes and round-tripped the full 47MB snapshot, no .tmp leftover,
live ~/.neuron untouched. Adds scripts/build-soul-darwin.sh (local elb replacement).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
22 lines
1.1 KiB
Bash
Executable File
22 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# build-soul-darwin.sh — replicate `elb` on macOS/arm64 with clang.
|
|
# Proven 2026-06-16: produces a Mach-O arm64 soul that boots and serves :7770.
|
|
# The official builder `elb` ships Linux-only (CI); this lets us build + test the
|
|
# darwin soul locally (e.g. to validate the atomic engram_save fix in isolation).
|
|
#
|
|
# Usage: scripts/build-soul-darwin.sh <path-to-neuron/dist> [output-binary]
|
|
set -e
|
|
DIST="${1:?usage: build-soul-darwin.sh <neuron/dist dir> [out]}"
|
|
OUT="${2:-./neuron}"
|
|
RT="$(cd "$(dirname "$0")/.." && pwd)/lang/el-compiler/runtime"
|
|
B="$(mktemp -d)"
|
|
# elc-generated dist modules use C89-style implicit cross-module declarations that
|
|
# Apple clang rejects as errors by default; resolve at link, so downgrade them.
|
|
CFLAGS="-Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion -I$B -I$DIST -I$RT"
|
|
cp "$RT/el_runtime.h" "$B/"
|
|
clang -c $CFLAGS "$RT/el_runtime.c" -o "$B/el_runtime.o"
|
|
for c in "$DIST"/*.c; do clang -c $CFLAGS "$c" -o "$B/$(basename "$c" .c).o"; done
|
|
# NOTE: link *.o once — do not also list el_runtime.o separately (duplicate symbols).
|
|
clang "$B"/*.o -o "$OUT" -lcurl -lm
|
|
echo "built $OUT"
|