Skip to content

Commit 8942ffe

Browse files
Yuruzuuclaude
andcommitted
fix(web): a side chat with a run keeps its draft when closed
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent db9cc56 commit 8942ffe

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎apps/web/src/hooks/useRightPanelSurfaceClose.browser.test.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ it.each([
167167
threadRemoved: false,
168168
cleared: false,
169169
},
170+
{
171+
name: "it has a run, so its removal can only be an archive",
172+
sideChatShell: { latestRun: { runId: "run-1" } },
173+
threadRemoved: true,
174+
cleared: false,
175+
},
170176
])(
171177
"clears a closed side chat's draft only after deletion: $name",
172178
async ({

‎apps/web/src/hooks/useRightPanelSurfaceClose.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,20 @@ export function useRightPanelSurfaceClose(input: {
7575
const sideChatRef = scopeThreadRef(ref.environmentId, surface.threadId);
7676
const shellIsLive = () =>
7777
appAtomRegistry.get(environmentShell.stateValueAtom(ref.environmentId)).status === "live";
78+
const sideChatShell = readThreadShell(sideChatRef);
7879
// Deleting and archiving both drop it from the live shell; an archived draft must survive.
79-
if (shellIsLive() && readThreadShell(sideChatRef) === null) return;
80+
if (shellIsLive() && sideChatShell === null) return;
81+
// The server keeps a side chat with a run, so a later removal is an archive, not this delete.
82+
const keptByServer = sideChatShell?.latestRun != null;
8083
if (!readEnvironmentScope(ref.environmentId, AuthOrchestrationOperateScope)) return;
8184
// The server keeps a side chat with a run or message. Reopen skips one it deleted.
8285
void deleteThread({
8386
environmentId: ref.environmentId,
8487
input: { threadId: surface.threadId, onlyIfUnused: true },
8588
}).then(async (result) => {
8689
// Success also covers a kept side chat, whose draft must survive.
87-
if (result._tag !== "Success" || !(await waitForThreadRemoval(sideChatRef))) return;
90+
if (keptByServer || result._tag !== "Success") return;
91+
if (!(await waitForThreadRemoval(sideChatRef))) return;
8892
if (shellIsLive()) useComposerDraftStore.getState().clearDraftThread(sideChatRef);
8993
});
9094
};

0 commit comments

Comments
 (0)