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: drop pending episode preview lint once the script is cleared (#13159)

Adam Eivy958dea546bbf
diff --git a/client/src/components/videoGen/EpisodeComposer.jsx b/client/src/components/videoGen/EpisodeComposer.jsx
index cb9cd3a677..49ac681f33 100644
--- a/client/src/components/videoGen/EpisodeComposer.jsx
+++ b/client/src/components/videoGen/EpisodeComposer.jsx
@@ -239,10 +239,16 @@ export default function EpisodeComposer({ initialScenes, onQueued }) {
// `sanitizedScenes`/`bible` are already fresh-only-on-change via useMemo, so
// depending on them directly (no JSON.stringify) is both cheaper and correct.
useEffect(() => {
- if (queuedJobId) return undefined;
- if (!hasContent) { setPreview(null); setPreviewLoading(false); return undefined; }
- setPreviewLoading(true);
+ // Every lifetime (including empty/queued transitions and disposal) takes a
+ // fresh id, so a lint response dispatched under an earlier lifetime is dropped.
const requestId = (previewRequestRef.current += 1);
+ const invalidate = () => {
+ clearTimeout(debounceRef.current);
+ previewRequestRef.current += 1;
+ };
+ if (queuedJobId) return invalidate;
+ if (!hasContent) { setPreview(null); setPreviewLoading(false); return invalidate; }
+ setPreviewLoading(true);
debounceRef.current = setTimeout(async () => {
const result = await lintContinuousVideoEpisode({
scenes: sanitizedScenes, bible, framings: framingsArrayFor(preview?.clips, framings),
@@ -253,7 +259,7 @@ export default function EpisodeComposer({ initialScenes, onQueued }) {
setPreview(result);
setPreviewLoading(false);
}, PREVIEW_DEBOUNCE_MS);
- return () => clearTimeout(debounceRef.current);
+ return invalidate;
// Re-runs on any scene/bible/framing edit; `preview` itself is excluded to
// avoid retriggering off its own write.
// eslint-disable-next-line react-hooks/exhaustive-deps
diff --git a/client/src/components/videoGen/EpisodeComposer.test.jsx b/client/src/components/videoGen/EpisodeComposer.test.jsx
index d009794122..7f0e251e28 100644
--- a/client/src/components/videoGen/EpisodeComposer.test.jsx
+++ b/client/src/components/videoGen/EpisodeComposer.test.jsx
@@ -99,4 +99,52 @@ describe('EpisodeComposer', () => {
rerender(<EpisodeComposer initialScenes={[{ sceneId: 's1', location: '', lines: [{ type: 'action', text: 'Imported scene' }] }]} />);
expect(await screen.findByDisplayValue('Imported scene')).toBeTruthy();
});
+
+ describe('preview lint lifetimes', () => {
+ // Deferred lint settles on demand so the test controls out-of-order arrival.
+ function deferLint() {
+ const pending = [];
+ lintContinuousVideoEpisode.mockImplementation(() => new Promise((resolve) => { pending.push(resolve); }));
+ return pending;
+ }
+ const flush = () => act(async () => { await Promise.resolve(); });
+
+ beforeEach(() => { vi.useFakeTimers(); });
+ afterEach(() => { vi.useRealTimers(); });
+
+ it('drops a pending lint response once the script is cleared', async () => {
+ const pending = deferLint();
+ render(<EpisodeComposer />);
+ const [textInput] = screen.getAllByPlaceholderText('what happens');
+ fireEvent.change(textInput, { target: { value: 'Mara paces the cell.' } });
+ act(() => { vi.advanceTimersByTime(1000); });
+ expect(lintContinuousVideoEpisode).toHaveBeenCalledTimes(1);
+
+ // Clear the only line while that lint is still in flight.
+ fireEvent.change(textInput, { target: { value: '' } });
+ await act(async () => { pending[0](PASSING_PREVIEW); });
+ await flush();
+
+ expect(screen.queryByText('fresh cut')).toBeNull();
+ expect(screen.getByRole('button', { name: /Queue episode/i })).toBeDisabled();
+ });
+
+ it('lets the newest edit win when an earlier lint resolves last', async () => {
+ const pending = deferLint();
+ render(<EpisodeComposer />);
+ const [textInput] = screen.getAllByPlaceholderText('what happens');
+ fireEvent.change(textInput, { target: { value: 'Mara paces the cell.' } });
+ act(() => { vi.advanceTimersByTime(1000); });
+ fireEvent.change(textInput, { target: { value: 'Mara stops.' } });
+ act(() => { vi.advanceTimersByTime(1000); });
+ expect(lintContinuousVideoEpisode).toHaveBeenCalledTimes(2);
+
+ await act(async () => { pending[1](FAILING_PREVIEW); });
+ await act(async () => { pending[0](PASSING_PREVIEW); });
+ await flush();
+
+ expect(screen.getByText(/no bible descriptor found for cast\/mara/)).toBeTruthy();
+ expect(screen.getByRole('button', { name: /Queue episode/i })).toBeDisabled();
+ });
+ });
});