From 9bae201ea30640cea5e8d8217490aebf90771e6d Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 18 Sep 2026 16:37:53 -0500 Subject: [PATCH] Route native question answers through their saved Paperclip cards Co-Authored-By: Paperclip --- ui/src/components/TaskChatThread.test.tsx | 20 +++++++++++--- ui/src/components/TaskChatThread.tsx | 33 ++++++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/ui/src/components/TaskChatThread.test.tsx b/ui/src/components/TaskChatThread.test.tsx index 887f7926f4b..6ea39c5c903 100644 --- a/ui/src/components/TaskChatThread.test.tsx +++ b/ui/src/components/TaskChatThread.test.tsx @@ -3566,7 +3566,7 @@ describe("TaskChatThread live transcript", () => { } }); - it("resolves a visible canonical input even while run adapter metadata is stale", async () => { + it.each([false, true])("resolves canonical input with stale adapter metadata (saved card: %s)", async (hasSavedCard) => { transcriptState.transcriptByRun.set("run-input", [ { kind: "runtime_request", @@ -3587,7 +3587,7 @@ describe("TaskChatThread live transcript", () => { prompt: "What should the server do?", required: true, answerMode: "single_select", - options: [{ id: "api", label: "Starter API" }], + options: [{ id: "api", label: "Starter API" }, { id: "worker", label: "Background worker" }], }, ], }, @@ -3597,8 +3597,19 @@ describe("TaskChatThread live transcript", () => { .spyOn(heartbeatsApi, "resolveRuntimeRequest") .mockResolvedValue({} as never); + const onSubmitInteractionAnswers = vi.fn().mockResolvedValue(undefined); + const saved = { + ...questionInteraction("saved-question", "What should the server do?", "2026-08-23T20:00:00.000Z"), + sourceRunId: "run-input", continuationPolicy: "none", + payload: { version: 1, runtimeRequestId: "question-1", + questionSet: transcriptState.transcriptByRun.get("run-input")[0].questionSet, + questions: [{ id: "goal", prompt: "What should the server do?", required: true, selectionMode: "single", + options: [{ id: "api", label: "Starter API" }, { id: "worker", label: "Background worker" }] }] }, + } as IssueThreadInteraction; render( {}} issueStatus="in_progress" @@ -3629,7 +3640,10 @@ describe("TaskChatThread live transcript", () => { ); await act(async () => submit?.click()); - expect(resolveRuntimeRequest).toHaveBeenCalledWith({ + if (hasSavedCard) { + expect(resolveRuntimeRequest).not.toHaveBeenCalled(); + expect(onSubmitInteractionAnswers).toHaveBeenCalledWith(saved, [{ questionId: "goal", optionIds: ["api"] }]); + } else expect(resolveRuntimeRequest).toHaveBeenCalledWith({ runId: "run-input", requestId: "question-1", turnId: "turn-1", diff --git a/ui/src/components/TaskChatThread.tsx b/ui/src/components/TaskChatThread.tsx index 2687e3638de..721d7f2e32e 100644 --- a/ui/src/components/TaskChatThread.tsx +++ b/ui/src/components/TaskChatThread.tsx @@ -2273,6 +2273,28 @@ export function TaskChatThread(props: TaskChatThreadProps) { item: TaskChatRuntimeRequestItem, decision: TaskChatRuntimeRequestDecision, ) => { + const projected = (interactions ?? []).find((interaction) => + interaction.kind === "ask_user_questions" && interaction.sourceRunId === item.runId && + interaction.payload.runtimeRequestId === item.requestId); + if (projected?.kind === "ask_user_questions") { + if (projected.status !== "pending") throw new Error("This question has already been answered or closed."); + if (decision.action === "cancel") { + if (!onCancelInteraction) throw new Error("Cancelling this question is unavailable."); + await onCancelInteraction(projected); + return; + } + if (decision.action !== "submit" || !("response" in decision) || !projected.payload.questionSet || !onSubmitInteractionAnswers) { + throw new Error("Submit the answer through the saved question card."); + } + const response = decision.response; + await onSubmitInteractionAnswers(projected, projected.payload.questionSet.questions.map(question => { + const answer = response.answers[question.id]; + const otherText = question.answerMode === "text" ? answer?.text?.trim() : answer?.customText?.trim(); + return { questionId: question.id, optionIds: question.answerMode === "text" ? [] : (answer?.selectedOptionIds ?? []), + ...(otherText ? { otherText } : {}) }; + })); + return; + } if (!item.turnId || !item.requestKind) { throw new Error( "This runtime request is missing the provider turn identity needed to resolve it.", @@ -2308,14 +2330,19 @@ export function TaskChatThread(props: TaskChatThreadProps) { resolution, }); }, - [], + [interactions, onSubmitInteractionAnswers, onCancelInteraction], ); const pendingComposerInputs = useMemo(() => { const result: PendingComposerInput[] = []; const runtimeKey = pendingRuntimeRequest ? `runtime:${pendingRuntimeRequest.runId}:${pendingRuntimeRequest.requestId}` : null; - if (pendingRuntimeRequest && runtimeKey) { + // A projected card owns the durable answer and forwards it to the live + // provider. Bypassing it leaves a pending card that blocks completion. + const projectedRuntime = pendingRuntimeRequest && (interactions ?? []).some(interaction => + interaction.kind === "ask_user_questions" && interaction.sourceRunId === pendingRuntimeRequest.runId && + interaction.payload.runtimeRequestId === pendingRuntimeRequest.requestId); + if (pendingRuntimeRequest && runtimeKey && !projectedRuntime) { result.push({ key: runtimeKey, kind: "runtime", @@ -2343,7 +2370,7 @@ export function TaskChatThread(props: TaskChatThreadProps) { ? `runtime:${interaction.sourceRunId}:${interaction.payload.runtimeRequestId}` : null; const key = recoveredRuntimeKey ?? `interaction:${interaction.id}`; - if (key === runtimeKey) continue; + result.push({ key, kind: "durable",