From c8ca682bf28e43d03e836de53b466809cbafb806 Mon Sep 17 00:00:00 2001 From: Steven Nance Date: Sat, 5 Dec 2026 06:09:46 +0100 Subject: [PATCH] fix(ui): remount the composer takeover card per pending input (#15121) ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents ask people for decisions through cards in the task chat > - The composer shows one pending card at a time in a takeover slot > - The checkbox card and the suggested-tasks card keep the selection, the reason and the page in local React state > - The takeover slot renders each pending card in the same position without a React `key`, so React reuses one card instance for the next pending card > - The next card then starts with the state of the card before it > - This pull request adds a `key` for each pending input, so each card mounts with its own state > - The benefit is that each card shows and sends only its own options ## Linked Issues or Issue Description No public issue exists for this bug. The description follows the bug report template. **What happened?** A task had two pending cards of the same kind. I answered the first card. The takeover slot then showed the second card, but the second card kept the selection state of the first card. The default ticks of the second card did not show. The card also wrote the selection of the first card into the saved draft of the second card. When I confirmed the second checkbox card, it sent option ids that belong to the first card. The server refused the request with `Unknown checkbox confirmation optionId`. **Expected behavior** Each pending card starts with its own default selection. Each card sends only its own option ids. Each card saves only its own draft. **Steps to reproduce** 1. Create two pending `request_checkbox_confirmation` interactions on one task. Give them different option ids and different `defaultSelectedOptionIds`. 2. Open the task. The composer takeover shows one of the cards. 3. Change the ticks on that card, then confirm it. 4. Look at the next card in the takeover slot. Its default ticks do not show. 5. Confirm the next card. The request fails with `Unknown checkbox confirmation optionId`. The same fault occurs with two pending `suggest_tasks` cards. **Paperclip version or commit** `master` at `1c07b5903b1b11139b1e1ce052a3cd4885865d90`. **Deployment mode** Self-hosted server. The bug is in the UI and does not depend on the deployment mode. Related work: a search of issues and pull requests found no report and no fix for this bug. #14613 and #9290 change the same cards, but they do not change how the takeover slot mounts a card. ## What Changed - `ui/src/components/TaskChatThread.tsx`: the takeover `TaskChatProtocolCard` and `TaskChatInteractionCard` now have `key={selectedPendingInput.key}`. React mounts a new card when the pending input changes. - `ui/src/components/TaskChatThread.test.tsx`: two new tests. One test covers two pending checkbox cards. One test covers two pending suggested-tasks cards. Each test answers the first card and then checks the ticks, the submitted ids and the saved draft of the second card. - The branch has two commits. The first commit adds only the tests. The second commit adds the fix. ## Verification Run these commands from the repository root: - `pnpm exec vitest run --project @paperclipai/ui ui/src/components/TaskChatThread.test.tsx` - On the tests-only commit: 2 failed, 195 passed. The two failures are the new tests. - On the head commit: 197 passed. - `pnpm exec vitest run --project @paperclipai/ui`: 679 test files passed, 7316 tests passed. - `pnpm --filter @paperclipai/ui typecheck`: no errors. - `pnpm check:token-gates`: all gates clean. - `pnpm check:tokens`: no forbidden tokens. Manual check: on a self-hosted build that has the same two-line change, two pending checkbox cards on one task were accepted one after the other. Each request sent the option ids of its own card. This build was not the head commit of this branch. I did not run `pnpm -r typecheck`, the full `pnpm test:run`, `pnpm build` or the browser suites. The change touches only the two UI files above. ## Risks Low risk. A card in the takeover slot now mounts again when the selected pending input changes. Unsaved local state of the card that leaves the slot is not kept in memory. Selections and reasons stay in the saved draft for each card, as before. The card does not mount again while the same pending input stays selected, because the key is stable for one pending input. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) from Anthropic, run as a coding agent with tool use (shell, file edit, test runs). The context window size of the run was not recorded. A person reviews the change before the pull request opens. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes (not applicable: no documentation describes this behavior) - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --- ui/src/components/TaskChatThread.test.tsx | 174 ++++++++++++++++++++++ ui/src/components/TaskChatThread.tsx | 4 + 2 files changed, 178 insertions(+) diff --git a/ui/src/components/TaskChatThread.test.tsx b/ui/src/components/TaskChatThread.test.tsx index 101d04d0152..60832eb9e98 100644 --- a/ui/src/components/TaskChatThread.test.tsx +++ b/ui/src/components/TaskChatThread.test.tsx @@ -4897,6 +4897,180 @@ describe.each([true, false])("Unanswered question history (conversationMode=%s)" }); }); +describe("TaskChatThread pending card takeover state", () => { + function pendingInteraction( + id: string, + kind: "request_checkbox_confirmation" | "suggest_tasks", + createdAt: string, + payload: Record, + ): IssueThreadInteraction { + return { + ...questionInteraction(id, id, createdAt), + kind, + payload: { version: 1, ...payload }, + } as IssueThreadInteraction; + } + + function takeover() { + const element = container.querySelector( + '[data-testid="task-chat-composer-takeover"]', + ); + expect(element).not.toBeNull(); + return element!; + } + + function tickedLabels() { + return Array.from( + takeover().querySelectorAll('[role="checkbox"][aria-checked="true"]'), + ).map((checkbox) => checkbox.closest("label")?.textContent); + } + + async function click(element: Element | null | undefined) { + expect(element).toBeTruthy(); + await act(async () => { + (element as HTMLElement).click(); + }); + } + + function button(label: string) { + return Array.from(takeover().querySelectorAll("button")).find( + (candidate) => candidate.textContent === label, + ); + } + + function checkbox(label: string) { + return Array.from(takeover().querySelectorAll("label")) + .find((candidate) => candidate.textContent === label) + ?.querySelector('[role="checkbox"]'); + } + + it("gives the next pending checkbox card its own ticks, submission and draft", async () => { + const first = pendingInteraction( + "checkbox-first", + "request_checkbox_confirmation", + "2026-08-25T18:00:02.000Z", + { + prompt: "First card", + options: [ + { id: "first-a", label: "First A" }, + { id: "first-b", label: "First B" }, + ], + defaultSelectedOptionIds: ["first-a"], + }, + ); + const second = pendingInteraction( + "checkbox-second", + "request_checkbox_confirmation", + "2026-08-25T18:00:01.000Z", + { + prompt: "Second card", + options: [ + { id: "second-a", label: "Second A" }, + { id: "second-b", label: "Second B" }, + ], + defaultSelectedOptionIds: ["second-b"], + }, + ); + const onAcceptInteraction = vi.fn(async () => {}); + const props = { + issueId: "issue-1", + comments: [], + onAdd: async () => {}, + onAcceptInteraction, + onRejectInteraction: async () => {}, + }; + + render(); + expect(takeover().textContent).toContain("First card"); + await click(checkbox("First B")); + expect(tickedLabels()).toEqual(["First A", "First B"]); + await click(button("Confirm selection")); + expect(onAcceptInteraction).toHaveBeenLastCalledWith(first, undefined, [ + "first-a", + "first-b", + ]); + + render( + , + ); + expect(takeover().textContent).toContain("Second card"); + expect(tickedLabels()).toEqual(["Second B"]); + expect( + JSON.parse( + localStorage.getItem( + "paperclip:task-input:issue-1:interaction:checkbox-second", + ) ?? "null", + ), + ).toEqual({ selected: ["second-b"], reason: "" }); + await click(button("Confirm selection")); + expect(onAcceptInteraction).toHaveBeenLastCalledWith(second, undefined, [ + "second-b", + ]); + }); + + it("gives the next pending suggested-tasks card its own selection", async () => { + const first = pendingInteraction( + "tasks-first", + "suggest_tasks", + "2026-08-25T18:00:02.000Z", + { + tasks: [ + { clientKey: "first-a", title: "First A" }, + { clientKey: "first-b", title: "First B" }, + ], + }, + ); + const second = pendingInteraction( + "tasks-second", + "suggest_tasks", + "2026-08-25T18:00:01.000Z", + { + tasks: [ + { clientKey: "second-a", title: "Second A" }, + { clientKey: "second-b", title: "Second B" }, + ], + }, + ); + const onAcceptInteraction = vi.fn(async () => {}); + const props = { + issueId: "issue-1", + comments: [], + onAdd: async () => {}, + onAcceptInteraction, + onRejectInteraction: async () => {}, + }; + + render(); + await click(checkbox("First B")); + expect(tickedLabels()).toEqual(["First A"]); + await click(button("Create selected")); + expect(onAcceptInteraction).toHaveBeenLastCalledWith(first, ["first-a"]); + + render( + , + ); + expect(tickedLabels()).toEqual(["Second A", "Second B"]); + expect( + JSON.parse( + localStorage.getItem( + "paperclip:task-input:issue-1:interaction:tasks-second", + ) ?? "null", + ), + ).toEqual({ selected: ["second-a", "second-b"], reason: "" }); + await click(button("Create selected")); + expect(onAcceptInteraction).toHaveBeenLastCalledWith(second, [ + "second-a", + "second-b", + ]); + }); +}); + describe("TaskChatThread composer alignment", () => { it("matches the thread width at every breakpoint", () => { render( {}} />); diff --git a/ui/src/components/TaskChatThread.tsx b/ui/src/components/TaskChatThread.tsx index e05880eedb6..6bc7af0127a 100644 --- a/ui/src/components/TaskChatThread.tsx +++ b/ui/src/components/TaskChatThread.tsx @@ -3133,9 +3133,12 @@ export function TaskChatThread(props: TaskChatThreadProps) { return agentMap?.get(assigneeAgentId) ?? null; }, [agentMap, currentAssigneeValue]); + // Keyed per pending input: the cards keep their selection, reason and page + // in local state, which must not carry over to the next pending card. const takeoverContent = selectedPendingInput ? ( selectedPendingInput.kind === "runtime" ? ( ) : (