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: do not strand a Remix handoff on a sibling history fetch's failure

[._.]/ Adam Eivy1ac495e1c2ef
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsx
index 4be1408392..6464ed6c3c 100644
--- a/client/src/pages/VideoGen.jsx
+++ b/client/src/pages/VideoGen.jsx
@@ -340,13 +340,26 @@ export default function VideoGen() {
// sentinel rather than `history.length` — the Remix handoff below has to tell
// "history is still in flight / failed to load" apart from "history loaded
// and has no such record", and an empty array is a legitimate loaded state.
+ //
+ // The mount fetch and the completion refresh share this one sentinel, so the
+ // handoff also needs to know whether ANOTHER fetch is still running before it
+ // trusts an 'error': a transient failure on a background refresh must not
+ // strand a handoff that the in-flight mount fetch is about to satisfy. The
+ // count is a ref because only the effects read it, and they run after commit.
const [historyLoad, setHistoryLoad] = useState('loading');
- const refreshHistory = useCallback(() => listVideoHistory()
- .then((items) => {
- setHistory(Array.isArray(items) ? items : []);
- setHistoryLoad('loaded');
- })
- .catch(() => setHistoryLoad('error')), []);
+ const historyInFlightRef = useRef(0);
+ // `silent` — this page owns the failure UI (the Remix banner below, and the
+ // gallery simply staying empty), so the shared toast would double it.
+ const refreshHistory = useCallback(() => {
+ historyInFlightRef.current += 1;
+ return listVideoHistory({ silent: true })
+ .then((items) => {
+ setHistory(Array.isArray(items) ? items : []);
+ setHistoryLoad('loaded');
+ })
+ .catch(() => setHistoryLoad('error'))
+ .finally(() => { historyInFlightRef.current -= 1; });
+ }, []);
useMediaCompletionRefresh({ onVideoCompleted: refreshHistory });
useEffect(() => { refreshHistory(); }, [refreshHistory]);
@@ -452,17 +465,18 @@ export default function VideoGen() {
// otherwise replay it over a form the user has been editing the whole time.
const remixHandoffId = searchParams.get('remix');
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);
// The restore waits on a history round trip, so unlike the old URL bundle
// (applied synchronously on mount) there is a window in which the form still
// holds the page defaults and is about to be replaced wholesale. Announce it
// and hold Generate: rendering here would spend GPU time on the defaults while
- // the user believes they are looking at the clip's settings.
- // Only Retry puts `historyLoad` back to 'loading' after it has settled, and
- // that is exactly a re-pending handoff — so the two conditions are enough.
- const remixHandoffPending = !!remixHandoffId && historyLoad === 'loading';
- // 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);
+ // the user believes they are looking at the clip's settings. The window runs
+ // from the parameter appearing until the handoff either restores (which strips
+ // it) or reports a problem — which also covers the wait on a sibling fetch
+ // below, with no second sentinel. Retry re-enters it by clearing the problem.
+ const remixHandoffPending = !!remixHandoffId && !remixHandoffProblem;
const consumeRemixHandoff = useCallback(() => {
setSearchParams((prev) => {
const next = new URLSearchParams(prev);
@@ -480,6 +494,12 @@ export default function VideoGen() {
// lie every time the page is opened faster than the history round trip.
// Any banner still up belongs to a previous handoff, so it goes.
if (historyLoad === 'loading') { setRemixHandoffProblem(null); return; }
+ // The sentinel is shared with the completion refresh, so an 'error' may
+ // belong to a background fetch that failed alongside the one this handoff is
+ // actually waiting on. Keep waiting while any fetch is still running, or a
+ // transient blip on the sibling would strand a handoff the in-flight request
+ // is about to satisfy.
+ if (historyLoad === 'error' && historyInFlightRef.current > 0) return;
settledRemixHandoffRef.current = remixHandoffId;
if (historyLoad === 'error') {
// Keep the param in the URL — Retry resolves this same handoff.
diff --git a/client/src/pages/VideoGen.remix.test.jsx b/client/src/pages/VideoGen.remix.test.jsx
index e9ba9c988e..3378e7ecac 100644
--- a/client/src/pages/VideoGen.remix.test.jsx
+++ b/client/src/pages/VideoGen.remix.test.jsx
@@ -217,6 +217,23 @@ describe('VideoGen cross-page Remix handoff', () => {
expect(screen.getByRole('button', { name: /Generate/ })).toBeEnabled();
});
+ it('keeps waiting when a background refresh fails beside the fetch it is waiting on', async () => {
+ // The mount fetch and the completion refresh write one shared load
+ // sentinel. A blip on the background one must not strand the handoff and
+ // leave "couldn't load your history" sitting over a gallery that loaded.
+ let settleMount;
+ state.listVideoHistory.mockReturnValueOnce(new Promise((resolve) => { settleMount = resolve; }));
+ await renderVideoGenPage(`/media/video?remix=${RECORD.id}`);
+
+ state.listVideoHistory.mockRejectedValueOnce(new Error('transient'));
+ await act(async () => { await state.completionRefresh.onVideoCompleted(); });
+ expect(screen.queryByText(/Couldn't load your render history/)).toBeNull();
+
+ await act(async () => { settleMount([RECORD]); });
+ await waitFor(() => expect(screen.getByLabelText('Prompt')).toHaveValue(RECORD.prompt));
+ expect(screen.queryByText(/Couldn't load your render history/)).toBeNull();
+ });
+
it('offers a retry when the history fetch fails, and restores once it succeeds', async () => {
state.listVideoHistory.mockRejectedValueOnce(new Error('offline'));
await renderVideoGenPage(`/media/video?remix=${RECORD.id}`);