Skip to content

Commit 37a63fb

Browse files
authored
fix(ui): catalog continuation silently dropped staged attachments (#123581)
A continuable catalog session exposes the full attachment surface (file inputs, plus-menu, paste), and the send button counts staged attachments as composed content — but continueCatalogSession required a non-empty text draft and always handed off attachments: []. Draft+images sent text only with the images silently vanishing (payloads leaked, never released); images-only made the enabled send button do nothing at all: the worst bug class, an action with no visible outcome and no recorded reason. Carry independently-owned attachment clones through the continuation handoff, mirroring the new-session sibling (chat-pane-session-creation.ts), and treat attachments as composed content in the guard so attachment-only continuations send. Empty draft with no attachments still no-ops.
1 parent ee6c2cb commit 37a63fb

2 files changed

Lines changed: 78 additions & 4 deletions

File tree

‎ui/src/pages/chat/chat-pane-history.test.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function createTestChatPane(params: { client: GatewayBrowserClient; sessions: Se
7979
const state = {
8080
agentsList: null,
8181
assistantAgentId: null,
82+
chatAttachments: [],
8283
chatError: null,
8384
chatHistoryPagination: { hasMore: false },
8485
chatLoading: false,
@@ -717,6 +718,70 @@ describe("chat pane catalog continuation lifecycle", () => {
717718
expect(state.handleSendChat).not.toHaveBeenCalled();
718719
});
719720

721+
it("carries staged attachments through the continuation handoff", async () => {
722+
const request = vi.fn().mockResolvedValue({ sessionKey: "agent:main:continued-attachments" });
723+
const { key, pane, state } = createCatalogContinuationPane(request);
724+
state.chatAttachments = [
725+
{
726+
id: "att-1",
727+
mimeType: "image/png",
728+
fileName: "shot.png",
729+
dataUrl: "data:image/png;base64,AAAA",
730+
},
731+
];
732+
733+
await pane.continueCatalogSession(key);
734+
735+
const handoff = consumePaneSessionHandoff(
736+
pane.context,
737+
pane.paneId,
738+
"agent:main:continued-attachments",
739+
);
740+
expect(handoff?.send).toBe(true);
741+
expect(handoff?.attachments).toHaveLength(1);
742+
expect(handoff?.attachments[0]).toMatchObject({
743+
mimeType: "image/png",
744+
fileName: "shot.png",
745+
dataUrl: "data:image/png;base64,AAAA",
746+
});
747+
});
748+
749+
it("continues an attachment-only draft instead of silently ignoring the send", async () => {
750+
const request = vi.fn().mockResolvedValue({ sessionKey: "agent:main:attachment-only" });
751+
const { key, pane, state } = createCatalogContinuationPane(request);
752+
state.chatMessage = "";
753+
state.chatAttachments = [
754+
{
755+
id: "att-2",
756+
mimeType: "image/png",
757+
fileName: "only.png",
758+
dataUrl: "data:image/png;base64,BBBB",
759+
},
760+
];
761+
762+
await pane.continueCatalogSession(key);
763+
764+
expect(request).toHaveBeenCalledWith("sessions.catalog.continue", key);
765+
const handoff = consumePaneSessionHandoff(
766+
pane.context,
767+
pane.paneId,
768+
"agent:main:attachment-only",
769+
);
770+
expect(handoff?.send).toBe(true);
771+
expect(handoff?.attachments).toHaveLength(1);
772+
});
773+
774+
it("still ignores a continuation with no draft and no attachments", async () => {
775+
const request = vi.fn();
776+
const { key, pane, state } = createCatalogContinuationPane(request);
777+
state.chatMessage = " ";
778+
state.chatAttachments = [];
779+
780+
await pane.continueCatalogSession(key);
781+
782+
expect(request).not.toHaveBeenCalled();
783+
});
784+
720785
it("does not stage or send a continuation rejected by its logical pane", async () => {
721786
const request = vi.fn().mockResolvedValue({ sessionKey: "agent:main:rejected-continuation" });
722787
const { key, pane, state } = createCatalogContinuationPane(request);

‎ui/src/pages/chat/chat-pane-history.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import {
1717
areUiSessionKeysEquivalent,
1818
parseAgentSessionKey,
1919
} from "../../lib/sessions/session-key.ts";
20-
import { replaceChatAttachmentsFromEditor } from "./attachment-payload-store.ts";
20+
import {
21+
cloneChatAttachmentsForIndependentOwner,
22+
replaceChatAttachmentsFromEditor,
23+
} from "./attachment-payload-store.ts";
2124
import type { ChatHistoryPagination } from "./chat-history-pagination.ts";
2225
import {
2326
loadChatHistory,
@@ -535,8 +538,14 @@ export abstract class ChatPaneHistory extends ChatPaneSession {
535538
const scope = this.captureConnectionScope();
536539
const state = scope?.state;
537540
const client = scope?.client;
538-
const draft = state?.chatMessage.trim();
539-
if (!scope || !state || !client || !draft || !this.catalogSession?.canContinue) {
541+
const draft = state?.chatMessage.trim() ?? "";
542+
// Attachments count as composed content: an image-only continuation must
543+
// send, not silently no-op while the send button looks live.
544+
if (!scope || !state || !client || !this.catalogSession?.canContinue) {
545+
return;
546+
}
547+
const attachments = cloneChatAttachmentsForIndependentOwner(state.chatAttachments);
548+
if (!draft && attachments.length === 0) {
540549
return;
541550
}
542551
const sourceSessionKey = state.sessionKey;
@@ -573,7 +582,7 @@ export abstract class ChatPaneHistory extends ChatPaneSession {
573582
return;
574583
}
575584
preparePaneSessionHandoff(this.context, this.paneId, result.sessionKey, {
576-
attachments: [],
585+
attachments,
577586
draft,
578587
send: true,
579588
});

0 commit comments

Comments
 (0)