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

fix: gate catalog-bundle pushes on live rows in any block, not just ingredients (#3926)

[._.]/ Adam Eivy23b49f9d9e81
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 464df12029..8a1fb0d973 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -38,6 +38,8 @@
## Changed
+- A federated catalog bundle whose live rows sit outside `ingredients` no longer bypasses the peer-sync schema-version gate. `applyIncomingPush` decided whether to gate the `catalog` category by looking at `catalogBundle.ingredients` alone, but the exporter already ships ingredient-free bundles (`refs` only), and catalog schema v4–v8 added `relations`, `tags`, `media` and `catalogTypes` blocks — so a peer on a newer catalog schema could push forward-shaped rows straight into an older receiver, which then tried to apply structures it can't interpret. The gate now counts a live row in ANY block of the bundle, including one added by a catalog version newer than the receiver knows about, and such a push is rejected with the usual 409 `PEER_SYNC_SCHEMA_VERSION_AHEAD`. Tombstone-only bundles stay exempt, so federated catalog deletes still converge across a version gap.
+
- Adding an app no longer writes a PM2 config into the project on its own. Importing a directory ran the PM2 standardizer the instant detection finished — dropping an `ecosystem.config.cjs` into the repo, commenting the ports out of its `.env` and Vite config, and cutting a git backup branch — before you had even saved the app. Only iOS/macOS/Swift/Xcode projects were exempt, so Docker stacks, Python services, static sites, and anything else you start another way all got a PM2 config they will never use, plus an LLM call nobody asked for. Standardizing is now a button in the Add App wizard that says what it will rewrite, and it is still available later from the Apps list. The wizard also shows the standardizer's live per-step detail while it runs (including the "no git repository, backup skipped" case) instead of one undifferentiated row.
- Standardizing an app is now refused server-side for apps PortOS never runs under PM2, and for PortOS itself. The rule previously lived only in which buttons happened to render, so the socket and HTTP entry points would happily standardize an iOS app — or rewrite PortOS's own `ecosystem.config.cjs`, the canonical source of its port map, from an LLM analysis. The Standardize button on an app's Overview tab is now hidden for PortOS too, matching the Archive button beside it.
diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.js
index 52375b36e1..163ebdffb6 100644
--- a/server/services/sharing/peerSync.test.js
+++ b/server/services/sharing/peerSync.test.js
@@ -3501,6 +3501,69 @@ describe('peerSync', () => {
// Gated before merge — bundle apply never runs.
expect(applyCatalogRemoteChanges).not.toHaveBeenCalled();
});
+
+ // #3926: the gate used to key on `ingredients` alone, so any bundle whose
+ // live rows sat in another block (`refs` today; `relations`/`tags`/`media`/
+ // `catalogTypes` from catalog v4–v8) slipped past it and got applied on a
+ // receiver that can't interpret the newer shape.
+ it.each([
+ ['relations', { ingredients: [], refs: [], relations: [{ fromIngredientId: 'cat-chr-1', toIngredientId: 'cat-chr-2', kind: 'ally-of', updatedAt: '2026-01-02T00:00:00Z' }] }],
+ ['tags', { ingredients: [], refs: [], tags: [{ id: 'cat-tag-1', label: 'Protagonists', parentId: null, updatedAt: '2026-01-02T00:00:00Z' }] }],
+ ['media', { ingredients: [], media: [{ ingredientId: 'cat-chr-1', mediaKey: 'img-1', mediaType: 'image', updatedAt: '2026-01-02T00:00:00Z' }] }],
+ ['refs', { ingredients: [], refs: [{ ingredientId: 'cat-chr-1', refKind: 'universe', refId: 'u1', role: 'canon-character', createdAt: '2026-01-02T00:00:00Z' }] }],
+ // A block this receiver's catalog version doesn't know about yet must
+ // gate too — that is precisely the payload the gate protects against.
+ ['an unknown future block', { ingredients: [], refs: [], someFutureBlock: [{ id: 'x1', updatedAt: '2026-01-02T00:00:00Z' }] }],
+ ])('receiver rejects a bundle whose only live rows are %s when the sender is schema-ahead on catalog', async (_label, catalogBundle) => {
+ vi.mocked(getBackendName).mockReturnValue('postgres');
+ const rejection = await applyIncomingPush({
+ kind: 'universe',
+ record: { id: 'u1', name: 'Foo', deleted: false, deletedAt: null },
+ assetManifest: [],
+ catalogBundle,
+ sourceInstanceId: 'peer-a',
+ portosMeta: { schemaVersions: { ...PORTOS_SCHEMA_VERSIONS, catalog: PORTOS_SCHEMA_VERSIONS.catalog + 1 }, portosVersion: '99.0.0' },
+ }).catch((err) => err);
+ expect(rejection.code).toBe('PEER_SYNC_SCHEMA_VERSION_AHEAD');
+ expect(rejection.details.ahead).toEqual([
+ { category: 'catalog', senderV: PORTOS_SCHEMA_VERSIONS.catalog + 1, receiverV: PORTOS_SCHEMA_VERSIONS.catalog },
+ ]);
+ expect(applyCatalogRemoteChanges).not.toHaveBeenCalled();
+ });
+
+ it('receiver applies an ingredient-free bundle when the sender is NOT schema-ahead', async () => {
+ // The widened gate must not turn into a blanket rejection: an
+ // equal-version sender's relations-only bundle still applies.
+ vi.mocked(getBackendName).mockReturnValue('postgres');
+ await applyIncomingPush({
+ kind: 'universe',
+ record: { id: 'u1', name: 'Foo', deleted: false, deletedAt: null },
+ assetManifest: [],
+ catalogBundle: { ingredients: [], refs: [], relations: [{ fromIngredientId: 'cat-chr-1', toIngredientId: 'cat-chr-2', kind: 'ally-of', updatedAt: '2026-01-02T00:00:00Z' }] },
+ sourceInstanceId: 'peer-a',
+ portosMeta: { schemaVersions: { ...PORTOS_SCHEMA_VERSIONS } },
+ });
+ expect(applyCatalogRemoteChanges).toHaveBeenCalledTimes(1);
+ });
+
+ it('receiver does NOT gate a tombstone-only bundle from a schema-ahead sender', async () => {
+ // Tombstone rows are id+deleted+deletedAt+updatedAt at every catalog
+ // version, so they stay exempt — otherwise federated catalog deletes
+ // would stall the moment one peer upgrades ahead.
+ vi.mocked(getBackendName).mockReturnValue('postgres');
+ await applyIncomingPush({
+ kind: 'universe',
+ record: { id: 'u1', name: 'Foo', deleted: false, deletedAt: null },
+ assetManifest: [],
+ catalogBundle: {
+ ingredients: [{ id: 'cat-chr-1', deleted: true, deletedAt: '2026-03-01T00:00:00Z', updatedAt: '2026-03-01T00:00:00Z' }],
+ relations: [{ id: 'cat-rel-1', deleted: true, deletedAt: '2026-03-01T00:00:00Z', updatedAt: '2026-03-01T00:00:00Z' }],
+ },
+ sourceInstanceId: 'peer-a',
+ portosMeta: { schemaVersions: { ...PORTOS_SCHEMA_VERSIONS, catalog: PORTOS_SCHEMA_VERSIONS.catalog + 1 }, portosVersion: '99.0.0' },
+ });
+ expect(applyCatalogRemoteChanges).toHaveBeenCalledTimes(1);
+ });
});
// -------------------------------------------------------------------------
diff --git a/server/services/sharing/peerSyncReceive.js b/server/services/sharing/peerSyncReceive.js
index a0e374aeb7..9d0448b685 100644
--- a/server/services/sharing/peerSyncReceive.js
+++ b/server/services/sharing/peerSyncReceive.js
@@ -82,6 +82,22 @@ async function applyCatalogBundle(catalogBundle, portosMeta) {
});
}
+/**
+ * True when a catalog bundle carries at least one LIVE (non-tombstone) row in
+ * any of its blocks. Every block of the catalog sync envelope is an array of
+ * rows (`ingredients`, `refs`, `relations`, `tags`, `media`, `catalogTypes`,
+ * …), so we scan array-valued keys generically instead of enumerating them —
+ * a block added by a catalog schema version NEWER than this receiver still
+ * counts, which is exactly the case the version gate exists to catch. A row
+ * that isn't a plain object counts as live (conservative: gate rather than
+ * wave through something we can't classify).
+ */
+function catalogBundleHasLiveRow(catalogBundle) {
+ return Object.values(catalogBundle).some(
+ (block) => Array.isArray(block) && block.some((row) => row?.deleted !== true),
+ );
+}
+
// --- Receiver-side push handler -----------------------------------------
/**
@@ -163,15 +179,21 @@ export async function applyIncomingPush(payload) {
if (record.deleted !== true && isPlainObject(linkedCollection) && linkedCollection.deleted !== true) {
for (const c of RECORD_KIND_SCHEMA_CATEGORIES.mediaCollection) relevantCategories.add(c);
}
- // A catalog bundle ships catalog-schema-shaped ingredient rows. Gate the
- // `catalog` category whenever the bundle carries at least one LIVE ingredient
- // — a sender ahead on `catalog` would push forward-shaped payload an older
- // receiver can't interpret. Tombstone-only bundles (all ingredients deleted)
- // are id+deleted+deletedAt+updatedAt — safe at every version, so they needn't
+ // A catalog bundle ships catalog-schema-shaped rows. Gate the `catalog`
+ // category whenever the bundle carries at least one LIVE row in ANY of its
+ // blocks — a sender ahead on `catalog` would otherwise push forward-shaped
+ // payload an older receiver can't interpret. The check must NOT be keyed on
+ // `ingredients` alone: today's exporter already emits ingredient-free
+ // bundles (`refs` only), and catalog v4–v8 added `relations`, `tags`,
+ // `media` and `catalogTypes` blocks — any of which a newer sender can bundle
+ // with no ingredients at all, slipping past an ingredients-only gate and
+ // landing forward-shaped rows on an older receiver (#3926). Scanning every
+ // array-valued block rather than an enumerated key list also covers blocks
+ // introduced by a FUTURE catalog version, which an older receiver cannot
+ // name by definition. Tombstone-only bundles (every row deleted) are
+ // id+deleted+deletedAt+updatedAt — safe at every version, so they needn't
// gate (same reasoning as the tombstone-record exemption above).
- if (record.deleted !== true && isPlainObject(catalogBundle) &&
- Array.isArray(catalogBundle.ingredients) &&
- catalogBundle.ingredients.some((i) => i?.deleted !== true)) {
+ if (record.deleted !== true && isPlainObject(catalogBundle) && catalogBundleHasLiveRow(catalogBundle)) {
for (const c of (RECORD_KIND_SCHEMA_CATEGORIES['cat-ingredient'] || ['catalog'])) relevantCategories.add(c);
}
// A bundled linked track (#1858) ships a live, full-shape `track` record. Gate