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

address review (codex): strip catalogBundle (like portosMeta) when an older peer's strict push schema rejects it

[._.]/ Adam Eivy76e3b1fd4b47
diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.js
index e1963a033e..c6e1f9f254 100644
--- a/server/services/sharing/peerSync.js
+++ b/server/services/sharing/peerSync.js
@@ -847,15 +847,27 @@ export async function pushRecordToPeer(sub, options = {}) {
// see schemaVersions, but until the user upgrades it that's the
// best-effort behavior we want (vs. permanently stranded pushes). Once
// they upgrade, the next push round naturally re-includes `portosMeta`.
- if (res && res.status === 400 && payload.portosMeta) {
+ // `catalogBundle` (catalog-federation push enrichment) is a second new
+ // top-level key an even-newer-than-version-gate-but-pre-catalog peer's strict
+ // schema also rejects. Strip whichever key(s) the receiver actually named —
+ // surgically, so a peer that supports `portosMeta` but not `catalogBundle`
+ // keeps its version-gate handshake. Zod `.strict()` lists all unrecognized
+ // keys in one issue, so a single retry covers both.
+ if (res && res.status === 400 && (payload.portosMeta || payload.catalogBundle)) {
const errBody = await res.clone().json().catch(() => null);
const details = Array.isArray(errBody?.context?.details) ? errBody.context.details : [];
- const mentionsMeta = details.some((d) => /portosMeta/.test(`${d?.path || ''} ${d?.message || ''}`));
- if (errBody?.code === 'VALIDATION_ERROR' && mentionsMeta) {
+ const mentions = (key) => details.some((d) => new RegExp(key).test(`${d?.path || ''} ${d?.message || ''}`));
+ if (errBody?.code === 'VALIDATION_ERROR' && (mentions('portosMeta') || mentions('catalogBundle'))) {
+ const legacyPayload = { ...payload };
+ const stripped = [];
+ if (mentions('portosMeta') && 'portosMeta' in legacyPayload) { delete legacyPayload.portosMeta; stripped.push('portosMeta'); }
+ if (mentions('catalogBundle') && 'catalogBundle' in legacyPayload) { delete legacyPayload.catalogBundle; stripped.push('catalogBundle'); }
+ // The universe record still lands; on a pre-catalog peer the catalog
+ // enrichments simply re-derive from the embedded canon on its backfill,
+ // and a re-push after it upgrades re-includes the stripped key(s).
console.log(
- `ℹ️ peerSync: ${peer.name || peer.instanceId} is on a pre-version-gate PortOS — retrying push without portosMeta envelope`,
+ `ℹ️ peerSync: ${peer.name || peer.instanceId} rejected newer envelope key(s) ${stripped.join(', ')} — retrying push without them`,
);
- const { portosMeta: _strip, ...legacyPayload } = payload;
res = await postPayload(legacyPayload);
}
}
diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.js
index a279cdd8be..876265c61f 100644
--- a/server/services/sharing/peerSync.test.js
+++ b/server/services/sharing/peerSync.test.js
@@ -2534,6 +2534,42 @@ describe('peerSync', () => {
expect(retryPayload.sourceInstanceId).toBe(firstPayload.sourceInstanceId);
});
+ it('falls back without catalogBundle when an older peer rejects the new key, keeping portosMeta', async () => {
+ // A peer that supports portosMeta but predates catalog federation
+ // rejects the new `catalogBundle` key with a strict VALIDATION_ERROR.
+ // The sender must strip ONLY catalogBundle (not portosMeta, which the
+ // peer supports) and retry, so the universe push still lands — the
+ // receiver re-derives the catalog enrichments from the embedded canon.
+ vi.mocked(getBackendName).mockReturnValue('postgres');
+ vi.mocked(getUniverse).mockResolvedValue({ id: 'u1', name: 'Foo' });
+ vi.mocked(getCatalogBundleForRef).mockResolvedValue({
+ ingredients: [{ id: 'cat-chr-1', type: 'character', name: 'Hero', updatedAt: '2026-01-02T00:00:00Z' }],
+ refs: [{ ingredientId: 'cat-chr-1', refKind: 'universe', refId: 'u1', role: 'canon-character', createdAt: '2026-01-02T00:00:00Z' }],
+ });
+ const firstCallBody = { ok: false, status: 400, json: async () => ({
+ code: 'VALIDATION_ERROR',
+ message: 'Validation failed',
+ context: { details: [{ path: '', message: "Unrecognized key(s) in object: 'catalogBundle'" }] },
+ }) };
+ firstCallBody.clone = () => firstCallBody;
+ const retryBody = { ok: true, status: 200, json: async () => ({}) };
+ vi.mocked(peerFetch).mockResolvedValueOnce(firstCallBody).mockResolvedValueOnce(retryBody);
+ const sub = await subscribePeer({
+ peerId: 'peer-a', recordKind: 'universe', recordId: 'u1',
+ }, { adoptedFromReverse: true });
+ const result = await pushRecordToPeer(sub);
+ expect(result.pushed).toBe(true);
+ const calls = vi.mocked(peerFetch).mock.calls;
+ expect(calls.length).toBe(2);
+ const firstPayload = JSON.parse(calls[0][1].body);
+ const retryPayload = JSON.parse(calls[1][1].body);
+ expect(firstPayload.catalogBundle).toBeDefined();
+ expect(retryPayload.catalogBundle).toBeUndefined();
+ // Surgical strip: portosMeta survives because the peer didn't reject it.
+ expect(retryPayload.portosMeta).toBeDefined();
+ expect(retryPayload.record.id).toBe('u1');
+ });
+
it('does NOT retry on a 400 whose validation error is unrelated to portosMeta', async () => {
// The retry is keyed on the `portosMeta` mention in the validation
// details — any other 400 (oversized field, unknown record key, etc.)