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: make a stranded video Remix handoff wait for Retry, and key it by id

[._.]/ Adam Eivy93f5cdd4c118
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsx
index 964953c1c4..3703029e54 100644
--- a/client/src/pages/VideoGen.jsx
+++ b/client/src/pages/VideoGen.jsx
@@ -442,11 +442,18 @@ export default function VideoGen() {
// The ref (not the stripped param) is what makes this one-shot: the strip is
// an async router update, so a completion refresh landing in the same tick
// would otherwise re-apply the handoff over edits the user has since made.
+ // It records the settled ID rather than a boolean, so a SECOND handoff
+ // arriving on the same mount is still honored.
const remixHandoffId = searchParams.get('remix');
- const remixHandoffAppliedRef = useRef(false);
+ const settledRemixHandoffRef = useRef(null);
// null while nothing is wrong; otherwise 'error' (the history fetch failed,
// retryable) or 'missing' (history loaded and holds no such record).
const [remixHandoffProblem, setRemixHandoffProblem] = useState(null);
+ // Set when the fetch failed under a pending handoff. The restore then waits
+ // for an explicit Retry instead of riding in on the next background refresh:
+ // a render completing minutes later would otherwise replay the handoff over
+ // a form the user has been editing since the banner appeared.
+ const [remixHandoffBlocked, setRemixHandoffBlocked] = useState(false);
const consumeRemixHandoff = useCallback(() => {
setSearchParams((prev) => {
const next = new URLSearchParams(prev);
@@ -455,18 +462,23 @@ export default function VideoGen() {
}, { replace: true });
}, [setSearchParams]);
useEffect(() => {
- if (!remixHandoffId || remixHandoffAppliedRef.current) return;
+ // No handoff in the URL — including right after this one consumed its own.
+ // Clearing the settled id here is what lets the NEXT handoff through, even
+ // when it names the same record.
+ if (!remixHandoffId) { settledRemixHandoffRef.current = null; return; }
+ if (settledRemixHandoffRef.current === remixHandoffId || remixHandoffBlocked) return;
// Still fetching: say nothing. Reporting "no such record" here would be a
// lie every time the page is opened faster than the history round trip.
if (historyLoad === 'loading') return;
if (historyLoad === 'error') {
- // Keep the param so Retry can resolve it once the fetch succeeds, and
- // leave the ref unset so the retry actually re-runs this effect.
+ // Keep the param so Retry can resolve it, and leave the handoff unsettled
+ // so that retry actually re-runs this effect.
setRemixHandoffProblem('error');
+ setRemixHandoffBlocked(true);
return;
}
const record = history.find((v) => String(v.id) === remixHandoffId);
- remixHandoffAppliedRef.current = true;
+ settledRemixHandoffRef.current = remixHandoffId;
if (record) {
applyRemix(record);
setRemixHandoffProblem(null);
@@ -474,21 +486,21 @@ export default function VideoGen() {
setRemixHandoffProblem('missing');
}
consumeRemixHandoff();
- }, [remixHandoffId, historyLoad, history, applyRemix, consumeRemixHandoff]);
+ }, [remixHandoffId, historyLoad, history, remixHandoffBlocked, applyRemix, consumeRemixHandoff]);
// Back to 'loading' first, so a retry that fails again still moves the state
- // ('loading' → 'error') and re-runs the effect above. Re-setting 'error' onto
- // 'error' is a no-op React bails on, which would leave the banner dismissed
- // after a second failure.
+ // ('loading' → 'error') and re-runs the effect above.
const retryRemixHandoff = useCallback(() => {
setHistoryLoad('loading');
setRemixHandoffProblem(null);
+ setRemixHandoffBlocked(false);
refreshHistory();
}, [refreshHistory]);
const dismissRemixHandoff = useCallback(() => {
- remixHandoffAppliedRef.current = true;
+ settledRemixHandoffRef.current = remixHandoffId;
setRemixHandoffProblem(null);
+ setRemixHandoffBlocked(false);
consumeRemixHandoff();
- }, [consumeRemixHandoff]);
+ }, [remixHandoffId, consumeRemixHandoff]);
// Finish a draft (#3696): same restore as Remix, but switched to the delivery
// model the draft's registry entry declares. Prefill only — the user presses
diff --git a/client/src/pages/VideoGen.remix.test.jsx b/client/src/pages/VideoGen.remix.test.jsx
index efbdbb881a..5bff54922a 100644
--- a/client/src/pages/VideoGen.remix.test.jsx
+++ b/client/src/pages/VideoGen.remix.test.jsx
@@ -192,6 +192,22 @@ describe('VideoGen cross-page Remix handoff', () => {
expect(screen.queryByText(/Couldn't load your render history/)).toBeNull();
});
+ it('waits for Retry rather than restoring from a background refresh after a failure', async () => {
+ state.listVideoHistory.mockRejectedValueOnce(new Error('offline'));
+ await renderVideoGenPage(`/media/video?remix=${RECORD.id}`);
+ await screen.findByText(/Couldn't load your render history/);
+
+ // The banner can sit for as long as the user leaves it there, and the form
+ // is live the whole time. A render finishing in the background re-fetches
+ // history — the stranded handoff must not ride in on it and wipe the form.
+ fireEvent.change(screen.getByLabelText('Prompt'), { target: { value: 'a kite over a field' } });
+ state.listVideoHistory.mockResolvedValue([RECORD]);
+ await act(async () => { await state.completionRefresh.onVideoCompleted(); });
+
+ expect(screen.getByLabelText('Prompt')).toHaveValue('a kite over a field');
+ expect(screen.getByRole('button', { name: 'Retry' })).toBeInTheDocument();
+ });
+
it('reports an actionable missing-record state when the load holds no such record', async () => {
state.listVideoHistory.mockResolvedValue([LEGACY_RECORD]);
await renderVideoGenPage('/media/video?remix=vid-deleted');