Skip to content

Commit 3447e85

Browse files
committed
fix(site): invalidate debug runs on chat interrupt
interruptChat was the only debug-run-producing mutation that didn't kick the Debug panel query on success. The other four (createChatMessage, editChatMessage, promoteChatQueuedMessage, regenerateChatTitle) all invalidate chatDebugRunsKey. Without it, the panel shows stale "running" for up to the 5s poll interval after the user interrupts. Change-Id: I086ca5dde03439f6bc48458b91f9d0f0e81041fa Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent c1afd99 commit 3447e85

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

site/src/api/queries/chats.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,15 +1179,18 @@ describe("mutation invalidation scope", () => {
11791179
);
11801180
});
11811181

1182-
it("interruptChat does not invalidate unrelated queries", async () => {
1182+
it("interruptChat invalidates debug runs without touching unrelated queries", async () => {
11831183
const queryClient = createTestQueryClient();
11841184
const chatId = "chat-1";
11851185
seedAllActiveQueries(queryClient, chatId);
11861186

1187-
// interruptChat has no onSuccess handler — the WebSocket
1188-
// delivers status changes in real-time.
11891187
const mutation = interruptChat(queryClient, chatId);
1190-
expect(mutation).not.toHaveProperty("onSuccess");
1188+
await mutation.onSuccess?.();
1189+
1190+
expect(
1191+
queryClient.getQueryState(chatDebugRunsKey(chatId))?.isInvalidated,
1192+
"chatDebugRunsKey should be invalidated",
1193+
).toBe(true);
11911194

11921195
for (const { label, key } of unrelatedKeys(chatId)) {
11931196
const state = queryClient.getQueryState(key);

site/src/api/queries/chats.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -984,11 +984,15 @@ export const editChatMessage = (queryClient: QueryClient, chatId: string) => ({
984984
},
985985
});
986986

987-
export const interruptChat = (_queryClient: QueryClient, chatId: string) => ({
987+
export const interruptChat = (queryClient: QueryClient, chatId: string) => ({
988988
mutationFn: () => API.experimental.interruptChat(chatId),
989-
// No onSuccess invalidation needed: the per-chat WebSocket
990-
// delivers the status change via setChatStatus, and the global
991-
// watchChats() WebSocket updates the sidebar.
989+
onSuccess: () => {
990+
// Chat status and sidebar state are covered by the per-chat
991+
// and watchChats() WebSockets, but the Debug panel uses polling.
992+
// Kick its list query so the run flips to "interrupted" without
993+
// waiting for the next poll cycle.
994+
void invalidateChatDebugRuns(queryClient, chatId);
995+
},
992996
});
993997

994998
export const deleteChatQueuedMessage = (

0 commit comments

Comments
 (0)