Skip to content

fix(app): Fix flaky e2e CI: refresh workspace dirs before canOpen check in navigateToProject#24641

Open
HaleTom wants to merge 9 commits into
anomalyco:devfrom
HaleTom:fix/project-switch-workspace-race
Open

fix(app): Fix flaky e2e CI: refresh workspace dirs before canOpen check in navigateToProject#24641
HaleTom wants to merge 9 commits into
anomalyco:devfrom
HaleTom:fix/project-switch-workspace-race

Conversation

@HaleTom
Copy link
Copy Markdown

@HaleTom HaleTom commented Apr 27, 2026

Issue for this PR

Closes #14461

Type of change

  • Bug fix

What does this PR do?

Fixes an intermittent e2e test failure in projects-switch.spec.ts line 90 (toHaveURL), which flakes on Windows CI.

Root cause: When switching back to a project after enabling workspaces, navigateToProject computes dirs from project.sandboxes. But sandbox population is asynchronous — the test just enabled workspaces, and project.sandboxes may not yet include the workspace directory. So canOpen(target.directory) returns false for the workspace dir, openSession bails silently, and the function falls through to navigate to the wrong URL. The toHaveURL assertion catches this intermediate wrong state.

This is Windows-specific because worktree.list and fsmonitor are slower on Windows, widening the async gap between "workspaces enabled" and "sandboxes populated."

Fix: Call ensureDirOpenable(target.directory) before any canOpen check inside openSession. ensureDirOpenable fetches the worktree list from the SDK when the cached dirs don't include the target directory, ensuring the workspace dir is always available before the check. It returns the canOpen result 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 in dirs.

How did you verify your code works?

  • bun typecheck passes
  • Root cause was traced through the full navigateToProjectopenSessioncanOpen chain
  • The flake could not be reproduced locally (Linux/Chromium, 1 worker) — it is Windows-specific / CI-specific due to slower worktree.list on Windows
  • Production-readiness review completed with no blocking issues

Related Issues

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…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.
Copilot AI review requested due to automatic review settings April 27, 2026 17:06
@HaleTom HaleTom requested a review from adamdotdevin as a code owner April 27, 2026 17:06
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Apr 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a race in project switching where workspace directories may not yet be present in the cached dirs list, causing session restoration to fail intermittently (notably on Windows CI).

Changes:

  • Refreshes workspace directory listings before canOpen() checks when opening a remembered/latest session.
  • Refreshes directory listings for the “resolve session via SDK” path to handle sessions that live in newly-enabled workspaces.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/app/src/pages/layout.tsx Outdated
Comment thread packages/app/src/pages/layout.tsx Outdated
Per Copilot review feedback on PR anomalyco#24641: refreshDirs() already returns
canOpen(), so calling canOpen() again immediately after is redundant.
Use the boolean return directly to simplify the control flow.
@HaleTom HaleTom marked this pull request as draft April 27, 2026 19:17
@github-actions github-actions Bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Apr 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@HaleTom HaleTom marked this pull request as ready for review April 27, 2026 19:30
@HaleTom HaleTom changed the title fix(app): refresh workspace dirs before canOpen check in navigateToProject fix(app): Fix flaky e2e CI: refresh workspace dirs before canOpen check in navigateToProject Apr 27, 2026
@HaleTom
Copy link
Copy Markdown
Author

HaleTom commented Apr 27, 2026

@rekram1-node pinging you as this is may still be blocking some PRs and I saw you recently merge a related PR.

Issues related:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky e2e: "switching back to a project opens the latest workspace session"

2 participants