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 (codex): withhold the repair completion marker while any row has an unresolved universe tag, so it retries once the universe lands
[._.]/ Adam Eivy5e5fbd6b3137
diff --git a/server/lib/catalogUniverseTags.js b/server/lib/catalogUniverseTags.jsindex 4c3bea5332..56ebab475c 100644--- a/server/lib/catalogUniverseTags.js+++ b/server/lib/catalogUniverseTags.js@@ -129,5 +129,8 @@ export function friendlifyUniverseTags(tags, nameForId, canonicalKey) {// run retries it instead of burning a no-op write.const removedLegacy = (idTags.length - unresolvedIdTags.length) > 0 || (sawMarker && !keepMarker);const changed = addedNames.length > 0 || removedLegacy;- return { tags: result, changed };+ // `unresolved` is true when this row STILL carries a legacy `universe:<id>`+ // tag we couldn't friendlify yet — the repair driver uses it to withhold the+ // completion marker so a future boot (after the universe arrives) retries.+ return { tags: result, changed, unresolved: unresolvedIdTags.length > 0 };}diff --git a/server/lib/catalogUniverseTags.test.js b/server/lib/catalogUniverseTags.test.jsindex 46e8cc5652..b04590b7d4 100644--- a/server/lib/catalogUniverseTags.test.js+++ b/server/lib/catalogUniverseTags.test.js@@ -111,7 +111,7 @@ describe('catalogUniverseTags — friendlifyUniverseTags', () => {});it('tolerates non-array input', () => {- expect(friendlifyUniverseTags(null, nameFor, canonicalKey)).toEqual({ tags: [], changed: false });- expect(friendlifyUniverseTags(undefined, nameFor, canonicalKey)).toEqual({ tags: [], changed: false });+ expect(friendlifyUniverseTags(null, nameFor, canonicalKey)).toEqual({ tags: [], changed: false, unresolved: false });+ expect(friendlifyUniverseTags(undefined, nameFor, canonicalKey)).toEqual({ tags: [], changed: false, unresolved: false });});});diff --git a/server/scripts/repairUniverseTags.js b/server/scripts/repairUniverseTags.jsindex 0240db145a..9b9dc3a2a9 100644--- a/server/scripts/repairUniverseTags.js+++ b/server/scripts/repairUniverseTags.js@@ -82,7 +82,7 @@ export async function repairUniverseTags({ force = false } = {}) {const nameMap = await buildUniverseNameMap();const nameForId = (id) => nameMap.get(id) || null;- const totals = { scanned: 0, rewritten: 0, errors: 0 };+ const totals = { scanned: 0, rewritten: 0, errors: 0, unresolved: 0 };// Page through every ingredient. Only character/place/object rows can carry// the legacy tags, but a tag-only scan is cheap and future-proof, so we walk// all rows and let the pure transform decide what's a no-op.@@ -94,7 +94,10 @@ export async function repairUniverseTags({ force = false } = {}) {if (!Array.isArray(rows) || rows.length === 0) break;for (const ing of rows) {totals.scanned++;- const { tags, changed } = friendlifyUniverseTags(ing.tags, nameForId, canonicalTagKey);+ const { tags, changed, unresolved } = friendlifyUniverseTags(ing.tags, nameForId, canonicalTagKey);+ // A row whose universe id can't be resolved yet is preserved (changed may+ // be false) — count it so the marker is withheld and a future boot retries.+ if (unresolved) totals.unresolved++;if (!changed) continue;try {// `source: 'sync'` keeps the rewrite out of the user-facing revision@@ -116,17 +119,19 @@ export async function repairUniverseTags({ force = false } = {}) {completedAt: new Date().toISOString(),stats: totals,};- // Only stamp the completion marker on a CLEAN pass. A row-level failure- // (transient DB error) increments totals.errors; writing the marker anyway- // would skip the whole repair next boot and strand those rows' legacy tags- // forever. Leaving the marker unwritten re-runs the (idempotent) repair next- // boot — already-friendlified rows are no-ops, so only the failed rows retry.- const wroteMarker = totals.errors === 0;+ // Only stamp the completion marker on a CLEAN, COMPLETE pass — no row-level+ // failures (transient DB errors) AND no rows left with an unresolved+ // `universe:<id>` tag (its universe hasn't arrived locally yet). Writing the+ // marker in either case would skip the whole repair next boot and strand+ // those rows' legacy tags forever. Withholding it re-runs the (idempotent)+ // repair next boot — already-friendlified rows are no-ops, so only the failed+ // / not-yet-resolvable rows retry.+ const wroteMarker = totals.errors === 0 && totals.unresolved === 0;if (wroteMarker) await writeMarker(payload);console.log(`🏷️ universe-tag repair: ${totals.scanned} scanned, ` +- `${totals.rewritten} rewritten, ${totals.errors} errors` ++ `${totals.rewritten} rewritten, ${totals.errors} errors, ${totals.unresolved} unresolved` +(wroteMarker ? '' : ' — marker NOT written (will retry next boot)'),);diff --git a/server/scripts/repairUniverseTags.test.js b/server/scripts/repairUniverseTags.test.jsindex 441cf46ad2..35dfceeb15 100644--- a/server/scripts/repairUniverseTags.test.js+++ b/server/scripts/repairUniverseTags.test.js@@ -105,6 +105,22 @@ describe('repairUniverseTags', () => {expect(fsState.written.version).toBe(2);});+ it('withholds the completion marker when a row has an unresolved universe tag (retries next boot)', async () => {+ // u-999 isn't in the universe name map — its universe hasn't arrived locally+ // yet. The legacy tag is preserved, the row counts as unresolved, and the+ // marker is NOT written so a future boot retries once the universe lands.+ dbState.ingredients = [{ id: 'cat-chr-1', tags: ['from-universe', 'universe:u-999', 'mentor'] }];++ const result = await repairUniverseTags();++ expect(result.skipped).toBe(false);+ expect(result.stats.unresolved).toBe(1);+ expect(result.markerWritten).toBe(false);+ expect(fsState.written).toBeNull();+ // Legacy tag preserved untouched for the retry.+ expect(dbState.ingredients[0].tags).toEqual(['from-universe', 'universe:u-999', 'mentor']);+ });+it('re-runs the walk when forced even with a marker present', async () => {fsState.marker = { version: 1 };dbState.ingredients = [{ id: 'cat-chr-1', tags: ['from-universe', 'universe:u-1'] }];