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: gate, hash, and ack the bundled linkedTrack like other bundles (#1858)
[._.]/ Adam Eivy82812b41afed
diff --git a/server/lib/peerSyncValidation.js b/server/lib/peerSyncValidation.jsindex 777fb9fe5e..245d975e8c 100644--- a/server/lib/peerSyncValidation.js+++ b/server/lib/peerSyncValidation.js@@ -238,15 +238,23 @@ const writersRoomExercisePushSchema = z.object({kind: z.literal('writersRoomExercise'),...peerSyncPushBase,}).strict();+// Optional bundled linked-track record (#1858) — a music-video project created+// the create-UI way stores `trackId` (not `uploadedAudioFilename`), so its+// master audio rides as a `music` asset-manifest entry AND the linked track+// RECORD rides here, so a peer subscribed to musicVideoProjects ONLY (no Tracks+// category) can resolve `project.trackId` at render time. ONLY valid on a+// music-video push (a track push IS the track; other kinds' `.strict()` reject+// it). Same wire shape as any record (id required, sanitizer handles the rest).+const linkedTrackField = { linkedTrack: peerWireRecordSchema.optional() };// Music Video projects (#1770) push the bare record (metadata + beat-aligned-// scenes[]) — no bundled children/linked collection. #1772 bundles referenced-// media (uploaded audio as a `music` entry, rendered scene clips as `video`-// entries) via the base `assetManifest`, which already accepts both kinds; no-// project-specific manifest field is needed (`.strict()` still rejects smuggled-// bundle keys, same posture as creativeDirectorProject/writersRoomFolder).+// scenes[]). #1772 bundles referenced media (uploaded audio as a `music` entry,+// rendered scene clips as `video` entries) via the base `assetManifest`; #1858+// adds the optional `linkedTrack` record bundle above (`.strict()` still rejects+// any OTHER smuggled bundle key, same posture as creativeDirectorProject).const musicVideoProjectPushSchema = z.object({kind: z.literal('musicVideoProject'),...peerSyncPushBase,+ ...linkedTrackField,}).strict();export const peerSyncPushSchema = z.discriminatedUnion('kind', [universePushSchema,diff --git a/server/routes/peerSync.test.js b/server/routes/peerSync.test.jsindex 3090df695d..58b5bb3061 100644--- a/server/routes/peerSync.test.js+++ b/server/routes/peerSync.test.js@@ -235,6 +235,37 @@ describe('peer-sync routes', () => {expect(res.status).toBe(200);});+ it('accepts a linkedTrack bundle on a music-video push (#1858)', async () => {+ // Regression: musicVideoProjectPushSchema's strict() branch must include+ // `linkedTrack` — without it every track-linked project push would 400 at+ // the receiver before its merge, stranding the master audio.+ svc.applyIncomingPush.mockResolvedValue({ missingAssets: [], reverseSubscriptionCreated: false, ackedDeletesUpTo: 0 });+ const res = await request(buildApp())+ .post('/api/peer-sync/push')+ .send({+ kind: 'musicVideoProject',+ record: { id: 'mv-1', trackId: 'track-1' },+ assetManifest: [],+ linkedTrack: { id: 'track-1', audioFilename: 'song.mp3' },+ sourceInstanceId: 'peer-a',+ });+ expect(res.status).toBe(200);+ });++ it('400s when a track push carries linkedTrack (no smuggled extra track)', async () => {+ const res = await request(buildApp())+ .post('/api/peer-sync/push')+ .send({+ kind: 'track',+ record: { id: 'track-1' },+ assetManifest: [],+ linkedTrack: { id: 'track-smuggled' },+ sourceInstanceId: 'peer-a',+ });+ expect(res.status).toBe(400);+ expect(svc.applyIncomingPush).not.toHaveBeenCalled();+ });+it('400s when a mediaCollection push carries linkedCollection (no smuggled extra collection)', async () => {// A mediaCollection push IS the collection — accepting linkedCollection// would be a side-channel to overwrite an unrelated collection.diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.jsindex 6baf2b2114..760d897054 100644--- a/server/services/sharing/peerSync.test.js+++ b/server/services/sharing/peerSync.test.js@@ -2643,6 +2643,21 @@ describe('peerSync', () => {expect(mergeTracksFromSync).not.toHaveBeenCalled();});+ it('signals trackSyncPending when the bundled linkedTrack merge fails (#1858)', async () => {+ // The linked track has no independent reconciliation cycle for a+ // musicVideoProjects-only subscriber, so a swallowed failure must surface+ // a pending flag that makes the sender withhold its hash and re-send.+ vi.mocked(mergeTracksFromSync).mockRejectedValueOnce(new Error('disk full'));+ const res = await applyIncomingPush({+ kind: 'musicVideoProject',+ record: { id: 'mv-9', trackId: 'track-9', deleted: false, deletedAt: null },+ linkedTrack: { id: 'track-9', audioFilename: 'linked.mp3' },+ assetManifest: [],+ sourceInstanceId: 'peer-a',+ });+ expect(res.trackSyncPending).toBe(true);+ });+it('routes a bundled manuscriptReview through mergeReviewFromSync on a series push', async () => {const manuscriptReview = {schemaVersion: 1,diff --git a/server/services/sharing/peerSyncPush.js b/server/services/sharing/peerSyncPush.jsindex c79e326898..134db92460 100644--- a/server/services/sharing/peerSyncPush.js+++ b/server/services/sharing/peerSyncPush.js@@ -210,6 +210,7 @@ export async function pushRecordToPeer(sub, options = {}) {record: payload.record,issues: payload.issues ?? null,linkedCollection: payload.linkedCollection ?? null,+ linkedTrack: payload.linkedTrack ?? null,manuscriptReview: payload.manuscriptReview ?? null,reverseOutline: payload.reverseOutline ?? null,assetManifest: payload.assetManifest ?? [],@@ -246,6 +247,12 @@ export async function pushRecordToPeer(sub, options = {}) {// a pre-#1348 peer's strict series schema rejects the `reverseOutline` key, so// the retry strips it and we withhold the hash to re-send once it upgrades.let outlineStrippedForLegacyPeer = false;+ // Same as the two flags above, for the #1858 bundled linked-track record — a+ // pre-feature peer's strict musicVideoProject push schema rejects the+ // `linkedTrack` key, so the retry strips it and we withhold the hash to+ // re-send once it upgrades (the track has no independent cycle for a+ // musicVideoProjects-only subscriber).+ let trackStrippedForLegacyPeer = false;// MIXED-VERSION COMPAT: an older receiver's push schema is still `.strict()`// without a `portosMeta` field, so it 400-rejects our envelope at Zod// validation BEFORE its schema-version gate code (which doesn't exist on@@ -278,8 +285,8 @@ export async function pushRecordToPeer(sub, options = {}) {const mentions = (key) => details.some((d) => new RegExp(key).test(`${d?.path || ''} ${d?.message || ''}`));if (isValidationError- && (payload.portosMeta || payload.catalogBundle || payload.manuscriptReview || payload.reverseOutline)- && (mentions('portosMeta') || mentions('catalogBundle') || mentions('manuscriptReview') || mentions('reverseOutline'))+ && (payload.portosMeta || payload.catalogBundle || payload.manuscriptReview || payload.reverseOutline || payload.linkedTrack)+ && (mentions('portosMeta') || mentions('catalogBundle') || mentions('manuscriptReview') || mentions('reverseOutline') || mentions('linkedTrack'))) {// (1) UNKNOWN ENVELOPE KEY — the peer recognizes the record `kind` but its// `.strict()` schema predates a newer top-level key we sent. Strip whichever@@ -291,6 +298,7 @@ export async function pushRecordToPeer(sub, options = {}) {if (mentions('catalogBundle') && 'catalogBundle' in legacyPayload) { delete legacyPayload.catalogBundle; stripped.push('catalogBundle'); }if (mentions('manuscriptReview') && 'manuscriptReview' in legacyPayload) { delete legacyPayload.manuscriptReview; stripped.push('manuscriptReview'); reviewStrippedForLegacyPeer = true; }if (mentions('reverseOutline') && 'reverseOutline' in legacyPayload) { delete legacyPayload.reverseOutline; stripped.push('reverseOutline'); outlineStrippedForLegacyPeer = true; }+ if (mentions('linkedTrack') && 'linkedTrack' in legacyPayload) { delete legacyPayload.linkedTrack; stripped.push('linkedTrack'); trackStrippedForLegacyPeer = true; }console.log(`ℹ️ peerSync: ${peer.name || peer.instanceId} rejected newer envelope key(s) ${stripped.join(', ')} — retrying push without them`,);@@ -399,6 +407,12 @@ export async function pushRecordToPeer(sub, options = {}) {// the key for a pre-#1348 peer). The outline has no independent reconciliation// path, so withhold lastPushedHash to re-send next cycle.const outlineSyncPending = body?.outlineSyncPending === true || outlineStrippedForLegacyPeer;+ // TRACK-STRANDED GUARD: same as the review/outline guards — the receiver merged+ // the project (returned 2xx) but its bundled linked-track merge threw, OR we+ // stripped the key for a pre-#1858 peer. The track has no independent+ // reconciliation path for a musicVideoProjects-only subscriber, so withhold+ // lastPushedHash to re-send next cycle.+ const trackSyncPending = body?.trackSyncPending === true || trackStrippedForLegacyPeer;// This push landed (receiver returned 2xx). Stamp the per-record confirmed-// delivery water-mark so tombstoneGc won't prune THIS record's tombstone// until its delete-push has been confirmed — even if a later push for a@@ -408,7 +422,7 @@ export async function pushRecordToPeer(sub, options = {}) {// the tombstone's deletedAt once it lands. The `missingAssets` case still// counts as confirmed delivery of the RECORD (merge ran on the receiver);// only the asset-stranded hash is withheld, not the confirmation mark.- await persistPushSuccess(sub.id, (missingCount > 0 || reviewSyncPending || outlineSyncPending) ? null : hash, { confirmedAtMs: Date.now() });+ await persistPushSuccess(sub.id, (missingCount > 0 || reviewSyncPending || outlineSyncPending || trackSyncPending) ? null : hash, { confirmedAtMs: Date.now() });if (Number.isFinite(body?.ackedDeletesUpTo) && body.ackedDeletesUpTo > 0) {await ackDeletesUpTo(sub.peerId, body.ackedDeletesUpTo).catch(() => {});}diff --git a/server/services/sharing/peerSyncReceive.js b/server/services/sharing/peerSyncReceive.jsindex 13d7c203e4..c9041557a1 100644--- a/server/services/sharing/peerSyncReceive.js+++ b/server/services/sharing/peerSyncReceive.js@@ -186,6 +186,14 @@ export async function applyIncomingPush(payload) {catalogBundle.ingredients.some((i) => i?.deleted !== true)) {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+ // the `tracks` category so a sender ahead on the track schema can't smuggle a+ // forward-shaped track row past the gate via a music-video push (same reasoning+ // as the linkedCollection gate above). Skip the gate for a tombstone track —+ // id+deleted+deletedAt+updatedAt is schema-safe at every version.+ if (record.deleted !== true && isPlainObject(linkedTrack) && linkedTrack.deleted !== true) {+ for (const c of RECORD_KIND_SCHEMA_CATEGORIES.track) relevantCategories.add(c);+ }const fullDiff = compareSchemaVersions(senderSchemaVersions, PORTOS_SCHEMA_VERSIONS);const versionDiff = scopeVersionDiff(fullDiff, [...relevantCategories]);if (versionDiff.ahead.length > 0) {@@ -246,6 +254,11 @@ export async function applyIncomingPush(payload) {let reviewSyncPending = false;// Same contract as reviewSyncPending, for the bundled reverse-outline doc.let outlineSyncPending = false;+ // Same contract again, for the #1858 bundled linked-track record: a+ // musicVideoProjects-only subscriber has NO independent `tracks` sync cycle,+ // so a swallowed merge failure would strand the record the receiver needs to+ // render. Signal so the sender withholds lastPushedHash and re-sends.+ let trackSyncPending = false;// Set true when a writersRoomWork merge accepted the remote (insert/remote-won)// — gates whether a present-but-different local draft body may be overwritten.let workMergeApplied = false;@@ -325,6 +338,7 @@ export async function applyIncomingPush(payload) {if (!localEphemeral && record.deleted !== true && isPlainObject(linkedTrack)) {await mergeTracksFromSync([linkedTrack], { source }).catch((err) => {console.log(`⚠️ peerSync: linkedTrack merge failed: ${err.message}`);+ trackSyncPending = true;});}}@@ -456,6 +470,7 @@ export async function applyIncomingPush(payload) {ackedDeletesUpTo,...(reviewSyncPending ? { reviewSyncPending: true } : {}),...(outlineSyncPending ? { outlineSyncPending: true } : {}),+ ...(trackSyncPending ? { trackSyncPending: true } : {}),};}