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(webui): keep late history pages out of the next chat (#2628)
ZedingZhangda30a57b80cf
diff --git a/apps/desktop/resources/lan-webui/app.js b/apps/desktop/resources/lan-webui/app.jsindex e72c9fdee..2234a67d3 100644--- a/apps/desktop/resources/lan-webui/app.js+++ b/apps/desktop/resources/lan-webui/app.js@@ -765,6 +765,9 @@const messages = el("div", { class: "messages" });if (nextCursor) {+ // A background refresh keeps the route object. Navigating away and back replaces it.+ const route = state.route;+ const stillOnPage = () => state.me && state.route === route;messages.append(el("button", {type: "button",class: "link load-older",@@ -773,12 +776,13 @@try {const before = scroller.scrollHeight;const page = await api("GET", `/v1/sessions/${enc(sessionId)}/history?cursor=${enc(nextCursor)}`);+ if (!stillOnPage()) return;chatState.older = [...page.items, ...chatState.older];chatState.olderCursor = page.nextCursor;await render({ refresh: true });- scroller.scrollTop += scroller.scrollHeight - before;+ if (stillOnPage()) scroller.scrollTop += scroller.scrollHeight - before;} catch (error) {- fail(error);+ if (stillOnPage()) fail(error);}},}));diff --git a/apps/desktop/test/lan-webui-browser-user-path.e2e.mjs b/apps/desktop/test/lan-webui-browser-user-path.e2e.mjsindex 40764a6e2..d1ce819ab 100644--- a/apps/desktop/test/lan-webui-browser-user-path.e2e.mjs+++ b/apps/desktop/test/lan-webui-browser-user-path.e2e.mjs@@ -341,6 +341,71 @@ test("a phone pairs with a formatted paste, uses projects and conversations, andassert.equal(server.devices().length, 0, "browser sign-out revoked its device");});+test("late history stays with its chat while the current chat can page through a refresh", { timeout: 60_000 }, async (t) => {+ const script = String.raw`(async () => {+ const wait = async (check) => {+ const deadline = performance.now() + 5000;+ while (!check()) {+ if (performance.now() > deadline) throw new Error("Timed out: " + check);+ await new Promise(requestAnimationFrame);+ }+ };+ const older = () => document.querySelector(".load-older");+ const messages = () => document.querySelector(".messages").textContent;+ const view = () => document.getElementById("app").dataset.view;+ let events;+ window.EventSource = class extends EventSource {+ constructor(url) { super(url); events = this; }+ };+ const refresh = async () => {+ const button = older();+ events.dispatchEvent(new MessageEvent("change", { data: "{}" }));+ await wait(() => older() && older() !== button);+ };+ const pages = new Map();+ const request = window.fetch.bind(window);+ window.fetch = async (path, options) => {+ const url = new URL(path, location.href);+ const id = url.pathname.split("/")[3];+ if (url.pathname.endsWith("/history")) {+ return new Promise((resolve) => pages.set(id, {+ cursor: url.searchParams.get("cursor"),+ finish: (text, nextCursor) => resolve(Response.json({ items: [{ id: text, role: "user", text }], nextCursor })),+ }));+ }+ const response = await request(path, options);+ if (path === "/v1/sessions/s-a1" || path === "/v1/sessions/s-b1") {+ const detail = await response.json();+ detail.messages.nextCursor = id === "s-a1" ? "80" : "40";+ return Response.json(detail);+ }+ return response;+ };++ await wait(() => document.getElementById("pair-code")?.value === window.__code);+ document.querySelector('.pair button[type="submit"]').click();+ await wait(() => view() === "home");+ location.hash = "#/s/s-a1";+ await wait(() => view() === "chat:s-a1" && older());+ older().click();+ await wait(() => pages.has("s-a1"));+ location.hash = "#/s/s-b1";+ await wait(() => view() === "chat:s-b1" && older());+ pages.get("s-a1").finish("Older message from A", "70");+ await refresh();+ const showedA = messages().includes("Older message from A");++ older().click();+ await wait(() => pages.has("s-b1"));+ await refresh();+ pages.get("s-b1").finish("Older message from B", null);+ await wait(() => messages().includes("Older message from B"));+ return JSON.stringify({ showedA, cursor: pages.get("s-b1").cursor, hasMore: Boolean(older()) });+ })()`;+ const { result } = await runPhone(t, script, { scan: true });+ assert.deepEqual(result, { showedA: false, cursor: "40", hasMore: false });+});+const scanJourney = String.raw`(async () => {const field = () => document.getElementById("pair-code");async function wait(check) {diff --git a/docs/spec/01-product/03-lan-webui-mvp.md b/docs/spec/01-product/03-lan-webui-mvp.mdindex 89f71a350..447eef3bd 100644--- a/docs/spec/01-product/03-lan-webui-mvp.md+++ b/docs/spec/01-product/03-lan-webui-mvp.md@@ -116,7 +116,9 @@ invalidate stale rows and deep links; do not redirect to a different session.Desktop defaults. Keep the previous binding on failure and let the userreload the choices. Running, queued, waiting, archived, scheduled, andextension-owned sessions cannot be changed from this picker.-- Page older history backwards without losing the reading position. Render+- Page older history backwards without losing the reading position. A page+ requested before navigating away must not change the new view's messages,+ pagination cursor or scroll position. Renderuser/assistant text, safe Markdown, code and bounded tool summaries in order.Unsupported cards or attachments get a typed, non-executable placeholder;do not fetch embedded remote images or open local files from transcript text.diff --git a/docs/spec/06-delivery/e2e/live-and-remote.md b/docs/spec/06-delivery/e2e/live-and-remote.mdindex ac539695a..5199cf5e9 100644--- a/docs/spec/06-delivery/e2e/live-and-remote.md+++ b/docs/spec/06-delivery/e2e/live-and-remote.md@@ -806,6 +806,8 @@ fixtures; do not use a user's running instance.- **Steps:** Double-tap New session in B, send text, stream a reply, then continuethe same session on Desktop. Queue a second message while busy and cancel it;interrupt the named active turn. Reopen the older B chat and load older pages.+ Delay a history response, switch chats, then release it. Load an older page+ in the current chat while a live update refreshes it.Create a temporary conversation from its own entry, and one in B from Home'sNew conversation picker. Reopen B's chat from Home's Recent list. Repeat withno configured model and with a pre-existing eligible empty conversation in B.@@ -820,6 +822,8 @@ fixtures; do not use a user's running instance.queued only by request; otherwise its client sees busy and keeps the draft.Canceled work never runs and stop preserves partial output. Paging olderitems keeps position, without wrong-project empty reuse or duplicate creates.+ A late page from the previous chat leaves the current transcript and cursor+ intact. A refresh within the current chat still allows its page to load.A temporary session has no project and never inherits A or B.Missing model blocks send, preserves text and points to Desktop setup.The selected model is used for the next turn and is visible on Desktop