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: keep the loader/executor boundary the extraction had collapsed (#3451)
[._.]/ Adam Eivya82f9d4aa8af
diff --git a/server/services/bootstrap.js b/server/services/bootstrap.jsindex 35fa959403..d372a2876c 100644--- a/server/services/bootstrap.js+++ b/server/services/bootstrap.js@@ -535,8 +535,10 @@ const runDatabaseBootPhase = () => runDatabasePhase({ensureSchema,// Versioned DB-migration runner (#1029): ordered schema-DELTA migrations// (renames / type changes / data transforms / embedding-dim changes) that- // ensureSchema()'s additive IF NOT EXISTS gates can't express.- runDbMigrations: async () => (await import('../scripts/run-db-migrations.js')).runDbMigrations(),+ // ensureSchema()'s additive IF NOT EXISTS gates can't express. Loading the+ // runner is a separate step from running it because only the latter is+ // fatal — a module that won't load falls to the group's log-and-continue.+ loadDbMigrationRunner: async () => (await import('../scripts/run-db-migrations.js')).runDbMigrations,migrateBibleToCatalog: async () => (await import('../scripts/migrateBibleToCatalog.js')).migrateBibleToCatalog(),// One-time data repair: rewrite legacy machine universe tags// (`from-universe`, `universe:<id>`) on backfilled rows into the friendly@@ -689,8 +691,10 @@ export const runBootSequence = ({ io, httpServer, localHttpServer, httpsEnabled,// covers rendered before the feature shipped. Runs after the series + issues// stores are warmed above so the derivation reads migrated records. Drives// the services, so it works on both the PG backend and the file escape hatch.- // Marker-gated, so it runs at most once regardless.- backfillSeriesCoverImages: async () => (await import('../scripts/backfillSeriesCoverImages.js')).backfillSeriesCoverImages(),+ // Marker-gated, so it runs at most once regardless. Loading it is a+ // separate step from running it: the sequence awaits the load (a script+ // that won't load is a real breakage) but never the backfill itself.+ loadSeriesCoverBackfill: async () => (await import('../scripts/backfillSeriesCoverImages.js')).backfillSeriesCoverImages,startListening: () => httpServer.listen(port, host, () => runPostListenSequence({announceListening: () => announceListening({ io, httpServer, localHttpServer, httpsEnabled, port }),diff --git a/server/services/bootstrapSequence.js b/server/services/bootstrapSequence.jsindex 54017ce387..56dd3eaa57 100644--- a/server/services/bootstrapSequence.js+++ b/server/services/bootstrapSequence.js@@ -161,12 +161,17 @@ export const gateOnDatabase = async ({* `reconcileCanonCatalog` last so it reconciles rows already at the current* payload-shape version.*+ * `loadDbMigrationRunner` is a separate step from running it on purpose: only a+ * migration that RAN and failed is fatal. A runner module that can't even be+ * loaded falls to the group's log-and-continue handler, exactly as it did when+ * the `await import(...)` sat outside the inner try.+ ** Skipped entirely when `!dbReady` (escape hatch) — every step below would throw.*/export const runDbAndCatalogMigrations = async ({dbReady,ensureSchema,- runDbMigrations,+ loadDbMigrationRunner,migrateBibleToCatalog,repairUniverseTags,migrateCatalogPayload,@@ -177,6 +182,7 @@ export const runDbAndCatalogMigrations = async ({if (!dbReady) return;try {await ensureSchema();+ const runDbMigrations = await loadDbMigrationRunner();try {await runDbMigrations();} catch (err) {@@ -270,8 +276,10 @@ export const runDatabasePhase = async ({ gate, migrate, warmStores, reconcileSta* reloaded jobs, and before a route can enqueue against a half-init queue.* 5. The database phase before `startListening`, so no request can land on a* partially-migrated install.- * 6. `backfillSeriesCoverImages` fire-and-forget: a cosmetic thumbnail- * backfill must never delay the server accepting requests.+ * 6. The series-cover backfill MODULE is awaited but the backfill RUN is not:+ * a cosmetic thumbnail pass must never delay the server accepting+ * requests, while a script that won't even load is a real breakage and+ * takes the fatal path.** Returns the chain's promise; a rejection anywhere in it is fatal.*/@@ -285,7 +293,7 @@ export const runPostRouteSequence = ({initSharing,recoverCreativeDirectorProjects,runDatabasePhase: databasePhase,- backfillSeriesCoverImages,+ loadSeriesCoverBackfill,startListening,onFatal = () => process.exit(1)}) => {@@ -311,7 +319,9 @@ export const runPostRouteSequence = ({recoverCreativeDirectorProjects();}).then(() => databasePhase())- .then(() => {+ .then(async () => {+ // Load awaited, run not — see point 6 above.+ const backfillSeriesCoverImages = await loadSeriesCoverBackfill();bestEffort(backfillSeriesCoverImages(), logFailure('series cover backfill failed at boot'));}).then(() => startListening())diff --git a/server/services/bootstrapSequence.test.js b/server/services/bootstrapSequence.test.jsindex 2c8cbe93a0..0f584c5681 100644--- a/server/services/bootstrapSequence.test.js+++ b/server/services/bootstrapSequence.test.js@@ -313,7 +313,8 @@ describe('runDbAndCatalogMigrations', () => {return {dbReady: true,ensureSchema: step('ensureSchema', () => Promise.resolve()),- runDbMigrations: step('runDbMigrations', () => Promise.resolve()),+ loadDbMigrationRunner: step('loadDbMigrationRunner', () =>+ Promise.resolve(step('runDbMigrations', () => Promise.resolve()))),migrateBibleToCatalog: step('migrateBibleToCatalog', () => Promise.resolve()),repairUniverseTags: step('repairUniverseTags', () => Promise.resolve()),migrateCatalogPayload: step('migrateCatalogPayload', () => Promise.resolve()),@@ -329,6 +330,7 @@ describe('runDbAndCatalogMigrations', () => {await runDbAndCatalogMigrations(buildDeps(recorder));expect(recorder.calls).toEqual(['ensureSchema',+ 'loadDbMigrationRunner','runDbMigrations','migrateBibleToCatalog','repairUniverseTags',@@ -347,14 +349,29 @@ describe('runDbAndCatalogMigrations', () => {it('treats a failed schema-delta migration as fatal and skips the rest', async () => {const recorder = createRecorder();const deps = buildDeps(recorder, {- runDbMigrations: recorder.step('runDbMigrations', () => Promise.reject(new Error('delta 42 failed')))+ loadDbMigrationRunner: recorder.step('loadDbMigrationRunner', () =>+ Promise.resolve(recorder.step('runDbMigrations', () => Promise.reject(new Error('delta 42 failed')))))});await runDbAndCatalogMigrations(deps);- expect(recorder.calls).toEqual(['ensureSchema', 'runDbMigrations']);+ expect(recorder.calls).toEqual(['ensureSchema', 'loadDbMigrationRunner', 'runDbMigrations']);expect(deps.onMigrationFailure).toHaveBeenCalledTimes(1);expect(console.error).toHaveBeenCalledWith(expect.stringContaining('DB migration failed at boot'));});+ it('is NOT fatal when the migration runner module itself cannot be loaded', async () => {+ // Only a migration that RAN and failed leaves a possibly-half-applied+ // install; a runner that never loaded applied nothing, so it takes the+ // group's log-and-continue path.+ const recorder = createRecorder();+ const deps = buildDeps(recorder, {+ loadDbMigrationRunner: recorder.step('loadDbMigrationRunner', () => Promise.reject(new Error('module missing')))+ });+ await runDbAndCatalogMigrations(deps);+ expect(deps.onMigrationFailure).not.toHaveBeenCalled();+ expect(recorder.calls).toEqual(['ensureSchema', 'loadDbMigrationRunner']);+ expect(console.error).toHaveBeenCalledWith(expect.stringContaining('catalog migrations failed at boot'));+ });+it('keeps booting when a best-effort catalog migration fails', async () => {const recorder = createRecorder();const deps = buildDeps(recorder, {@@ -364,7 +381,13 @@ describe('runDbAndCatalogMigrations', () => {expect(deps.onMigrationFailure).not.toHaveBeenCalled();expect(console.error).toHaveBeenCalledWith(expect.stringContaining('catalog migrations failed at boot'));// Later steps are skipped (they share one try block) but boot continues.- expect(recorder.calls).toEqual(['ensureSchema', 'runDbMigrations', 'migrateBibleToCatalog', 'repairUniverseTags']);+ expect(recorder.calls).toEqual([+ 'ensureSchema',+ 'loadDbMigrationRunner',+ 'runDbMigrations',+ 'migrateBibleToCatalog',+ 'repairUniverseTags'+ ]);});});@@ -460,7 +483,8 @@ describe('runPostRouteSequence — post-route boot order', () => {initSharing: step('initSharing', () => Promise.resolve()),recoverCreativeDirectorProjects: step('recoverCreativeDirectorProjects', () => Promise.resolve()),runDatabasePhase: step('runDatabasePhase', () => Promise.resolve({ dbReady: true })),- backfillSeriesCoverImages: step('backfillSeriesCoverImages', () => Promise.resolve()),+ loadSeriesCoverBackfill: step('loadSeriesCoverBackfill', () =>+ Promise.resolve(step('backfillSeriesCoverImages', () => Promise.resolve()))),startListening: step('startListening'),onFatal: vi.fn(),...overrides@@ -481,6 +505,7 @@ describe('runPostRouteSequence — post-route boot order', () => {'initSharing','recoverCreativeDirectorProjects','runDatabasePhase',+ 'loadSeriesCoverBackfill','backfillSeriesCoverImages','startListening']);@@ -534,7 +559,8 @@ describe('runPostRouteSequence — post-route boot order', () => {recoverStuckClassifications: recorder.step('recoverStuckClassifications', () => stuck.promise),initSharing: recorder.step('initSharing', () => deferred().promise),recoverCreativeDirectorProjects: recorder.step('recoverCreativeDirectorProjects', () => deferred().promise),- backfillSeriesCoverImages: recorder.step('backfillSeriesCoverImages', () => deferred().promise)+ loadSeriesCoverBackfill: recorder.step('loadSeriesCoverBackfill', () =>+ Promise.resolve(recorder.step('backfillSeriesCoverImages', () => deferred().promise)))});// None of these ever settle; the server must still start listening.await runPostRouteSequence(deps);@@ -542,6 +568,33 @@ describe('runPostRouteSequence — post-route boot order', () => {stuck.resolve();});+ it('awaits the series-cover backfill MODULE but not the backfill itself', async () => {+ const recorder = createRecorder();+ const load = deferred();+ const deps = buildDeps(recorder, {+ loadSeriesCoverBackfill: recorder.step('loadSeriesCoverBackfill', () => load.promise)+ });+ const done = runPostRouteSequence(deps);+ await flush();+ expect(recorder.calls).not.toContain('startListening');+ // A script that won't even load is a real breakage, so the load sits on the+ // fatal path; the cosmetic backfill run never delays the listener.+ load.resolve(recorder.step('backfillSeriesCoverImages', () => deferred().promise));+ await done;+ expect(recorder.calls).toContain('startListening');+ expect(deps.onFatal).not.toHaveBeenCalled();+ });++ it('is fatal when the series-cover backfill module cannot be loaded', async () => {+ const recorder = createRecorder();+ const deps = buildDeps(recorder, {+ loadSeriesCoverBackfill: recorder.step('loadSeriesCoverBackfill', () => Promise.reject(new Error('script missing')))+ });+ await runPostRouteSequence(deps);+ expect(deps.onFatal).toHaveBeenCalledTimes(1);+ expect(recorder.calls).not.toContain('startListening');+ });+it('finishes the database phase before the listener opens', async () => {const recorder = createRecorder();const gate = deferred();@@ -573,7 +626,8 @@ describe('runPostRouteSequence — post-route boot order', () => {const deps = buildDeps(recorder, {recoverStuckClassifications: recorder.step('recoverStuckClassifications', () => Promise.reject(new Error('brain boom'))),initSharing: recorder.step('initSharing', () => Promise.reject(new Error('bucket gone'))),- backfillSeriesCoverImages: recorder.step('backfillSeriesCoverImages', () => Promise.reject(new Error('no covers')))+ loadSeriesCoverBackfill: recorder.step('loadSeriesCoverBackfill', () =>+ Promise.resolve(recorder.step('backfillSeriesCoverImages', () => Promise.reject(new Error('no covers')))))});await runPostRouteSequence(deps);await flush();