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: align narration offsets to untrimmed text + drop stale/changed-prose responses (#1304)
[._.]/ Adam Eivyba47074c874b
diff --git a/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx b/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsxindex a127678745..7182df9232 100644--- a/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx+++ b/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx@@ -45,16 +45,24 @@ export default function ManuscriptReadAloud({ open, onClose, section }) {const audioRef = useRef(null);const mountedRef = useRef(true);useEffect(() => () => { mountedRef.current = false; }, []);+ // Live mirror of the prose the modal is showing, so an in-flight narration+ // response can detect that the section's text changed (edit, reformat, accepted+ // fix, or a section swap) while it was synthesizing and discard itself rather+ // than apply stale audio/offsets to different prose.+ const contentRef = useRef(content);+ contentRef.current = content;- // Reset narration when the section being read changes or the modal closes —- // stale segments belong to a different issue's prose.+ // Reset narration when the prose being read changes — a different issue/stage,+ // or the SAME section edited under it. The cached segments + their char offsets+ // belong to the exact text they were synthesized from; reusing them against+ // changed prose would misalign the highlight and play the wrong sentence.const resetNarration = () => {setSegments(null);setCurrentIndex(-1);setIsPlaying(false);setElapsedMs(0);};- useEffect(() => { resetNarration(); }, [section?.issueId, section?.stageId]);+ useEffect(() => { resetNarration(); }, [section?.issueId, section?.stageId, content]);useEffect(() => { if (!open) { setIsPlaying(false); } }, [open]);// Cumulative start offset (ms) per segment + total, for the progress bar.@@ -87,6 +95,7 @@ export default function ManuscriptReadAloud({ open, onClose, section }) {return;}setLoading(true);+ const reqContent = content; // snapshot — discard if the prose changes mid-flightconst result = await narratePipelineProse(content, voiceId || undefined, { silent: true }).catch((err) => {toast.error(err.message || 'Failed to narrate');@@ -94,7 +103,9 @@ export default function ManuscriptReadAloud({ open, onClose, section }) {});if (!mountedRef.current) return;setLoading(false);- if (!result) return;+ // Drop the response if the section's text changed while it synthesized — its+ // offsets belong to `reqContent`, not the current prose.+ if (contentRef.current !== reqContent || !result) return;const segs = Array.isArray(result.segments) ? result.segments : [];setSegments(segs);setElapsedMs(0);diff --git a/server/routes/pipeline/audio.js b/server/routes/pipeline/audio.jsindex daa63ee667..a0b9d13729 100644--- a/server/routes/pipeline/audio.js+++ b/server/routes/pipeline/audio.js@@ -96,7 +96,10 @@ router.post('/tts/synthesize', asyncHandler(async (req, res) => {// manuscript editor can play a karaoke-style read-along. Non-destructive — the// WAVs land in PATHS.audio exactly like /tts/preview + the dialogue render.const ttsNarrateSchema = z.object({- text: z.string().trim().min(1).max(12000),+ // Do NOT trim: the segment start/end offsets are computed against this exact+ // string and the client slices its original `content` with them, so trimming+ // here would shift every span. narrateProse rejects all-whitespace text.+ text: z.string().min(1).max(12000),voiceId: z.string().trim().max(200).optional(),});router.post('/tts/narrate', asyncHandler(async (req, res) => {