Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,19 @@ export function createWebuiSessionWorkflows(deps: {
const page = await port.loadSessions(cursor);
if (!disposed && read === flatRead && mutation !== catalogMutation) return loadMore(cursor);
if (!isCurrent()) return;
commitCatalog((current) => reduceWebuiCatalogFlatAppended(current, page), revision);
commitCatalog((current) => {
const loaded = reduceWebuiCatalogFlatAppended(current, page);
return setWebuiCatalogFlatError(loaded, undefined);
}, revision);
} catch (reason) {
if (!disposed && read === flatRead && mutation !== catalogMutation) return loadMore(cursor);
if (!disposed && read === flatRead) throw reason;
if (!disposed && read === flatRead) {
// A page that fails to load is a failure the rail has to say out loud.
// The catalog carries the message so the rail shows it as a toast, and
// the read settles instead of rejecting: the caller asked for a page,
// not for an exception it cannot route anywhere.
commitCatalog((current) => setWebuiCatalogFlatError(current, message(reason)));
}
} finally {
if (flatPending === read) flatPending = undefined;
if (isCurrent()) commitCatalog((current) => setWebuiCatalogFlatLoading(current, false));
Expand Down
30 changes: 30 additions & 0 deletions packages/webui/src/client/features/sessions/ui/SessionRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ function WebuiProjectListView({
const [visibleProjectSessionCounts, setVisibleProjectSessionCounts] =
useState<Readonly<Record<string, number>>>({});
const [visibleProjectCount, setVisibleProjectCount] = useState(PROJECT_GROUP_BATCH_SIZE);
const [requestedProjects, setRequestedProjects] = useState<ReadonlySet<string>>(() => new Set());
const requestedCursor = useRef<string | undefined>(undefined);
const retriedCursor = useRef<string | undefined>(undefined);
const toggleProjectExpansion = useCallback((projectKey: string) => {
projectExpansionTouched.current = true;
requestedCursor.current = undefined;
setRequestedProjects((current) => new Set(current).add(projectKey));
setExpandedProjects((current) => {
const next = new Set(current);
if (next.has(projectKey)) next.delete(projectKey);
Expand Down Expand Up @@ -500,6 +505,31 @@ function WebuiProjectListView({
!expandedProjects.has(autoExpandedProjectKey)
? new Set(expandedProjects).add(autoExpandedProjectKey)
: expandedProjects;
// Project records cover the whole catalog, while page.sessions is paginated
// globally. An explicitly opened project can therefore be empty until later
// pages arrive. Continue only until it has its first visible batch; remember
// the cursor so a failed request does not cause an automatic retry loop.
useEffect(() => {
if (loading || !page.hasMore || !page.nextCursor || !onLoadMore || query?.trim()) return;
const needsPage = projects.some((project) =>
requestedProjects.has(project.key) && expandedProjects.has(project.key) &&
project.sessionIds.filter((id) => !pinnedSessions?.[id]).length < PROJECT_SESSION_BATCH_SIZE,
);
if (!needsPage) return;
const cursor = page.nextCursor;
if (requestedCursor.current === cursor) {
// This cursor was already asked for and the request failed. The failure
// is on screen now, so one retry is allowed: a user who opened a
// project must not be left with a silently half-loaded list. A second
// failure waits for the next expand.
if (error === undefined || retriedCursor.current === cursor) return;
retriedCursor.current = cursor;
} else {
retriedCursor.current = undefined;
}
requestedCursor.current = cursor;
onLoadMore();
}, [error, expandedProjects, loading, onLoadMore, page.hasMore, page.nextCursor, pinnedSessions, projects, query, requestedProjects]);
const selectedChildParentId = selectedSessionId && treePage
? treePage.sessions.find((node) =>
node.childSessions.some((child) => child.sessionId === selectedSessionId),
Expand Down
22 changes: 21 additions & 1 deletion packages/webui/test/browser/rail-search.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@

import { expect } from "@playwright/test";

import { openApp, test } from "./harness.mjs";
import { configureFixture, openApp, test } from "./harness.mjs";

test("expanding a project loads sessions beyond the first catalog page", async ({ page }) => {
await configureFixture(page, () => {
window.__fixture.setProjects([
{ projectId: 1, projectKind: "workspace", workspaceDir: "/synthetic/other", pinned: false, hidden: false, orderIndex: 0, recentAtMs: 2, latestActivityAtMs: 2, sessionCount: 1 },
{ projectId: 2, projectKind: "workspace", workspaceDir: "/synthetic/older", pinned: true, hidden: false, orderIndex: 0, recentAtMs: 1, latestActivityAtMs: 1, sessionCount: 1 },
]);
window.__fixture.setResponse("listSessions", { sessions: [{ sessionId: "first", agentName: "main", title: "First page", workspaceDir: "/synthetic/other", createdAt: 2, updatedAt: 2 }], hasMore: true, nextCursor: "next" });
});
await openApp(page);
await expect(page.locator('[data-webui-project-link="/synthetic/older"]')).toBeVisible();
await page.evaluate(() => window.__fixture.setResponse("listSessions", { sessions: [{ sessionId: "older", agentName: "main", title: "Older session", workspaceDir: "/synthetic/older", createdAt: 1, updatedAt: 1 }], hasMore: false }));
const project = page.locator('[data-webui-project-link="/synthetic/older"]');
if (await project.getAttribute("aria-expanded") === "true") await project.click();
await project.click();
await expect(page.locator('[data-webui-session-link="older"]')).toBeVisible();
await project.click();
await expect(project).toHaveAttribute("aria-expanded", "false");
await expect(project.locator("xpath=../..").locator('[data-webui-section-expanded]')).toHaveAttribute("data-webui-section-expanded", "false");
});

test.beforeEach(async ({ page }) => {
page.on("pageerror", (error) => console.error("BROWSER_PAGE_ERROR", error.stack ?? error.message));
Expand Down
12 changes: 12 additions & 0 deletions packages/webui/test/unit/webui-session-catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ describe("B21 catalog query ordering", () => {
expect(store.getSnapshot().catalog.flat.error).toBeUndefined();
expect(store.getSnapshot().catalog.flat.loading).toBe(false);
});
it("reports a failed page load instead of dropping it", async () => {
const store = createWebuiSessionStore();
let reject!: (reason: unknown) => void;
const failed = new Promise<never>((_, fail) => { reject = fail; });
const workflows = createWebuiSessionWorkflows({ store, composer: purger(), port: {
loadSessions: () => failed,
} as unknown as Parameters<typeof createWebuiSessionWorkflows>[0]["port"] });
const read = workflows.loadMore("next-page");
reject(new Error("page failed")); await read;
expect(store.getSnapshot().catalog.flat.error).toBe("page failed");
expect(store.getSnapshot().catalog.flat.loading).toBe(false);
});
it.each(["renamed", "pinned", "visibility"] as const)("reconciles initial flat/tree membership after an unknown %s fact without a refresh storm", async (kind) => {
const store = createWebuiSessionStore();
const flat = pendingPage(); const replacementFlat = pendingPage();
Expand Down
Loading