Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(chat): isolate asktool card state by request (#961)

Yuxinof71679d76aa7
diff --git a/apps/desktop/src/components/Composer.tsx b/apps/desktop/src/components/Composer.tsx
index afe8707df..d964d6be4 100644
--- a/apps/desktop/src/components/Composer.tsx
+++ b/apps/desktop/src/components/Composer.tsx
@@ -513,7 +513,7 @@ export function Composer({
<PlanApprovalBar proposal={planCheckpoint} />
) : null}
{pendingAsk ? (
- <AskToolCard request={pendingAsk} queued={queuedAsks} />
+ <AskToolCard key={pendingAsk.requestId} request={pendingAsk} queued={queuedAsks} />
) : null}
{nativeReadOnly ? (
<div className="composer-status" role="status">
diff --git a/docs/spec/04-ux/11-asktool-question-card.md b/docs/spec/04-ux/11-asktool-question-card.md
index 97a3d1d0e..6fa429028 100644
--- a/docs/spec/04-ux/11-asktool-question-card.md
+++ b/docs/spec/04-ux/11-asktool-question-card.md
@@ -70,3 +70,11 @@ contains scroll chaining, and preserves keyboard scroll padding. The question
header, question text, custom-answer input, and Skip / Next / Submit actions
remain visible while the user scrolls through the options. This behavior also
applies on narrow screens; the card does not rely on page-level scrolling.
+
+## Request transitions
+
+The question index, draft answers, and submission state belong to the displayed
+request. Switching chats or advancing the pending queue mounts a fresh card at
+question one with empty answers and enabled actions. State from the previous
+request must not leak into the destination request. Unsubmitted card drafts are
+local to the mounted card and are reset when it is replaced.
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 7e68fd896..53921df1f 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -9354,6 +9354,13 @@ This test plan spec is accepted when:
- **Milestone**: M5
- **Status**: Draft (unit coverage active; desktop journey pending)
+- **Request transition regression**: Keep a one-question request pending in chat
+ B. In chat A, advance a two-question request to question two, then select B.
+ B must show its first question with fresh answer state and a usable composer,
+ without rendering the application error screen. Also queue two requests in
+ one session: submit the first, answer the second differently, and verify both
+ resolutions contain their own request IDs and selected values.
+
#### E2E-124: Window controls minimize to the taskbar and close to the chosen surface
- **Preconditions**: Built desktop app on macOS, Windows, and Linux; English
diff --git a/docs/zh-CN/spec/04-ux/11-asktool-question-card.md b/docs/zh-CN/spec/04-ux/11-asktool-question-card.md
index 66670d99e..b086a986e 100644
--- a/docs/zh-CN/spec/04-ux/11-asktool-question-card.md
+++ b/docs/zh-CN/spec/04-ux/11-asktool-question-card.md
@@ -40,3 +40,9 @@ Asktool 卡是内联输入框批准表面,而不是许可
| 选项标记 | `--text-xs-plus` | 11.5 px | — | 与选项文本成比例 |
| 自定义输入文本 | `--text-sm-plus` | 12.5 px | — | 与选项文本一致 |
| 拒绝按钮 | `--text-xs` | 11 px | — | 安静的次要动作 |
+
+## 请求切换
+
+题号、草稿答案和提交状态属于当前显示的请求。切换聊天或推进等待队列时,新卡片从
+第一题开始,答案为空且操作可用。前一个请求的状态不得带入目标请求。未提交的卡片
+草稿仅保存在已挂载的卡片内,卡片被替换时会重置。
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 5a74013f8..93a6da29d 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -6213,6 +6213,11 @@ eleven-tool-round desktop paths are verified by
- **里程碑**:M5
- **状态**:草案(单位覆盖范围有效;桌面旅程待定)
+- **请求切换回归**:在聊天 B 留下一个单题请求。在聊天 A 将双题请求推进到第二题,
+ 再切换到 B。B 应显示自己的第一题、空白答案和可用输入框,不应出现应用错误页。
+ 在同一会话排队两个请求,提交第一个后为第二个选择不同答案,确认两次提交分别包含
+ 自己的请求 ID 和所选答案。
+
#### E2E-124:最小化隐藏跨平台托盘中的窗口
- **先决条件**:在 macOS、Windows 和 Linux 上构建桌面应用程序;英语
diff --git a/scripts/e2e/composer-submission.tsx b/scripts/e2e/composer-submission.tsx
index 569aea502..e37aab317 100644
--- a/scripts/e2e/composer-submission.tsx
+++ b/scripts/e2e/composer-submission.tsx
@@ -43,6 +43,58 @@ export async function verifyComposerSubmission(imagePath: string, i18n: i18n) {
flushSync(() => root.render(<I18nextProvider i18n={i18n}><Composer /></I18nextProvider>));
await painted();
assert(errors.length === 0, `composer render failed: ${errors.map(String)}`);
+ // Each queued request and each chat must own a fresh question-card state.
+ const originalResolveAskTool = api.resolveAskTool;
+ const resolutions: Parameters<typeof api.resolveAskTool>[] = [];
+ api.resolveAskTool = async (...args) => { resolutions.push(args); };
+ try {
+ const asks = ["first", "second"].map((id) => ({
+ requestId: id, sessionId, toolCallId: id,
+ questions: [{ question: id + " question", options: ["Yes", "No"], multiSelect: false }],
+ }));
+ flushSync(() => useAppStore.setState({ pendingAsks: { [sessionId]: asks } }));
+ await painted();
+ host.querySelector<HTMLButtonElement>(".asktool-option")!.click();
+ await painted();
+ host.querySelector<HTMLButtonElement>(".asktool-card-actions button:last-child")!.click();
+ await painted();
+ await painted();
+ const nextSubmit = host.querySelector<HTMLButtonElement>(".asktool-card-actions button:last-child");
+ assert(nextSubmit && !nextSubmit.disabled, "next request must be answerable");
+ assert(host.querySelector(".asktool-question")?.textContent === "second question",
+ "submitting the first request must display the next queued question");
+ assert(!host.querySelector(".asktool-option.selected"), "next request must not inherit selected answers");
+ host.querySelectorAll<HTMLButtonElement>(".asktool-option")[1].click();
+ await painted();
+ nextSubmit.click();
+ await painted();
+ await painted();
+ assert(resolutions.length === 2 && resolutions[1][0].requestId === "second"
+ && JSON.stringify(resolutions[1][0].answers) === '[["No"]]',
+ "the second answer must resolve the second request with its own selection");
+ flushSync(() => useAppStore.setState({ pendingAsks: {} }));
+ await painted();
+ flushSync(() => useAppStore.setState({ pendingAsks: {
+ [sessionId]: [{...asks[0], questions:[...asks[0].questions,{question:"A second question",options:["Choice"]}]}],
+ "other-session": [{...asks[1],sessionId:"other-session"}],
+ } }));
+ await painted();
+ host.querySelector<HTMLButtonElement>(".asktool-card-actions button:last-child")!.click();
+ await painted();
+ flushSync(() => useAppStore.setState({ activeSessionId:"other-session" }));
+ await painted();
+ assert(errors.length === 0 && host.querySelector(".composer-input"),
+ "switching from question 2 to another chat with one question must keep Composer mounted");
+ assert(host.querySelector(".asktool-question")?.textContent === "second question",
+ "switching chats must display the destination question");
+ assert(host.querySelectorAll(".asktool-indicator").length === 1,
+ "destination request must not inherit the previous question count");
+ } finally {
+ api.resolveAskTool = originalResolveAskTool;
+ flushSync(() => useAppStore.setState({ pendingAsks: {}, activeSessionId:sessionId }));
+ }
+ prefill("retry draft", [attachment]);
+ await painted();
// Do not flush the click: an immediate rejection must beat React's next render.
sendButton().click();
await painted();