Skip to content

Commit 67ec544

Browse files
authored
fix: keep new sidebar sessions visible (#100981)
1 parent 1de014b commit 67ec544

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Docs: https://docs.openclaw.ai
2121

2222
### Fixes
2323

24+
- **Control UI session creation:** keep newly created sessions at the front of the stable sidebar order after selecting another session. Thanks @shakkernerd.
2425
- **FTS-only memory startup:** skip plugin capability discovery when `memorySearch.provider` is explicitly `none`, avoiding an unnecessary cold-start scan.
2526
- **Control UI agent model labels:** show each selected agent's effective model in the Default picker option instead of the global model. (#100719, #77690, #77440) Thanks @hyspacex.
2627
- **Control UI inbound image previews:** render canonical inbound media references through the authenticated ticket route after chat-history reloads. (#100725, #90172, #89591) Thanks @sweetcornna.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class AppSidebar extends LitElement {
133133
@state() private sessionsLoading = false;
134134

135135
private stopSessionsSubscription: (() => void) | undefined;
136+
private stopSessionCreatedSubscription: (() => void) | undefined;
136137
private stopAgentsSubscription: (() => void) | undefined;
137138
private stopAgentSelectionSubscription: (() => void) | undefined;
138139
private stopGatewaySubscription: (() => void) | undefined;
@@ -159,6 +160,8 @@ export class AppSidebar extends LitElement {
159160
this.closeSessionSortMenu();
160161
this.stopSessionsSubscription?.();
161162
this.stopSessionsSubscription = undefined;
163+
this.stopSessionCreatedSubscription?.();
164+
this.stopSessionCreatedSubscription = undefined;
162165
this.stopAgentsSubscription?.();
163166
this.stopAgentsSubscription = undefined;
164167
this.stopAgentSelectionSubscription?.();
@@ -178,6 +181,7 @@ export class AppSidebar extends LitElement {
178181
if (
179182
!context ||
180183
this.stopSessionsSubscription ||
184+
this.stopSessionCreatedSubscription ||
181185
this.stopAgentsSubscription ||
182186
this.stopAgentSelectionSubscription ||
183187
this.stopGatewaySubscription
@@ -189,6 +193,9 @@ export class AppSidebar extends LitElement {
189193
this.stopSessionsSubscription = context.sessions.subscribe((snapshot) => {
190194
this.updateSessions(snapshot);
191195
});
196+
this.stopSessionCreatedSubscription = context.sessions.subscribeCreated((key) => {
197+
this.promoteCreatedSession(key);
198+
});
192199
this.stopAgentsSubscription = context.agents.subscribe(() => {
193200
this.requestUpdate();
194201
});
@@ -255,6 +262,20 @@ export class AppSidebar extends LitElement {
255262
);
256263
};
257264

265+
private promoteCreatedSession(sessionKey: string) {
266+
const currentOrder = this.sessionCreatedOrder.get(sessionKey);
267+
if (currentOrder === 0) {
268+
return;
269+
}
270+
for (const [key, order] of this.sessionCreatedOrder) {
271+
if (key !== sessionKey && (currentOrder === undefined || order < currentOrder)) {
272+
this.sessionCreatedOrder.set(key, order + 1);
273+
}
274+
}
275+
this.sessionCreatedOrder.set(sessionKey, 0);
276+
this.requestUpdate();
277+
}
278+
258279
private getSessionNavigationState() {
259280
const context = this.context;
260281
const routeSessionKey = this.getRouteSessionKey();

‎ui/src/lib/sessions/index.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export type SessionCapability = {
183183
checkpointId: string,
184184
options?: { agentId?: string | null },
185185
) => Promise<SessionsCompactionRestoreResult>;
186+
subscribeCreated: (listener: (key: string) => void) => () => void;
186187
subscribe: (listener: (state: SessionState) => void) => () => void;
187188
dispose: () => void;
188189
};
@@ -496,6 +497,7 @@ export function createSessionCapability(gateway: SessionGateway): SessionCapabil
496497
let subscribedClient: GatewayBrowserClient | null = null;
497498
let lastListOptions: SessionListOptions = {};
498499
const listeners = new Set<(next: SessionState) => void>();
500+
const createdListeners = new Set<(key: string) => void>();
499501

500502
const requestList = async (
501503
options: SessionListOptions = {},
@@ -648,6 +650,11 @@ export function createSessionCapability(gateway: SessionGateway): SessionCapabil
648650
return null;
649651
}
650652
await refresh({ agentId: params.agentId, force: true });
653+
// Creation can originate outside the sidebar. Notify presentation owners
654+
// after refresh so they can reconcile the new row without guessing from list churn.
655+
for (const listener of createdListeners) {
656+
listener(key);
657+
}
651658
return key;
652659
} catch (error) {
653660
publish({ ...state, error: String(error) });
@@ -1019,6 +1026,10 @@ export function createSessionCapability(gateway: SessionGateway): SessionCapabil
10191026
listCheckpoints,
10201027
branchCheckpoint,
10211028
restoreCheckpoint,
1029+
subscribeCreated(listener) {
1030+
createdListeners.add(listener);
1031+
return () => createdListeners.delete(listener);
1032+
},
10221033
subscribe(listener) {
10231034
listeners.add(listener);
10241035
return () => listeners.delete(listener);
@@ -1027,6 +1038,7 @@ export function createSessionCapability(gateway: SessionGateway): SessionCapabil
10271038
disposed = true;
10281039
stopGateway();
10291040
stopEvents();
1041+
createdListeners.clear();
10301042
listeners.clear();
10311043
inFlight = null;
10321044
queuedRefresh = null;

0 commit comments

Comments
 (0)