Skip to content

Commit 7e8412e

Browse files
authored
fix(ui): stabilize the sidebar session list with a single projection owner (#129150)
* fix(ui): stabilize sidebar session list with a single projection owner The sidebar flickered as gateway events arrived: rows popped out when runs ended (active/pinned page bypass), rows jumped within createdAt ties after paging (per-publish created-order pruning), child trees auto-collapsed when a descendant went idle (per-render derivation), and running-row subtitles blank-flashed between observer/narration updates. SidebarSessionProjection now owns all presentation stability for the sidebar lifetime: sticky page membership with user-action reset boundaries, a monotonic bounded created-order registry, latched child expansion with an explicit collapsed-by-user mode, and a last-subtitle hold per active run. The scattered mechanisms it replaces are deleted (limitSidebarSessionRows, partitionSidebarVisibleSections, per-publish order pruning, three expansion key sets). * fix(ui): hold running-row subtitles across run rotation with a display floor Live A/B on a dev gateway showed two residual subtitle defects: the hold was keyed to the exact active-run-id set, so the queued->running rotation still blanked the row, and racing ambient sources (observer digest, narration, work path) swapped the line A->B->A within a second. The hold now lives for the session's running lifetime and ambient replacements respect a 2s minimum display floor (matching the narration throttle); attention, agent status, and the queued explanation bypass the floor because the operator must act on them. * test(ui): assert subtitle holds on non-localized sources The run-rotation and critical-replacement tests asserted the localized queued string through the shared i18n singleton; in the striped ui CI lane (shared module graph, isolate=false) that resolution is environment- sensitive and failed in checks-node-compact-large-11. Narration and agentStatusNote exercise the same hold invariants with raw strings. * fix(ui): reset sticky sidebar membership when grouping changes ClawSweeper finding: grouping switches can re-emit the same section id (e.g. ungrouped) with a different row population, so sticky keys must not carry across; grouping now joins the membership reset boundary with a regression row in the boundary table. The created-sort e2e migrates to the sticky contract: an externally discovered newest session still lands on top, and the previously visible page is retained instead of evicted.
1 parent d647a9b commit 7e8412e

14 files changed

Lines changed: 1144 additions & 265 deletions

‎ui/src/components/app-sidebar-session-navigation-logic.ts‎

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ import {
1414
resolveSessionWorkSubtitle,
1515
} from "../lib/session-display.ts";
1616
import { isSessionRunActive } from "../lib/session-run-state.ts";
17-
import {
18-
groupSidebarSessionRows,
19-
type SidebarSessionSection,
20-
type SidebarSessionsGrouping,
21-
} from "../lib/sessions/grouping.ts";
2217
import {
2318
compareSessionRowsByUpdatedAt,
2419
filterVisibleSessionRows,
@@ -43,9 +38,7 @@ import {
4338
} from "../lib/sessions/session-key.ts";
4439
import { reconcileSidebarZone } from "../lib/sidebar-zone.ts";
4540
import {
46-
limitSidebarSessionRows,
4741
SIDEBAR_SESSION_NO_ATTENTION,
48-
SIDEBAR_SESSION_PAGE_SIZE,
4942
type SidebarRecentSession,
5043
type SidebarSessionSortMode,
5144
type SidebarSessionStatusFilter,
@@ -296,79 +289,6 @@ export function buildSidebarSessionNavigationState(input: {
296289
};
297290
}
298291

299-
export type SidebarVisibleSections = {
300-
sections: (SidebarSessionSection<SidebarRecentSession> & {
301-
totalRowCount: number;
302-
visibleRowCount: number;
303-
visibleLimit: number;
304-
collapsedVisibleRowCount: number;
305-
renderHeader: boolean;
306-
})[];
307-
expandedRows: SidebarRecentSession[];
308-
visibleRows: SidebarRecentSession[];
309-
};
310-
311-
export function partitionSidebarVisibleSections(input: {
312-
rows: SidebarRecentSession[];
313-
grouping: SidebarSessionsGrouping;
314-
knownGroups: string[] | undefined;
315-
selfOwnerId?: string | null;
316-
catalogIds?: readonly string[];
317-
sectionOrder?: readonly string[];
318-
collapsedSections: ReadonlySet<string>;
319-
hideEmptyOwnerFilteredGroup: (category: string | undefined, rowCount: number) => boolean;
320-
visibleSessionLimits: ReadonlyMap<string, number>;
321-
}): SidebarVisibleSections {
322-
const { grouping, knownGroups, selfOwnerId, sectionOrder, catalogIds } = input;
323-
const sectionOptions = { grouping, knownGroups, selfOwnerId, sectionOrder, catalogIds };
324-
const sections = groupSidebarSessionRows(input.rows, sectionOptions).filter(
325-
(section) =>
326-
section.id !== "pinned" &&
327-
!input.hideEmptyOwnerFilteredGroup(section.category, section.rows.length),
328-
);
329-
// A lone catch-all sits directly under the global Sessions toolbar. Empty
330-
// Coding does not render, while empty custom/Groups sections remain targets.
331-
const ungroupedHasPeerHeader = sections.some(
332-
(section) => section.id !== "ungrouped" && (section.id !== "work" || section.rows.length > 0),
333-
);
334-
// Accepted tradeoff: headerless means no collapse control, so a stored
335-
// ungrouped-collapsed preference is deliberately inert here — honoring it
336-
// would blank the whole list with no affordance to undo. It re-applies
337-
// unchanged once a peer section returns.
338-
const expandedRows: SidebarRecentSession[] = [];
339-
const visibleRows: SidebarRecentSession[] = [];
340-
// totalRowCount is the pre-pagination size: headers and empty-zone
341-
// checks must not mistake a page-filtered section for an empty one.
342-
const limitedSections: SidebarVisibleSections["sections"] = [];
343-
for (const section of sections) {
344-
const totalRowCount = section.rows.length;
345-
const renderHeader = section.id !== "ungrouped" || ungroupedHasPeerHeader;
346-
const collapsed = renderHeader && input.collapsedSections.has(section.id);
347-
const visibleLimit = input.visibleSessionLimits.get(section.id) ?? SIDEBAR_SESSION_PAGE_SIZE;
348-
const collapsedVisibleRowCount = limitSidebarSessionRows(
349-
section.rows,
350-
SIDEBAR_SESSION_PAGE_SIZE,
351-
).length;
352-
let visibleRowCount = 0;
353-
if (!collapsed) {
354-
expandedRows.push(...section.rows);
355-
section.rows = limitSidebarSessionRows(section.rows, visibleLimit);
356-
visibleRows.push(...section.rows);
357-
visibleRowCount = section.rows.length;
358-
}
359-
limitedSections.push(
360-
Object.assign(section, {
361-
totalRowCount,
362-
visibleRowCount,
363-
visibleLimit,
364-
collapsedVisibleRowCount,
365-
renderHeader,
366-
}),
367-
);
368-
}
369-
return { sections: limitedSections, expandedRows, visibleRows };
370-
}
371-
372292
export function buildReconciledSidebarZone(input: {
373293
sidebarEntries: readonly string[];
374294
rows: SidebarRecentSession[];
@@ -657,23 +577,6 @@ export function findProjectedSidebarSession(input: {
657577
return undefined;
658578
}
659579

660-
export function promoteSidebarSessionCreatedOrder(
661-
createdOrder: Map<string, number>,
662-
sessionKey: string,
663-
): boolean {
664-
const currentOrder = createdOrder.get(sessionKey);
665-
if (currentOrder === 0) {
666-
return false;
667-
}
668-
for (const [key, order] of createdOrder) {
669-
if (key !== sessionKey && (currentOrder === undefined || order < currentOrder)) {
670-
createdOrder.set(key, order + 1);
671-
}
672-
}
673-
createdOrder.set(sessionKey, 0);
674-
return true;
675-
}
676-
677580
export function applySidebarSessionOwnerFilter(input: {
678581
projected: SidebarRecentSession[];
679582
ownerFacet: SessionsListResult["owners"];

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

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
22
import type { PropertyValues } from "lit";
33
import { state } from "lit/decorators.js";
4+
import type { SessionObserverDigest } from "../../../packages/gateway-protocol/src/schema/sessions.js";
45
import type { GatewaySessionRow, SessionsListResult } from "../api/types.ts";
56
import { serializeSidebarEntry } from "../app-navigation.ts";
67
import { isSessionRouteId } from "../app-route-paths.ts";
@@ -45,8 +46,6 @@ import {
4546
findSidebarMainSessionRow,
4647
findProjectedSidebarSession,
4748
someSidebarSessionInTree,
48-
partitionSidebarVisibleSections,
49-
promoteSidebarSessionCreatedOrder,
5049
resolveSidebarAgentChipSubtitle,
5150
resolveActiveSidebarAgent,
5251
resolveSidebarHomeAttention,
@@ -55,9 +54,12 @@ import {
5554
resolveSidebarMainSessionKey,
5655
toggleSidebarSessionSelection,
5756
type SidebarSessionNavigationState,
58-
type SidebarVisibleSections,
5957
} from "./app-sidebar-session-navigation-logic.ts";
6058
import { SessionPullRequestIndicatorsController } from "./app-sidebar-session-pr-indicators.ts";
59+
import {
60+
SidebarSessionProjection,
61+
type SidebarVisibleSections,
62+
} from "./app-sidebar-session-projection.ts";
6163
import { projectSessionTree } from "./app-sidebar-session-tree.ts";
6264
import {
6365
loadStoredHiddenSessionCatalogIds,
@@ -83,6 +85,7 @@ import type { SidebarMenusController } from "./sidebar-menus-controller.ts";
8385
export class AppSidebarSessionNavigationElement extends AppSidebarBase {
8486
@state() sessionSortMode: SidebarSessionSortMode = loadStoredSidebarSessionSortMode();
8587

88+
readonly sessionProjection = new SidebarSessionProjection();
8689
readonly sessionData = new SessionDataController(this);
8790
private readonly sessionPullRequestIndicators = new SessionPullRequestIndicatorsController(this, {
8891
getConnected: () => this.connected,
@@ -108,7 +111,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
108111
b,
109112
sortMode: this.effectiveSessionSortMode(),
110113
owners: this.selectedAgentSessionResult()?.owners,
111-
createdOrder: this.sessionData.sessionCreatedOrder,
114+
createdOrder: this.sessionProjection.createdOrder,
112115
});
113116

114117
private sessionPeopleSortCapability(): boolean | undefined {
@@ -147,9 +150,6 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
147150
sessionOwnershipVisible = false;
148151

149152
@state() selectedSessionKeys: ReadonlySet<string> = new Set();
150-
@state() protected expandedChildSessionKeys: ReadonlySet<string> = new Set();
151-
@state() protected collapsedActiveChildSessionKeys: ReadonlySet<string> = new Set();
152-
@state() fullyShownChildSessionKeys: ReadonlySet<string> = new Set();
153153
@state() sessionsGrouping: SidebarSessionsGrouping = loadStoredSidebarSessionsGrouping();
154154
@state() sessionsShowCron = loadStoredSidebarSessionsShowCron();
155155
@state() sessionsShowPreview = loadStoredSidebarSessionsShowPreview();
@@ -166,10 +166,11 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
166166
);
167167

168168
private sessionSelectionAnchor: string | null = null;
169-
private collapsedActiveRouteKey: string | null = null;
170169
private readonly runtimeSampledAtByRow = new WeakMap<GatewaySessionRow, number>();
171170
private readonly attention = new SessionAttentionController(this);
172171

172+
declare readonly sidebarNarrationLines: ReadonlyMap<string, string>;
173+
declare readonly sidebarObserverDigests: ReadonlyMap<string, SessionObserverDigest>;
173174
declare readonly sessionOrganizer: SessionOrganizerController;
174175
declare readonly sidebarMenus: SidebarMenusController;
175176

@@ -194,7 +195,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
194195
}
195196

196197
promoteCreatedSession(sessionKey: string) {
197-
if (promoteSidebarSessionCreatedOrder(this.sessionData.sessionCreatedOrder, sessionKey)) {
198+
if (this.sessionProjection.promoteCreatedSession(sessionKey)) {
198199
this.requestUpdate();
199200
}
200201
}
@@ -218,12 +219,6 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
218219
void this.context?.sessions.setOwnerFilter(null);
219220
}
220221
const activeRouteKey = isSessionRouteId(this.activeRouteId) ? this.getRouteSessionKey() : "";
221-
if (activeRouteKey !== this.collapsedActiveRouteKey) {
222-
this.collapsedActiveRouteKey = activeRouteKey;
223-
if (this.collapsedActiveChildSessionKeys.size > 0) {
224-
this.collapsedActiveChildSessionKeys = new Set();
225-
}
226-
}
227222
if (isSessionRouteId(this.activeRouteId)) {
228223
void this.sessionData.loadActiveSessionLineage(activeRouteKey);
229224
}
@@ -333,7 +328,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
333328
/** Collapsed zones keep full rows for true header counts and status dots. */
334329
protected zonedVisibleSections(rows: SidebarRecentSession[]): SidebarVisibleSections {
335330
const grouping = this.effectiveSessionsGrouping();
336-
return partitionSidebarVisibleSections({
331+
return this.sessionProjection.project({
337332
rows,
338333
grouping,
339334
knownGroups: grouping === "category" ? this.knownSessionGroups() : [],
@@ -348,6 +343,20 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
348343
hideEmptyOwnerFilteredGroup: (category, rowCount) =>
349344
this.sessionOwnerFilterActive && Boolean(category) && rowCount === 0,
350345
visibleSessionLimits: this.sessionData.visibleSessionLimits,
346+
sortMode: this.effectiveSessionSortMode(),
347+
statusFilter: this.sessionsStatusFilter,
348+
agentId: this.expandedAgentId(),
349+
connectionIdentity:
350+
this.context?.gateway.snapshot.phase === "connected"
351+
? (this.context.gateway.snapshot.client ?? null)
352+
: null,
353+
listSource: this.context?.sessions ?? null,
354+
subtitle: {
355+
sidebarLiveActivity: this.sidebarLiveActivity,
356+
showPreview: this.sessionsShowPreview,
357+
narrationLines: this.sidebarNarrationLines,
358+
observerDigests: this.sidebarObserverDigests,
359+
},
351360
});
352361
}
353362

@@ -478,7 +487,7 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
478487
return;
479488
}
480489
this.clearSessionSelection();
481-
this.expandedChildSessionKeys = new Set();
490+
this.sessionProjection.resetMembership();
482491
this.sessionData.visibleSessionLimits.clear();
483492
context.agentSelection.set(nextAgentId);
484493
void this.sessionData.refreshSidebarSessions(nextAgentId);
@@ -749,35 +758,25 @@ export class AppSidebarSessionNavigationElement extends AppSidebarBase {
749758
};
750759

751760
isSessionChildrenExpanded(session: SidebarRecentSession): boolean {
752-
return (
753-
this.expandedChildSessionKeys.has(session.key) ||
754-
(session.containsActiveDescendant && !this.collapsedActiveChildSessionKeys.has(session.key))
755-
);
761+
return this.sessionProjection.isChildrenExpanded(session.key);
762+
}
763+
764+
isSessionChildrenFullyShown(sessionKey: string): boolean {
765+
return this.sessionProjection.isChildrenFullyShown(sessionKey);
756766
}
757767

758768
toggleSessionChildren(session: SidebarRecentSession) {
759-
const next = new Set(this.expandedChildSessionKeys);
760-
const collapsedActive = new Set(this.collapsedActiveChildSessionKeys);
761-
const fullyShown = new Set(this.fullyShownChildSessionKeys);
762-
if (this.isSessionChildrenExpanded(session)) {
763-
next.delete(session.key);
764-
fullyShown.delete(session.key);
765-
if (session.containsActiveDescendant) {
766-
collapsedActive.add(session.key);
767-
}
769+
if (!this.sessionProjection.toggleChildren(session).expanded) {
768770
this.sessionData.discardEmptyChildSessionSnapshot(session.key);
769771
} else {
770-
next.add(session.key);
771-
collapsedActive.delete(session.key);
772772
this.sessionData.retryChildSessions(session.key);
773773
}
774-
this.expandedChildSessionKeys = next;
775-
this.collapsedActiveChildSessionKeys = collapsedActive;
776-
this.fullyShownChildSessionKeys = fullyShown;
774+
this.requestUpdate();
777775
}
778776

779777
showMoreChildren(sessionKey: string) {
780-
this.fullyShownChildSessionKeys = new Set(this.fullyShownChildSessionKeys).add(sessionKey);
778+
this.sessionProjection.showMoreChildren(sessionKey);
779+
this.requestUpdate();
781780
}
782781

783782
agentUnreadCount(agentId: string): number {

0 commit comments

Comments
 (0)