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): keep fresh-install re-import hatch open, align run order
Adam Eivyb3d1207baf35
diff --git a/server/scripts/migrateUniversesToDB.js b/server/scripts/migrateUniversesToDB.jsindex c087449166..8f11dc0e5a 100644--- a/server/scripts/migrateUniversesToDB.js+++ b/server/scripts/migrateUniversesToDB.js@@ -97,10 +97,12 @@ export async function migrateUniversesToDB() {const legacyDir = join(PATHS.data, LEGACY_DIRNAME);const dirStat = await stat(legacyDir).catch(() => null);- // Fresh install (no legacy dir): stamp the marker so we don't re-probe every- // boot, and return.+ // Fresh install (no legacy dir): no-op WITHOUT stamping the marker. The probe+ // is a single stat per boot — cheap — and NOT stamping keeps the recovery+ // escape hatch open: a user who later restores data/universes.imported back to+ // data/universes (to re-import after a rollback) gets a real import on the next+ // boot. Stamping here would silently suppress that forever.if (!dirStat || !dirStat.isDirectory()) {- await writeMarker({ migratedAt: new Date().toISOString(), imported: 0, runs: 0, reason: 'fresh-install' });return { ok: true, reason: 'fresh-install', imported: 0, runs: 0 };}diff --git a/server/scripts/migrateUniversesToDB.test.js b/server/scripts/migrateUniversesToDB.test.jsindex 07f3040159..8610dfec52 100644--- a/server/scripts/migrateUniversesToDB.test.js+++ b/server/scripts/migrateUniversesToDB.test.js@@ -87,10 +87,12 @@ beforeEach(() => {});describe('migrateUniversesToDB', () => {- it('fresh install (no legacy dir): stamps marker, imports nothing', async () => {+ it('fresh install (no legacy dir): no-op WITHOUT a marker (keeps the recovery re-import hatch open)', async () => {const result = await importer();expect(result).toMatchObject({ ok: true, reason: 'fresh-install', imported: 0 });- expect(MARKER in files).toBe(true);+ // No marker stamped — a later restore of data/universes.imported → data/universes+ // must re-import on the next boot rather than being silently suppressed.+ expect(MARKER in files).toBe(false);expect(uTable.size).toBe(0);});diff --git a/server/services/universeBuilder/store.js b/server/services/universeBuilder/store.jsindex a2500cb10c..79e3cf22f5 100644--- a/server/services/universeBuilder/store.js+++ b/server/services/universeBuilder/store.js@@ -79,7 +79,14 @@ function makeFileBackend(dir) {loadRuns: async (universeId = null) => {const ti = await cs.loadTypeIndex();const runs = runsOf(ti);- return universeId ? runs.filter((r) => r?.universeId === universeId) : runs;+ const scoped = universeId ? runs.filter((r) => r?.universeId === universeId) : runs;+ // Match the PG backend's `created_at DESC, id DESC` order so the two+ // backends return runs identically (the service's listRuns re-sorts by+ // createdAt anyway, but a direct facade consumer shouldn't see backend-+ // dependent order). Copy before sort — runsOf returns the live array.+ return [...scoped].sort((a, b) =>+ (b?.createdAt || '').localeCompare(a?.createdAt || '')+ || (b?.id || '').localeCompare(a?.id || ''));},appendRun: async (run) => {const ti = await cs.loadTypeIndex();diff --git a/server/services/universeBuilder/store.test.js b/server/services/universeBuilder/store.test.jsindex a13f94cd9d..9319080ed4 100644--- a/server/services/universeBuilder/store.test.js+++ b/server/services/universeBuilder/store.test.js@@ -100,6 +100,13 @@ describe('universe store facade — file backend', () => {expect((await s.loadRuns()).map((r) => r.universeId)).toEqual(['u-B']);});+ it('loadRuns returns newest-first (created_at DESC, id DESC) to match the PG backend', async () => {+ const s = getUniverseStore(passthroughSanitize);+ await s.appendRun({ id: 'r-old', universeId: 'u-1', jobIds: [], promptCount: 1, createdAt: '2026-01-01T00:00:00.000Z' });+ await s.appendRun({ id: 'r-new', universeId: 'u-1', jobIds: [], promptCount: 1, createdAt: '2026-01-02T00:00:00.000Z' });+ expect((await s.loadRuns()).map((r) => r.id)).toEqual(['r-new', 'r-old']);+ });+it('verifySchemaVersion reports the file collection version', async () => {const s = getUniverseStore(passthroughSanitize);await s.writeRecord('u-1', { id: 'u-1', name: 'X' });