Skip to content

Commit bb6fc63

Browse files
committed
fix(sessions): unify the sidebar roster page behind one define
Restores the documented bounded sessions.list default so the SDK's no-arg sessions.list() and the TUI's `opts ?? {}` keep the 100-row page that docs/cli/sessions.md promises, then fixes the sidebar on its own terms. The sidebar had three separate limits: SIDEBAR_AGENT_SESSION_LIST_LIMIT (60) in the query it actually sent, DEFAULT_SESSION_LIST_QUERY.limit (50) injected when a caller omitted one, and a 60-row ownerFirst floor. All three collapse into SIDEBAR_SESSION_ROSTER_LIMIT = 200, which the roster query, the roster default, and the Gateway startup prewarm now share so the warm cache matches what the UI asks for. Load-more is unified. Section "Show more" only reveals rows the roster already holds; fetching the next page is one list-level control shown whenever the Gateway reports hasMore. That fetch used to be gated on `section.id === "ungrouped"`, so only the catch-all could pull pages and a starved category could never recover its own rows -- with no affordance saying so. Because a fetched page is useless if the rows land behind a section's cap, the roster control also advances every section by a page. The Sessions page keeps its own SESSIONS_PAGE_DEFAULT_LIMIT: that limit is an explicit operator-edited field, so tuning the roster never moves it.
1 parent eb9b576 commit bb6fc63

24 files changed

Lines changed: 171 additions & 86 deletions

‎src/gateway/server-startup-handler-prewarm.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
resetGatewayWorkAdmission,
44
tryBeginGatewayRootWorkAdmission,
55
} from "../process/gateway-work-admission.js";
6+
import { SIDEBAR_SESSION_ROSTER_LIMIT } from "../shared/session-list-limits.js";
67

78
const mocks = vi.hoisted(() => ({
89
events: [] as string[],
@@ -61,7 +62,7 @@ afterEach(() => {
6162
});
6263

6364
describe("scheduleGatewayHandlerPrewarm", () => {
64-
it("warms the full session roster and process-stable plugin data in dashboard order", async () => {
65+
it("warms the sidebar roster page and process-stable plugin data in dashboard order", async () => {
6566
vi.useFakeTimers();
6667
const cfg = {
6768
agents: { list: [{ id: "main", default: true }, { id: "research" }] },
@@ -101,6 +102,7 @@ describe("scheduleGatewayHandlerPrewarm", () => {
101102
includeDerivedTitles: true,
102103
includeGlobal: true,
103104
includeUnknown: true,
105+
limit: SIDEBAR_SESSION_ROSTER_LIMIT,
104106
},
105107
}),
106108
);

‎src/gateway/server-startup-handler-prewarm.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { listAgentIds } from "../agents/agent-scope-config.js";
22
import type { OpenClawConfig } from "../config/types.openclaw.js";
33
import { getActiveGatewayRootWorkCount } from "../process/gateway-work-admission.js";
4+
import { SIDEBAR_SESSION_ROSTER_LIMIT } from "../shared/session-list-limits.js";
45
import { scheduleGatewayIdleTask, type GatewayIdleTaskHandle } from "./server-idle-task.js";
56

67
const SIDEBAR_PREWARM_MAX_SESSION_ENTRIES = 2_000;
@@ -40,6 +41,7 @@ async function prewarmGatewaySessionListData(cfg: OpenClawConfig, agentId: strin
4041
includeDerivedTitles: true,
4142
includeGlobal: true,
4243
includeUnknown: true,
44+
limit: SIDEBAR_SESSION_ROSTER_LIMIT,
4345
},
4446
});
4547
}

‎src/gateway/session-utils-list.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import type {
7070
*/
7171
const SESSIONS_LIST_YIELD_BATCH_SIZE = 10;
7272

73+
const SESSIONS_LIST_DEFAULT_LIMIT = 100;
7374
const SESSIONS_LIST_TRANSCRIPT_FIELD_ROWS = 100;
7475
const SESSIONS_LIST_TRANSCRIPT_USAGE_MAX_BYTES = 64 * 1024;
7576

@@ -443,6 +444,7 @@ function prepareSessionList(params: ListSessionsFromStoreParams) {
443444
opts,
444445
now,
445446
entryFilter,
447+
defaultLimit: SESSIONS_LIST_DEFAULT_LIMIT,
446448
getRowContext:
447449
hasSpawnedByFilter || Boolean(normalizeOptionalString(opts.search))
448450
? getRowContext

‎src/gateway/session-utils-owners.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ it("keeps the serialized list response deterministic for the current filter path
568568
storePath: "/tmp/openclaw-session-byte-parity",
569569
});
570570
const expectedSerializedResponse = [
571-
'{"ts":1000000,"path":"/tmp/openclaw-session-byte-parity","count":1,"totalCount":1,"nextOffset":null,"hasMore":false,"owners":[]',
571+
'{"ts":1000000,"path":"/tmp/openclaw-session-byte-parity","count":1,"totalCount":1,"limitApplied":100,"nextOffset":null,"hasMore":false,"owners":[]',
572572
',"defaults":{"modelProvider":"openai","model":"gpt-5.4","contextTokens":200000,"agentRuntime":{"id":"codex","cloudPlacementSupported":false,"devicePlacementSupported":false,"source":"implicit"},"thinkingLevels":[{"id":"off","label":"off"},{"id":"minimal","label":"minimal"},{"id":"low","label":"low"},{"id":"medium","label":"medium"},{"id":"high","label":"high"},{"id":"xhigh","label":"xhigh"}],"thinkingOptions":["off","minimal","low","medium","high","xhigh"],"thinkingDefault":"off"}',
573573
',"sessions":[{"key":"global","visibility":"shared","createdActor":{"type":"system","id":"creator-b"},"kind":"global","classification":"global","agentId":"main","isMain":false,"isBackground":false,"subject":"needle global","updatedAt":999999,"archived":false,"pinned":false,"unread":false,"sessionId":"session-global","thinkingLevels":[{"id":"off","label":"off"},{"id":"minimal","label":"minimal"},{"id":"low","label":"low"},{"id":"medium","label":"medium"},{"id":"high","label":"high"},{"id":"xhigh","label":"xhigh"}],"thinkingOptions":["off","minimal","low","medium","high","xhigh"],"thinkingDefault":"off","effectiveFastMode":false,"effectiveFastModeSource":"default","fastAutoOnSeconds":60,"totalTokens":1,"totalTokensFresh":true,"estimatedCostUsd":0,"effectiveResponseUsage":"off","effectiveQueueMode":"steer","modelProvider":"openai","model":"gpt-5.4","modelOverrideSource":null,"agentRuntime":{"id":"codex","cloudPlacementSupported":false,"devicePlacementSupported":false,"source":"implicit"},"contextTokens":100}]}',
574574
].join("");

‎src/gateway/session-utils.test.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ describe("gateway session utils", () => {
550550
expect(buildGatewaySessionEventFields({ sessionRow: row }).observerDigest).toBeNull();
551551
});
552552

553-
test("session lists return every row when the caller sets no limit", async () => {
553+
test("session lists apply a bounded default and expose truncation metadata", async () => {
554554
const cfg = createModelDefaultsConfig({ primary: "openai/gpt-5.4" });
555555
const store = Object.fromEntries(
556556
Array.from({ length: 101 }, (_value, index) => [
@@ -571,16 +571,14 @@ describe("gateway session utils", () => {
571571
opts: {},
572572
});
573573

574-
// A truncated roster silently empties sidebar categories whose newest
575-
// session falls outside the page, so an unset limit must hold everything.
576-
expect(listed.sessions).toHaveLength(101);
577-
expect(listed.count).toBe(101);
574+
expect(listed.sessions).toHaveLength(100);
575+
expect(listed.count).toBe(100);
578576
expect(listed.totalCount).toBe(101);
579-
expect(listed.limitApplied).toBeUndefined();
580-
expect(listed.nextOffset).toBeNull();
581-
expect(listed.hasMore).toBe(false);
577+
expect(listed.limitApplied).toBe(100);
578+
expect(listed.nextOffset).toBe(100);
579+
expect(listed.hasMore).toBe(true);
582580
expect(listed.sessions[0]?.key).toBe("session-0");
583-
expect(listed.sessions.at(-1)?.key).toBe("session-100");
581+
expect(listed.sessions.at(-1)?.key).toBe("session-99");
584582
});
585583

586584
test("session lists honor explicit caller limits", () => {

‎src/shared/session-list-limits.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
/** Owner-first rosters retain this window independently of shared-page pagination. */
22
export const SESSIONS_LIST_OWNER_LIMIT = 60;
3+
4+
/** Rows the Control UI sidebar roster requests in one page. Sized so a normal
5+
* install holds every session; beyond it the list's Load more control fetches
6+
* the next page, so a category whose newest session falls outside this window
7+
* is reachable rather than silently empty. Tune here. */
8+
export const SIDEBAR_SESSION_ROSTER_LIMIT = 200;

‎ui/src/components/app-sidebar-session-list-render.ts‎

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ type SessionCatalogRenderSnapshot = {
5555
function renderSessionSection(params: {
5656
host: SidebarSessionListHost;
5757
section: RenderableSessionSection;
58-
nativeSessionsHaveMore?: boolean;
5958
}) {
6059
const { host, section } = params;
6160
const totalRowCount = section.totalRowCount;
@@ -238,24 +237,55 @@ function renderSessionSection(params: {
238237
)}
239238
</div>`
240239
: nothing}
241-
${renderSessionPagination({
242-
host,
243-
section,
244-
nativeSessionsHaveMore: params.nativeSessionsHaveMore ?? false,
245-
})}
240+
${renderSessionPagination({ host, section })}
246241
`}
247242
</div>
248243
`;
249244
}
250245

246+
/** Fetching a page is useless if the new rows land behind a section's local cap,
247+
* so an explicit roster load reveals a page in every section too -- otherwise
248+
* the click can look like nothing happened. */
249+
function renderRosterLoadMore(
250+
host: SidebarSessionListHost,
251+
sections: RenderableSessionSection[],
252+
hasMore: boolean | undefined,
253+
) {
254+
if (!hasMore) {
255+
return nothing;
256+
}
257+
return html`
258+
<div class="sidebar-session-pagination sidebar-session-pagination--roster">
259+
<button
260+
type="button"
261+
class="sidebar-session-pagination__button"
262+
aria-label=${t("chat.selectors.loadMoreRosterSessions")}
263+
@click=${() => {
264+
void host.loadMoreSidebarSessions().then(() => {
265+
for (const section of sections) {
266+
host.setVisibleSessionLimit(
267+
section.id,
268+
section.visibleLimit + SIDEBAR_SESSION_PAGE_SIZE,
269+
);
270+
}
271+
});
272+
}}
273+
>
274+
${t("chat.selectors.loadMoreRosterSessions")}
275+
</button>
276+
</div>
277+
`;
278+
}
279+
280+
/** Section paging only reveals rows the roster already holds. Fetching the next
281+
* roster page is a list-level action because it feeds every section at once --
282+
* bolting it to one section left the others unable to recover missing rows. */
251283
function renderSessionPagination(params: {
252284
host: SidebarSessionListHost;
253285
section: RenderableSessionSection;
254-
nativeSessionsHaveMore: boolean;
255286
}) {
256287
const { host, section } = params;
257-
const canLoadMore = section.id === "ungrouped" && params.nativeSessionsHaveMore;
258-
const canShowMore = section.visibleRowCount < section.totalRowCount || canLoadMore;
288+
const canShowMore = section.visibleRowCount < section.totalRowCount;
259289
const canShowLess =
260290
section.visibleRowCount > SIDEBAR_SESSION_SEE_LESS_THRESHOLD &&
261291
section.visibleRowCount > section.collapsedVisibleRowCount;
@@ -270,11 +300,10 @@ function renderSessionPagination(params: {
270300
class="sidebar-session-pagination__button"
271301
aria-label=${t("chat.selectors.loadMoreSessions")}
272302
@click=${() => {
273-
const nextLimit = section.visibleLimit + SIDEBAR_SESSION_PAGE_SIZE;
274-
host.setVisibleSessionLimit(section.id, nextLimit);
275-
if (canLoadMore && nextLimit > section.totalRowCount) {
276-
void host.loadMoreSidebarSessions();
277-
}
303+
host.setVisibleSessionLimit(
304+
section.id,
305+
section.visibleLimit + SIDEBAR_SESSION_PAGE_SIZE,
306+
);
278307
}}
279308
>
280309
${t("chat.selectors.loadMoreSessions")}
@@ -404,11 +433,7 @@ function renderSessionListBody(params: {
404433
) {
405434
return nothing;
406435
}
407-
return renderSessionSection({
408-
host,
409-
section,
410-
nativeSessionsHaveMore: params.nativeSessionsHaveMore,
411-
});
436+
return renderSessionSection({ host, section });
412437
},
413438
)}
414439
`;
@@ -496,6 +521,7 @@ export function renderSessionList(params: {
496521
catalogs: params.catalogs,
497522
catalogRenderer: params.catalogRenderer,
498523
})}
524+
${renderRosterLoadMore(host, params.sections, params.nativeSessionsHaveMore)}
499525
${host.sessionsStatusFilter === "archived" && params.empty
500526
? html`<span class="sidebar-session-empty-hint"
501527
>${t("sessionsView.noArchivedSessions")}</span

‎ui/src/components/app-sidebar-session-types.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ export type SidebarSessionPatch = {
239239
category?: string | null;
240240
};
241241

242-
export const SIDEBAR_AGENT_SESSION_LIST_LIMIT = 60;
243242
export const SIDEBAR_SESSION_PAGE_SIZE = 10;
244243
export const SIDEBAR_SESSION_SEE_LESS_THRESHOLD = 30;
245244

‎ui/src/components/session-data-controller-events.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SIDEBAR_SESSION_ROSTER_LIMIT } from "../../../src/shared/session-list-limits.ts";
12
import type { RouteId } from "../app-route-paths.ts";
23
import type { ApplicationContext } from "../app/context.ts";
34
import { readPresenceEntries, type PresencePayload } from "../app/user-profile.ts";
@@ -8,10 +9,9 @@ import type {
89
SessionListSnapshot,
910
} from "../lib/sessions/index.ts";
1011
import { normalizeAgentId } from "../lib/sessions/session-key.ts";
11-
import {
12-
SIDEBAR_AGENT_SESSION_LIST_LIMIT,
13-
type SidebarSessionStatusFilter,
14-
type SidebarSessionOwnerFilter,
12+
import type {
13+
SidebarSessionOwnerFilter,
14+
SidebarSessionStatusFilter,
1515
} from "./app-sidebar-session-types.ts";
1616

1717
type SidebarSessionListOwner = {
@@ -99,7 +99,7 @@ export function sidebarSessionListQuery(owner: SidebarSessionQueryOwner, agentId
9999
involvingMe: involvingMe || undefined,
100100
agentId,
101101
archivedFilter: owner.sidebarSessionStatusFilter(),
102-
limit: SIDEBAR_AGENT_SESSION_LIST_LIMIT,
102+
limit: SIDEBAR_SESSION_ROSTER_LIMIT,
103103
includeDerivedTitles: true,
104104
includeLastMessage: true,
105105
} as const;

‎ui/src/e2e/dashboards-list-demand.e2e.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Control UI E2E proves dashboard tabs do not multiply server-owned session-list demand.
21
import { mkdir } from "node:fs/promises";
32
import path from "node:path";
43
import type { Page } from "playwright";
54
import { expect, it } from "vitest";
5+
// Control UI E2E proves dashboard tabs do not multiply server-owned session-list demand.
6+
import { SIDEBAR_SESSION_ROSTER_LIMIT } from "../../../src/shared/session-list-limits.ts";
67
import {
78
installMockGateway,
89
waitForControlUiRoute,
@@ -20,6 +21,7 @@ const DASHBOARD_REQUEST_PARAMS = {
2021
configuredAgentsOnly: true,
2122
includeGlobal: true,
2223
includeUnknown: true,
24+
limit: SIDEBAR_SESSION_ROSTER_LIMIT,
2325
} as const;
2426

2527
function sessionsResult(key: string, label: string, updatedAt: number) {
@@ -102,7 +104,8 @@ suite.define(() => {
102104
retryable: true,
103105
});
104106
// Confirm the real store consumed the failed wire response before capturing the UI.
105-
await page.waitForFunction(() => {
107+
// The predicate runs in the page, so the limit crosses as an argument.
108+
await page.waitForFunction((rosterLimit) => {
106109
const app = document.querySelector("openclaw-app") as HTMLElement & {
107110
runtime?: {
108111
context: {
@@ -119,12 +122,13 @@ suite.define(() => {
119122
const appContext = app.runtime?.context;
120123
return (
121124
appContext?.sessions.listSnapshot({
125+
limit: rosterLimit,
122126
boardFace: "dashboard",
123127
archivedFilter: "all",
124128
agentId: appContext.agentSelection.state.scopeId ?? undefined,
125129
}).error === "Dashboard refresh unavailable"
126130
);
127-
});
131+
}, SIDEBAR_SESSION_ROSTER_LIMIT);
128132
await page.screenshot({ path: path.join(artifactDir, "refresh-failed.png") });
129133
expect(await dashboards.getByText("Deploy monitor", { exact: true }).isVisible()).toBe(true);
130134
expect(await page.locator("openclaw-router-outlet").getAttribute("inert")).toBeNull();

0 commit comments

Comments
 (0)