fix(sidebar): preserve pinned sessions and folder refs on empty session list (#1706)

Added sessions.length === 0 guard to useSidebarPersistence.ts and
sessions.length === 0 && archivedSessions.length === 0 guard to
useSessionFolderCleanup.ts. Prevents data loss when server returns
empty list during transient failures.

Co-authored-by: Leonid Skorobogatyy <bash@opencode.itc.local>
This commit is contained in:
bashrusakh
2026-06-23 22:01:24 +03:00
committed by GitHub
co-authored by Leonid Skorobogatyy
parent 2fd86db6a7
commit 83256ba924
2 changed files with 8 additions and 0 deletions
@@ -38,6 +38,10 @@ export const useSessionFolderCleanup = (args: Args): void => {
return;
}
if (sessions.length === 0 && archivedSessions.length === 0) {
return;
}
const idsByScope = new Map<string, Set<string>>();
sessions.forEach((session) => {
const directory = normalizePath((session as Session & { directory?: string | null }).directory ?? null);
@@ -154,6 +154,10 @@ export const useSidebarPersistence = (args: Args) => {
return;
}
if (sessions.length === 0) {
return;
}
const existingSessionIds = new Set(sessions.map((session) => session.id));
setPinnedSessionIds((prev) => {
let changed = false;