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 non-converging catalog user-type sync: strict-newer LWW instead of >=
[._.]/ Adam Eivy4c3f71586967
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 3f19039fdb..3f1536f2ca 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -10,6 +10,8 @@## Fixed+- **Catalog user-type sync now converges instead of re-applying every cycle** — federated catalog *user-defined types* used an at-or-newer (`>=`) last-write-wins comparison, so a peer re-sending a type you already held at the same timestamp was re-adopted, re-written, and re-counted as a change on every sync cycle. The logs showed a constant non-zero count (e.g. `Synced with <peer>: 3 catalog changes`) once a minute forever, and the slice was rewritten needlessly each pass. The merge now uses strict-newer (`>`), matching the SQL LWW guard every other catalog kind already uses (`EXCLUDED.updated_at > …updated_at`): an equal-clock echo is a skip, so the merge is idempotent and the cycle settles to zero changes. (`server/services/catalogSync.js`)+- **[issue-1080] Notes synced from other machines become searchable promptly** — a Brain note, daily-log entry, person, project, or idea created or edited on one of your machines is now re-indexed into semantic memory on the others as soon as it syncs, instead of waiting for a full manual re-sync. Edits and deletes that arrive from a peer also refresh or retire the matching memory entry, so search no longer surfaces stale copies of records that changed elsewhere. A new **Refresh embeddings** button on the Brain graph re-indexes everything in one pass to heal anything that drifted before this fix.## Changeddiff --git a/server/services/catalogSync.js b/server/services/catalogSync.jsindex 1c62b5f6e7..c99ff5b329 100644--- a/server/services/catalogSync.js+++ b/server/services/catalogSync.js@@ -346,8 +346,14 @@ export async function applyUserTypesFromPeer(incoming = []) {// system types always win and are never represented in this slice.if (!id || INGREDIENT_TYPE_IDS.includes(id)) { skipped++; continue; }const existing = byId.get(id);- // LWW: adopt when no local copy, or the peer's clock is at-or-newer.- if (!existing || clockOf(peer) >= clockOf(existing)) {+ // LWW: adopt when no local copy, or the peer's clock is STRICTLY newer.+ // Must be `>`, not `>=` — an equal clock means the peer is echoing a type+ // we already hold, so re-adopting it re-writes the slice and re-counts it+ // as an applied change every cycle, and the merge never converges (the peer+ // keeps re-sending it on the next envelope). Strict `>` mirrors the SQL LWW+ // guard every other catalog kind uses (`EXCLUDED.updated_at > … .updated_at`+ // in upsertScrapFromPeer / upsertTagFromPeer): equal clock = no-op = skip.+ if (!existing || clockOf(peer) > clockOf(existing)) {byId.set(id, { ...peer, id });applied++;} else {diff --git a/server/services/catalogSync.userTypes.test.js b/server/services/catalogSync.userTypes.test.jsindex b320a3178b..0fdab44115 100644--- a/server/services/catalogSync.userTypes.test.js+++ b/server/services/catalogSync.userTypes.test.js@@ -80,6 +80,21 @@ describe('applyRemoteChanges — catalogTypes LWW merge', () => {expect(store.catalogUserTypes[0].label).toBe('New');});+ it('LWW: an equal-clock echo of a held type is a no-op (sync converges)', async () => {+ // Regression: the merge used `>=`, so a peer re-sending a type we already+ // hold at the SAME updatedAt was re-adopted, re-written, and re-counted as+ // an applied change every cycle — the "Synced: N catalog changes" log never+ // dropped to 0. Strict `>` makes an equal clock a skip, so it converges.+ store = { catalogUserTypes: [{ id: 'faction', label: 'Faction', primaryContentKey: 'creed', fields: [], updatedAt: '2026-01-01' }] };+ const echo = { id: 'faction', label: 'Faction', primaryContentKey: 'creed', fields: [], updatedAt: '2026-01-01' };+ for (let cycle = 0; cycle < 3; cycle++) {+ const stats = await applyRemoteChanges({ portosMeta: meta, catalogTypes: [echo] });+ expect(stats.catalogTypes.applied).toBe(0);+ expect(stats.catalogTypes.skipped).toBe(1);+ }+ expect(store.catalogUserTypes).toHaveLength(1);+ });+it('skips a peer type colliding with a built-in system id', async () => {const stats = await applyRemoteChanges({ portosMeta: meta, catalogTypes: [{ id: 'character', label: 'Hijack', primaryContentKey: 'x', fields: [], updatedAt: '2027-01-01' }] });expect(stats.catalogTypes.applied).toBe(0);