Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(chat): lock queued prompt actions until admission completes
yuxino72c21cc2466a
diff --git a/apps/desktop/src/features/chat/composer/ComposerStatus.tsx b/apps/desktop/src/features/chat/composer/ComposerStatus.tsxindex 0ebe4369b..c104aa84f 100644--- a/apps/desktop/src/features/chat/composer/ComposerStatus.tsx+++ b/apps/desktop/src/features/chat/composer/ComposerStatus.tsx@@ -61,12 +61,17 @@ export function ComposerStatus({item.draft.fileReferences.map((reference) => reference.name).join(", ") ||t("chat.queuedPromptEmpty");const promoted = isPromotedQueuedPrompt(item);- const sendNowLocked =- approvalPending || promoted || isPendingQueuedPrompt(item);- // A promoted row is already the next turn: every edit action is- // locked, and the disabled controls say why instead of going quiet.+ const pending = isPendingQueuedPrompt(item);+ const actionsLocked = promoted || pending;+ const sendNowLocked = approvalPending || actionsLocked;+ // Pending rows have no actionable Host id; promoted rows already+ // belong to the next turn. Explain both locked states.const actionLabel = (action: string) =>- promoted ? `${action} · ${t("chat.sendNowPending")}` : action;+ promoted+ ? `${action} · ${t("chat.sendNowPending")}`+ : pending+ ? `${action} · ${t("common.saving")}`+ : action;return (<divkey={item.id}@@ -83,8 +88,8 @@ export function ComposerStatus({className="composer-queued-prompt-action composer-queued-prompt-move-up"tooltip={actionLabel(t("chat.moveQueuedPromptUp"))}ariaLabel={actionLabel(t("chat.moveQueuedPromptUp"))}- disabled={promoted}- aria-disabled={promoted}+ disabled={actionsLocked}+ aria-disabled={actionsLocked}onClick={() => void moveQueuedPrompt(item.id, "up")}><IconArrowUp size={13} aria-hidden />@@ -94,8 +99,8 @@ export function ComposerStatus({className="composer-queued-prompt-action composer-queued-prompt-move-down"tooltip={actionLabel(t("chat.moveQueuedPromptDown"))}ariaLabel={actionLabel(t("chat.moveQueuedPromptDown"))}- disabled={promoted}- aria-disabled={promoted}+ disabled={actionsLocked}+ aria-disabled={actionsLocked}onClick={() => void moveQueuedPrompt(item.id, "down")}><IconArrowDown size={13} aria-hidden />@@ -114,8 +119,8 @@ export function ComposerStatus({className="composer-queued-prompt-action composer-queued-prompt-edit"tooltip={actionLabel(t("chat.editQueuedPrompt"))}ariaLabel={actionLabel(t("chat.editQueuedPrompt"))}- disabled={promoted}- aria-disabled={promoted}+ disabled={actionsLocked}+ aria-disabled={actionsLocked}onClick={() => editQueuedPrompt(item.id)}><IconPencil size={13} aria-hidden />@@ -125,8 +130,8 @@ export function ComposerStatus({className="composer-queued-prompt-action composer-queued-prompt-remove"tooltip={actionLabel(t("chat.removeQueuedPrompt"))}ariaLabel={actionLabel(t("chat.removeQueuedPrompt"))}- disabled={promoted}- aria-disabled={promoted}+ disabled={actionsLocked}+ aria-disabled={actionsLocked}onClick={() => removeQueuedPrompt(item.id)}><IconX size={13} aria-hidden />diff --git a/apps/desktop/src/stores/slices/queue-slice.ts b/apps/desktop/src/stores/slices/queue-slice.tsindex d4efd4cac..cee3f62de 100644--- a/apps/desktop/src/stores/slices/queue-slice.ts+++ b/apps/desktop/src/stores/slices/queue-slice.ts@@ -118,13 +118,13 @@ export function createQueueSlice({});}- /** Drop one row locally and, unless it is still optimistic, at the Host. */+ /** Only acknowledged rows have a Host id that can actually be removed. */function detachQueuedPrompt(sessionId: string, promptId: string): void {+ if (promptId.startsWith("pending:")) return;set((state) => ({queuedPrompts: removeQueuedPrompt(state.queuedPrompts, sessionId, promptId),}));queuedDrafts.delete(promptId);- if (promptId.startsWith("pending:")) return;void api.removeQueuedPrompt(promptId).catch((error) => {get().showToast(error instanceof Error ? error.message : String(error),@@ -206,7 +206,9 @@ export function createQueueSlice({sessionId,promptId,);- if (!item || isPromotedQueuedPrompt(item)) return;+ if (!item || isPendingQueuedPrompt(item) || isPromotedQueuedPrompt(item)) {+ return;+ }// `item.content` is token-stripped; the row's captured draft is the text// and the inline file references the user actually wrote.const restored: ComposerPrefill = {diff --git a/apps/desktop/test/composer-send-state.test.mjs b/apps/desktop/test/composer-send-state.test.mjsindex a4bfe505b..3e5b8272b 100644--- a/apps/desktop/test/composer-send-state.test.mjs+++ b/apps/desktop/test/composer-send-state.test.mjs@@ -139,12 +139,12 @@ test("running prompts use a removable per-session queue with priority actions",/\{promoted \? t\("chat\.sendNowPending"\) : t\("chat\.sendNow"\)\}/,);assert.equal(- (composer.match(/disabled=\{promoted\}/g) ?? []).length,+ (composer.match(/disabled=\{actionsLocked\}/g) ?? []).length,8,- "four promoted rows set disabled and aria-disabled on move up/down, edit, and remove",+ "four pending or promoted row actions set disabled and aria-disabled on move up/down, edit, and remove",);assert.equal(- (composer.match(/aria-disabled=\{promoted\}/g) ?? []).length,+ (composer.match(/aria-disabled=\{actionsLocked\}/g) ?? []).length,4,"each locked action carries its own aria-disabled state",);diff --git a/apps/desktop/test/queue-pending-actions.test.mjs b/apps/desktop/test/queue-pending-actions.test.mjsnew file mode 100644index 000000000..ad9883cfb--- /dev/null+++ b/apps/desktop/test/queue-pending-actions.test.mjs@@ -0,0 +1,82 @@+import assert from "node:assert/strict";+import test from "node:test";+import { fileURLToPath } from "node:url";+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { createServer } from "vite";+import { IPC } from "@pi-desktop/shared";++test("pending queue actions stay locked until admission succeeds", async (t) => {+ const server = await createServer({+ root: fileURLToPath(new URL("..", import.meta.url)),+ configFile: false,+ server: { middlewareMode: true, hmr: false, ws: false },+ esbuild: { jsx: "automatic" },+ appType: "custom",+ optimizeDeps: { noDiscovery: true, include: [] },+ });+ const previousWindow = globalThis.window;+ try {+ const { createQueueSlice } = await server.ssrLoadModule("/src/stores/slices/queue-slice.ts");+ const { ComposerStatus } = await server.ssrLoadModule("/src/features/chat/composer/ComposerStatus.tsx");+ for (const action of ["removeQueuedPrompt", "editQueuedPrompt"]) {+ await t.test(action, async () => {+ let resolvePush;+ const admission = new Promise((resolve) => { resolvePush = resolve; });+ let entries = [];+ const removed = [];+ globalThis.window = { piDesktop: { invoke: async (channel, payload) => {+ if (channel === IPC.invoke.agentQueuePush) {+ await admission;+ const entry = { ...payload, id: "durable-turn", createdAt: "2026-09-21T00:00:00Z" };+ entries = [entry];+ return { ok: true, data: entry };+ }+ if (channel === IPC.invoke.agentQueueList) return { ok: true, data: { entries } };+ if (channel === IPC.invoke.agentQueueRemove) {+ removed.push(payload.turnId);+ entries = entries.filter((entry) => entry.id !== payload.turnId);+ return { ok: true, data: {} };+ }+ throw new Error(`Unexpected IPC: ${channel}`);+ } } };+ let state = { activeSessionId: "session-a", queuedPrompts: {}, showToast: assert.fail };+ const slice = createQueueSlice({+ get: () => state,+ set: (patch) => { state = { ...state, ...(typeof patch === "function" ? patch(state) : patch) }; },+ promptAttachmentsFromDraft: () => [],+ });+ Object.assign(state, slice);+ const draft = { text: "Please review this file", fileReferences: [{ path: "/test/example.ts", name: "example.ts" }] };+ const saving = slice.enqueuePrompt(draft.text, draft);+ const pending = state.queuedPrompts["session-a"][0];+ const renderButtons = () => renderToStaticMarkup(createElement(ComposerStatus, {+ t: (key) => key, queuedPrompts: state.queuedPrompts["session-a"] ?? [],+ ...slice, approvalPending: false, enhancementError: null, droppedDirectories: [],+ })).match(/<button\b[^>]*>/g) ?? [];+ const pendingButtons = renderButtons();+ assert.equal(pendingButtons.length, 5);+ assert.ok(pendingButtons.every((button) => / disabled=""/.test(button)), "all pending row actions must be disabled");+ slice[action](pending.id);+ assert.deepEqual(state.queuedPrompts["session-a"], [pending], "pending row must not appear deleted");+ assert.equal(state.composerPrefill, undefined, "pending edit must not restore a second draft");+ assert.deepEqual(removed, []);+ resolvePush();+ assert.equal(await saving, true);+ await slice.refreshQueuedPrompts("session-a");+ assert.ok(renderButtons().every((button) => !/ disabled=""/.test(button)), "acknowledged row actions unlock");+ slice[action]("durable-turn");+ await slice.refreshQueuedPrompts("session-a");+ assert.deepEqual(removed, ["durable-turn"]);+ assert.deepEqual(entries, []);+ assert.deepEqual(state.queuedPrompts["session-a"] ?? [], []);+ if (action === "editQueuedPrompt") {+ assert.deepEqual(state.composerPrefill, { sessionId: "session-a", ...draft });+ }+ });+ }+ } finally {+ globalThis.window = previousWindow;+ await server.close();+ }+});diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 12ecac6ad..a99b4ea5e 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -2733,6 +2733,10 @@ reasoning-level control.current reply/tool batch completes normally, before every waiting row. Thefirst promoted row starts the turn and the rest join it as adjacent usermessages, so the block is answered once. When idle it starts immediately.+- A pending queue row is locked until Host admission returns its durable id: move+ up/down, Send now, edit, and remove are disabled. Edit/remove tooltips explain+ that it is saving. Direct edit/remove actions leave the pending row and draft+ unchanged; after admission, ordinary waiting-row actions become available.- A promoted row is locked: move up/down, edit, and remove are disabled withtheir tooltip and `aria-disabled` state intact, and the Send now button readsas already decided (`chat.sendNowPending`). The row carries a distinctdiff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.mdindex bb0595e27..6a44c11fe 100644--- a/docs/spec/04-ux/09-interaction-patterns.md+++ b/docs/spec/04-ux/09-interaction-patterns.md@@ -724,7 +724,9 @@ may be retained while exactly one workspace supplies the visible shell context.append to that session's Host-owned, persisted FIFO queue; session switchingnever moves or clears another session's queue.- The queue renders above the composer. Each row has an independently- keyboard-reachable Remove action and a Send now action.+ keyboard-reachable Remove action and a Send now action once Host admission+ returns a durable id. While admission is pending, row actions are disabled+ and edit/remove leave both the queue and composer draft unchanged.- Send now moves its row to the head and requests the new `agent/stop` channel.The current assistant response and completed tool batch finish normally;after `agent_end` and durable turn finalization, the promoted row isdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 0aa54929f..de38db785 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -1231,7 +1231,8 @@ identify the platform validation still needed.`04-ux/09-interaction-patterns.md` (§1.6, §11)- **Acceptance**: C (session isolation, chat & stream)- **Milestone**: M2-- **Status**: Unit-covered (`composer-send-state.test.mjs`); full UI scenario Draft+- **Status**: Unit-covered (`composer-send-state.test.mjs`); pending-admission component/store user path+ covered (`queue-pending-actions.test.mjs`); full UI scenario Draft#### E2E-011b: Create a new session from a retained project group@@ -1380,7 +1381,9 @@ identify the platform validation still needed.follow-ups through their turn boundaries. Repeat with a provider error and animmediate abort. 9) With waiting rows, use move up and move down and confirmthe persisted order follows. 10) Edit a waiting row while the composer holds- text, then with an empty composer.+ text, then with an empty composer. 11) Delay Host queue admission. Attempt to+ edit/remove the pending row, release admission, then edit/remove the durable+ row. Repeat with a captured file-reference draft.- **Expected**: The single submit slot contains exactly one button in everystate: disabled Send while idle and empty, enabled Send while running withcontent (which queues the prompt), and Stop while running with an empty@@ -1402,7 +1405,10 @@ identify the platform validation still needed.is pending; each subsequent turn starts once in FIFO order, without anotherclick or session switch. Repeated terminal handling does not double-dispatch.Other sessions' queues remain unchanged, and quitting while finalization is- pending preserves queued work without starting another turn.+ pending preserves queued work without starting another turn. Pending-admission+ rows disable all five actions and remain visible without restoring a second+ draft. Once acknowledged, remove deletes the durable row and edit restores+ exactly its captured draft; neither row reappears after refresh.- **Specs linked**: `03-runtime/01-ipc-protocol.md` (§5.6),`04-ux/08-component-spec.md` (§11),`04-ux/09-interaction-patterns.md` (§3.4), ADR 0118, ADR 0213, ADR 0265diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.mdindex bf720f1be..4395e52bc 100644--- a/docs/zh-CN/spec/04-ux/08-component-spec.md+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md@@ -1964,6 +1964,9 @@ MainChat 底部的输入区域,用于撰写和发送提示。支持多行输顶掉它。随后请求 `agent/stop`,当前回复/工具批次正常结束后释放优先区块,并先于所有等待条目启动。第一条优先行启动回合,其余作为相邻的用户消息加入同一回合,因此整块只被回复一次。会话空闲时立即启动。+- 入队尚未完成的行在 Host 返回持久化 id 前保持锁定:上移/下移、立即发送、编辑和删除+ 均禁用,编辑/删除提示说明正在保存。直接调用编辑/删除也不改变该行或草稿;+ 入队确认后恢复普通等待行的操作。- 被提升的行会被锁定:上移/下移、编辑和删除均被禁用,但仍保留 tooltip 与`aria-disabled` 状态,立即发送按钮显示为已决定(`chat.sendNowPending`)。该行使用不同的提升外观,避免被误认为普通等待行。diff --git a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md b/docs/zh-CN/spec/04-ux/09-interaction-patterns.mdindex bc480ebea..84dfadeb9 100644--- a/docs/zh-CN/spec/04-ux/09-interaction-patterns.md+++ b/docs/zh-CN/spec/04-ux/09-interaction-patterns.md@@ -601,6 +601,8 @@### 3.5 向当前回合补充指令+- Host 入队尚未返回持久化 id 时,排队行操作保持禁用;编辑和删除不会改变条目或+ 输入框草稿,确认完成后恢复普通等待行的操作。- 运行中普通发送和回车发送仍将 follow-up 加入 Host 持久 FIFO。`Alt+Enter` 将可见草稿立即提交到当前回合,macOS 对应 `Option+Enter`。开启或关闭回车发送均可使用,且优先于已打开的自动完成菜单;空闲时正常发送。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.mdindex 35e0ca654..61fb0193f 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@@ -8491,3 +8491,14 @@ the latest destination. These assertions measure work counts, not device FPS.- **Status:** Automated by `node --experimental-strip-typesscripts/e2e-scheduled-workspace.mjs`, using production Electron dispatch andreal Rust/stdio/SQLite. Only external inference is replaced with an observer.++### E2E-011f 补充:入队确认前的操作锁定++- **前提**:会话正在回复,可控制 Host 入队请求的完成时刻。+- **步骤**:发送一条后续消息,暂停入队;尝试编辑或删除;释放入队后再次编辑或删除,+ 然后刷新队列。用带文件引用的草稿重复。+- **预期**:未确认时五个行操作都禁用,条目不消失,也不回填第二份草稿;+ 确认后删除能移除持久化条目,编辑完整回填草稿及文件引用,刷新不会恢复已移除条目。+- **规格**:`04-ux/08-component-spec.md`、`04-ux/09-interaction-patterns.md`。+- **验收 / 里程碑**:C、Quality / M6+。+- **状态**:组件与状态层用户路径由 `queue-pending-actions.test.mjs` 覆盖。