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: field-scoped video history search and single remix hydration (#12996)

[._.]/ Adam Eivyd2856bd4e2ea
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsx
index 4906ff3017..37b3458556 100644
--- a/client/src/pages/VideoGen.jsx
+++ b/client/src/pages/VideoGen.jsx
@@ -581,10 +581,15 @@ export default function VideoGen() {
}
// The page loads only the newest HISTORY_PAGE_LIMIT records, so an older
// clip is hydrated by id before it is called missing.
- getVideoHistoryItem(remixHandoffId, { silent: true })
- .then((older) => { applyRemix(older); setRemixHandoffProblem(null); })
- .catch(() => setRemixHandoffProblem('missing'))
- .finally(consumeRemixHandoff);
+ // The id is marked settled above, so a history refresh mid-flight cannot
+ // start a second lookup. A handoff that changed or cleared meanwhile resets
+ // that ref, which makes this answer stale.
+ const id = remixHandoffId;
+ const current = () => settledRemixHandoffRef.current === id;
+ getVideoHistoryItem(id, { silent: true })
+ .then((older) => { if (current()) { applyRemix(older); setRemixHandoffProblem(null); } })
+ .catch(() => { if (current()) setRemixHandoffProblem('missing'); })
+ .finally(() => { if (current()) consumeRemixHandoff(); });
}, [remixHandoffId, historyLoad, history, applyRemix, consumeRemixHandoff]);
// Back to 'loading' first, so a retry that fails again still moves the state
// ('loading' → 'error') and re-runs the effect above.
diff --git a/client/src/pages/VideoGen.remix.test.jsx b/client/src/pages/VideoGen.remix.test.jsx
index 7e33a7b709..a41359fdc4 100644
--- a/client/src/pages/VideoGen.remix.test.jsx
+++ b/client/src/pages/VideoGen.remix.test.jsx
@@ -192,6 +192,15 @@ describe('VideoGen cross-page Remix handoff', () => {
]));
});
+ it('restores a record older than the history page by hydrating it by id', async () => {
+ state.listVideoHistory.mockResolvedValue([]);
+ state.getVideoHistoryItem.mockResolvedValue(RECORD);
+ await renderVideoGenPage(`/media/video?remix=${RECORD.id}`);
+ await waitFor(() => expect(screen.getByLabelText('Prompt')).toHaveValue(RECORD.prompt));
+ expect(state.getVideoHistoryItem).toHaveBeenCalledTimes(1);
+ expect(screen.queryByText(/no longer in your history/)).toBeNull();
+ });
+
it('says nothing about a missing record while the history fetch is still in flight', async () => {
let settleHistory;
state.listVideoHistory.mockReturnValue(new Promise((resolve) => { settleHistory = resolve; }));
diff --git a/client/src/test/videoGenPageMocks.jsx b/client/src/test/videoGenPageMocks.jsx
index 5f3bc29972..0119a1b756 100644
--- a/client/src/test/videoGenPageMocks.jsx
+++ b/client/src/test/videoGenPageMocks.jsx
@@ -70,6 +70,8 @@ export const state = {
universeStyle: DEFAULT_UNIVERSE_STYLE,
/** `GET /api/video-gen/history`; a spy so a suite can defer it, reject it, or seed records. */
listVideoHistory: vi.fn(),
+ /** `GET /api/video-gen/history/:id`, the fallback for a record older than the page load. */
+ getVideoHistoryItem: vi.fn(),
/**
* Last props handed to the panels below, captured by mocks that still render
* NOTHING — the five older suites assert over the DOM, so a probe element
@@ -96,7 +98,7 @@ export const state = {
runtimeStatus: { installed: true, ready: true, current: true },
};
-const SPIES = ['getVideoGenStatus', 'getVideoGenModelContext', 'generateVideo', 'previewVideoPrompt', 'start', 'startWhenIdle', 'repair', 'cancel', 'refresh', 'listVideoHistory', 'listLorasFull'];
+const SPIES = ['getVideoGenStatus', 'getVideoGenModelContext', 'generateVideo', 'previewVideoPrompt', 'start', 'startWhenIdle', 'repair', 'cancel', 'refresh', 'listVideoHistory', 'getVideoHistoryItem', 'listLorasFull'];
/** Restore every documented default, including fresh spies. Call it first in `beforeEach`. */
export function resetVideoGenMockState() {
@@ -123,6 +125,7 @@ export function resetVideoGenMockState() {
state.runtimeStatus = { installed: true, ready: true, current: true };
for (const key of SPIES) state[key].mockReset();
state.listVideoHistory.mockResolvedValue([]);
+ state.getVideoHistoryItem.mockRejectedValue(new Error('Video history entry not found'));
state.previewVideoPrompt.mockResolvedValue(null);
state.listLorasFull.mockImplementation(async () => state.availableLoras);
}
@@ -191,7 +194,7 @@ vi.mock('../services/api', () => ({
previewVideoPrompt: (...args) => state.previewVideoPrompt(...args),
cancelVideoGen: vi.fn(async () => ({})),
listVideoHistory: (...args) => state.listVideoHistory(...args),
- getVideoHistoryItem: vi.fn(async () => { throw new Error('Video history entry not found'); }),
+ getVideoHistoryItem: (...args) => state.getVideoHistoryItem(...args),
deleteVideoHistoryItem: vi.fn(async () => ({})),
setVideoHidden: vi.fn(async () => ({})),
extractLastFrame: vi.fn(async () => ({})),
diff --git a/server/services/videoGen/historyList.js b/server/services/videoGen/historyList.js
index fc93d62fa6..14b40b7ab2 100644
--- a/server/services/videoGen/historyList.js
+++ b/server/services/videoGen/historyList.js
@@ -24,6 +24,18 @@ const catalogRow = entry => ({
...(entry.trimmedFrom ? { trimmedFrom: entry.trimmedFrom } : {}),
});
+// Mirrors client lib/mediaSearch.js buildMediaHaystack: field-scoped, so a token
+// like "prompt" or "true" cannot match JSON key names or flags.
+const haystack = entry => [
+ entry.prompt, entry.metadata?.prompt, entry.negativePrompt, entry.negative_prompt, entry.modelId, entry.model,
+ entry.filename, entry.id, entry.seed != null ? `seed ${entry.seed}` : '',
+ entry.width && entry.height ? `${entry.width}x${entry.height}` : '',
+ ...[entry.loraFilenames, entry.lora_filenames].flatMap(v => Array.isArray(v) ? v : []),
+ entry.universeName, entry.entryName, entry.entryLabel, entry.entryCategory, entry.entryKind,
+ entry.extractedFromVideoId ? 'extracted frame' : '', entry.stitchedFrom ? 'stitched' : '',
+ entry.upscaledFrom ? 'upscaled 2x' : '',
+].filter(v => typeof v === 'string' || typeof v === 'number').join(' ').toLowerCase();
+
const time = value => Date.parse(value) || 0;
/**
@@ -36,7 +48,7 @@ export async function listVideoHistoryQuery({ limit, offset, q, hidden, compact
const tokens = q.trim().toLowerCase().split(/\s+/).filter(Boolean);
const matching = (Array.isArray(history) ? history : []).filter(entry => entry
&& (hidden === undefined || !!entry.hidden === hidden)
- && (!tokens.length || tokens.every(token => JSON.stringify(entry).toLowerCase().includes(token))));
+ && (!tokens.length || (text => tokens.every(token => text.includes(token)))(haystack(entry))));
const paged = limit !== undefined;
const ordered = paged
? [...matching].sort((a, b) => time(b.createdAt) - time(a.createdAt) || String(a.id).localeCompare(String(b.id)))
diff --git a/server/services/videoGen/historyList.test.js b/server/services/videoGen/historyList.test.js
index e848fccda7..d4cb462759 100644
--- a/server/services/videoGen/historyList.test.js
+++ b/server/services/videoGen/historyList.test.js
@@ -42,6 +42,8 @@ describe('listVideoHistoryQuery', () => {
it('searches the full prompt beyond the compact preview and honors hidden', async () => {
const hit = await listVideoHistoryQuery(parse({ q: 'needle', compact: 'true' }), history);
expect(hit.map(r => r.id)).toEqual(['new']);
+ const keyName = await listVideoHistoryQuery(parse({ q: 'createdat', compact: 'true' }), history);
+ expect(keyName).toEqual([]);
const visible = await listVideoHistoryQuery(parse({ hidden: 'false', compact: 'true' }), history);
expect(visible.map(r => r.id)).toEqual(['old', 'mid']);
});