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([manuscript-review-sync]): address codex review — allow manuscriptReview through the push schema + older-peer strip-retry
[._.]/ Adam Eivyd3282b644418
diff --git a/server/lib/validation.js b/server/lib/validation.jsindex d3dbadb571..558baed415 100644--- a/server/lib/validation.js+++ b/server/lib/validation.js@@ -1510,10 +1510,26 @@ const universePushSchema = z.object({...linkedCollectionField,...catalogBundleField,}).strict();+// Optional bundled manuscript-review sibling doc — a series push carries the+// "Finish the draft" comment set (data/pipeline-series/{id}/manuscript-review.json)+// so review-only edits propagate via the per-record push pipeline. ONLY valid on+// series pushes. `.passthrough()` on the review + each comment (same rationale as+// portosMeta) so a newer sender that adds a comment field doesn't 400 at this+// receiver BEFORE its merge — `sanitizeReview` clamps/drops everything on apply.+// Comments are bounded (5000) so the array can't be used to force unbounded work.+const manuscriptReviewField = {+ manuscriptReview: z.object({+ schemaVersion: z.number().int().min(0).max(1_000_000).optional(),+ comments: z.array(z.object({+ id: z.string().trim().min(1).max(120),+ }).passthrough()).max(5000),+ }).passthrough().optional(),+};const seriesPushSchema = z.object({kind: z.literal('series'),...peerSyncPushBase,...linkedCollectionField,+ ...manuscriptReviewField,issues: z.array(peerWireRecordSchema).max(1000).optional(),}).strict();const mediaCollectionPushSchema = z.object({diff --git a/server/routes/peerSync.test.js b/server/routes/peerSync.test.jsindex 357272bb43..05a33fcbac 100644--- a/server/routes/peerSync.test.js+++ b/server/routes/peerSync.test.js@@ -110,6 +110,44 @@ describe('peer-sync routes', () => {}));});+ it('accepts a series push that bundles a manuscriptReview (Finish-the-draft comment set)', async () => {+ // Regression: seriesPushSchema is `.strict()`, so without the+ // manuscriptReview field the production review-bearing series push 400s+ // at the Zod boundary before applyIncomingPush ever runs.+ svc.applyIncomingPush.mockResolvedValue({ missingAssets: [], reverseSubscriptionCreated: false, ackedDeletesUpTo: 0 });+ const res = await request(buildApp())+ .post('/api/peer-sync/push')+ .send({+ kind: 'series',+ record: { id: 's1' },+ issues: [],+ manuscriptReview: {+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }],+ },+ assetManifest: [],+ sourceInstanceId: 'peer-a',+ });+ expect(res.status).toBe(200);+ expect(svc.applyIncomingPush).toHaveBeenCalledWith(expect.objectContaining({+ manuscriptReview: expect.objectContaining({ comments: expect.any(Array) }),+ }));+ });++ it('400s when a universe push carries manuscriptReview (series-only field, no side-channel)', async () => {+ const res = await request(buildApp())+ .post('/api/peer-sync/push')+ .send({+ kind: 'universe',+ record: { id: 'u1' },+ assetManifest: [],+ manuscriptReview: { schemaVersion: 1, comments: [] },+ sourceInstanceId: 'peer-a',+ });+ expect(res.status).toBe(400);+ expect(svc.applyIncomingPush).not.toHaveBeenCalled();+ });+it('400s on an invalid kind (Zod boundary catches before service)', async () => {const res = await request(buildApp()).post('/api/peer-sync/push')diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.jsindex 451596fb48..46cb5c50e3 100644--- a/server/services/sharing/peerSync.js+++ b/server/services/sharing/peerSync.js@@ -966,22 +966,30 @@ export async function pushRecordToPeer(sub, options = {}) {// they upgrade, the next push round naturally re-includes `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)) {+ // schema also rejects. `manuscriptReview` (the bundled "Finish the draft"+ // review doc) is a third — a pre-feature peer's series push schema is still+ // `.strict()` without it, so it 400-rejects a review-bearing series push and+ // would strand the series + issues. This retry is exactly what makes the+ // review's "degrades gracefully on older peers" contract hold (see+ // schemaVersions.js): strip the unknown key the older peer can't parse so the+ // record/issues still land; the review reaches it once it upgrades. Strip+ // whichever key(s) the receiver actually named — surgically, so a peer that+ // supports `portosMeta` but not `catalogBundle`/`manuscriptReview` keeps its+ // version-gate handshake. Zod `.strict()` lists all unrecognized keys in one+ // issue, so a single retry covers all of them.+ if (res && res.status === 400 && (payload.portosMeta || payload.catalogBundle || payload.manuscriptReview)) {const errBody = await res.clone().json().catch(() => null);const details = Array.isArray(errBody?.context?.details) ? errBody.context.details : [];const mentions = (key) => details.some((d) => new RegExp(key).test(`${d?.path || ''} ${d?.message || ''}`));- if (errBody?.code === 'VALIDATION_ERROR' && (mentions('portosMeta') || mentions('catalogBundle'))) {+ if (errBody?.code === 'VALIDATION_ERROR' && (mentions('portosMeta') || mentions('catalogBundle') || mentions('manuscriptReview'))) {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).+ if (mentions('manuscriptReview') && 'manuscriptReview' in legacyPayload) { delete legacyPayload.manuscriptReview; stripped.push('manuscriptReview'); }+ // The series + issues still land; on a pre-feature peer the review simply+ // doesn't propagate until it upgrades, and a re-push after it upgrades+ // re-includes the stripped key(s).console.log(`ℹ️ peerSync: ${peer.name || peer.instanceId} rejected newer envelope key(s) ${stripped.join(', ')} — retrying push without them`,);diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.jsindex 0408ad8e3c..67d9800147 100644--- a/server/services/sharing/peerSync.test.js+++ b/server/services/sharing/peerSync.test.js@@ -2864,6 +2864,44 @@ describe('peerSync', () => {expect(retryPayload.record.id).toBe('u1');});+ it('falls back without manuscriptReview when a pre-feature peer rejects the new key, keeping series + issues', async () => {+ // A pre-manuscript-review-sync peer's seriesPushSchema is still+ // `.strict()` without `manuscriptReview`, so it 400-rejects a review-+ // bearing series push. The sender must strip ONLY manuscriptReview and+ // retry so the series + issues still land (the review reaches the peer+ // once it upgrades). This is what makes the review's "degrades+ // gracefully on older peers" contract hold.+ vi.mocked(getSeries).mockResolvedValue({ id: 's1', name: 'Series' });+ vi.mocked(listIssues).mockResolvedValue([{ id: 'i1', seriesId: 's1', number: 1 }]);+ vi.mocked(getReview).mockResolvedValue({+ schemaVersion: 1,+ comments: [{ id: 'mrc-1', problem: 'pacing', status: 'open', updatedAt: '2026-06-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: 'manuscriptReview'" }] },+ }) };+ 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: 'series', recordId: 's1',+ }, { 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.manuscriptReview).toBeDefined();+ expect(retryPayload.manuscriptReview).toBeUndefined();+ // Surgical strip: portosMeta survives, and the series + issues still land.+ expect(retryPayload.portosMeta).toBeDefined();+ expect(retryPayload.record.id).toBe('s1');+ expect(retryPayload.issues).toHaveLength(1);+ });+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.)