Skip to content

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

fix(chat): keep restored live turns visibly running

Seraph-x0a6f6a06f445
diff --git a/apps/desktop/src/components/SessionPane.tsx b/apps/desktop/src/components/SessionPane.tsx
index c40194fbb..39428ad9d 100644
--- a/apps/desktop/src/components/SessionPane.tsx
+++ b/apps/desktop/src/components/SessionPane.tsx
@@ -79,16 +79,17 @@ export const SessionPane = memo(function SessionPane({
onLoadOlder={() => loadTranscriptPage(sessionId, "before")}
searchTarget={searchTarget}
readingWindow={transcript.historical}
+ liveTail={transcript.liveTail}
onRestoreReading={restoreReading}
hasMoreAfter={transcript.hasMoreAfter}
onLoadNewer={() => loadTranscriptPage(sessionId, "after")}
onReturnToLatest={() => returnToLatest(sessionId)}
navigationLoading={transcript.loading}
isRunning={isRunning}
- pendingPermission={transcript.historical ? undefined : pendingPermission}
+ pendingPermission={transcript.liveTail ? pendingPermission : undefined}
queuedPermissions={queuedPermissions}
- askPending={transcript.historical ? false : askPending}
- planningState={transcript.historical ? undefined : planningState}
+ askPending={transcript.liveTail ? askPending : false}
+ planningState={transcript.liveTail ? planningState : undefined}
paneVisible={visible}
/>
</TranscriptDisclosureProvider>
diff --git a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
index 101219041..ec0d8381b 100644
--- a/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
+++ b/apps/desktop/src/features/chat/transcript/ChatTranscript.tsx
@@ -54,6 +54,8 @@ type ChatTranscriptProps = {
paneVisible?: boolean;
searchTarget?: TranscriptSearchTarget | null;
readingWindow?: boolean;
+ /** The displayed range includes this session's canonical live tail. */
+ liveTail?: boolean;
onRestoreReading?: RestoreTranscriptReading;
hasMoreAfter?: boolean;
onLoadNewer?: () => Promise<void>;
@@ -89,6 +91,7 @@ function TranscriptBody({
paneVisible = true,
searchTarget = null,
readingWindow = false,
+ liveTail = !readingWindow,
onRestoreReading,
hasMoreAfter = false,
onLoadNewer,
@@ -99,7 +102,7 @@ function TranscriptBody({
const openTranscriptMenu = useTranscriptMenu();
const { copyText, selectText } = useChatTextActions();
const showToast = useAppStore((state) => state.showToast);
- const transcriptRunning = isRunning && !readingWindow;
+ const transcriptRunning = isRunning && liveTail;
const latestTurnResult = useAppStore((state) =>
sessionId ? state.latestTurnResults[sessionId] : undefined,
);
@@ -148,7 +151,8 @@ function TranscriptBody({
compactions,
hasMoreBefore,
onLoadOlder,
- isRunning: transcriptRunning,
+ // Rejoining live output is not a new turn: keep the reader's scroll owner.
+ isRunning: isRunning && !readingWindow,
pendingPermission,
askPending,
approvalPending,
@@ -315,7 +319,7 @@ function TranscriptBody({
{t("chat.loadLaterMessages")}
</button>
) : null}
- {!readingWindow ? (
+ {liveTail ? (
<TurnOutcomeCard
messages={messages}
result={latestTurnResult}
diff --git a/apps/desktop/src/hooks/use-transcript-view.ts b/apps/desktop/src/hooks/use-transcript-view.ts
index c778fed5e..f15508956 100644
--- a/apps/desktop/src/hooks/use-transcript-view.ts
+++ b/apps/desktop/src/hooks/use-transcript-view.ts
@@ -19,6 +19,9 @@ export function useTranscriptView(sessionId: string) {
focus: view?.focus ?? null,
parentMessage: view?.parentMessage,
historical: Boolean(view?.focus || view?.restored),
+ // A restored range keeps reading ownership after joining live output.
+ // Only the canonical tail can carry this session's running presentation.
+ liveTail: !view?.focus && !view?.hasMoreAfter && messages.at(-1) === live.at(-1),
loading: Boolean(view?.loading),
};
}
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index 0cc6a2bb8..10af5a7b6 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -759,6 +759,11 @@ may be retained while exactly one workspace supplies the visible shell context.
- Background sessions continue without adding progress chrome to the visible
session or moving focus. Reduced motion therefore has no progress-card
transitions to preserve.
+- A restored reading range that has reached the canonical live tail presents
+ the session's running phase, elapsed time, and interaction waits normally.
+ Keeping its reading bookmark does not mean the turn has finished. Rejoining
+ live output preserves the viewport rather than acting like a new turn.
+ Explicit search, unread later pages, and disjoint snapshots remain historical.
### 2.5 Turn outcome closure
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 1e8b666fd..094fef49c 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -2104,6 +2104,24 @@ identify the platform validation still needed.
- **Milestone**: M2
- **Status**: Source-level regression covered; full visual scenario Draft
+#### E2E-TRANSCRIPT-restored-live-tail-status
+
+- **Preconditions**: An isolated renderer with two retained session panes, a
+ running turn with tool output, and the real Composer and SessionPane.
+- **Steps**: Restore a bookmark during selection revalidation; append live
+ output; switch away and reveal the running pane; inspect an unread history
+ range and an explicit search at the tail; settle and abort the turn.
+- **Expected**: The restored live tail keeps a running process header while
+ Stop is available. Content updates and pane reveal do not falsely show
+ Finished. The restored range and scroll offset remain owned by the reader.
+ Another session, unread pages, and explicit search do not inherit live
+ status. Terminal completion and abort show Finished and Stopped respectively.
+- **Automation**: `node scripts/e2e-transcript-reading-position.mjs`
+ (`transcriptLiveTailProbe`).
+- **Specs linked**: `04-ux/09-interaction-patterns.md` §2.4
+- **Acceptance**: C (session switching and running status)
+- **Status**: Automated isolated Electron regression
+
#### E2E-207: Open large and long sessions through bounded transcript windows
- **Preconditions**: A session contains a message with at least 50 MB of text
diff --git a/scripts/e2e-transcript-reading-position.mjs b/scripts/e2e-transcript-reading-position.mjs
index 36abe4759..edafd6c81 100644
--- a/scripts/e2e-transcript-reading-position.mjs
+++ b/scripts/e2e-transcript-reading-position.mjs
@@ -51,7 +51,8 @@ app.whenReady().then(async () => {
const scrolling = await window.webContents.executeJavaScript("globalThis.transcriptReadingPositionProbe()");
const session = scrolling.ok ? await window.webContents.executeJavaScript("globalThis.sessionReadingPositionProbe()") : null;
const continuation = session?.ok ? await window.webContents.executeJavaScript("globalThis.transcriptContinuationProbe()") : null;
- const result = { ok: scrolling.ok && session?.ok && continuation?.ok, scrolling, session, continuation };
+ const liveTail = continuation?.ok ? await window.webContents.executeJavaScript("globalThis.transcriptLiveTailProbe()") : null;
+ const result = { ok: scrolling.ok && session?.ok && continuation?.ok && liveTail?.ok, scrolling, session, continuation, liveTail };
console.log("READING_POSITION_PROBE " + JSON.stringify(result));
app.exit(result.ok ? 0 : 1);
} catch (error) { console.error(error); app.exit(1); }
@@ -70,7 +71,7 @@ app.whenReady().then(async () => {
assert(line, `No probe result (exit=${code}): ${output.slice(-4000)}`);
const result = JSON.parse(line.slice("READING_POSITION_PROBE ".length));
console.log(JSON.stringify(result));
- assert.equal(code, 0, result.scrolling?.error ?? result.session?.error ?? result.continuation?.error ?? output.slice(-4000));
+ assert.equal(code, 0, result.scrolling?.error ?? result.session?.error ?? result.continuation?.error ?? result.liveTail?.error ?? output.slice(-4000));
assert.equal(result.ok, true);
} finally {
await rm(temp, { recursive: true, force: true });
diff --git a/scripts/e2e/transcript-live-tail.tsx b/scripts/e2e/transcript-live-tail.tsx
new file mode 100644
index 000000000..9568f8624
--- /dev/null
+++ b/scripts/e2e/transcript-live-tail.tsx
@@ -0,0 +1,145 @@
+import { createRoot } from "react-dom/client";
+import { flushSync } from "react-dom";
+import { createInstance } from "i18next";
+import { I18nextProvider } from "react-i18next";
+import { en } from "@pi-desktop/i18n";
+import type { UiMessage } from "@pi-desktop/shared";
+import { SessionPane } from "../../apps/desktop/src/components/SessionPane";
+import { Composer } from "../../apps/desktop/src/components/Composer";
+import { useAppStore } from "../../apps/desktop/src/stores/app-store";
+import type { AppState } from "../../apps/desktop/src/stores/app-state";
+
+const frame = () => new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
+function assert(condition: unknown, label: string): asserts condition {
+ if (!condition) throw new Error(label);
+}
+async function until(predicate: () => boolean, label: string) {
+ for (let index = 0; index < 240; index++) {
+ if (predicate()) return;
+ await frame();
+ }
+ throw new Error(`Timed out: ${label}`);
+}
+function Surface() {
+ const active = useAppStore((state) => state.activeSessionId);
+ return <>
+ <div className="session-panes">
+ {["live-tail", "other-tail"].map((id) => <SessionPane key={id} sessionId={id} visible={id === active} />)}
+ </div>
+ <Composer />
+ </>;
+}
+
+declare global { var transcriptLiveTailProbe: () => Promise<unknown>; }
+globalThis.transcriptLiveTailProbe = async () => {
+ const i18n = createInstance();
+ await i18n.init({ lng: "en", resources: { en: { translation: en } } });
+ const initial = useAppStore.getState();
+ const host = document.createElement("div");
+ host.style.cssText = "position:fixed;inset:0;display:flex;flex-direction:column";
+ document.body.append(host);
+ const root = createRoot(host);
+ const createdAt = new Date(Date.now() - 30_000).toISOString();
+ const user: UiMessage = { id: "live-user", role: "user",
+ content: Array.from({ length: 30 }, (_, index) => `Inspect file ${index}.`).join("\n\n"), createdAt };
+ const tool: UiMessage = { id: "live-tool", role: "tool", content: "file contents", toolName: "Read",
+ toolStatus: "success", toolCallId: "live-read", createdAt };
+ const answer: UiMessage = { id: "live-answer", role: "assistant", content: "Still inspecting.", status: "streaming", createdAt };
+ let messages = [user, tool, answer];
+ const set = (patch: Partial<AppState>) => flushSync(() => useAppStore.setState(patch));
+ const label = () => host.querySelector('[data-session-pane="live-tail"] .tool-activity-label');
+ const activeLabel = () => Boolean(label()?.classList.contains("running"));
+ const stop = () => host.querySelector('[aria-label="' + i18n.t("chat.stopGenerating") + '"]');
+ try {
+ set({
+ activeSessionId: "live-tail", selectingSessionId: "live-tail", messages,
+ retainedSessionIds: ["live-tail", "other-tail"], retainedTranscripts: { "other-tail": [] },
+ sessions: ["live-tail", "other-tail"].map((id) => ({ id, title: id, mode: "agent", permissionMode: "ask",
+ thinkingLevel: "off", createdAt, updatedAt: createdAt, messageCount: messages.length })),
+ sessionHistory: {}, transcriptViews: {}, sessionCompactions: {}, pendingPlans: {},
+ pendingPermissions: {}, pendingAsks: {}, planningStates: {}, agentStatuses: {},
+ runningSessions: { "live-tail": true }, isRunning: true, queuedPrompts: {},
+ providers: [], providerModels: {}, plugins: [], workspace: undefined,
+ settings: { defaultMode: "agent", theme: "light", enterToSend: true, onboardingDismissed: true,
+ ...initial.settings, smoothStreaming: false },
+ });
+ flushSync(() => root.render(<I18nextProvider i18n={i18n}><Surface /></I18nextProvider>));
+ await frame();
+ assert(activeLabel(), "ordinary live process must be running");
+ assert(stop(), "the running composer must offer Stop");
+ const bookmark = { pinned: false, messageId: user.id, offset: 0, scrollTop: 0, windowSize: 60 };
+ // Public restore action used by a retained pane during selection revalidation.
+ await useAppStore.getState().restoreTranscriptReading("live-tail", bookmark, new AbortController().signal);
+ await frame();
+ assert(useAppStore.getState().transcriptViews["live-tail"]?.restored, "exercise an actual restored view");
+ assert(activeLabel(), "restored live tail must not say Finished while the composer can stop it");
+ const duration = () => host.querySelector('[data-session-pane="live-tail"] .turn-duration')?.textContent;
+ const beforeTick = duration();
+ await until(() => duration() !== beforeTick, "elapsed time keeps ticking without output deltas");
+ set({ planningStates: { "live-tail": "planning" } });
+ assert(host.querySelector('[data-session-pane="live-tail"] [data-testid="planning-indicator"]'),
+ "restored live tail keeps its planning feedback");
+ set({ planningStates: {}, pendingPermissions: { "live-tail": [{
+ sessionId: "live-tail", requestId: "permission", toolCallId: "permission-call", toolName: "Bash",
+ argsPreview: { command: "pwd" }, risk: "low", reason: "fixture",
+ }] } });
+ assert(host.querySelector('[data-session-pane="live-tail"] .permission-card button'),
+ "restored live tail must not hide an actionable approval");
+ assert(!host.querySelector('[data-session-pane="live-tail"] .transcript-runtime-status > *'),
+ "approval replaces generic running feedback");
+ set({ pendingPermissions: {} });
+ const reading = useAppStore.getState().transcriptViews["live-tail"];
+ const scroll = host.querySelector<HTMLElement>('[data-session-pane="live-tail"] .thread-scroll')!;
+ assert(scroll.scrollHeight > scroll.clientHeight + 200, "exercise an overflowing transcript");
+ scroll.dispatchEvent(new WheelEvent("wheel", { bubbles: true, deltaY: -500 }));
+ scroll.scrollTop = 160;
+ scroll.dispatchEvent(new Event("scroll", { bubbles: true }));
+ await frame();
+ const scrollTop = scroll.scrollTop;
+ assert(scrollTop > 0 && scrollTop < scroll.scrollHeight - scroll.clientHeight,
+ "the reader must be away from both ends of the transcript");
+ messages = [user, tool, { ...answer, content: "Output continues after restoration." }];
+ set({ messages, selectingSessionId: undefined });
+ await frame();
+ assert(host.textContent?.includes("Output continues after restoration."), "canonical output must keep updating");
+ assert(activeLabel(), "a content delta must not turn the header into Finished");
+ assert(useAppStore.getState().transcriptViews["live-tail"] === reading && scroll.scrollTop === scrollTop,
+ "live status must preserve the restored range and reading offset");
+ set({ activeSessionId: "other-tail", messages: [], retainedTranscripts: { "live-tail": messages, "other-tail": [] }, isRunning: false });
+ await frame();
+ assert(!host.querySelector('[data-session-pane="other-tail"] .turn-process.active'), "running state must not leak to another session");
+ set({ activeSessionId: "live-tail", messages, isRunning: true });
+ await frame();
+ assert(activeLabel(), "revealing a retained running session must preserve its status");
+ const view = useAppStore.getState().transcriptViews["live-tail"]!;
+ set({ transcriptViews: { "live-tail": { ...view, hasMoreAfter: true } } });
+ await frame();
+ assert(!activeLabel(), "a restored page with an unread gap remains historical");
+ set({ transcriptViews: { "live-tail": { ...view, focus: { sessionId: "live-tail", messageId: user.id, query: "", requestId: 1 } } } });
+ await frame();
+ assert(!activeLabel(), "an explicit search at the tail must not claim a live process");
+ set({ transcriptViews: { "live-tail": { ...view, messages: [
+ { ...user, id: "disjoint-user" }, { ...tool, id: "disjoint-tool" },
+ ] } } });
+ await frame();
+ assert(!activeLabel(), "a disjoint range must not claim the canonical live turn");
+ set({ transcriptViews: { "live-tail": view }, runningSessions: {}, isRunning: false });
+ await frame();
+ assert(label()?.textContent === i18n.t("chat.processCompleted") && !activeLabel(), "only settled run state shows Finished");
+ set({ messages: [user, tool, { ...answer, status: "aborted" }] });
+ await frame();
+ assert(label()?.textContent === i18n.t("chat.processStopped"), "abort retains its stopped status");
+ set({ messages: [user, tool, { ...answer, status: "complete", error: {
+ code: "UNKNOWN", message: "Fixture failure", retriable: false,
+ } }] });
+ await frame();
+ assert(label()?.textContent === i18n.t("chat.processFailed"), "failure retains its failed status");
+ return { ok: true, restoredLiveStatus: true, retainedSessionStatus: true, historicalIsolation: true };
+ } catch (error) {
+ return { ok: false, error: error instanceof Error ? error.stack : String(error), label: label()?.textContent, stop: Boolean(stop()) };
+ } finally {
+ flushSync(() => root.unmount());
+ host.remove();
+ useAppStore.setState(initial);
+ }
+};
diff --git a/scripts/e2e/transcript-reading-position.tsx b/scripts/e2e/transcript-reading-position.tsx
index dfb4887ab..f7d704f2f 100644
--- a/scripts/e2e/transcript-reading-position.tsx
+++ b/scripts/e2e/transcript-reading-position.tsx
@@ -1,5 +1,6 @@
import "./session-reading-position";
import "./transcript-continuation";
+import "./transcript-live-tail";
import { useCallback } from "react";
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";