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 release-review findings: converge editorial-review sync + guard async client callbacks

[._.]/ Adam Eivyffed7ee9b0cb
diff --git a/.changelog/v2.20.0.md b/.changelog/v2.20.0.md
index 066f884462..ff25e9ecb2 100644
--- a/.changelog/v2.20.0.md
+++ b/.changelog/v2.20.0.md
@@ -54,6 +54,8 @@ Released: 2026-06-11
- **Manuscript "Generate fix" no longer surfaces the prompt's own example as the edit** — a fix run could come back with the JSON example's placeholder text as the suggestion (BEFORE: *"a verbatim excerpt copied EXACTLY from that issue's manuscript above — the span you are replacing"*, AFTER: *"that same span rewritten to close the gap"*) when a model echoed the output-contract example instead of filling it in. That bogus edit could never be located in the manuscript, so Accept would have failed with "Anchor text is no longer present." Two changes close it: the fix's JSON example now uses obviously-schematic `<…>` field descriptions plus an explicit "do not copy the bracketed values" rule (so the model is far less likely to echo it), and `normalizeFix` now drops any edit whose `find`/`replace` still matches the example placeholder text (old prose-style *or* new bracketed) — so an echo collapses to the existing "did not return a usable fix — try again" retry instead of presenting an unappliable diff. The prompt change ships as migration 084 (existing installs auto-upgrade their copy; customized prompts are left intact and warned). (`server/services/pipeline/manuscriptFix.js`, `data.reference/prompts/stages/pipeline-manuscript-fix.md`, `scripts/migrations/084-manuscript-fix-example-placeholders.js`)
+- **Editorial-review sync now converges instead of re-applying every cycle** — the manuscript editorial-review merge (`mergeReviewFromSync`) used an at-or-newer (`>=`) last-write-wins comparison, so a peer re-sending a review comment you already held at the same timestamp was re-adopted and the review file re-written on every sync cycle — the same write-amplification/non-convergence bug fixed for the creative catalog this release. The merge now uses strict-newer (`>`), matching the `mergeIssuesFromSync` LWW guard every sibling already uses: an equal-clock echo is a skip, so the merge is idempotent. (`server/services/pipeline/manuscriptReview.js`)
+
- **Catalog user-type sync now converges instead of re-applying every cycle** — federated catalog *user-defined types* used an at-or-newer (`>=`) last-write-wins comparison, so a peer re-sending a type you already held at the same timestamp was re-adopted, re-written, and re-counted as a change on every sync cycle. The logs showed a constant non-zero count (e.g. `Synced with <peer>: 3 catalog changes`) once a minute forever, and the slice was rewritten needlessly each pass. The merge now uses strict-newer (`>`), matching the SQL LWW guard every other catalog kind already uses (`EXCLUDED.updated_at > …updated_at`): an equal-clock echo is a skip, so the merge is idempotent and the cycle settles to zero changes. (`server/services/catalogSync.js`)
- **[issue-1080] Notes synced from other machines become searchable promptly** — a Brain note, daily-log entry, person, project, or idea created or edited on one of your machines is now re-indexed into semantic memory on the others as soon as it syncs, instead of waiting for a full manual re-sync. Edits and deletes that arrive from a peer also refresh or retire the matching memory entry, so search no longer surfaces stale copies of records that changed elsewhere. A new **Refresh embeddings** button on the Brain graph re-indexes everything in one pass to heal anything that drifted before this fix.
diff --git a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx
index 0681dedba9..ffdc934de5 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptImpactPreview.jsx
@@ -16,7 +16,7 @@
* red/green. Diffs per changed section, never one giant concatenation.
*/
-import { useMemo, useState } from 'react';
+import { useEffect, useMemo, useRef, useState } from 'react';
import { Check, Loader2, X } from 'lucide-react';
import Modal from '../../ui/Modal';
import HunkDiff from '../../ui/HunkDiff';
@@ -47,6 +47,12 @@ export default function ManuscriptImpactPreview({ open, onClose, seriesId, secti
// null when idle, { done, total } while the accept-all pass runs.
const [acceptState, setAcceptState] = useState(null);
+ // The accept-all pass awaits one network round-trip per note; if the user
+ // closes the preview mid-batch, late callbacks must not fire into a torn-down
+ // parent. Never reset to true (handles dev-mode double-mount cleanly).
+ const mountedRef = useRef(true);
+ useEffect(() => () => { mountedRef.current = false; }, []);
+
const changed = useMemo(() => {
if (!open) return [];
const edits = editsBySectionKey(comments, fixDrafts);
@@ -85,9 +91,11 @@ export default function ManuscriptImpactPreview({ open, onClose, seriesId, secti
errors.push(err?.message || 'accept failed');
return null;
});
+ if (!mountedRef.current) return;
if (result) onAccepted(result);
setAcceptState((s) => (s ? { ...s, done: s.done + 1 } : s));
}
+ if (!mountedRef.current) return;
setAcceptState(null);
const applied = targets.length - errors.length;
if (errors.length) {
diff --git a/client/src/pages/VideoTimelineEditor.jsx b/client/src/pages/VideoTimelineEditor.jsx
index f9b5e606a8..464aea1c11 100644
--- a/client/src/pages/VideoTimelineEditor.jsx
+++ b/client/src/pages/VideoTimelineEditor.jsx
@@ -353,6 +353,10 @@ export default function VideoTimelineEditor() {
// Wait for metadata before seeking — seek-before-load silently no-ops
// and the user sees frame 0 of the clip instead of `inSec + within`.
video.onloadedmetadata = () => {
+ // Rapid scrubbing across clip boundaries reassigns src (and this
+ // handler) before the prior metadata load fires; bail if this src is
+ // no longer the one we want so a stale load can't seek the new clip.
+ if (lastSrcRef.current !== src) return;
video.currentTime = wantTime;
if (playingRef.current) video.play().catch(() => {});
};
diff --git a/server/services/pipeline/manuscriptReview.js b/server/services/pipeline/manuscriptReview.js
index 907202d437..21ccc95f14 100644
--- a/server/services/pipeline/manuscriptReview.js
+++ b/server/services/pipeline/manuscriptReview.js
@@ -316,7 +316,12 @@ export async function mergeReviewFromSync(seriesId, remoteReview) {
const byId = new Map(local.comments.map((c) => [c.id, c]));
for (const rc of remote.comments) {
const lc = byId.get(rc.id);
- if (!lc || new Date(rc.updatedAt).getTime() >= new Date(lc.updatedAt).getTime()) {
+ // Strict-newer (`>`) so an equal-clock echo is a skip, matching the
+ // `mergeIssuesFromSync` LWW guard. With `>=`, a peer re-sending a comment
+ // we already hold at the same timestamp re-adopts + re-writes it every
+ // sync cycle (write amplification + non-convergence) — the same bug
+ // catalogSync.js fixed this release.
+ if (!lc || new Date(rc.updatedAt).getTime() > new Date(lc.updatedAt).getTime()) {
byId.set(rc.id, rc);
}
}
diff --git a/server/services/pipeline/manuscriptReview.test.js b/server/services/pipeline/manuscriptReview.test.js
index 4f4959ab55..bfc4b2db65 100644
--- a/server/services/pipeline/manuscriptReview.test.js
+++ b/server/services/pipeline/manuscriptReview.test.js
@@ -70,6 +70,30 @@ describe('manuscriptReview — record-event emission on write', () => {
expect(updates).toEqual([]);
});
+ it('mergeReviewFromSync is strict-LWW: newer remote wins, equal-clock echo is a no-op', async () => {
+ // Local holds a comment the user has acted on (status 'accepted').
+ await mergeReviewFromSync('ser-lww', {
+ schemaVersion: 1,
+ comments: [{ id: 'c1', problem: 'note', status: 'accepted', updatedAt: '2026-06-02T00:00:00Z' }],
+ });
+
+ // Equal-clock echo from a peer (same updatedAt) carrying a different status
+ // must NOT overwrite the local copy — otherwise a full-snapshot sync cycle
+ // re-adopts and re-writes it forever (write amplification / non-convergence).
+ let merged = await mergeReviewFromSync('ser-lww', {
+ schemaVersion: 1,
+ comments: [{ id: 'c1', problem: 'note', status: 'open', updatedAt: '2026-06-02T00:00:00Z' }],
+ });
+ expect(merged.comments.find((c) => c.id === 'c1').status).toBe('accepted');
+
+ // A strictly-newer remote DOES win.
+ merged = await mergeReviewFromSync('ser-lww', {
+ schemaVersion: 1,
+ comments: [{ id: 'c1', problem: 'note', status: 'dismissed', updatedAt: '2026-06-03T00:00:00Z' }],
+ });
+ expect(merged.comments.find((c) => c.id === 'c1').status).toBe('dismissed');
+ });
+
it('persists replacementStrategy (explicit value, derived from category, and legacy fallback)', async () => {
const seeded = await seedReviewFromFindings('ser-4', [
{ category: 'comic-structure', problem: 'page is prose', suggestion: 'Panel 1 …', anchorQuote: 'PAGE 5' },