Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): make sprite run resolution and migration writes crash/fork-safe
[._.]/ Adam Eivy0c96c86af748
diff --git a/scripts/migrations/202-neutral-sprite-run-dirs.js b/scripts/migrations/202-neutral-sprite-run-dirs.jsindex d37a4ad93d..d2e477698f 100644--- a/scripts/migrations/202-neutral-sprite-run-dirs.js+++ b/scripts/migrations/202-neutral-sprite-run-dirs.js@@ -60,7 +60,16 @@ const NEUTRAL_DIR = 'runs';const exists = (abs) => stat(abs).then(() => true, () => false);const sha256File = async (abs) => createHash('sha256').update(await readFile(abs)).digest('hex');const readJson = async (abs) => { try { return JSON.parse(await readFile(abs, 'utf8')); } catch { return null; } };-const writeJson = (abs, obj) => writeFile(abs, `${JSON.stringify(obj, null, 2)}\n`);+// Atomic write (temp + rename) so a crash mid-migration can never leave a torn,+// unparseable state file (selection / walk-set / pointer) behind — the prior+// file stays intact and the idempotent gate re-triggers cleanly on the retry.+// Inlined rather than importing server/lib/fileUtils so the migration keeps its+// minimal fs+crypto dependency surface.+const writeJson = async (abs, obj) => {+ const tmp = `${abs}.202.tmp`;+ await writeFile(tmp, `${JSON.stringify(obj, null, 2)}\n`);+ await rename(tmp, abs);+};// Rewrite a record-relative path VALUE that starts with `grok/`. Only the// path prefix is matched, so provenance strings that merely CONTAIN "grok"diff --git a/server/services/sprites/walk.js b/server/services/sprites/walk.jsindex 6865dbe652..7a257ee9d7 100644--- a/server/services/sprites/walk.js+++ b/server/services/sprites/walk.js@@ -104,10 +104,16 @@ async function loadRunRecordAt(recordId, runDirRel) {}async function loadRunRecord(recordId, runId) {- // Prefer the neutral runs/ layout; fall back to legacy grok/ so approve /- // rerun / attach still resolve a candidate on an un-migrated install or fork.- return (await loadRunRecordAt(recordId, `runs/${runId}`))- || loadRunRecordAt(recordId, `grok/${runId}`);+ // Runs the write-actions (generate/attach/rerun/approve) touch always live+ // under the neutral runs/ layout: new generations write there, and migration+ // 202 moves every legacy grok/ run there at boot before the first request.+ // So resolve runs/ only — do NOT fall back to grok/ here. A grok/ straggler+ // (un-migrated fork, or a record migration 202 skipped on a collision) is+ // still DISPLAYED via getWalkState's dual-dir scan, but a mutation would need+ // its files where the persisted runPath (runs/) and packageRun's output dir+ // point, so acting on it before migration completes returns RUN_NOT_FOUND+ // rather than silently splitting the run across two directories.+ return loadRunRecordAt(recordId, runRelPath(runId));}async function saveRunRecord(recordId, run) {