Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
feat(session-collaboration): run a worker's report at the next turn boundary
Tioit-Wang6828ff8f3dab
diff --git a/apps/desktop/electron/main/services/session-collaboration.ts b/apps/desktop/electron/main/services/session-collaboration.tsindex dc2e30b6d..a20413d18 100644--- a/apps/desktop/electron/main/services/session-collaboration.ts+++ b/apps/desktop/electron/main/services/session-collaboration.ts@@ -134,7 +134,7 @@ export function createSessionCollaborationService(deps: SessionCollaborationDepeif (!deps.isPluginLoaded(current.pluginId)) fail("ABORTED", "The sending plugin is no longer enabled");// beginTurn rechecks the persisted authorization ceiling at execution,// including when a queued turn resumes after settings have changed.- await bridge.agentHost.startTurn(DESKTOP_PRINCIPAL, {+ const started = await bridge.agentHost.startTurn(DESKTOP_PRINCIPAL, {sessionId: current.targetSessionId,input: { text: current.content, sessionMessageId: current.id },admission: "queue",@@ -142,6 +142,22 @@ export function createSessionCollaborationService(deps: SessionCollaborationDepecontext: { requestId: `session-message:${current.id}` },});checkCurrent(host);+ // A worker's report is not user input that was queued a minute ago. When+ // the target is busy, the receipt must run at the very next turn boundary+ // (promoted, ADR 0265) instead of behind everything the user already+ // queued. A turn that already started, or a queue move that lost a race,+ // is not an error.+ if (current.kind === "completion" && started.turn.status === "queued") {+ await bridge.queue.prioritize(started.turn.id).catch((error: unknown) => {+ if (errorCode(error) !== "CONFLICT") {+ deps.log("Session completion delivery could not be prioritized", {+ messageId: current.id,+ turnId: started.turn.id,+ error: String(error),+ });+ }+ });+ }const accepted = (await host.call<{ message: SessionCollaborationMessage }>("session.collaboration.message", { messageId: current.id },)).message;diff --git a/docs/adr/0265-turn-queue-priority-block-and-row-actions.md b/docs/adr/0265-turn-queue-priority-block-and-row-actions.mdindex efb5698e5..e4572e51f 100644--- a/docs/adr/0265-turn-queue-priority-block-and-row-actions.md+++ b/docs/adr/0265-turn-queue-priority-block-and-row-actions.md@@ -82,6 +82,12 @@ queue at all even though the Host already orders it by a durable `position`.reason, canceling its approvals and inputs) and lets the queue run, and themodule's drain request is remembered while a pass is running instead of beingdropped.+Session collaboration completion receipts are promoted automatically. A worker's+report is not input the user queued a minute ago: when the receiving session is+busy, the receipt runs at the very next turn boundary instead of behind the+plain queue. The move is the same promotion a row action performs, so it inherits+the steering rules above — a Desktop-owned turn never has another session's text+injected into it, and the report becomes that session's next turn.## Consequences and validationdiff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.mdindex 6f3e4941e..2e5469603 100644--- a/docs/spec/07-plugins/03-plugin-api.md+++ b/docs/spec/07-plugins/03-plugin-api.md@@ -1018,6 +1018,9 @@ host records creator provenance and does not impose a fixed concurrency ceiling.A requested completion callback is a host-owned `completion` message linked tothe source delivery and is created at most once after the actual target turnsettles, including a delivery fenced as `interrupted` by an application restart.+A completion receipt is promoted in the target session's turn queue, so a busy+target runs it at the next turn boundary ahead of input the user queued earlier+(ADR 0265); it is never injected into another session's running turn.The callback is session data, not a new user authorization, and completionmessages do not trigger another callback.diff --git a/docs/zh-CN/spec/07-plugins/03-plugin-api.md b/docs/zh-CN/spec/07-plugins/03-plugin-api.mdindex 1d96667e7..62df3f258 100644--- a/docs/zh-CN/spec/07-plugins/03-plugin-api.md+++ b/docs/zh-CN/spec/07-plugins/03-plugin-api.md@@ -840,6 +840,8 @@ Session ID,并复用该会话的项目、模型、上下文和权限配置;`同时运行多少个 worker 由调用方插件自行决定:宿主只记录创建来源,不施加固定的并发上限。请求的完成回调是宿主拥有的 `completion` 消息,链接到源投递,并且只在实际目标回合结算后最多创建一次;被应用重启栅栏标记为 `interrupted` 的投递也一样会生成该回执。+完成回执会在目标会话的回合队列中被提升,因此繁忙的目标会在下一个回合边界优先执行它,+而不是排在用户早先排队的输入之后(ADR 0265);它永远不会被注入另一个会话正在运行的回合。回调是会话数据,不是新的用户授权;完成消息不会触发另一个回调。渲染器可以读取单独的侧边栏协作投影,但插件面板不能绕过此网关调用变更操作。