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: 防止旧全量历史读取覆盖新会话缓存
geng yue20cdaef74fcf
diff --git a/apps/desktop/src/stores/runtime/session-runtime.ts b/apps/desktop/src/stores/runtime/session-runtime.tsindex a7e541ab4..8b0f7121a 100644--- a/apps/desktop/src/stores/runtime/session-runtime.ts+++ b/apps/desktop/src/stores/runtime/session-runtime.ts@@ -214,10 +214,11 @@ export function createSessionRuntime({ get, set }: StoreAccess): SessionRuntime}async function loadFullSessionMessages(id: string, cache = true): Promise<UiMessage[] | null> {+ const previous = sessionTranscriptCache.get(id);const detail = await api.getSession(id);if (!detail.session) return null;const messages = detail.session.messages ?? [];- if (cache) cacheSessionTranscript(id, messages, {+ if (cache && sessionTranscriptCache.get(id) === previous) cacheSessionTranscript(id, messages, {messageStart: 0,hasMoreBefore: false,});diff --git a/apps/desktop/test/full-transcript-refresh-race.test.mjs b/apps/desktop/test/full-transcript-refresh-race.test.mjsnew file mode 100644index 000000000..089754095--- /dev/null+++ b/apps/desktop/test/full-transcript-refresh-race.test.mjs@@ -0,0 +1,34 @@+import assert from "node:assert/strict";+import { register } from "node:module";+import test from "node:test";+register(new URL("./helpers/ts-import-hooks.mjs", import.meta.url));+const { createSessionRuntime } = await import("../src/stores/runtime/session-runtime.ts");+const { api } = await import("../src/lib/api.ts");++test("late full-history read cannot replace a newer streaming cache", async t => {+ const old = { id: "old", role: "user", content: "original" };+ const live = { id: "live", role: "assistant", content: "new reply", status: "streaming" };+ const state = { activeSessionId: "session", messages: [old], retainedTranscripts: {}, runningSessions: {} };+ const runtime = createSessionRuntime({ get: () => state, set() {} });+ runtime.cacheSessionTranscript("session", [old]);+ let finish;+ t.mock.method(api, "getSession", () => new Promise(resolve => { finish = resolve; }));+ const reading = runtime.loadFullSessionMessages("session");+ const newer = [old, live];+ runtime.cacheSessionTranscript("session", newer);+ finish({ session: { messages: [old] } });+ assert.deepEqual(await reading, [old]);+ assert.equal(runtime.sessionTranscriptCache.get("session"), newer);+});++test("unchanged full-history reads can populate the cache, while uncached reads leave it alone", async t => {+ const state = { activeSessionId: "session", messages: [], retainedTranscripts: {}, runningSessions: {} };+ const runtime = createSessionRuntime({ get: () => state, set() {} });+ const history = [{ id: "history", role: "user", content: "earlier input" }];+ t.mock.method(api, "getSession", async () => ({ session: { messages: history } }));+ assert.equal(await runtime.loadFullSessionMessages("session", false), history);+ assert.equal(runtime.sessionTranscriptCache.has("session"), false);+ assert.equal(await runtime.loadFullSessionMessages("session"), history);+ assert.equal(runtime.sessionTranscriptCache.get("session"), history);+ assert.deepEqual(runtime.sessionHistoryCache.get("session"), { messageStart: 0, hasMoreBefore: false });+});diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 55ee6f22e..b8c160bef 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -1,5 +1,9 @@# 08. Component Spec+A full transcript read may fill its session cache only when that cache has not+changed during the request. New streaming or edit snapshots retain ownership;+the caller still receives the requested history for its own action validation.+Live delegation reconstruction crosses system notices as well as steeringmessages. An ordinary user prompt remains the run boundary. A running Taskbehind a system notice must not become aborted on navigation (Refs #1990).diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 8d3fd8660..1403beee9 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -1,5 +1,12 @@# 04. E2E Test Plan+### E2E-TRANSCRIPT-full-read-cache-race++Hold a full-history read, publish a newer streaming snapshot, then resolve the+old read. The caller receives history while the session cache keeps the newer+snapshot. Coverage: `full-transcript-refresh-race.test.mjs` plus existing+session-runtime update regressions. No provider execution is required.+### E2E-SUBAGENT-system-notice-reconstructionReconstruct a transcript with a running Task followed by a system notice.diff --git a/docs/zh-CN/spec/04-ux/08-component-spec.md b/docs/zh-CN/spec/04-ux/08-component-spec.mdindex 69011ffcb..fb20a1d16 100644--- a/docs/zh-CN/spec/04-ux/08-component-spec.md+++ b/docs/zh-CN/spec/04-ux/08-component-spec.md@@ -1,5 +1,8 @@# 08. 组件规格+全量会话读取仅在请求期间缓存未改变时写入该会话缓存。新的流式消息或编辑+快照保留所有权;调用方仍得到读取的历史,用于独立动作校验。+运行中子代理状态重建跨过系统通知及 steering 消息,普通用户提示仍作为回合边界。系统通知之前仍在运行的 Task 不会因导航而显示已停止(Refs #1990)。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 a1e9b5c5d..1edd76182 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@@ -1,5 +1,11 @@# 04. E2E 测试 Plan+### E2E-TRANSCRIPT-full-read-cache-race++保持全量历史读取请求,发布新的流式快照,再返回旧读取结果。调用方得到历史,+会话缓存保留新快照。覆盖 `full-transcript-refresh-race.test.mjs` 和现有会话+更新回归,不执行模型请求。+### E2E-SUBAGENT-system-notice-reconstruction重建运行中的 Task 后接系统通知的会话,生产条目构建、运行状态选择及结果