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([manuscript-review-sync]): treat manifest reviewRefs as authoritative on import

[._.]/ Adam Eivy449b1fe25faf
diff --git a/server/services/sharing/importer.js b/server/services/sharing/importer.js
index 04dc3b4cd3..58a5186093 100644
--- a/server/services/sharing/importer.js
+++ b/server/services/sharing/importer.js
@@ -628,20 +628,26 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =
});
}
- // Merge the bundled manuscript-review sibling doc (if the sender shipped one)
- // into local state, LWW-per-comment. Keyed by seriesId under records/reviews/
- // — read by seriesId rather than via `recordIds` because the review has no
- // record id of its own. An older sender (no reviews/ folder) → null → skip;
- // a newer sender whose review LWW-loses every comment is a harmless no-op.
- // `mergeReviewFromSync` does not emit a record event, so no re-export loop.
+ // Merge the bundled manuscript-review sibling doc into local state,
+ // LWW-per-comment. Keyed by seriesId under records/reviews/ — read by
+ // seriesId rather than via `recordIds` because the review has no record id of
+ // its own. The manifest's `reviewRefs` is AUTHORITATIVE: only merge a review
+ // file the THIS manifest declared. The exporter writes (but never deletes) a
+ // review file, so a stale file from a prior export can linger in the bucket;
+ // a later manifest that shipped an emptied review declares `reviewRefs: []`,
+ // and reading the lingering file anyway would resurrect dismissed comments.
+ // Legacy manifests (no reviewRefs) → empty set → nothing merged (those
+ // senders never bundled a review file either).
// A merge FAILURE (transient write/parse error) must NOT silently advance the
// cursor — the review has no independent reconciliation cycle (it only rides
// the series push/export), so a swallowed failure would drop it permanently.
// Surface it as a pending condition (like recordImportFailures /
// collectionPending*) so processManifest leaves the manifest retryable.
+ // `mergeReviewFromSync` does not emit a record event, so no re-export loop.
+ const declaredReviews = new Set((Array.isArray(manifest.reviewRefs) ? manifest.reviewRefs : []).filter(isSafeRecordId));
const reviewMergeFailures = [];
for (const s of records.series) {
- if (skipSeriesMerge.has(s.id)) continue;
+ if (skipSeriesMerge.has(s.id) || !declaredReviews.has(s.id)) continue;
const review = await readJSONFile(join(bucket.path, 'records', 'reviews', `${s.id}.json`), null, { logError: false });
if (review) {
await mergeReviewFromSync(s.id, review).catch((err) => {
diff --git a/server/services/sharing/integration.test.js b/server/services/sharing/integration.test.js
index b1588ce3e5..b8704e0528 100644
--- a/server/services/sharing/integration.test.js
+++ b/server/services/sharing/integration.test.js
@@ -268,6 +268,27 @@ describe('sharing round-trip', () => {
expect(restored.comments).toHaveLength(1);
});
+ it('ignores a stale review file the manifest did not declare (no resurrection of cleared comments)', async () => {
+ const bucket = await buckets.createBucket({ name: 'StaleReviewBucket', path: tempBucket, mode: 'auto-merge' });
+ const s = await series.createSeries({ name: 'Stale Review Series', logline: 'A' });
+ await issues.createIssue({ seriesId: s.id, title: 'Issue 1' });
+ // Export with NO review → manifest declares reviewRefs: [] and writes no file.
+ const exp = await exporter.exportSeries(s.id, bucket.id);
+ // Simulate a lingering stale review file from an earlier export (the
+ // exporter writes but never deletes review files).
+ mkdirSync(join(tempBucket, 'records', 'reviews'), { recursive: true });
+ writeFileSync(
+ join(tempBucket, 'records', 'reviews', `${s.id}.json`),
+ JSON.stringify({ schemaVersion: 1, comments: [{ id: 'mrc-stale', problem: 'old note', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }] }),
+ );
+ await series.deleteSeries(s.id);
+ simulateRemoteSender(tempBucket, exp.filename);
+ await importer.processManifest(bucket.id, exp.filename);
+ // The manifest declared no review, so the lingering file must NOT be merged.
+ const after = await manuscriptReview.getReview(s.id);
+ expect(after.comments).toHaveLength(0);
+ });
+
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' });