Skip to content

Open source CapCut alternative.

TypeScript

fix(site): a deleted or pruned chat thread re-homes its scene run instead of hiding it

David Le5242a5fa80b9
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index 34160e1a..5b2b20c6 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -137,6 +137,11 @@ function writeThreads(list: ChatThread[]) {
...list.slice(0, THREAD_LIMIT),
...list.slice(THREAD_LIMIT).filter((t) => threadOwnsAssets(t.id)),
];
+ // A pruned thread's scene run re-homes so its card stays reachable.
+ const keptIds = new Set(kept.map((t) => t.id));
+ for (const t of list) {
+ if (!keptIds.has(t.id)) useGenScene.getState().orphanThread(t.id);
+ }
try {
localStorage.setItem(threadsKey(), JSON.stringify(slimForStorage(kept)));
} catch {
@@ -223,6 +228,9 @@ export function AiPanel({ onClose }: { onClose: () => void }) {
// The thread's chat-only assets go with it; anything placed or filed
// into Media/Library stays.
deleteChatAssets(id);
+ // A scene run this thread owned becomes unowned, so its card (and any
+ // Approve gate the user still has to answer) doesn't vanish with it.
+ useGenScene.getState().orphanThread(id);
// If the open chat was deleted, start a fresh one so it can't re-save
// itself on the next message and resurrect the thread.
if (activeChat === id) setActiveChat(crypto.randomUUID());
diff --git a/site/src/cut/lib/genScene.ts b/site/src/cut/lib/genScene.ts
index 02c2af25..fdce8ba1 100644
--- a/site/src/cut/lib/genScene.ts
+++ b/site/src/cut/lib/genScene.ts
@@ -484,6 +484,9 @@ interface GenSceneState {
restyle: (style: string) => { ok: boolean; message: string };
/** Rebuild + resume a persisted run when a project loads. */
hydrate: (projectId: string, project: VideoProject) => void;
+ /** A chat thread died — a run it owned becomes unowned so its card (and
+ * Approve gate) stays reachable. */
+ orphanThread: (chatId: string) => void;
dismiss: () => void;
}
@@ -658,6 +661,19 @@ export const useGenScene = create<GenSceneState>((set, get) => ({
}
},
+ orphanThread: (chatId) => {
+ // The owning chat thread is gone (deleted, or pruned off the history cap).
+ // Re-home the run to "unowned" so its card — and an Approve gate waiting on
+ // the user — shows in whatever thread is open instead of nowhere. The
+ // orchestrator's plan drops the id too, so the next save persists the
+ // re-homing and a reload doesn't resurrect the orphan.
+ for (const orch of orchestrators.values()) {
+ if (orch.project.chatId === chatId) orch.project.chatId = undefined;
+ }
+ const run = get().run;
+ if (run?.chatId === chatId) set({ run: { ...run, chatId: null } });
+ },
+
dismiss: () => {
const run = get().run;
// Dismissing an unrendered plan abandons it: the orchestrator stops and