Skip to content

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

fix(desktop): clear task badge when restoring chat

vastsa3a9516a4d7d3
diff --git a/apps/desktop/src/features/app/useAppShellRuntime.tsx b/apps/desktop/src/features/app/useAppShellRuntime.tsx
index 08d0f0869..248969144 100644
--- a/apps/desktop/src/features/app/useAppShellRuntime.tsx
+++ b/apps/desktop/src/features/app/useAppShellRuntime.tsx
@@ -49,6 +49,9 @@ export function useAppShellRuntime() {
const ready = useAppStore((s) => s.ready);
const page = useAppStore((s) => s.page);
const activeSessionId = useAppStore((s) => s.activeSessionId);
+ const acknowledgeSessionOutcome = useAppStore(
+ (s) => s.acknowledgeSessionOutcome,
+ );
const showToast = useAppStore((s) => s.showToast);
const handleAgentEvent = useAppStore((s) => s.handleAgentEvent);
const handlePlansChanged = useAppStore((s) => s.handlePlansChanged);
@@ -417,6 +420,19 @@ export function useAppShellRuntime() {
.catch(() => undefined);
}, [activeSessionId, page]);
+ useEffect(() => {
+ const acknowledgeFocusedSession = () => {
+ if (!ready || page !== "chat" || !activeSessionId) return;
+ // Restoring the existing chat from the taskbar is a read action even
+ // when the active session did not change. Keep the host row and shell
+ // badge in sync with what the user can now see.
+ void acknowledgeSessionOutcome(activeSessionId).catch(() => undefined);
+ };
+
+ window.addEventListener("focus", acknowledgeFocusedSession);
+ return () => window.removeEventListener("focus", acknowledgeFocusedSession);
+ }, [acknowledgeSessionOutcome, activeSessionId, page, ready]);
+
useEffect(() => {
if (!ready) return;
void refreshPluginThemes();
diff --git a/apps/desktop/src/stores/slices/session-slice.ts b/apps/desktop/src/stores/slices/session-slice.ts
index e3e0c6bf4..d7f48174a 100644
--- a/apps/desktop/src/stores/slices/session-slice.ts
+++ b/apps/desktop/src/stores/slices/session-slice.ts
@@ -242,6 +242,7 @@ export function createSessionSlice({
);
}
set({ selectingSessionId: id, page: "chat" });
+ const outcomeAcknowledgement = get().acknowledgeSessionOutcome(id);
const commitSelection = (
messages: UiMessage[],
@@ -421,7 +422,6 @@ export function createSessionSlice({
}
rememberSessionCompactions(id, detail.session);
void get().restorePendingPlan(id);
- void get().acknowledgeSessionOutcome(id);
const selected = get().sessions.find((session) => session.id === id);
if (
selected &&
@@ -459,6 +459,7 @@ export function createSessionSlice({
}
}
} finally {
+ await outcomeAcknowledgement;
if (runtime.isCurrentSessionSelection(selection)) {
runtime.clearSessionSelection(selection);
set((state) =>
diff --git a/apps/desktop/test/notification-contract.test.mjs b/apps/desktop/test/notification-contract.test.mjs
index 54956b4b0..4084c680f 100644
--- a/apps/desktop/test/notification-contract.test.mjs
+++ b/apps/desktop/test/notification-contract.test.mjs
@@ -17,6 +17,7 @@ const [
apiSource,
storeSource,
appSource,
+ shellRuntimeSource,
sidebarSource,
pluginRuntimeSource,
] =
@@ -24,8 +25,9 @@ const [
read("../../../packages/shared/src/protocol.ts"),
readMainSource(),
read("../src/lib/api.ts"),
- readStoreSource(),
+ readStoreSource(),
readAppSource(),
+ read("../src/features/app/useAppShellRuntime.tsx"),
read("../src/components/Sidebar.tsx"),
read("../electron/main/plugin-runtime.ts"),
]);
@@ -84,6 +86,19 @@ test("the visible chat session suppresses durable task notifications", () => {
assert.match(appSource, /setNotificationViewingSession\(viewingSessionId\)/);
});
+test("restoring the focused chat acknowledges its session outcome", () => {
+ assert.match(shellRuntimeSource, /acknowledgeSessionOutcome/);
+ assert.match(
+ shellRuntimeSource,
+ /window\.addEventListener\("focus", acknowledgeFocusedSession\)/,
+ );
+ assert.match(
+ shellRuntimeSource,
+ /ready \|\| page !== "chat" \|\| !activeSessionId/,
+ );
+ assert.match(shellRuntimeSource, /acknowledgeSessionOutcome\(activeSessionId\)/);
+});
+
test("sidebar terminal outcomes are notification-backed, not lifecycle-backed", () => {
const terminalStart = eventsSource.indexOf('} else if (event.type === "agent_end" || event.type === "error")');
const terminalEnd = eventsSource.indexOf(' if (event.type === "planning_state")', terminalStart);
diff --git a/apps/desktop/test/sidebar-session-status.test.mjs b/apps/desktop/test/sidebar-session-status.test.mjs
index e856e2800..ed0147c6c 100644
--- a/apps/desktop/test/sidebar-session-status.test.mjs
+++ b/apps/desktop/test/sidebar-session-status.test.mjs
@@ -66,11 +66,23 @@ test("prioritizes in-progress and selected states over terminal outcomes", () =>
assert.equal(sidebarSessionStatus({ running: false, selected: false }), null);
});
-test("opening a conversation acknowledges its outcome badge", () => {
+test("opening a conversation acknowledges its outcome badge before loading details", () => {
const sessionSource = readStoreModuleSync("slices/session-slice.ts");
const catalogSource = readStoreModuleSync("slices/catalog-slice.ts");
const selectBlock = sessionSource.match(/selectSession: async[\s\S]*?\n newSession:/)?.[0] ?? "";
- assert.match(selectBlock, /acknowledgeSessionOutcome\(id\)/);
+ const acknowledgementStart = selectBlock.indexOf(
+ "const outcomeAcknowledgement = get().acknowledgeSessionOutcome(id);",
+ );
+ const detailLoadStart = selectBlock.indexOf(
+ "const detailPromise = runtime.loadSessionDetail(id",
+ );
+ assert.ok(acknowledgementStart >= 0);
+ assert.ok(detailLoadStart >= 0);
+ assert.ok(
+ acknowledgementStart < detailLoadStart,
+ "session outcome acknowledgement must start before detail loading",
+ );
+ assert.match(selectBlock, /await outcomeAcknowledgement/);
const ackBlock = catalogSource.slice(
catalogSource.indexOf("acknowledgeSessionOutcome: async"),
diff --git a/docs/spec/04-ux/07-ui-design-system.md b/docs/spec/04-ux/07-ui-design-system.md
index 32e69e91b..0470566cc 100644
--- a/docs/spec/04-ux/07-ui-design-system.md
+++ b/docs/spec/04-ux/07-ui-design-system.md
@@ -260,12 +260,14 @@ turn clears the prior terminal outcome; abort clears the live indicator without
creating a failure. Opening a conversation acknowledges its unread terminal
outcome: the terminal mark clears immediately and the matching durable task
notification is marked read so the mark cannot return after a notification
-refresh or app restart. Outcomes already marked read never produce a terminal
-mark. Marking the row read, marking all rows read, or clearing the inbox also
-dismisses any matching task-native banner; a late event for that durable id
-cannot restore the mark, row, or banner. Reduced-motion mode disables the
-breathing animation while retaining its orange fill and localized accessible
-name.
+refresh or app restart. Restoring/focusing the app with that conversation still
+visible in the chat applies the same acknowledgement without requiring a
+session switch; other sessions remain unread. Outcomes already marked read
+never produce a terminal mark. Marking the row read, marking all rows read, or
+clearing the inbox also dismisses any matching task-native banner; a late event
+for that durable id cannot restore the mark, row, or banner. Reduced-motion mode
+disables the breathing animation while retaining its orange fill and localized
+accessible name.
### 4.6 Tailwind CSS variable stub
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 9fb7de6f9..cbba43b56 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -3849,6 +3849,10 @@ Sidebar footer Popover (360px max)
and scrolls the transcript to its latest content. The successful read also
dismisses the matching task-native banner before a late activation can
surface it again.
+- Restoring/focusing the app from its taskbar or Dock while an unread terminal
+ outcome's session is already visible in the chat marks that session's
+ matching durable notifications read; it does not mark outcomes belonging to
+ other sessions.
- Mark all read is idempotent and preserves rows; it dismisses every outstanding
task-native banner. Clear deletes every inbox row, dismisses all task-native
banners, and leaves sessions, transcripts, and turns intact. These actions
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 6b555bbe7..a5439d7cc 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -4213,22 +4213,26 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
turn; notification inbox starts empty.
- **Steps**: 1) Focus and view session A, then complete a turn in A. 2) While
still focused on A, fail a turn in background session B. 3) Unfocus the
- window and complete another turn in A. 4) Abort a fourth turn. 5) Repeat each
- terminal RPC. 6) Confirm the main titlebar has no bell, then open the bell in
- the expanded sidebar footer and switch between All and Unread. 7) Mark one
+ window and complete another turn in A. 4) Restore/focus the app from its
+ taskbar or Dock without switching sessions and confirm A's visible terminal
+ outcome is acknowledged. 5) Abort a fourth turn. 6) Repeat each terminal
+ RPC. 7) Confirm the main titlebar has no bell, then open the bell in
+ the expanded sidebar footer and switch between All and Unread. 8) Mark one
row read and confirm its session has no terminal sidebar mark, then
- close/reopen the popover and restart the app. 8) Select the other session
- from its terminal-marked sidebar row. 9) Generate a host fixture with 205
- eligible terminal turns. 10) Use Mark all read, then Clear. 11) While a
+ close/reopen the popover and restart the app. 9) Select the other session
+ from its terminal-marked sidebar row. 10) Generate a host fixture with 205
+ eligible terminal turns. 11) Use Mark all read, then Clear. 12) While a
native task banner and a renderer refresh are still in flight, deliver a
delayed `notification.changed` payload for a cleared/read durable id and a
- duplicate payload for an id that is already present. 12) On Windows, create
+ duplicate payload for an id that is already present. 13) On Windows, create
one unread successful outcome while the bell has no failure rows. Open the
empty bell popover, use Mark all read, then create another success and use
- Clear. 13) Create enough unread outcomes for a two-digit count and inspect
+ Clear. 14) Create enough unread outcomes for a two-digit count and inspect
the taskbar overlay before and after marking all outcomes read.
-- **Expected**: A's visible-current completion creates no row or terminal sidebar mark. Exactly two rows
- exist, newest first: the unfocused A completion and background B failure,
+- **Expected**: A's visible-current completion creates no row or terminal
+ sidebar mark. Restoring/focusing the app with A already visible clears A's
+ matching durable outcome and taskbar count without clearing B. Exactly two
+ rows exist, newest first: the unfocused A completion and background B failure,
with localized labels, snapshotted session titles, and B's stable code.
Abort/repeated terminal calls create no row. The former footer Help shortcut
is absent; the 32px footer bell and its upward-opening popover replace it.