Compare commits

..
Author SHA1 Message Date
paseo-bot[bot]andClaude Opus 5.5 fc1f715184 Count background workspaces in the badge while Show background is on
The sidebar shows background workspaces when Show background is on, so
the dock badge and favicon now count them in that case too. They follow
the same setting the sidebar reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 11:35:44 +00:00
paseo-bot[bot] 40275bc3a4 Keep background workspaces out of the dock badge and favicon
A workspace created with `--background` is hidden from the sidebar, but an
agent finishing in it still counted toward the macOS dock badge and turned
the web favicon to attention, pointing at something the user cannot see.

The dock badge now skips background workspaces, and the favicon skips
agents whose workspace is background, the same way both already skipped
background agents. The favicon selector also rescans when the workspace
map changes, so an agent synced before its workspace is dropped once the
workspace arrives.

Closes #9975
2026-11-17 11:21:51 +00:00
10 changed files with 142 additions and 98 deletions
@@ -97,15 +97,18 @@ export class ImportSessionFlow {
await target.scrollIntoViewIfNeeded();
await expect(target).toBeInViewport();
}
/**
* Scrolls the virtualized list, the only one that leaves rows unmounted. A row handle is no way
* in: the list unmounts rows as it scrolls, and a detached row has no scroller above it.
*/
private async scrollList(forward: boolean) {
await this.page.getByTestId("import-session-list").evaluate((list, advance) => {
list.scrollTop = advance ? list.scrollTop + list.clientHeight * 0.8 : 0;
list.dispatchEvent(new Event("scroll"));
}, forward);
await this.page
.locator('[data-testid^="import-session-session-"]')
.first()
.evaluate((row, advance) => {
let element = row.parentElement;
while (element && !["auto", "scroll"].includes(getComputedStyle(element).overflowY))
element = element.parentElement;
if (!element) throw new Error("Import list has no scroll owner");
element.scrollTop = advance ? element.scrollTop + element.clientHeight * 0.8 : 0;
element.dispatchEvent(new Event("scroll"));
}, forward);
}
async search(query: string) {
await this.page.getByTestId("import-session-search").fill(query);
@@ -117,18 +120,11 @@ export class ImportSessionFlow {
await this.page.getByTestId("import-session-search").fill("");
await expect(this.page.getByTestId("import-session-load-more")).toBeVisible();
}
/** Load more keeps the reader down the list instead of sending them back to the top. */
async loadMore() {
const loadMore = this.page.getByTestId("import-session-load-more");
const topRow = this.page.getByTestId((await this.rowIds())[0]!);
await expect(topRow).toBeInViewport();
await loadMore.click();
// The next page is the last and short, so the button leaves once it lands.
await expect(loadMore).toHaveCount(0);
await expect(this.page.getByText("Loading sessions...", { exact: true })).toHaveCount(0);
await expect(topRow).not.toBeInViewport();
await this.page.getByTestId("import-session-load-more").click();
await this.revealSession("fixture-root-20");
await expect(this.page.getByText("Root session 20", { exact: true })).toBeInViewport();
await expect(this.page.getByTestId("import-session-load-more")).toHaveCount(0);
}
async retryProvider(provider: string, label: string) {
await this.expectProviderError(label);
@@ -17,11 +17,6 @@ export function nextPageLimit(limit: number): number {
return PAGE_LIMITS.find((candidate) => candidate > limit) ?? limit;
}
/** The page Load more grew this limit from, or null for the first page. */
export function previousPageLimit(limit: number): number | null {
return PAGE_LIMITS.findLast((candidate) => candidate < limit) ?? null;
}
export function requiresImportSessionsHostUpgrade(input: {
supportsSnapshot: boolean;
workspaceId?: string | null;
@@ -1172,44 +1172,6 @@ describe("ImportSessionSheet", () => {
});
});
it("keeps the loaded list in place while Load more fetches the next page", async () => {
let releaseNextPage: () => void = () => undefined;
const nextPage = new Promise<void>((resolve) => {
releaseNextPage = resolve;
});
const fetchRecentProviderSessions = vi.fn(async (options: { limit?: number } | undefined) => {
if (options?.limit !== 15) await nextPage;
return {
requestId: "recent-provider-sessions",
entries: createPageOfEntries(options?.limit === 15 ? 15 : 20),
};
});
renderSheet(createRecentSessionsClient(fetchRecentProviderSessions, vi.fn()), {
cwd: null,
snapshot: { supportsSnapshot: true, entries: [createSnapshotEntry("claude")] },
});
fireEvent.click(await screen.findByTestId("import-session-load-more"));
// The list the user scrolled to Load more is the one they keep: replacing it would drop
// them back at the top, behind a loading state, until the larger page lands.
const list = screen.getByTestId("import-session-list");
await waitFor(() => {
expect(fetchRecentProviderSessions).toHaveBeenCalledWith({
providers: ["claude"],
limit: 45,
});
});
expect(screen.getByTestId("import-session-list")).toBe(list);
expect(screen.queryByText("Loading sessions...")).toBeNull();
releaseNextPage();
await waitFor(() => {
expect(screen.queryByTestId("import-session-load-more")).toBeNull();
});
expect(screen.getByTestId("import-session-list")).toBe(list);
});
it("stops the refresh spinner and retries only the failed provider", async () => {
const fetchRecentProviderSessions = vi.fn(
async (options: { providers?: string[] } | undefined) => {
@@ -1,6 +1,6 @@
import React, { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Pressable, type PressableStateCallbackType, Text, View } from "react-native";
import { useMutation, useQueries, useQueryClient, type QueryClient } from "@tanstack/react-query";
import { keepPreviousData, useMutation, useQueries, useQueryClient } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import type {
DaemonClient,
@@ -40,7 +40,6 @@ import {
resolveDirectoryLabel,
nextPageLimit,
PER_PROVIDER_LIMIT,
previousPageLimit,
type ProviderErrorRow,
resolveImportTarget,
resolveProvidersToFetch,
@@ -101,12 +100,11 @@ interface SessionsQueryConfig {
// Query's default retry would keep the header spinner turning and pile up
// in-flight daemon requests behind a dead provider (#2512).
retry: false;
placeholderData: () => RecentSessionsResponse | undefined;
placeholderData: typeof keepPreviousData;
queryFn: () => Promise<RecentSessionsResponse>;
}
function buildSessionsQueriesConfig(args: {
queryClient: QueryClient;
providersToFetch: AgentProvider[] | null;
visible: boolean;
client: RecentProviderSessionsClient | null;
@@ -115,24 +113,14 @@ function buildSessionsQueriesConfig(args: {
limit: number;
hostDisconnectedMessage?: string;
}): SessionsQueryConfig[] {
const { queryClient, providersToFetch, visible, client, cwd, query, limit } = args;
const { hostDisconnectedMessage } = args;
const { providersToFetch, visible, client, cwd, query, limit, hostDisconnectedMessage } = args;
if (providersToFetch === null) return [];
const enabled = visible && Boolean(client);
const previousLimit = previousPageLimit(limit);
return providersToFetch.map((provider) => ({
queryKey: buildSessionsQueryKey({ cwd, query, limit, provider }),
enabled,
retry: false as const,
// While Load more fetches the next page, keep showing the page it grew from. React Query's
// keepPreviousData cannot do this here: useQueries gives a changed key a new observer, which
// has no previous data, so the rows would vanish and the list would remount at the top.
placeholderData: () =>
previousLimit === null
? undefined
: queryClient.getQueryData<RecentSessionsResponse>(
buildSessionsQueryKey({ cwd, query, limit: previousLimit, provider }),
),
placeholderData: keepPreviousData,
queryFn: async () => {
if (!client) {
throw new Error(hostDisconnectedMessage ?? i18n.t("workspace.terminal.hostDisconnected"));
@@ -534,7 +522,6 @@ export function ImportSessionSheet({
const queriesConfig = useMemo(
() =>
buildSessionsQueriesConfig({
queryClient,
providersToFetch,
visible,
client,
@@ -543,7 +530,7 @@ export function ImportSessionSheet({
limit: pageLimit,
hostDisconnectedMessage: t("workspace.terminal.hostDisconnected"),
}),
[queryClient, providersToFetch, visible, client, scopeCwd, query, pageLimit, t],
[providersToFetch, visible, client, scopeCwd, query, pageLimit, t],
);
const queries = useQueries({ queries: queriesConfig });
+11 -2
View File
@@ -6,6 +6,7 @@ import { createMacDockBadgeCountSelector } from "@/utils/desktop-badge-state";
import { createFaviconStatusSelector, type FaviconStatus } from "@/utils/favicon-status";
import { isNative } from "@/constants/platform";
import { useSessionStore } from "@/stores/session-store";
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
import { useHosts } from "@/runtime/host-runtime";
type ColorScheme = "dark" | "light";
@@ -85,8 +86,16 @@ export function useFaviconStatus() {
// The favicon reads the whole fleet, so it has to keep every host's directory loading even
// though it no longer subscribes to the agent maps.
useAllDirectoryDemand({ serverIds, enabled: !isNative });
const selectFaviconStatus = useMemo(createFaviconStatusSelector, []);
const selectMacDockBadgeCount = useMemo(createMacDockBadgeCountSelector, []);
// Background workspaces count exactly when the sidebar shows them.
const showBackground = useSidebarViewStore((state) => state.showBackground);
const selectFaviconStatus = useMemo(
() => createFaviconStatusSelector({ showBackground }),
[showBackground],
);
const selectMacDockBadgeCount = useMemo(
() => createMacDockBadgeCountSelector({ showBackground }),
[showBackground],
);
const status = useSessionStore(selectFaviconStatus);
const dockBadgeCount = useSessionStore(selectMacDockBadgeCount);
const [colorScheme, setColorScheme] = useState<ColorScheme>(getSystemColorScheme);
@@ -73,6 +73,18 @@ describe("desktop-badge-state", () => {
expect(selectMacDockBadgeCount(state)).toBe(3);
});
it("leaves out background workspaces, which the sidebar hides", () => {
const hidden = { ...workspace("a", "attention"), background: true };
expect(selectMacDockBadgeCount(stateWith(hidden))).toBeUndefined();
expect(selectMacDockBadgeCount(stateWith(hidden, workspace("b", "failed")))).toBe(1);
});
it("counts background workspaces while Show background puts them in the sidebar", () => {
const hidden = { ...workspace("a", "attention"), background: true };
expect(selectMacDockBadgeCount(stateWith(hidden), { showBackground: true })).toBe(1);
expect(createMacDockBadgeCountSelector({ showBackground: true })(stateWith(hidden))).toBe(1);
});
it("recounts only when a workspace map is replaced", () => {
const select = createMacDockBadgeCountSelector();
const state = stateWith(workspace("a", "attention"));
+16 -6
View File
@@ -19,11 +19,21 @@ export function isWorkspaceActionableForDesktopBadge(status: DesktopBadgeWorkspa
* The macOS dock badge only needs a count, so count here instead of materialising every
* workspace status and comparing the whole list on every store write.
*/
export function selectMacDockBadgeCount(state: WorkspaceStatusSource): number | undefined {
export interface DockBadgeOptions {
/** Count background workspaces too, as the sidebar shows them while Show background is on. */
showBackground?: boolean;
}
export function selectMacDockBadgeCount(
state: WorkspaceStatusSource,
options: DockBadgeOptions = {},
): number | undefined {
let actionableCount = 0;
for (const session of Object.values(state.sessions)) {
if (!session) continue;
for (const workspace of session.workspaces.values()) {
// A hidden background workspace would leave the badge pointing at nothing in the sidebar.
if (workspace.background && !options.showBackground) continue;
if (isWorkspaceActionableForDesktopBadge(workspace.status)) actionableCount += 1;
}
}
@@ -31,11 +41,11 @@ export function selectMacDockBadgeCount(state: WorkspaceStatusSource): number |
}
/** A session-store selector for the dock badge count that recounts only when a workspace map changes. */
export function createMacDockBadgeCountSelector(): (
state: WorkspaceStatusSource,
) => number | undefined {
export function createMacDockBadgeCountSelector(
options: DockBadgeOptions = {},
): (state: WorkspaceStatusSource) => number | undefined {
return memoizeOnSessionMaps<WorkspaceStatusSession, WorkspaceStatusSource, number | undefined>(
(session) => session.workspaces,
selectMacDockBadgeCount,
(session) => [session.workspaces],
(state) => selectMacDockBadgeCount(state, options),
);
}
+59 -2
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import type { Agent } from "@/stores/session-store";
import type { Agent, WorkspaceDescriptor } from "@/stores/session-store";
import { createFaviconStatusSelector, deriveFaviconStatus } from "./favicon-status";
function agent(input: Partial<Agent> & { id: string }): Agent {
@@ -14,7 +14,21 @@ function agent(input: Partial<Agent> & { id: string }): Agent {
}
function stateWith(...agents: Agent[]) {
return { sessions: { srv: { agents: new Map(agents.map((entry) => [entry.id, entry])) } } };
return stateWithWorkspaces([], ...agents);
}
function stateWithWorkspaces(
workspaces: Array<Pick<WorkspaceDescriptor, "id" | "background">>,
...agents: Agent[]
) {
return {
sessions: {
srv: {
agents: new Map(agents.map((entry) => [entry.id, entry])),
workspaces: new Map(workspaces.map((entry) => [entry.id, entry])),
},
},
};
}
describe("deriveFaviconStatus", () => {
@@ -50,6 +64,37 @@ describe("deriveFaviconStatus", () => {
),
).toBe("none");
});
it("ignores agents in background workspaces, which the sidebar hides", () => {
const hidden = { id: "ws-hidden", background: true };
expect(
deriveFaviconStatus(
stateWithWorkspaces(
[hidden],
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
agent({ id: "b", workspaceId: "ws-hidden", status: "running" }),
),
),
).toBe("none");
expect(
deriveFaviconStatus(
stateWithWorkspaces(
[hidden, { id: "ws-shown", background: false }],
agent({ id: "a", workspaceId: "ws-hidden", status: "running" }),
agent({ id: "b", workspaceId: "ws-shown", requiresAttention: true }),
),
),
).toBe("attention");
});
it("counts agents in background workspaces while Show background puts them in the sidebar", () => {
const state = stateWithWorkspaces(
[{ id: "ws-hidden", background: true }],
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
);
expect(deriveFaviconStatus(state, { showBackground: true })).toBe("attention");
expect(createFaviconStatusSelector({ showBackground: true })(state)).toBe("attention");
});
});
describe("createFaviconStatusSelector", () => {
@@ -63,6 +108,18 @@ describe("createFaviconStatusSelector", () => {
expect(select({ sessions: { ...state.sessions } })).toBe("running");
});
it("rescans when a workspace map is replaced", () => {
const select = createFaviconStatusSelector();
const state = stateWithWorkspaces(
[],
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
);
expect(select(state)).toBe("attention");
// The agent synced before its workspace; only the workspace map changes.
const workspaces = new Map([["ws-hidden", { id: "ws-hidden", background: true }]]);
expect(select({ sessions: { srv: { ...state.sessions.srv, workspaces } } })).toBe("none");
});
it("rescans when an agent map is replaced", () => {
const select = createFaviconStatusSelector();
expect(select(stateWith(agent({ id: "a", status: "running" })))).toBe("running");
+22 -6
View File
@@ -1,10 +1,11 @@
import type { Agent } from "@/stores/session-store";
import type { Agent, WorkspaceDescriptor } from "@/stores/session-store";
import { memoizeOnSessionMaps } from "./memoize-on-session-maps";
export type FaviconStatus = "none" | "running" | "attention";
interface FaviconAgentSession {
agents: ReadonlyMap<string, Agent>;
workspaces: ReadonlyMap<string, Pick<WorkspaceDescriptor, "background">>;
}
interface FaviconAgentSource {
@@ -16,13 +17,22 @@ interface FaviconAgentSource {
* three states here instead of building the aggregated agent list: the list allocates a
* projection per agent, deep-compares it and sorts every agent on the host on each update.
*/
export function deriveFaviconStatus(state: FaviconAgentSource): FaviconStatus {
export interface FaviconStatusOptions {
/** Count agents in background workspaces too, as the sidebar shows them while Show background is on. */
showBackground?: boolean;
}
export function deriveFaviconStatus(
state: FaviconAgentSource,
options: FaviconStatusOptions = {},
): FaviconStatus {
let hasAttention = false;
let hasNeedsInput = false;
for (const session of Object.values(state.sessions)) {
if (!session) continue;
for (const agent of session.agents.values()) {
if (agent.background || agent.archivedAt) continue;
if (!options.showBackground && isInBackgroundWorkspace(agent, session)) continue;
if (agent.status === "running") return "running";
if (agent.requiresAttention) hasAttention = true;
if (agent.pendingPermissions.length > 0) hasNeedsInput = true;
@@ -31,10 +41,16 @@ export function deriveFaviconStatus(state: FaviconAgentSource): FaviconStatus {
return hasAttention || hasNeedsInput ? "attention" : "none";
}
/** A session-store selector for the favicon status that rescans only when an agent map changes. */
export function createFaviconStatusSelector(): (state: FaviconAgentSource) => FaviconStatus {
function isInBackgroundWorkspace(agent: Agent, session: FaviconAgentSession): boolean {
return agent.workspaceId ? session.workspaces.get(agent.workspaceId)?.background === true : false;
}
/** A session-store selector for the favicon status that rescans only when an agent or workspace map changes. */
export function createFaviconStatusSelector(
options: FaviconStatusOptions = {},
): (state: FaviconAgentSource) => FaviconStatus {
return memoizeOnSessionMaps<FaviconAgentSession, FaviconAgentSource, FaviconStatus>(
(session) => session.agents,
deriveFaviconStatus,
(session) => [session.agents, session.workspaces],
(state) => deriveFaviconStatus(state, options),
);
}
@@ -4,18 +4,18 @@ interface SessionsSource<TSession> {
/**
* Wraps a whole-store selector so it reruns only when one of the per-session maps it reads has
* changed. Session-store writes that leave those maps alone (timeline updates, drafts) then cost
* changed. `pickMaps` returns every map the selector reads from one session. Session-store writes that leave those maps alone (timeline updates, drafts) then cost
* a reference check per host instead of a walk over every entry.
*/
export function memoizeOnSessionMaps<TSession, TState extends SessionsSource<TSession>, TResult>(
pickMap: (session: TSession) => unknown,
pickMaps: (session: TSession) => readonly unknown[],
derive: (state: TState) => TResult,
): (state: TState) => TResult {
let previousMaps: unknown[] | null = null;
let previousResult: TResult;
return (state) => {
const maps = Object.values(state.sessions).map((session) =>
session ? pickMap(session) : undefined,
const maps = Object.values(state.sessions).flatMap((session) =>
session ? pickMaps(session) : [undefined],
);
if (
previousMaps &&