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:
@@ -6,7 +6,9 @@ import { desktopHostsGet, getDesktopHostApiUrl, locationMatchesHost, redactSensi
|
||||
import { getSyncChildStores, getAllSyncSessions } from '@/sync/sync-refs';
|
||||
import { opencodeClient } from '@/lib/opencode/client';
|
||||
import { useGlobalSessionStatusStore, applyGlobalSessionStatusSnapshot } from '@/sync/global-session-status';
|
||||
import { compareSessionsByLifecycleOrder, useSessionOrderingStore } from '@/sync/session-ordering';
|
||||
import { useNotificationStore } from '@/sync/notification-store';
|
||||
import { useSessionPinnedStore } from '@/stores/useSessionPinnedStore';
|
||||
import { respondToPermission } from '@/sync/session-actions';
|
||||
import {
|
||||
useGlobalSessionsStore,
|
||||
@@ -119,8 +121,14 @@ const questionLabel = (request: QuestionRequest): string => {
|
||||
return first?.header || first?.question || 'Question';
|
||||
};
|
||||
|
||||
const updatedAt = (session: Session): number =>
|
||||
session.time?.updated ?? session.time?.created ?? 0;
|
||||
const compareSessionOrder = (left: Session, right: Session): number => (
|
||||
compareSessionsByLifecycleOrder(
|
||||
left,
|
||||
right,
|
||||
useSessionPinnedStore.getState().ids,
|
||||
useSessionOrderingStore.getState().rankById,
|
||||
)
|
||||
);
|
||||
|
||||
const basenameOf = (p: string): string => {
|
||||
const norm = p.replace(/\\/g, '/').replace(/\/+$/, '');
|
||||
@@ -300,7 +308,7 @@ const collectStatusPollDirectories = (): Map<string, string[]> => {
|
||||
allSessions
|
||||
.filter((s) => s?.id && !s.parentID)
|
||||
.slice()
|
||||
.sort((a, b) => updatedAt(b) - updatedAt(a))
|
||||
.sort(compareSessionOrder)
|
||||
.slice(0, MAX_SESSIONS)
|
||||
.forEach((session) => {
|
||||
const directory = resolveGlobalSessionDirectory(session);
|
||||
@@ -378,7 +386,7 @@ const buildSnapshot = (instanceName: string): TraySnapshot => {
|
||||
const sessions: TraySession[] = allSessions
|
||||
.filter((s) => s?.id && !s.parentID) // root rows; sub-session work rolls up
|
||||
.slice()
|
||||
.sort((a, b) => updatedAt(b) - updatedAt(a)) // most recently updated first
|
||||
.sort(compareSessionOrder)
|
||||
.slice(0, MAX_SESSIONS)
|
||||
.map((session) => {
|
||||
const family = [session.id, ...collectDescendants(session.id)];
|
||||
@@ -524,6 +532,8 @@ export const useTraySync = (): void => {
|
||||
// Cross-project status map: fed live by the sync dispatcher from the global
|
||||
// event stream, and seeded/reconciled by the poll below.
|
||||
const unsubscribeGlobalStatus = useGlobalSessionStatusStore.subscribe(() => scheduleFlush());
|
||||
const unsubscribeSessionOrder = useSessionOrderingStore.subscribe(() => scheduleFlush());
|
||||
const unsubscribePinnedSessions = useSessionPinnedStore.subscribe(() => scheduleFlush());
|
||||
|
||||
// Make the tray self-sufficient: load the full cross-project list now
|
||||
// (independent of the sidebar) and refresh it periodically so sessions from
|
||||
@@ -573,6 +583,8 @@ export const useTraySync = (): void => {
|
||||
unsubscribeGit();
|
||||
unsubscribeUI();
|
||||
unsubscribeGlobalStatus();
|
||||
unsubscribeSessionOrder();
|
||||
unsubscribePinnedSessions();
|
||||
unsubscribeQuota();
|
||||
unsubscribeRegistry?.();
|
||||
for (const unsub of storeUnsubs.values()) unsub();
|
||||
|
||||
Reference in New Issue
Block a user