From 5bc52a15ad6c7a2c6a39231a766b409e6c6197a3 Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Thu, 16 Apr 2026 20:18:08 +0300 Subject: [PATCH] fix: remove risky worktree recovery on session switch --- packages/ui/src/sync/session-ui-store.ts | 43 +----------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/packages/ui/src/sync/session-ui-store.ts b/packages/ui/src/sync/session-ui-store.ts index f25c4575..6dedde84 100644 --- a/packages/ui/src/sync/session-ui-store.ts +++ b/packages/ui/src/sync/session-ui-store.ts @@ -28,7 +28,6 @@ import { flattenAssistantTextParts } from "@/lib/messages/messageText" import { EXECUTION_FORK_META_TEXT } from "@/lib/messages/executionMeta" import { waitForWorktreeBootstrap } from "@/lib/worktrees/worktreeBootstrap" import { waitForPendingDraftWorktreeRequest } from "@/lib/worktrees/pendingDraftWorktree" -import { canonicalizeWorktreeState } from "@/lib/gitApi" import type { ProjectEntry } from "@/lib/api/types" import { getSyncSessions, @@ -52,7 +51,7 @@ import { useInputStore, type SyntheticContextPart } from "./input-store" import { useSelectionStore } from "./selection-store" import { useViewportStore } from "./viewport-store" import { useSessionWorktreeStore } from "./session-worktree-store" -import { buildAttachmentFromCanonicalization, getAttachedSessionDirectory } from "./session-worktree-contract" +import { getAttachedSessionDirectory } from "./session-worktree-contract" export type { AttachedFile } @@ -352,25 +351,6 @@ const getAttachmentForSession = (sessionId: string | null | undefined): SessionW return useSessionWorktreeStore.getState().getAttachment(sessionId) } -const recoverSessionAttachment = async ( - sessionId: string, - directory: string, - existingAttachment?: SessionWorktreeAttachment, -): Promise => { - try { - const canonical = await canonicalizeWorktreeState(directory) - const attachment = buildAttachmentFromCanonicalization(canonical, { - existingAttachment, - fallbackDirectory: directory, - }) - useSessionWorktreeStore.getState().setAttachment(sessionId, attachment) - return attachment - } catch (error) { - console.warn("Failed to canonicalize session worktree state:", error) - return null - } -} - const resolveSessionDirectory = ( sessionId: string | null | undefined, getWtMeta: (id: string) => WorktreeMetadata | undefined, @@ -426,7 +406,6 @@ export const useSessionUIStore = create()((set, get) => ({ const previousSessionId = get().currentSessionId const directoryState = useDirectoryStore.getState() - const existingAttachment = getAttachmentForSession(id) const sessionDir = resolveSessionDirectory( id, @@ -462,21 +441,6 @@ export const useSessionUIStore = create()((set, get) => ({ if (id) { markSessionViewed(id) setActiveSession(resolvedDir ?? "", id) - - if (resolvedDir && (!existingAttachment || existingAttachment.legacy)) { - void recoverSessionAttachment(id, resolvedDir, existingAttachment).then((attachment) => { - const canonicalDirectory = getAttachedSessionDirectory(attachment, resolvedDir) - if (!canonicalDirectory) return - const currentDirectory = normalizePath(useDirectoryStore.getState().currentDirectory ?? null) - if (canonicalDirectory === currentDirectory) return - try { - useDirectoryStore.getState().setDirectory(canonicalDirectory, { showOverlay: false }) - opencodeClient.setDirectory(canonicalDirectory) - } catch (error) { - console.warn("Failed to apply canonicalized session directory:", error) - } - }) - } } }, @@ -934,11 +898,6 @@ export const useSessionUIStore = create()((set, get) => ({ const session = await createSessionAction(title, dir, parentID ?? null) if (!session) return null - const sessionDirectory = normalizePath((session as { directory?: string }).directory ?? dir ?? null) - if (sessionDirectory) { - await recoverSessionAttachment(session.id, sessionDirectory) - } - if (targetFolderId) { const scopeKey = directoryOverride || get().lastLoadedDirectory || session.directory if (scopeKey) {