Repository navigation
Conversation
…oject When switching projects after enabling workspaces, navigateToProject would fail to find the workspace directory in dirs (computed from project.sandboxes) because sandbox population is asynchronous. This caused openSession to return false and navigate to the wrong URL, flaking the e2e project-switch test on Windows CI where the async gap is wider. Fix: call refreshDirs before canOpen checks in openSession, ensuring the worktree list is fetched from the SDK when the cached dirs don't include the target directory.
Per Copilot review feedback on PR #24641: refreshDirs() already returns canOpen(), so calling canOpen() again immediately after is redundant. Use the boolean return directly to simplify the control flow.
Address review feedback: track the latest requested project root and abort stale navigateToProject calls when user quickly switches projects.
Prevents stale project navigations from running fallback logic (clearLastProjectSession, fallback navigation) when the user has already switched to a different project.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ported from anomalyco/opencode#24641
Issue for this PR
Closes projects-switch e2e flake #14461
Type of change
What does this PR do?
Fixes an intermittent e2e test failure in
projects-switch.spec.tsline 90 (toHaveURL), which flakes on Windows CI.Root cause: When switching back to a project after enabling workspaces,
navigateToProjectcomputesdirsfromproject.sandboxes. But sandbox population is asynchronous — the test just enabled workspaces, andproject.sandboxesmay not yet include the workspace directory. SocanOpen(target.directory)returnsfalsefor the workspace dir,openSessionbails silently, and the function falls through to navigate to the wrong URL. ThetoHaveURLassertion catches this intermediate wrong state.This is Windows-specific because
worktree.listandfsmonitorare slower on Windows, widening the async gap between "workspaces enabled" and "sandboxes populated."Fix: Call
ensureDirOpenable(target.directory)before anycanOpencheck insideopenSession.ensureDirOpenablefetches the worktree list from the SDK when the cacheddirsdon't include the target directory, ensuring the workspace dir is always available before the check. It returns thecanOpenresult directly, so the call site uses its boolean return as the guard.Also added
ensureDirOpenable(resolved.directory)for the SDK session resolution path, where the resolved session might be in a workspace dir not yet indirs.How did you verify your code works?
bun typecheckpassesnavigateToProject→openSession→canOpenchainworktree.liston WindowsRelated Issues
Checklist
Note on force pushes to main
This PR was originally raised as #594 but was auto-closed when the
mainbranch was force-pushed (see #760). Force-pushing to a shared branch breaks PR reopenability and orphans review comments.