fix: make session ordering follow activity lifecycle
Session lists now promote a conversation when it starts working and again when it settles, instead of reacting to every streaming timestamp update. This keeps ordering responsive without bringing back the sidebar churn removed by the recent performance work. Apply the same user-visible order across Recent, project and worktree groups, session switchers, mobile navigation, widgets, the command palette, and the desktop tray. Preserve pinned priority, freeze timestamp fallback ordering, and keep child-session activity scoped to siblings under the same parent so it never moves the root conversation. Seed reconnect snapshots without synthetic jumps, clear ephemeral ranks on deletion and runtime changes, and cover lifecycle transitions, mixed root/child trees, metadata-only updates, and project-group ordering with regression tests.
This commit is contained in:
@@ -4,7 +4,9 @@ import type { ProjectEntry } from '@/lib/api/types';
|
||||
import { useUIStore } from '@/stores/useUIStore';
|
||||
import { resolveGlobalSessionDirectory, useGlobalSessionsStore } from '@/stores/useGlobalSessionsStore';
|
||||
import { useProjectsStore } from '@/stores/useProjectsStore';
|
||||
import { useSessionPinnedStore } from '@/stores/useSessionPinnedStore';
|
||||
import { useNotificationStore } from '@/sync/notification-store';
|
||||
import { compareSessionsByLifecycleOrder, useSessionOrderingStore } from '@/sync/session-ordering';
|
||||
import { getRuntimeKey } from '@/lib/runtime-switch';
|
||||
|
||||
/**
|
||||
@@ -31,7 +33,7 @@ export interface MobileWidgetSnapshot {
|
||||
runtimeKey: string;
|
||||
/** Count of sessions needing attention — same signal that drives the app-icon badge. */
|
||||
attentionCount: number;
|
||||
/** Most-recently-updated top-level sessions, newest first (capped for the medium widget). */
|
||||
/** Top-level sessions in the app's shared lifecycle order (capped for the medium widget). */
|
||||
recentSessions: MobileWidgetSession[];
|
||||
}
|
||||
|
||||
@@ -73,9 +75,11 @@ export const buildMobileWidgetSnapshot = (): MobileWidgetSnapshot => {
|
||||
const unseenBySession = useNotificationStore.getState().index.session.unseenCount;
|
||||
const notifyOnSubtasks = useUIStore.getState().notifyOnSubtasks;
|
||||
const projects = useProjectsStore.getState().projects;
|
||||
const pinnedSessionIds = useSessionPinnedStore.getState().ids;
|
||||
const sessionOrderRanks = useSessionOrderingStore.getState().rankById;
|
||||
|
||||
let attentionCount = 0;
|
||||
const topLevel: Array<{ id: string; title: string; updated: number; unread: boolean; project: string }> = [];
|
||||
const topLevel: Array<{ session: Session; unread: boolean; project: string }> = [];
|
||||
|
||||
for (const session of sessions) {
|
||||
const isSubtask = parentIdOf(session) !== null;
|
||||
@@ -86,19 +90,17 @@ export const buildMobileWidgetSnapshot = (): MobileWidgetSnapshot => {
|
||||
}
|
||||
if (!isSubtask) {
|
||||
topLevel.push({
|
||||
id: session.id,
|
||||
title: session.title ?? '',
|
||||
updated: session.time?.updated ?? session.time?.created ?? 0,
|
||||
session,
|
||||
unread: needsAttention,
|
||||
project: projectLabelForDirectory(resolveGlobalSessionDirectory(session), projects),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
topLevel.sort((a, b) => b.updated - a.updated);
|
||||
topLevel.sort((a, b) => compareSessionsByLifecycleOrder(a.session, b.session, pinnedSessionIds, sessionOrderRanks));
|
||||
const recentSessions = topLevel
|
||||
.slice(0, RECENT_LIMIT)
|
||||
.map(({ id, title, unread, project }) => ({ id, title, unread, project }));
|
||||
.map(({ session, unread, project }) => ({ id: session.id, title: session.title ?? '', unread, project }));
|
||||
|
||||
return { runtimeKey: getRuntimeKey(), attentionCount, recentSessions };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user