Skip to content

Commit bc4623b

Browse files
fix(ui): keep volatile sends retryable after reconnect
1 parent 2afb165 commit bc4623b

6 files changed

Lines changed: 34 additions & 53 deletions

File tree

‎ui/src/e2e/chat-flow.active-run-follow-ups.e2e.test.ts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ suite.define(() => {
435435
}
436436
});
437437

438-
it("projects one disconnected state across queued follow-ups and run controls", async () => {
438+
it("projects one disconnected state for an offline steer follow-up", async () => {
439439
const context = await suite.newBrowserContext({
440440
locale: "en-US",
441441
serviceWorkers: "block",
@@ -446,7 +446,7 @@ suite.define(() => {
446446

447447
try {
448448
await page.goto(`${suite.server.baseUrl}settings/appearance`);
449-
await page.locator("[data-settings-follow-up-mode]").selectOption("queue");
449+
await page.locator("[data-settings-follow-up-mode]").selectOption("steer");
450450
await page.locator("[data-settings-send-shortcut]").selectOption("enter");
451451
await page.goto(`${suite.server.baseUrl}chat`);
452452

@@ -456,23 +456,18 @@ suite.define(() => {
456456
await gateway.waitForRequest("chat.send");
457457
await page.getByRole("button", { name: "Stop generating" }).waitFor({ timeout: 10_000 });
458458

459-
const followUpText = "wait behind the active run";
460-
await composer.fill(followUpText);
461-
await page.getByRole("button", { name: "Queue message" }).click();
462-
await page
463-
.locator(".chat-queue__item", { hasText: followUpText })
464-
.getByText("Waiting for current run")
465-
.waitFor({ timeout: 10_000 });
466-
467459
await gateway.setOnline(false);
468460
await waitForControlUiGatewayReconnecting(page);
469461

462+
const followUpText = "steer after the gateway returns";
463+
await composer.fill(followUpText);
464+
await page.locator(".agent-chat__composer-actions .chat-send-btn--send").click();
465+
470466
const rows = page.locator(".chat-queue__item");
471467
await expect.poll(() => rows.count()).toBe(1);
472468
await expect.poll(() => rows.getByText("Waiting for reconnect").count()).toBe(1);
473-
expect(await rows.getByText("Waiting for current run").count()).toBe(0);
474469
expect(await rows.getByText("Steer", { exact: true }).count()).toBe(0);
475-
expect(await page.getByRole("button", { name: "Stop generating" }).count()).toBe(0);
470+
await expectRequestCountStable(gateway, "chat.send", 1);
476471
} finally {
477472
await suite.closeBrowserContext(context);
478473
}

‎ui/src/pages/chat/chat-composer-actions.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ describe("renderChatComposer controls", () => {
280280
expect(button(view.container, t("chat.composer.startVoiceInput")).disabled).toBe(true);
281281
});
282282

283-
it("disables Stop while disconnected from an abortable run", () => {
283+
it("keeps Stop available while disconnected for an abortable run", () => {
284284
const onAbort = vi.fn();
285285
const { container } = renderComposer({ connected: false, canAbort: true, onAbort });
286-
expect(container.querySelector('[aria-label="Stop generating"]')).toBeNull();
287-
expect(onAbort).not.toHaveBeenCalled();
286+
const stop = button(container, t("chat.runControls.stopGenerating"));
287+
expect(stop.disabled).toBe(false);
288+
stop.click();
289+
expect(onAbort).toHaveBeenCalledOnce();
288290
});
289291

290292
it("offers Steer only for eligible queued messages during an active run", () => {
@@ -559,7 +561,7 @@ describe("renderChatComposer controls", () => {
559561
onAbort: vi.fn(),
560562
sendShortcut: "enter" as const,
561563
},
562-
tooltip: t("chat.runControls.send"),
564+
tooltip: t("chat.runControls.queue"),
563565
},
564566
];
565567
for (const testCase of unavailable) {
@@ -627,7 +629,6 @@ describe("renderChatComposer controls", () => {
627629
id: "reconnect-1",
628630
text: "send me once the gateway is back",
629631
createdAt: 1,
630-
queueMode: "steer",
631632
sendError: "chat.send unavailable during gateway restart",
632633
sendState: "waiting-reconnect",
633634
},
@@ -639,7 +640,6 @@ describe("renderChatComposer controls", () => {
639640
item?.querySelector('.chat-queue__icon path[d="M21 5v12a2 2 0 0 1-2 2h-6"]'),
640641
).not.toBeNull();
641642
expect(item?.querySelector(".chat-queue__error")).toBeNull();
642-
expect(item?.querySelectorAll(".chat-queue__badge")).toHaveLength(1);
643643
const state = item?.querySelector(".chat-queue__badge--reconnect");
644644
expect(state?.textContent?.trim()).toBe("Waiting for reconnect");
645645
expect(state?.getAttribute("title")).toBe("chat.send unavailable during gateway restart");

‎ui/src/pages/chat/chat-composer-queue.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,16 @@ describe("chat composer queue reordering", () => {
403403
expect(onQueueEditCancel).not.toHaveBeenCalled();
404404
});
405405

406-
it("projects an offline transition on each row without a queue header", () => {
406+
it("projects one offline state on each row without a queue header", () => {
407407
const container = renderQueue({
408408
offline: true,
409-
queue: [{ id: "a", text: "a", createdAt: 1, sendState: "waiting-idle" }],
409+
queue: [{ id: "a", text: "a", createdAt: 1, queueMode: "steer", sendState: "waiting-idle" }],
410410
onQueueRemove: vi.fn(),
411411
});
412412

413413
const row = container.querySelector(".chat-queue__item");
414414
expect(row?.classList.contains("chat-queue__item--reconnect")).toBe(true);
415+
expect(row?.querySelectorAll(".chat-queue__badge")).toHaveLength(1);
415416
expect(row?.querySelector(".chat-queue__badge--reconnect")?.textContent?.trim()).toBe(
416417
t("chat.queue.states.waitingForReconnect"),
417418
);

‎ui/src/pages/chat/chat-queue.ts‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,24 +452,26 @@ export function clearPendingQueueItemsForRun(
452452

453453
export function markQueuedChatSendsWaitingForReconnect(host: ChatQueueScopedSessionHost) {
454454
const items = chatOutboxOwner(host).allItems(host);
455-
const waitForReconnect = (current: ChatQueueItem): ChatQueueItem => ({
456-
...current,
457-
sendState: "waiting-reconnect",
458-
});
459455
for (const item of items) {
460456
if (!item.sendRunId || (item.sendState !== "sending" && item.sendState !== "waiting-idle")) {
461457
continue;
462458
}
463459
if (isVolatileQueuedMessage(host, item.id)) {
464-
updateVolatileQueuedMessage(host, item.id, waitForReconnect);
465-
} else {
466-
updateQueuedMessageForSession(
467-
host,
468-
item.sessionKey ?? host.sessionKey,
469-
item.id,
470-
waitForReconnect,
471-
item.agentId,
472-
);
460+
updateVolatileQueuedMessage(host, item.id, (current) => ({
461+
...current,
462+
sendState: "unconfirmed",
463+
}));
464+
continue;
473465
}
466+
updateQueuedMessageForSession(
467+
host,
468+
item.sessionKey ?? host.sessionKey,
469+
item.id,
470+
(current) => ({
471+
...current,
472+
sendState: "waiting-reconnect",
473+
}),
474+
item.agentId,
475+
);
474476
}
475477
}

‎ui/src/pages/chat/chat-send.test.ts‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ let removeQueuedMessage: typeof import("./chat-queue.ts").removeQueuedMessage;
193193
let removeDeliveredQueuedChatSendForRun: typeof import("./chat-queue.ts").removeDeliveredQueuedChatSendForRun;
194194
let removeVisibleOrScopedQueuedMessageWithoutReleasing: typeof import("./chat-queue.ts").removeVisibleOrScopedQueuedMessageWithoutReleasing;
195195
let markQueuedChatSendsWaitingForReconnect: typeof import("./chat-queue.ts").markQueuedChatSendsWaitingForReconnect;
196-
let keepVolatileQueuedMessage: typeof import("./chat-queue.ts").keepVolatileQueuedMessage;
197196
let subscribeChatOutboxProjection: typeof import("./chat-queue.ts").subscribeChatOutboxProjection;
198197
let syncVisibleChatQueueProjection: typeof import("./chat-queue.ts").syncVisibleChatQueueProjection;
199198
let readChatQueueForScope: typeof import("./chat-queue.ts").readChatQueueForScope;
200-
let readQueuedMessageById: typeof import("./chat-queue.ts").readQueuedMessageById;
201199
let flushChatQueueForEvent: typeof import("./chat-send-actions.ts").flushChatQueueForEvent;
202200
let retryReconnectableQueuedChatSends: typeof import("./chat-send-actions.ts").retryReconnectableQueuedChatSends;
203201
let retryQueuedChatMessage: typeof import("./chat-send-actions.ts").retryQueuedChatMessage;
@@ -225,10 +223,8 @@ async function loadChatHelpers(): Promise<void> {
225223
removeDeliveredQueuedChatSendForRun,
226224
removeQueuedMessage,
227225
markQueuedChatSendsWaitingForReconnect,
228-
keepVolatileQueuedMessage,
229226
removeVisibleOrScopedQueuedMessageWithoutReleasing,
230227
readChatQueueForScope,
231-
readQueuedMessageById,
232228
subscribeChatOutboxProjection,
233229
syncVisibleChatQueueProjection,
234230
} = await import("./chat-queue.ts"));
@@ -7795,16 +7791,8 @@ describe("handleSendChat", () => {
77957791
).toEqual([expect.objectContaining({ sendAttempts: 1, sendState: "waiting-reconnect" })]);
77967792
});
77977793

7798-
it("projects every active queued send as waiting after a disconnect", () => {
7794+
it("marks saved session queued sends waiting after a disconnect", () => {
77997795
const host = makeChatHost({ chatQueue: [] });
7800-
const volatile = {
7801-
id: "volatile-send",
7802-
text: "in flight",
7803-
createdAt: 0,
7804-
sendRunId: "run-volatile",
7805-
sendState: "sending" as const,
7806-
sessionKey: "agent:a",
7807-
};
78087796
writeChatQueueForScope(host, "agent:a", [
78097797
{
78107798
id: "pending-send-a",
@@ -7815,15 +7803,10 @@ describe("handleSendChat", () => {
78157803
sessionKey: "agent:a",
78167804
},
78177805
]);
7818-
keepVolatileQueuedMessage(host, "agent:a", volatile, undefined, { retryable: true });
78197806

78207807
markQueuedChatSendsWaitingForReconnect(host);
78217808

7822-
expect(readQueuedMessageById(host, volatile.id)).toMatchObject({
7823-
sendRunId: "run-volatile",
7824-
sendState: "waiting-reconnect",
7825-
});
7826-
expect(readQueuedMessageById(host, "pending-send-a")).toMatchObject({
7809+
expect(readChatQueueForScope(host, "agent:a")[0]).toMatchObject({
78277810
sendRunId: "run-a",
78287811
sendState: "waiting-reconnect",
78297812
});

‎ui/src/pages/chat/components/chat-composer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function renderChatComposer(props: ChatComposerProps) {
8181
state.slashCommandDispatchConnected = props.connected;
8282
const canCompose = props.canSend;
8383
const isBusy = props.sending || props.stream !== null;
84-
const canAbort = Boolean(props.connected && props.canAbort && props.onAbort);
84+
const canAbort = Boolean(props.canAbort && props.onAbort);
8585
const hasTerminalStatus = hasTerminalRunStatus(props.runStatus);
8686
const showAbortableUi = canAbort && !hasTerminalStatus;
8787
const submittedProgress = props.queue.find((item) =>

0 commit comments

Comments
 (0)