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]): declare bundled review in the manifest so out-of-order cloud delivery can't drop it
[._.]/ Adam Eivy2a22cb632536
diff --git a/server/services/sharing/exporter.js b/server/services/sharing/exporter.jsindex 1db4d4c3d9..61ef71f847 100644--- a/server/services/sharing/exporter.js+++ b/server/services/sharing/exporter.js@@ -414,8 +414,10 @@ export async function exportSeries(seriesId, bucketId, opts = {}) {// Skip when empty so we don't litter the bucket with no-op review files; an// importer that finds no file simply leaves the local review untouched.const review = await getReview(series.id).catch(() => null);+ const reviewRefs = [];if (review && Array.isArray(review.comments) && review.comments.length > 0) {await atomicWrite(join(bucket.path, 'records', 'reviews', `${series.id}.json`), review);+ reviewRefs.push(series.id);}for (const issue of issues) {@@ -464,7 +466,7 @@ export async function exportSeries(seriesId, bucketId, opts = {}) {return [...jobRefGroups.flat(), ...imageRefs.filter(Boolean), ...videoRefs.filter(Boolean), ...imageRefRefs.filter(Boolean)];});- const manifest = { ...manifestStub, recordIds, assetRefs };+ const manifest = { ...manifestStub, recordIds, assetRefs, reviewRefs };const filename = await writeManifest(bucket.path, manifest);await pruneAfterExport(bucket, senderInstanceId);return { manifestId, filename, recordCount: recordIds.length, assetCount: assetRefs.length };diff --git a/server/services/sharing/importer.js b/server/services/sharing/importer.jsindex ad506f0d0b..04dc3b4cd3 100644--- a/server/services/sharing/importer.js+++ b/server/services/sharing/importer.js@@ -945,6 +945,18 @@ export async function processManifest(bucketId, manifestFilename) {}const { records, missing: missingRecords } = await readReferencedRecords(bucket.path, manifest);+ // Declared manuscript-review files (records/reviews/<seriesId>.json) that the+ // manifest says are bundled but haven't landed on disk yet. Cloud-relayed+ // buckets (Drive/Dropbox) deliver files out of order, so the manifest can be+ // processed before its review file syncs; without this wait the importer+ // would read null, treat it as "no review", and markProcessed — permanently+ // dropping the review. Mirror the missingRecords pending gate. Legacy+ // manifests have no `reviewRefs` → empty → no wait (back-compat).+ const declaredReviewRefs = Array.isArray(manifest.reviewRefs) ? manifest.reviewRefs : [];+ const missingReviews = declaredReviewRefs.filter(+ (sid) => isSafeRecordId(sid) && !existsSync(join(bucket.path, 'records', 'reviews', `${sid}.json`)),+ );+// Always copy assets + media-job records ahead of the merge so canon and// pipeline records that reference them point at present files. Asset and// record-bundle sync can both lag behind manifest sync in Drive/Dropbox/etc.;@@ -984,9 +996,10 @@ export async function processManifest(bucketId, manifestFilename) {console.log(`⚠️ sharing: bucket=${bucket.name} manifest=${manifest.id} kind=${manifest.kind} collectionUniverse=${collectionTombstonedUniverse} is deleted locally — ${outcome.collectionItemsDeferred ?? 0} item(s) skipped; restore universe to import`);return { processed: true, manifest, outcome };}- if (assetCopy.missing.length > 0 || missingRecords.length > 0 || collectionPendingUniverse || collectionPendingSeries || legacyCanonPendingUniverses || legacyCanonPendingFailures || recordImportFailures || reviewMergeFailures) {+ if (assetCopy.missing.length > 0 || missingRecords.length > 0 || missingReviews.length > 0 || collectionPendingUniverse || collectionPendingSeries || legacyCanonPendingUniverses || legacyCanonPendingFailures || recordImportFailures || reviewMergeFailures) {if (assetCopy.missing.length > 0) outcome.pendingAssets = assetCopy.missing;if (missingRecords.length > 0) outcome.pendingRecords = missingRecords;+ if (missingReviews.length > 0) outcome.pendingReviews = missingReviews;if (collectionPendingUniverse) outcome.pendingCollectionUniverse = collectionPendingUniverse;if (collectionPendingSeries) outcome.pendingCollectionSeries = collectionPendingSeries;if (legacyCanonPendingUniverses) outcome.pendingLegacyCanonUniverses = legacyCanonPendingUniverses;@@ -994,7 +1007,7 @@ export async function processManifest(bucketId, manifestFilename) {if (recordImportFailures) outcome.pendingRecordImportFailures = recordImportFailures;if (reviewMergeFailures) outcome.pendingReviewMergeFailures = reviewMergeFailures;sharingEvents.emit('manifest-processed', { bucketId, manifestId: manifest.id, manifestFilename, outcome });- console.log(`⏳ sharing: bucket=${bucket.name} manifest=${manifest.id} kind=${manifest.kind} mode=${bucket.mode} waitingForAssets=${assetCopy.missing.length} waitingForRecords=${missingRecords.length}${collectionPendingUniverse ? ` waitingForUniverse=${collectionPendingUniverse}` : ''}${collectionPendingSeries ? ` waitingForSeries=${collectionPendingSeries}` : ''}${legacyCanonPendingUniverses ? ` waitingForLegacyCanonUniverses=${legacyCanonPendingUniverses.join(',')}` : ''}${legacyCanonPendingFailures ? ` legacyCanonFailures=${legacyCanonPendingFailures.join(',')}` : ''}${recordImportFailures ? ` recordImportFailures=${recordImportFailures.join(',')}` : ''}${reviewMergeFailures ? ` reviewMergeFailures=${reviewMergeFailures.join(',')}` : ''}`);+ console.log(`⏳ sharing: bucket=${bucket.name} manifest=${manifest.id} kind=${manifest.kind} mode=${bucket.mode} waitingForAssets=${assetCopy.missing.length} waitingForRecords=${missingRecords.length}${missingReviews.length > 0 ? ` waitingForReviews=${missingReviews.length}` : ''}${collectionPendingUniverse ? ` waitingForUniverse=${collectionPendingUniverse}` : ''}${collectionPendingSeries ? ` waitingForSeries=${collectionPendingSeries}` : ''}${legacyCanonPendingUniverses ? ` waitingForLegacyCanonUniverses=${legacyCanonPendingUniverses.join(',')}` : ''}${legacyCanonPendingFailures ? ` legacyCanonFailures=${legacyCanonPendingFailures.join(',')}` : ''}${recordImportFailures ? ` recordImportFailures=${recordImportFailures.join(',')}` : ''}${reviewMergeFailures ? ` reviewMergeFailures=${reviewMergeFailures.join(',')}` : ''}`);return { processed: true, pending: true, manifest, outcome };}await markProcessed(bucketId, manifestFilename, manifest.id);@@ -1103,6 +1116,17 @@ export async function promoteInboxItem(bucketId, manifestId) {missingAssets: assetCopy.missing,});}+ // Same out-of-order delivery guard as the auto-merge path: a declared review+ // file that hasn't landed yet must block the promote, or applyAutoMerge would+ // read null and silently drop the review.+ const missingReviews = (Array.isArray(manifest.reviewRefs) ? manifest.reviewRefs : [])+ .filter((sid) => isSafeRecordId(sid) && !existsSync(join(bucket.path, 'records', 'reviews', `${sid}.json`)));+ if (missingReviews.length > 0) {+ throw Object.assign(new Error(`Manifest reviews are still syncing (${missingReviews.length} missing)`), {+ code: 'SHARING_REVIEWS_PENDING',+ missingReviews,+ });+ }await mergeMediaJobRecords(bucket.path, manifest.recordIds);const availableAssetKeys = new Set(assetCopy.available.map((ref) => `${ref.kind}:${ref.ref}`));const outcome = await applyAutoMerge(bucket, manifest, records, { availableAssetKeys });diff --git a/server/services/sharing/integration.test.js b/server/services/sharing/integration.test.jsindex c057085068..b1588ce3e5 100644--- a/server/services/sharing/integration.test.js+++ b/server/services/sharing/integration.test.js@@ -236,6 +236,38 @@ describe('sharing round-trip', () => {expect(existsSync(join(tempBucket, 'records', 'reviews', `${s.id}.json`))).toBe(false);});+ it('keeps a manifest pending when a declared review file has not synced yet (out-of-order delivery)', async () => {+ const bucket = await buckets.createBucket({ name: 'ReviewLagBucket', path: tempBucket, mode: 'auto-merge' });+ const s = await series.createSeries({ name: 'Review Lag Series', logline: 'A' });+ await issues.createIssue({ seriesId: s.id, title: 'Issue 1' });+ await manuscriptReview.seedReviewFromFindings(s.id, [+ { problem: 'Act II sags', severity: 'medium', anchorQuote: 'the road', issueNumber: 1 },+ ]);+ const exp = await exporter.exportSeries(s.id, bucket.id);+ const reviewFile = join(tempBucket, 'records', 'reviews', `${s.id}.json`);+ expect(existsSync(reviewFile)).toBe(true);++ // Simulate the manifest + series arriving before the review file (cloud+ // relay delivers files out of order): stash the review file aside.+ const stashed = readFileSync(reviewFile, 'utf-8');+ rmSync(reviewFile);+ await series.deleteSeries(s.id);+ simulateRemoteSender(tempBucket, exp.filename);++ const r1 = await importer.processManifest(bucket.id, exp.filename);+ // The manifest declared the review (reviewRefs), so the importer must wait+ // — NOT markProcessed and drop it.+ expect(r1.pending).toBe(true);+ expect(r1.outcome.pendingReviews).toContain(s.id);++ // The review file lands → reprocess → it merges.+ writeFileSync(reviewFile, stashed);+ const r2 = await importer.processManifest(bucket.id, exp.filename);+ expect(r2.pending).toBeFalsy();+ const restored = await manuscriptReview.getReview(s.id);+ expect(restored.comments).toHaveLength(1);+ });+it('keeps a manifest retryable when the bundled review merge fails (no silent drop)', async () => {const bucket = await buckets.createBucket({ name: 'ReviewFailBucket', path: tempBucket, mode: 'auto-merge' });const s = await series.createSeries({ name: 'Review Fail Series', logline: 'A' });diff --git a/server/services/sharing/manifest.js b/server/services/sharing/manifest.jsindex e1d37a6a1e..cca64d3d29 100644--- a/server/services/sharing/manifest.js+++ b/server/services/sharing/manifest.js@@ -144,7 +144,7 @@ export function hasBeenProcessed(cursor, manifestFilename, manifestId = null) {* content-changes re-process correctly.*/export function buildManifest({- kind, senderInstanceId, source, sourceBio, recordIds, assetRefs,+ kind, senderInstanceId, source, sourceBio, recordIds, assetRefs, reviewRefs,bucketId, bucketName, note, producedByVersion, subscription, collection,portosSchemaVersions,}) {@@ -180,6 +180,13 @@ export function buildManifest({bucketName: bucketName || bucketId,recordIds: Array.isArray(recordIds) ? recordIds : [],assetRefs: Array.isArray(assetRefs) ? assetRefs : [],+ // Series ids whose manuscript-review sibling doc (records/reviews/<id>.json)+ // is bundled in this manifest. Declared separately from `recordIds` because+ // the review is keyed by seriesId, not a record id of its own — so the+ // importer can WAIT for the review file to land before markProcessed+ // (cloud-relayed buckets deliver files out of order). Absent on legacy+ // manifests → importer treats as "no declared reviews".+ reviewRefs: Array.isArray(reviewRefs) ? reviewRefs : [],// Optional payload for universe/series shares — the linked media// collection so recipients gain the same set of generated images and// the link is restored on their side. Either `universeId` (universe-