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): preserve unresolved universe tags for retry, skip completion marker after row failures, deep-link to the real #canon anchor
[._.]/ Adam Eivy77adacc4f51e
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsxindex 5603c85b91..d24c4a6779 100644--- a/client/src/pages/CatalogIngredient.jsx+++ b/client/src/pages/CatalogIngredient.jsx@@ -378,7 +378,7 @@ export default function CatalogIngredient() {</div>{record.type === 'character' && (- <ReferenceSheetPanel payload={payload} universeRef={universeRef} ingredientId={record.id} />+ <ReferenceSheetPanel payload={payload} universeRef={universeRef} />)}<div className="grid grid-cols-1 md:grid-cols-2 gap-4">@@ -511,9 +511,9 @@ function CanonListFields({ payload, fields }) {// Builder surface, which carries the universe's full style data (styleNotes,// influences, palette, render settings) the renderer needs. Rendering inline// here would duplicate that heavy pipeline — the deep-link keeps one render-// path. The character anchor (`#char-<ingredientId>`) lets the universe page-// scroll to the matching entry.-function ReferenceSheetPanel({ payload, universeRef, ingredientId }) {+// path. The link targets the universe's `#canon` section (the anchor the+// Universe Builder hash-scroll resolves).+function ReferenceSheetPanel({ payload, universeRef }) {const sheets = payload?.referenceSheets && typeof payload.referenceSheets === 'object'? Object.entries(payload.referenceSheets).filter(([, v]) => typeof v === 'string' && v): [];@@ -525,8 +525,12 @@ function ReferenceSheetPanel({ payload, universeRef, ingredientId }) {];const hasSheet = variants.length > 0;+ // Deep-link to the universe's canon section (`id="canon"`, the one anchor the+ // Universe Builder hash-scroll handler resolves) — a per-character anchor+ // isn't rendered there, so #canon lands the user on the canon surface where+ // the character + its render controls live.const universePath = universeRef?.refId- ? `/universes/${encodeURIComponent(universeRef.refId)}#char-${encodeURIComponent(ingredientId)}`+ ? `/universes/${encodeURIComponent(universeRef.refId)}#canon`: null;return (diff --git a/server/lib/catalogUniverseTags.js b/server/lib/catalogUniverseTags.jsindex 762e978209..4c3bea5332 100644--- a/server/lib/catalogUniverseTags.js+++ b/server/lib/catalogUniverseTags.js@@ -76,24 +76,31 @@ export function universeIdFromLegacyTag(tag) {export function friendlifyUniverseTags(tags, nameForId, canonicalKey) {const input = Array.isArray(tags) ? tags : [];const kept = [];- const universeIds = [];- let sawLegacy = false;+ let sawMarker = false;+ const idTags = []; // { id, original } in encounter order, first-seen-per-id+ const seenId = new Set();for (const tag of input) {if (isLegacyUniverseTag(tag)) {- sawLegacy = true;const id = universeIdFromLegacyTag(tag);- if (id && !universeIds.includes(id)) universeIds.push(id);+ if (!id) { sawMarker = true; continue; } // the `from-universe` marker+ if (!seenId.has(id)) { seenId.add(id); idTags.push({ id, original: tag }); }continue;}kept.push(tag);}- // Resolve names for every distinct universe id; skip unresolved ones.+ // Resolve each id to a friendly name. When a name CAN'T be resolved yet (the+ // universe arrived after this ingredient, or the local lookup misses), KEEP+ // the `universe:<id>` machine tag so a later run can still friendlify it —+ // dropping it here would lose the id permanently (the row would need a manual+ // re-link). The structured ref in catalog_ingredient_refs still owns querying.const names = [];- for (const id of universeIds) {+ const unresolvedIdTags = [];+ for (const { id, original } of idTags) {const name = nameForId(id);if (typeof name === 'string' && name.trim()) names.push(name.trim());+ else unresolvedIdTags.push(original);}// De-dup the friendly names against kept tags + each other.@@ -106,10 +113,21 @@ export function friendlifyUniverseTags(tags, nameForId, canonicalKey) {addedNames.push(name);}- const result = [...kept, ...addedNames];- // `changed` when we stripped any legacy tag OR added any friendly name.- // (A row could carry `universe:<id>` whose name dedups against an existing- // user tag — still changed, because the machine tag was removed.)- const changed = sawLegacy || addedNames.length > 0;+ // Keep the `from-universe` marker only while an id is still unresolved, so the+ // row stays flagged for a retry; drop it once every id resolved.+ const keepMarker = sawMarker && unresolvedIdTags.length > 0;+ const result = [+ ...kept,+ ...addedNames,+ ...unresolvedIdTags,+ ...(keepMarker ? [LEGACY_UNIVERSE_MARKER_TAG] : []),+ ];++ // `changed` only when we actually rewrote something: a friendly name was+ // added, OR a legacy tag was REMOVED (a resolved id-tag dropped, or the marker+ // dropped). If every id is unresolved we leave the row untouched so the next+ // 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 };}diff --git a/server/lib/catalogUniverseTags.test.js b/server/lib/catalogUniverseTags.test.jsindex 25cb58fc2e..46e8cc5652 100644--- a/server/lib/catalogUniverseTags.test.js+++ b/server/lib/catalogUniverseTags.test.js@@ -58,14 +58,29 @@ describe('catalogUniverseTags — friendlifyUniverseTags', () => {expect(tags).toEqual(['hero', 'noir']);});- it('drops an unresolved universe id tag but adds no name (and still reports changed)', () => {+ it('PRESERVES an unresolved universe id tag (+ marker) for a later retry and reports NOT changed', () => {+ // The universe name can't resolve yet (it arrived after this ingredient, or+ // the local lookup misses). Dropping the id tag would lose it forever, so we+ // keep it untouched and report changed=false so the row retries next run.const { tags, changed } = friendlifyUniverseTags(['hero', 'universe:u-deleted', 'from-universe'],nameFor,canonicalKey,);+ expect(changed).toBe(false);+ expect(tags).toEqual(['hero', 'universe:u-deleted', 'from-universe']);+ });++ it('friendlifies the resolved id but KEEPS an unresolved sibling id (partial resolve)', () => {+ // u-1 resolves, u-deleted doesn't: add the resolved name, drop u-1, keep+ // u-deleted (+ the marker) so the still-unresolved one retries later.+ const { tags, changed } = friendlifyUniverseTags(+ ['hero', 'universe:u-1', 'universe:u-deleted', 'from-universe'],+ nameFor,+ canonicalKey,+ );expect(changed).toBe(true);- expect(tags).toEqual(['hero']);+ expect(tags).toEqual(['hero', 'My Cool Universe', 'universe:u-deleted', 'from-universe']);});it('dedupes the friendly name against an existing user tag (case-insensitive)', () => {diff --git a/server/scripts/repairUniverseTags.js b/server/scripts/repairUniverseTags.jsindex f15510e799..0240db145a 100644--- a/server/scripts/repairUniverseTags.js+++ b/server/scripts/repairUniverseTags.js@@ -116,12 +116,19 @@ export async function repairUniverseTags({ force = false } = {}) {completedAt: new Date().toISOString(),stats: totals,};- await writeMarker(payload);+ // 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;+ 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` ++ (wroteMarker ? '' : ' — marker NOT written (will retry next boot)'),);- return { skipped: false, ...payload };+ return { skipped: false, markerWritten: wroteMarker, ...payload };}