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): fix full-page corruption + backfill edits onto existing notes

[._.]/ Adam Eivydede5e120770
diff --git a/server/services/pipeline/manuscriptReview.js b/server/services/pipeline/manuscriptReview.js
index 6a8a92184a..907202d437 100644
--- a/server/services/pipeline/manuscriptReview.js
+++ b/server/services/pipeline/manuscriptReview.js
@@ -187,22 +187,59 @@ export async function seedReviewFromFindings(seriesId, findings, { runId = null,
if (!candidate) continue;
// `replace` (the with-edits in-place rewrite) isn't part of the stored
// comment shape, so sanitizeComment drops it — stash it on the candidate so
- // the append loop below can build the comment's `fix` from it.
+ // the append + backfill paths below can build the comment's `fix` from it.
if (typeof f?.replace === 'string' && f.replace) candidate.replace = f.replace;
candidates.push(candidate);
}
const freshKeys = new Set(candidates.map(findingKey));
+ // Look up a re-surfaced finding (and its `replace`) by key, so an EXISTING
+ // open comment with no fix can be backfilled when a with-edits re-run finds
+ // it again. First candidate wins (matches the append loop's dedupe order).
+ const candidateByKey = new Map();
+ for (const c of candidates) { const k = findingKey(c); if (!candidateByKey.has(k)) candidateByKey.set(k, c); }
+
+ // Build the pre-seeded fix for a finding from { find: anchorQuote, replace }
+ // via the same shaper the manual "Generate fix" path uses, so the editor
+ // shows the diff + Accept with no per-comment fix call. Returns null (→ stays
+ // advice-only, falls back to manual fix generation) when:
+ // - there's no `replace`, no `anchorQuote`, or no resolved section;
+ // - the anchor can't be located even whitespace-tolerantly (shapeAnchoredEdit
+ // flags `fuzzy`): the bulk pass has no per-comment warning, so an
+ // unappliable fix would present a diff whose Accept silently fails;
+ // - the finding is a `full-page` (comic-structure) replacement: there the
+ // `anchorQuote` is only the malformed page's OPENING text while `replace`
+ // is the complete rewritten page, so splicing `replace` over just the
+ // anchor would leave the rest of the page behind. The manual fix path
+ // handles full-page substitution correctly; defer to it.
+ const buildSeedFix = (comment, section) => {
+ if (!section || !comment.replace || !comment.anchorQuote) return null;
+ if (comment.replacementStrategy === 'full-page') return null;
+ const edit = shapeAnchoredEdit(section, { find: comment.anchorQuote, replace: comment.replace });
+ return edit && !edit.fuzzy ? fixFromEdits([edit]) : null;
+ };
// Carry every existing comment forward. In 'fresh' mode, an open comment the
// new pass no longer surfaces is flipped to dismissed (a synced status
// change, not a deletion — see the doc comment). Accepted/dismissed are
- // always left untouched.
+ // always left untouched. A with-edits re-run also backfills a fix onto an
+ // existing open comment that has none yet (so enabling "generate edits" on a
+ // series whose notes came from an earlier findings-only run still drafts them).
let dismissedCount = 0;
+ let backfilledCount = 0;
const carried = review.comments.map((c) => {
if (mode === 'fresh' && c.status === 'open' && !freshKeys.has(findingKey(c))) {
dismissedCount += 1;
return sanitizeComment({ ...c, status: 'dismissed', updatedAt: now });
}
+ if (c.status === 'open' && !c.fix) {
+ const match = candidateByKey.get(findingKey(c));
+ const section = c.issueNumber != null ? byNumber.get(c.issueNumber) : null;
+ const fix = match?.replace ? buildSeedFix({ ...c, replace: match.replace }, section) : null;
+ if (fix) {
+ backfilledCount += 1;
+ return sanitizeComment({ ...c, fix, updatedAt: now });
+ }
+ }
return c;
});
@@ -218,20 +255,8 @@ export async function seedReviewFromFindings(seriesId, findings, { runId = null,
candidate.issueId = section.issueId;
candidate.stageId = section.stageId;
}
- // With-edits pass: the finding carried a concrete `replace` rewrite of its
- // `anchorQuote`. Pre-seed the comment's fix from { find: anchorQuote,
- // replace } via the same shaper the manual "Generate fix" path uses, so the
- // editor shows the diff + Accept with no per-comment fix call. Skipped when
- // there's no anchor to splice over, no resolved section, or no replace —
- // those findings stay advice-only and fall back to manual fix generation.
- // Also skipped when the anchor can't be located even whitespace-tolerantly
- // (shapeAnchoredEdit flags that as `fuzzy`): unlike the manual path, the
- // bulk pass has no per-comment warning, so an unappliable fix would present
- // a diff whose Accept silently fails — leave it advice-only instead.
- if (candidate.replace && candidate.anchorQuote && section) {
- const edit = shapeAnchoredEdit(section, { find: candidate.anchorQuote, replace: candidate.replace });
- if (edit && !edit.fuzzy) candidate.fix = fixFromEdits([edit]);
- }
+ const fix = buildSeedFix(candidate, section);
+ if (fix) candidate.fix = fix;
// `replace` is consumed into `fix` (or dropped) — it's not part of the
// stored comment shape (sanitizeComment ignores unknown keys, but be tidy).
delete candidate.replace;
@@ -244,10 +269,11 @@ export async function seedReviewFromFindings(seriesId, findings, { runId = null,
// The review is a sibling of the series record, so a review-only change
// doesn't move the series `index.json` — emit a series `updated` event so
// the peer-sync push + bucket re-export fire (both hash the review into
- // their payload). Only when something actually changed — appended findings
- // OR opens auto-dismissed by a 'fresh' re-run. Skipped on the sync RECEIVE
- // path (`mergeReviewFromSync`) to avoid an echo loop.
- if (fresh.length > 0 || dismissedCount > 0) emitRecordUpdated('series', seriesId);
+ // their payload). Only when something actually changed — appended findings,
+ // opens auto-dismissed by a 'fresh' re-run, OR fixes backfilled onto existing
+ // opens. Skipped on the sync RECEIVE path (`mergeReviewFromSync`) to avoid
+ // an echo loop.
+ if (fresh.length > 0 || dismissedCount > 0 || backfilledCount > 0) emitRecordUpdated('series', seriesId);
return next;
});
}
diff --git a/server/services/pipeline/manuscriptReview.test.js b/server/services/pipeline/manuscriptReview.test.js
index 1d363d373a..4f4959ab55 100644
--- a/server/services/pipeline/manuscriptReview.test.js
+++ b/server/services/pipeline/manuscriptReview.test.js
@@ -214,4 +214,49 @@ describe('manuscriptReview — with-edits fix seeding', () => {
]);
expect(seeded.comments[0].fix).toBeNull();
});
+
+ it('does NOT pre-seed a fix for a full-page (comic-structure) finding — anchor is only the page opening', async () => {
+ // The anchor ("The hero") is present, but for full-page the replace is the
+ // whole rewritten page; splicing it over just the anchor would corrupt the
+ // page, so the seed defers to the manual full-page fix path (fix stays null).
+ const seeded = await seedReviewFromFindings('ser-fullpage', [
+ {
+ category: 'comic-structure', replacementStrategy: 'full-page',
+ problem: 'page is prose', anchorQuote: 'The hero',
+ replace: 'Panel 1\nDescription: …\nPanel 2\nDescription: …', issueNumber: 1,
+ },
+ ]);
+ expect(seeded.comments[0].fix).toBeNull();
+ });
+
+ it('backfills a fix onto an existing open comment that lacked one when a with-edits re-run re-surfaces it', async () => {
+ // First pass: findings-only (no replace) → comment lands advice-only.
+ const first = await seedReviewFromFindings('ser-backfill', [
+ { problem: 'abrupt ending', anchorQuote: 'She left.', issueNumber: 1 },
+ ]);
+ expect(first.comments[0].fix).toBeNull();
+ const id = first.comments[0].id;
+
+ // Second pass: same finding (same key) now carries a replace. It's deduped
+ // out of the append path, but the carried-forward open comment is backfilled.
+ const second = await seedReviewFromFindings('ser-backfill', [
+ { problem: 'abrupt ending', anchorQuote: 'She left.', replace: 'She left, but paused.', issueNumber: 1 },
+ ]);
+ expect(second.comments).toHaveLength(1);
+ const c = second.comments[0];
+ expect(c.id).toBe(id); // same comment, not a duplicate
+ expect(c.fix).toBeTruthy();
+ expect(c.fix.replace).toBe('She left, but paused.');
+ });
+
+ it('does NOT overwrite an existing fix on backfill (only fills comments that lack one)', async () => {
+ const first = await seedReviewFromFindings('ser-backfill-keep', [
+ { problem: 'abrupt ending', anchorQuote: 'She left.', replace: 'She left, but paused.', issueNumber: 1 },
+ ]);
+ const original = first.comments[0].fix.replace;
+ const second = await seedReviewFromFindings('ser-backfill-keep', [
+ { problem: 'abrupt ending', anchorQuote: 'She left.', replace: 'A DIFFERENT rewrite.', issueNumber: 1 },
+ ]);
+ expect(second.comments[0].fix.replace).toBe(original); // untouched
+ });
});