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
fix: re-point stale prompt migrations at the shipped bodies they must upgrade to (#3817)
[._.]/ Adam Eivy44f4dbc9ff24
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 53c9bd8396..af879a3e25 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -94,3 +94,4 @@- **A video LoRA in the wrong key layout is now refused with the reason instead of quietly rendering an un-LoRA'd clip.** Downloaded LoRAs ship in several incompatible safetensors key conventions, and the LTX-2 loader fuses exactly one of them: `lora_A`/`lora_B` rank pairs, optionally under a `diffusion_model.` prefix. A kohya/LyCORIS file (`lora_down`/`lora_up` + `alpha`) or a diffusers/PEFT-prefixed file matches nothing in the transformer — so the render burned its full GPU time and came back looking like the LoRA had never been selected, with no error anywhere to explain it. Confusingly, kohya files are commonly published *with* the ComfyUI `diffusion_model.` prefix, so the prefix alone was never a reliable signal. PortOS now classifies the layout from the safetensors header (`bare` / `comfyui` / `diffusers` / `kohya` / `not_a_lora`) at install time, records it in the LoRA's sidecar, and backfills it on the next listing for LoRAs installed earlier. A render that selects an un-fusable one fails up front with a 400 naming the layout and what to use instead. A file whose header can't be read stays "undetermined" and is still allowed through — unreadable is not the same as unusable.- **A generated Three.js model is now checked for parts modelled inside each other.** Every existing gate reads one part at a time — the schema proves each geometry is well formed, the coverage gate proves the assembly backs the inventory, and the cross-section gate proves the identity parts have real depth — so nothing ever compared two parts to each other, and the whole class of defect where sibling parts occupy the *same* space was invisible: a greeble modelled at the wrong scale and swallowed whole by the hull it was meant to sit on, a limb rooted a full radius inside a torso, an eye socket punched clean through the back of a skull. All of those render perfectly from the hero camera the model generated for itself and only read as broken once you orbit or explode the assembly. A new cross-part penetration gate reconstructs each part's world placement (the same rotation/scale composition the preview applies), derives an analytic solid per geometry type — a torus is measured as a ring rather than a filled disc, a hollow lathe as hollow, an extrude's hole as empty space — and samples one part's interior against another's, flagging a part that is entirely inside an unrelated one as an error and a pair that shares most of the smaller part's volume as a warning. It reports rather than rejects, and it is deliberately quiet where it cannot be sure: parts parented together or declared as attachments are exempt (embedding is what those relationships are *for*), and a shallow seated joint or anything inside a transparent part comes back as an undecided note that a refinement pass is never told to "fix". Findings land on the record, show up in a new panel on the model detail page, and an unsteered refinement now asks for each part to get its own volume alongside the existing coverage and depth feedback.- **A resumed arc verification no longer forgets why its last rewrite was rejected.** When Series Autopilot restored a safe checkpoint after a regressive rewrite, it persisted both the standing blockers and the rejected candidate's new blockers — but a fresh Resume discarded the latter before calling the resolver. That made the new run liable to repeat the same bad trade from the same checkpoint. A resumed arc gate now carries the bounded discarded set into every normal, corrective, and isolated resolve attempt as explicit avoid evidence, while non-arc and non-regression pauses start clean as before. If a discarded latent defect is later found in the checkpoint itself, it is removed from the avoid set while it is the active repair target, so the resolver never receives contradictory "fix this" and "avoid this" instructions.+- **A fresh install's prompt migrations stopped silently skipping the character-foundation upgrades they exist to apply.** Several stage prompts are targeted by more than one hash-driven migration, and each one names the body it expects to end at. When later migrations re-shipped `pipeline-character-foundation.md`, `pipeline-judge-foundation.md`, and `universe-character-expand.md`, the earlier migrations that also target those files were left naming the superseded body as current — so on a fresh install they saw today's shipped prompt, classified it as "customized by the user", and skipped rather than upgraded: exactly the silent no-op the drift assertions exist to catch, and the reason the migration suites were failing on `main`. Migrations 027, 171, 240, 241, 243, 248, and 255 now point at the live bodies and carry every superseded hash in their accepted-old sets, so an install stopped at any intermediate body still upgrades. A new repo-wide guard sweeps every numbered migration against `data.reference` in one pass — including migrations that ship no test of their own — and fails with the full list of stale entries, so the next prompt edit that strands its predecessors names them all at once instead of hiding until CI turns red.diff --git a/scripts/migrations/007-places-int-ext-time-of-day.js b/scripts/migrations/007-places-int-ext-time-of-day.jsindex 27d670ae0d..1df63c534c 100644--- a/scripts/migrations/007-places-int-ext-time-of-day.js+++ b/scripts/migrations/007-places-int-ext-time-of-day.js@@ -22,11 +22,14 @@ const md5 = (str) => {// `buildPromptDriftTables` sweep picks up this file's hashes from a single// source of truth instead of re-mirroring them by hand.export const ACCEPTED_OLD_MD5 = {- 'writers-room-places.md': '7f1f80eb63d67a21161994cde115045e',+ 'writers-room-places.md': [+ '7f1f80eb63d67a21161994cde115045e',+ '24a33628cc94d80fa5ca60831d973daf', // this migration's own body, superseded by 022+ ],};export const NEW_SHIPPED_MD5 = {- 'writers-room-places.md': '24a33628cc94d80fa5ca60831d973daf',+ 'writers-room-places.md': 'a7f68e51dd6b4421d20f5bd9d855d9b4', // post-022 (setting → place rename)};export default {@@ -59,7 +62,7 @@ export default {continue;}- if (existingMd5 !== ACCEPTED_OLD_MD5[filename]) {+ if (!ACCEPTED_OLD_MD5[filename].includes(existingMd5)) {console.warn(`⚠️ places extraction prompt ${filename} has been customized — skipping auto-update.\n` +` To pick up the new intExt / timeOfDay fields, diff:\n` +diff --git a/scripts/migrations/027-text-stage-prompts-entities-summary.js b/scripts/migrations/027-text-stage-prompts-entities-summary.jsindex a723de610c..de8574304f 100644--- a/scripts/migrations/027-text-stage-prompts-entities-summary.js+++ b/scripts/migrations/027-text-stage-prompts-entities-summary.js@@ -65,6 +65,7 @@ export const ACCEPTED_OLD_MD5 = {'universe-character-expand.md': ['ef109eb8e12ddb664c11c790271b5139', // pre-027 shipped'67b6e73ed47f318451a730088b4cff14', // post-027 / pre-171 (character framework)+ '177b6e4e8bdf445308cf8ac423cd5ad8', // post-171 / pre-257 (complete expand fields)],};@@ -72,7 +73,7 @@ export const NEW_SHIPPED_MD5 = {'pipeline-prose.md': '4cb3ef48309f3673570cf80e4d544b54', // post-169 (cross-issue continuity)'pipeline-teleplay.md': '2ea9974ac3803658b2314db1f5818b77', // post-128 (canonical scene list)'pipeline-comic-script.md': '49af30c05f008b20f6998a0f113f7d87', // post-127 (scene markers)- 'universe-character-expand.md': '177b6e4e8bdf445308cf8ac423cd5ad8', // post-171 (character framework)+ 'universe-character-expand.md': '924fe8836f3014873d1789e98e997db2', // post-257 (complete expand fields)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/123-arc-resolve-episode-corrections.js b/scripts/migrations/123-arc-resolve-episode-corrections.jsindex b5b5644234..81386be249 100644--- a/scripts/migrations/123-arc-resolve-episode-corrections.js+++ b/scripts/migrations/123-arc-resolve-episode-corrections.js@@ -23,11 +23,12 @@ export const ACCEPTED_OLD_MD5 = {'pipeline-arc-resolve.md': ['cc27b4da1d1a13c35e35d1c2d6183815', // post-123 / pre-245 — the episodes[] channel, before edits had to name a finding'5b340885c6e8f8afc63424d6b5bc7eb7', // pre-123 (episodes forbidden)+ '96f73a7e90526d65ef2bb100fb1cd4bf', // post-251 (field-sparse bounded patches), superseded by 254],};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-resolve.md': '96f73a7e90526d65ef2bb100fb1cd4bf', // post-251 (field-sparse bounded patches)+ 'pipeline-arc-resolve.md': '31eca76b68f40de1b93734fe9bc9f4bb', // post-254 (character arcs)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/171-character-framework-prompt.js b/scripts/migrations/171-character-framework-prompt.jsindex 4eebc9d58e..6fab6af0fe 100644--- a/scripts/migrations/171-character-framework-prompt.js+++ b/scripts/migrations/171-character-framework-prompt.js@@ -27,12 +27,15 @@ import { makePromptReplaceMigration } from './_lib.js';// Pre-change shipped hash (the current shipped body before #2175 remainder).export const ACCEPTED_OLD_MD5 = {- 'universe-character-expand.md': ['67b6e73ed47f318451a730088b4cff14'], // post-027+ 'universe-character-expand.md': [+ '67b6e73ed47f318451a730088b4cff14', // post-027+ '177b6e4e8bdf445308cf8ac423cd5ad8', // superseded by 257 (complete expand fields)+ ],};// Post-change shipped hash (character framework fields added).export const NEW_SHIPPED_MD5 = {- 'universe-character-expand.md': '177b6e4e8bdf445308cf8ac423cd5ad8',+ 'universe-character-expand.md': '924fe8836f3014873d1789e98e997db2', // post-257 (complete expand fields)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/240-character-foundation-exhaustive-cast.js b/scripts/migrations/240-character-foundation-exhaustive-cast.jsindex d36c954413..0556d5a6bc 100644--- a/scripts/migrations/240-character-foundation-exhaustive-cast.js+++ b/scripts/migrations/240-character-foundation-exhaustive-cast.js@@ -11,11 +11,15 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-character-foundation.md': ['f1c0b75a8161c0bc7f26752d148a5c1c'],+ 'pipeline-character-foundation.md': [+ 'f1c0b75a8161c0bc7f26752d148a5c1c',+ 'd6c449c06de73a0868141c899b26e52c', // superseded by 255 (visual foundation)+ '04419e382f3b46ed92bfaaa1d4f39e13', // superseded by 256 (series-linked cast)+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-character-foundation.md': 'd6c449c06de73a0868141c899b26e52c',+ 'pipeline-character-foundation.md': 'b7d2bac347e11171606f4c6acfcd32e1', // post-256 (series-linked cast)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/241-foundation-judge-repair-ownership.js b/scripts/migrations/241-foundation-judge-repair-ownership.jsindex 00b46d76e4..3f626b9c27 100644--- a/scripts/migrations/241-foundation-judge-repair-ownership.js+++ b/scripts/migrations/241-foundation-judge-repair-ownership.js@@ -12,11 +12,15 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-judge-foundation.md': ['74c0244e641dcf7a73e9c83123ebdee9'],+ 'pipeline-judge-foundation.md': [+ '74c0244e641dcf7a73e9c83123ebdee9',+ 'edf7850d0c724c63761bc9fb667227d9', // superseded by 255 (visual foundation)+ '02a8e9215ba534b333f3a29f11f3ac4f', // superseded by 256 (series-linked cast)+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-judge-foundation.md': 'edf7850d0c724c63761bc9fb667227d9', // post-248 protected author intent+ 'pipeline-judge-foundation.md': 'e44b6c50d741bbd21fc86f481684c410', // post-256 (series-linked cast)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/243-post-arc-character-transition-ownership.js b/scripts/migrations/243-post-arc-character-transition-ownership.jsindex b870416280..b04bc2ce84 100644--- a/scripts/migrations/243-post-arc-character-transition-ownership.js+++ b/scripts/migrations/243-post-arc-character-transition-ownership.js@@ -10,11 +10,15 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-character-foundation.md': ['cda34127b40754ddbcc8544e3d82572b'],+ 'pipeline-character-foundation.md': [+ 'cda34127b40754ddbcc8544e3d82572b',+ 'd6c449c06de73a0868141c899b26e52c', // superseded by 255 (visual foundation)+ '04419e382f3b46ed92bfaaa1d4f39e13', // superseded by 256 (series-linked cast)+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-character-foundation.md': 'd6c449c06de73a0868141c899b26e52c',+ 'pipeline-character-foundation.md': 'b7d2bac347e11171606f4c6acfcd32e1', // post-256 (series-linked cast)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/248-foundation-judge-author-intent.js b/scripts/migrations/248-foundation-judge-author-intent.jsindex be57bb4cab..bc91eb999b 100644--- a/scripts/migrations/248-foundation-judge-author-intent.js+++ b/scripts/migrations/248-foundation-judge-author-intent.js@@ -12,11 +12,15 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-judge-foundation.md': ['4c0bd349ff4d329048c9f4ac068745d4'],+ 'pipeline-judge-foundation.md': [+ '4c0bd349ff4d329048c9f4ac068745d4',+ 'edf7850d0c724c63761bc9fb667227d9', // superseded by 255 (visual foundation)+ '02a8e9215ba534b333f3a29f11f3ac4f', // superseded by 256 (series-linked cast)+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-judge-foundation.md': 'edf7850d0c724c63761bc9fb667227d9',+ 'pipeline-judge-foundation.md': 'e44b6c50d741bbd21fc86f481684c410', // post-256 (series-linked cast)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/255-character-visual-foundation.js b/scripts/migrations/255-character-visual-foundation.jsindex 110e72cebf..8db265969a 100644--- a/scripts/migrations/255-character-visual-foundation.js+++ b/scripts/migrations/255-character-visual-foundation.js@@ -13,13 +13,19 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-character-foundation.md': ['d6c449c06de73a0868141c899b26e52c'],- 'pipeline-judge-foundation.md': ['edf7850d0c724c63761bc9fb667227d9'],+ 'pipeline-character-foundation.md': [+ 'd6c449c06de73a0868141c899b26e52c',+ '04419e382f3b46ed92bfaaa1d4f39e13', // this migration's own body, superseded by 256+ ],+ 'pipeline-judge-foundation.md': [+ 'edf7850d0c724c63761bc9fb667227d9',+ '02a8e9215ba534b333f3a29f11f3ac4f', // this migration's own body, superseded by 256+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-character-foundation.md': '04419e382f3b46ed92bfaaa1d4f39e13',- 'pipeline-judge-foundation.md': '02a8e9215ba534b333f3a29f11f3ac4f',+ 'pipeline-character-foundation.md': 'b7d2bac347e11171606f4c6acfcd32e1', // post-256 (series-linked cast)+ 'pipeline-judge-foundation.md': 'e44b6c50d741bbd21fc86f481684c410', // post-256 (series-linked cast)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/255-character-visual-foundation.test.js b/scripts/migrations/255-character-visual-foundation.test.jsindex 577fa07f08..75ebeb1e24 100644--- a/scripts/migrations/255-character-visual-foundation.test.js+++ b/scripts/migrations/255-character-visual-foundation.test.js@@ -28,7 +28,10 @@ describe('migration 255 — character visual foundation', () => {);expect(architect).toContain('physicalDescription` must be 50–100 words');expect(architect).toContain('"colorPalette"');- expect(judge).toContain('blank render identity');+ // Migration 256 widened the phrase from "blank render identity" to+ // "blank profile/render identity" — the render-identity requirement this+ // migration shipped survived, so assert the surviving substring.+ expect(judge).toContain('render identity is still an incomplete character foundation');expect(judge).toContain('cannot score above 5');});});diff --git a/scripts/migrations/_shippedHashDrift.test.js b/scripts/migrations/_shippedHashDrift.test.jsnew file mode 100644index 0000000000..604b1c9dfc--- /dev/null+++ b/scripts/migrations/_shippedHashDrift.test.js@@ -0,0 +1,83 @@+/**+ * Repo-wide drift guard for hash-driven prompt-replace migrations.+ *+ * `_testHelpers.js` already asserts "NEW_SHIPPED_MD5 matches the live+ * data.reference body" — but only for migrations that ship their own+ * `*.test.js` and opt into `runPromptMigrationTests`. That leaves the failure+ * mode this file exists to close: a prompt edit re-points the NEWEST migration+ * that targets a file, and every EARLIER migration targeting the same file+ * keeps naming the superseded body as current. Those stale migrations then+ * classify today's shipped body as "customized" and silently skip the upgrade+ * on a fresh install (issue #3817 — migrations 007, 027, 123, 171, 240, 241,+ * 243, 248 and 255 had all drifted this way behind edits shipped by 022, 254,+ * 255, 256 and 257; the last two were found by this sweep, not by the issue).+ *+ * One sweep over every numbered migration catches it in a single place,+ * including migrations that carry no test file of their own.+ */+import { describe, it, expect } from 'vitest';+import { readdir, readFile } from 'fs/promises';+import { dirname, join } from 'path';+import { fileURLToPath, pathToFileURL } from 'url';++import { tryReadFile } from '../../server/lib/fileUtils.js';+import { md5 } from './_lib.js';++const migrationsDir = dirname(fileURLToPath(import.meta.url));+const referenceDir = join(migrationsDir, '..', '..', 'data.reference', 'prompts');++/**+ * Prompts that no longer ship in `data.reference` and so have no live body to+ * drift against. Their migrations stay for installs that still hold the old+ * file. Named explicitly rather than inferred from "the file is missing" —+ * otherwise a typo'd filename, or a `_partials` fragment whose migration forgot+ * to export `DRIFT_SUBDIRS`, would read as "retired" and silently pass.+ */+const RETIRED_PROMPTS = new Set([+ 'pipeline-tv-script.md', // renamed to pipeline-teleplay.md+]);++/** Every numbered migration that exports a NEW_SHIPPED_MD5 table. */+const loadShippedTables = async () => {+ const files = (await readdir(migrationsDir))+ .filter((f) => /^\d.*\.js$/.test(f) && !f.endsWith('.test.js'))+ .sort();+ const tables = [];+ for (const file of files) {+ const source = await readFile(join(migrationsDir, file), 'utf-8');+ if (!source.includes('NEW_SHIPPED_MD5')) continue;+ const mod = await import(pathToFileURL(join(migrationsDir, file)).href);+ if (!mod.NEW_SHIPPED_MD5) continue;+ tables.push({ file, current: mod.NEW_SHIPPED_MD5, subdirs: mod.DRIFT_SUBDIRS || {} });+ }+ return tables;+};++describe('shipped prompt-hash drift (all migrations)', () => {+ it('every migration NEW_SHIPPED_MD5 matches the live data.reference body', async () => {+ const tables = await loadShippedTables();+ expect(tables.length).toBeGreaterThan(0);++ const drifted = [];+ for (const { file, current, subdirs } of tables) {+ for (const [name, hash] of Object.entries(current)) {+ const subdir = subdirs[name] || 'stages';+ const body = await tryReadFile(join(referenceDir, subdir, name));+ if (body === null) {+ if (RETIRED_PROMPTS.has(name)) continue;+ drifted.push(+ `${file} → ${name}: no live body at data.reference/prompts/${subdir}/ ` ++ '(wrong DRIFT_SUBDIRS, a typo, or a retirement that belongs in RETIRED_PROMPTS)',+ );+ continue;+ }+ const live = md5(body);+ if (live !== hash) drifted.push(`${file} → ${name}: has ${hash}, live is ${live}`);+ }+ }++ // Reported as a list so one run names EVERY stale migration — the whole+ // point is that a prompt edit typically strands several at once.+ expect(drifted).toEqual([]);+ });+});