Skip to content

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

review: nonce-suffix seeded route-test names; clarify catalog-before-universe friendlify edge

[._.]/ Adam Eivy5bc587214d90
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 260019bd99..962dfffb56 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,7 +2,7 @@
## Changed
-- **[catalog-import-sync-hardening] Catalog bulk-import keeps scraps; legacy universe tags self-heal across peers.** Bulk-importing markdown that carries a `### Scraps` subsection now persists those scraps as `catalog_scraps` rows + source links inside the same transaction (previously the round-tripped scraps were silently dropped on import); the response reports a `scrapsCreated` count. Separately, an ingredient synced from an older or offline peer *after* the one-time boot tag-repair ran would reintroduce raw `from-universe` / `universe:<uuid>` machine tags via last-writer-wins — those are now friendlified to the universe NAME on inbound sync, so the repair self-heals on every sync instead of only at boot. Internal: the seven near-identical per-kind apply loops in `catalogSync.applyRemoteChanges` collapse into a single `applyKind` helper (pure refactor, behavior-identical), and `createScrap` gains a `{ client }` transaction option. Adds route-level Postgres integration tests for `/bulk-import` and revision `/restore`.
+- **[catalog-import-sync-hardening] Catalog bulk-import keeps scraps; legacy universe tags self-heal across peers.** Bulk-importing markdown that carries a `### Scraps` subsection now persists those scraps as `catalog_scraps` rows + source links inside the same transaction (previously the round-tripped scraps were silently dropped on import); the response reports a `scrapsCreated` count. Separately, an ingredient synced from an older or offline peer *after* the one-time boot tag-repair ran would reintroduce raw `from-universe` / `universe:<uuid>` machine tags via last-writer-wins — those are now friendlified to the universe NAME on inbound sync — re-applying the repair whenever an ingredient is (re)synced and its universe is resolvable locally, instead of only at boot (a catalog row that arrives before its universe keeps its machine tags and is cleaned up on the next sync or by the boot repair). Internal: the seven near-identical per-kind apply loops in `catalogSync.applyRemoteChanges` collapse into a single `applyKind` helper (pure refactor, behavior-identical), and `createScrap` gains a `{ client }` transaction option. Adds route-level Postgres integration tests for `/bulk-import` and revision `/restore`.
- **[federated-media-sync-followups] Sync integrity, local LLM, voice, and service hardening.** Federated sync badges now distinguish offline peers from peers that need a PortOS update, series integrity checks include child-issue assets, and records with images missing prompt sidecars show a dedicated "Metadata missing" status. Tombstone pushes now bypass the schema-version cooldown so deletes converge immediately. Internal cleanup: the AI toolkit receives Ollama readiness through an injected hook, Linux Ollama startup uses persistent `systemctl enable --now` / `disable --now`, migration 037 streams history conversion instead of materializing the union in memory, Local LLM backend switching writes `.env` atomically, the Voice settings UI can pin a vision model, and the LTX2 negative-prompt patch only targets namespaced constants modules.
- **[catalog-tests + catalog-ddl-drift-test] Catalog stack now has unit-test coverage + a DDL parity guard.** Internal: pure unit tests for the catalog Zod validators, the peer-sync envelope apply path (per-kind dispatch, per-row isolation, schema-version gate, cursor normalization), and the extraction service (stage frames, isolation, light-shape sanitizer). A new structural parity test diffs the catalog DDL between `server/scripts/init-db.sql` (fresh-install path) and the `catalogDDL` array in `server/lib/db.js:ensureSchema()` (upgrade path) — table columns, indexes, trigger functions, triggers, the `type` CHECK list, and the `search_tsv` payload-field set must match in both files, so a future PR can't update one and forget the other.
diff --git a/server/routes/catalog.test.js b/server/routes/catalog.test.js
index 16bf6eb748..47cd1ec32d 100644
--- a/server/routes/catalog.test.js
+++ b/server/routes/catalog.test.js
@@ -57,6 +57,11 @@ function makeApp() {
return app;
}
+// Per-run nonce so seeded names/refs can't collide with residue left by a
+// prior aborted run (cleanup hard-deletes by id, but a unique nonce keeps the
+// assertions and any leftover rows unambiguous).
+const NONCE = Date.now();
+
const createdIngredientIds = new Set();
const createdScrapIds = new Set();
@@ -74,7 +79,7 @@ afterAll(async () => {
describe.skipIf(!dbReady)('POST /api/catalog/bulk-import — scrap persistence', () => {
it('persists a round-tripped `### Scraps` bullet as a catalog_scraps row + source link', async () => {
const markdown = [
- '## Character: Scrap Persist Hero',
+ `## Character: Scrap Persist Hero ${NONCE}`,
'',
'A protagonist used to verify scrap persistence.',
'',
@@ -106,7 +111,7 @@ describe.skipIf(!dbReady)('POST /api/catalog/bulk-import — scrap persistence',
it('creates no scrap rows for a JSON import (no scraps carried)', async () => {
const r = await request(makeApp())
.post('/api/catalog/bulk-import')
- .send({ format: 'json', payload: JSON.stringify([{ type: 'idea', name: 'Scrapless Idea', payload: { description: 'x' } }]) });
+ .send({ format: 'json', payload: JSON.stringify([{ type: 'idea', name: `Scrapless Idea ${NONCE}`, payload: { description: 'x' } }]) });
expect(r.status).toBe(201);
expect(r.body.scrapsCreated).toBe(0);
@@ -118,13 +123,13 @@ describe.skipIf(!dbReady)('POST /api/catalog/bulk-import — scrap persistence',
describe.skipIf(!dbReady)('POST /api/catalog/bulk-import — export-bundle ref recreation', () => {
it('recreates the bundle ref link from `bundleRef` and honors per-row role', async () => {
- const seriesId = `test-series-${Date.now()}`;
+ const seriesId = `test-series-${NONCE}`;
const bundle = {
version: 1,
ref: { kind: 'series', id: seriesId },
ingredients: [
- { type: 'character', name: 'Bundle Cast A', payload: { physicalDescription: 'a' }, roleForExportedRef: 'lead' },
- { type: 'character', name: 'Bundle Cast B', payload: { physicalDescription: 'b' } },
+ { type: 'character', name: `Bundle Cast A ${NONCE}`, payload: { physicalDescription: 'a' }, roleForExportedRef: 'lead' },
+ { type: 'character', name: `Bundle Cast B ${NONCE}`, payload: { physicalDescription: 'b' } },
],
};
@@ -137,12 +142,12 @@ describe.skipIf(!dbReady)('POST /api/catalog/bulk-import — export-bundle ref r
for (const c of r.body.created) createdIngredientIds.add(c.id);
const linked = await catalogDB.listIngredientsForRef('series', seriesId);
- expect(linked.map((x) => x.ingredient.name).sort()).toEqual(['Bundle Cast A', 'Bundle Cast B']);
+ expect(linked.map((x) => x.ingredient.name).sort()).toEqual([`Bundle Cast A ${NONCE}`, `Bundle Cast B ${NONCE}`]);
// Per-row role precedence: row A carried `roleForExportedRef: 'lead'`, row B
// fell back to the `bulk-<kind>` default.
const roleByName = Object.fromEntries(linked.map((x) => [x.ingredient.name, x.role]));
- expect(roleByName['Bundle Cast A']).toBe('lead');
- expect(roleByName['Bundle Cast B']).toBe('bulk-series');
+ expect(roleByName[`Bundle Cast A ${NONCE}`]).toBe('lead');
+ expect(roleByName[`Bundle Cast B ${NONCE}`]).toBe('bulk-series');
});
});
@@ -150,7 +155,7 @@ describe.skipIf(!dbReady)('POST /api/catalog/ingredients/:id/revisions/:revision
it('restores the revision payload verbatim, preserving its schemaVersion, and records a new revision', async () => {
// Seed an ingredient, then write an "old shape" payload (schemaVersion 0) so
// a later restore can prove the marker is preserved, not re-stamped.
- const ing = await catalogDB.createIngredient({ type: 'concept', name: 'Restore Probe', payload: { description: 'v-current' } });
+ const ing = await catalogDB.createIngredient({ type: 'concept', name: `Restore Probe ${NONCE}`, payload: { description: 'v-current' } });
createdIngredientIds.add(ing.id);
await catalogDB.updateIngredient(ing.id, { payload: { schemaVersion: 0, description: 'old-shape' } });
@@ -175,8 +180,8 @@ describe.skipIf(!dbReady)('POST /api/catalog/ingredients/:id/revisions/:revision
});
it('404s when the revision belongs to a different ingredient', async () => {
- const a = await catalogDB.createIngredient({ type: 'concept', name: 'Restore Owner A', payload: { description: 'a' } });
- const b = await catalogDB.createIngredient({ type: 'concept', name: 'Restore Owner B', payload: { description: 'b' } });
+ const a = await catalogDB.createIngredient({ type: 'concept', name: `Restore Owner A ${NONCE}`, payload: { description: 'a' } });
+ const b = await catalogDB.createIngredient({ type: 'concept', name: `Restore Owner B ${NONCE}`, payload: { description: 'b' } });
createdIngredientIds.add(a.id);
createdIngredientIds.add(b.id);
await catalogDB.updateIngredient(a.id, { payload: { description: 'a2' } });
diff --git a/server/services/catalogSync.js b/server/services/catalogSync.js
index 94f0a8ceb1..027268359b 100644
--- a/server/services/catalogSync.js
+++ b/server/services/catalogSync.js
@@ -191,9 +191,13 @@ export async function applyRemoteChanges(envelope = {}) {
// repair (repairUniverseTags.js) already ran would otherwise reintroduce the
// raw machine tags via LWW, and the boot repair's marker means it never runs
// again to clean them up. Rewriting them to the friendly universe NAME here
- // makes the repair self-heal on every sync instead of only at boot. The
- // universe name map is built lazily — and only when a row actually carries the
- // marker — so an envelope with no legacy rows never issues the universe query.
+ // re-applies the repair whenever an ingredient is (re)synced and its universe
+ // is resolvable locally — rather than only at boot. When the ingredient
+ // arrives BEFORE its universe, the row keeps its machine tags (changed=false)
+ // and is friendlified on the next sync once the universe is known, or by the
+ // boot repair, whichever fires first. The universe name map is built lazily —
+ // and only when a row actually carries the marker — so an envelope with no
+ // legacy rows never issues the universe query.
let universeNameMap = null;
const ensureUniverseNameMap = async () => {
if (universeNameMap) return universeNameMap;