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: register the minted friendly universe tag in the canonical taxonomy on sync (#3942)
[._.]/ Adam Eivyaca5621c1bf0
diff --git a/server/services/catalogSync.js b/server/services/catalogSync.jsindex 63706f8257..ad36a793a0 100644--- a/server/services/catalogSync.js+++ b/server/services/catalogSync.js@@ -44,6 +44,7 @@ import {upsertRelationFromPeer,upsertTagFromPeer,upsertMediaFromPeer,+ normalizeTags,} from './catalogDB.js';import { compareSchemaVersions, PORTOS_SCHEMA_VERSIONS } from '../lib/schemaVersions.js';import { friendlifyUniverseTags, LEGACY_UNIVERSE_MARKER_TAG } from '../lib/catalogUniverseTags.js';@@ -237,6 +238,25 @@ export async function applyRemoteChanges(envelope = {}) {}return universeNameMap;};+ // The friendly universe NAME is minted locally — it isn't one of the peer's+ // `envelope.tags` rows — so nothing else in the apply registers it in the+ // canonical `catalog_tags` taxonomy, and tag autocomplete would never suggest+ // it. The old follow-up `updateIngredient` got that for free (it runs every+ // patched tag through `normalizeTags`); register the minted labels explicitly+ // instead. Cached per apply and scoped to the labels this rewrite ADDS, so a+ // 100-row envelope registers one label once rather than re-normalizing every+ // row's whole tag array. The stored canonical label wins on casing, matching+ // what `normalizeTags` would have written.+ const universeTagLabels = new Map(); // canonical key → stored canonical label+ const registerUniverseTagLabel = async (label) => {+ const key = canonicalTagKey(label);+ if (!key) return label;+ if (universeTagLabels.has(key)) return universeTagLabels.get(key);+ const [stored] = await normalizeTags([label]);+ const canonical = stored || label;+ universeTagLabels.set(key, canonical);+ return canonical;+ };const friendlifyIngredientTagsBeforeApply = async (ing) => {const hasMarker = Array.isArray(ing?.tags) && ing.tags.some((t) => typeof t === 'string' && t.trim().toLowerCase() === LEGACY_UNIVERSE_MARKER_TAG);@@ -244,7 +264,14 @@ export async function applyRemoteChanges(envelope = {}) {const map = await ensureUniverseNameMap();const { tags, changed } = friendlifyUniverseTags(ing.tags, (id) => map.get(id) || null, canonicalTagKey);if (!changed) return ing; // nothing resolvable yet — keep the machine tags for a later pass- return { ...ing, tags };+ const inboundKeys = new Set(ing.tags.map((t) => canonicalTagKey(t)).filter(Boolean));+ const registered = [];+ for (const tag of tags) {+ // Tags the peer already sent ride through untouched (same as every other+ // peer-upserted row); only the newly minted universe names are registered.+ registered.push(inboundKeys.has(canonicalTagKey(tag)) ? tag : await registerUniverseTagLabel(tag));+ }+ return { ...ing, tags: registered };};// Tags first — they carry a `parent_id` self-FK (handled by the parent-lessdiff --git a/server/services/catalogSync.test.js b/server/services/catalogSync.test.jsindex ff1af6d041..61fc949932 100644--- a/server/services/catalogSync.test.js+++ b/server/services/catalogSync.test.js@@ -29,6 +29,9 @@ vi.mock('./catalogDB.js', () => ({upsertTagFromPeer: vi.fn(),upsertMediaFromPeer: vi.fn(),updateIngredient: vi.fn(),+ // Registers a label in the canonical tag taxonomy and echoes back the STORED+ // label (existing casing wins) — the default double mirrors that contract.+ normalizeTags: vi.fn(async (labels) => labels),}));vi.mock('../lib/schemaVersions.js', async () => {@@ -493,6 +496,48 @@ describe('applyRemoteChanges — legacy universe tag friendlify on inbound sync'expect(tagsUpserted(1)).toEqual(['My Universe']);});+ it('registers the minted universe name in the canonical tag taxonomy, once per apply', async () => {+ catalogDB.upsertIngredientFromPeer.mockResolvedValue({ applied: true, isInsert: true });+ universeBuilder.listUniverses.mockResolvedValueOnce([{ id: 'u-1', name: 'My Universe' }]);++ await applyRemoteChanges({+ ingredients: [+ { ...ingredient(['hero', 'from-universe', 'universe:u-1']), id: 'i-1' },+ { ...ingredient(['hero', 'from-universe', 'universe:u-1']), id: 'i-2' },+ ],+ });++ // The friendly name is minted locally — it is NOT one of the peer's tag rows —+ // so without this the label would never reach `catalog_tags` / autocomplete.+ // Only the ADDED label is registered, and only once across the envelope.+ expect(catalogDB.normalizeTags).toHaveBeenCalledTimes(1);+ expect(catalogDB.normalizeTags).toHaveBeenCalledWith(['My Universe']);+ });++ it('writes the STORED canonical casing when the minted tag already exists', async () => {+ catalogDB.upsertIngredientFromPeer.mockResolvedValueOnce({ applied: true, isInsert: true });+ universeBuilder.listUniverses.mockResolvedValueOnce([{ id: 'u-1', name: 'my universe' }]);+ catalogDB.normalizeTags.mockResolvedValueOnce(['My Universe']); // pre-existing row's casing wins++ await applyRemoteChanges({+ ingredients: [ingredient(['hero', 'from-universe', 'universe:u-1'])],+ });++ expect(tagsUpserted()).toEqual(['hero', 'My Universe']);+ });++ it('does not re-register tags the peer already sent', async () => {+ catalogDB.upsertIngredientFromPeer.mockResolvedValueOnce({ applied: true, isInsert: true });+ universeBuilder.listUniverses.mockResolvedValueOnce([{ id: 'u-1', name: 'hero' }]);++ // The minted name collides with an inbound tag → nothing new to register.+ await applyRemoteChanges({+ ingredients: [ingredient(['hero', 'from-universe', 'universe:u-1'])],+ });++ expect(catalogDB.normalizeTags).not.toHaveBeenCalled();+ });+it('isolates a friendlify failure as a prepare error and still applies the raw row', async () => {catalogDB.upsertIngredientFromPeer.mockResolvedValueOnce({ applied: true, isInsert: true });universeBuilder.listUniverses.mockRejectedValueOnce(new Error('universe read failed'));