Worktree setup canceled when switching Glass agent chats; leaves broken worktree with no recovery UI

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Creating a new agent worktree starts .cursor/setup-worktree-unix.sh (~60s). If I switch to another agent chat or navigate in Glass within ~1 second, setup aborts with Canceled before a shell session starts. The UI shows “Setup script failed” / “Canceled” but gives no way to retry in-product.

The worktree directory and branch remain. Setup never completes unless you manually rerun the script in a terminal. I lost work because the failure looked like a throwaway incomplete setup.

Steps to Reproduce

Open a project in the Agents (Glass) window that has .cursor/worktrees.json with a setup-worktree-unix script (~60s runtime).
Create a New Worktree agent session.
Within ~1–2 seconds, switch to another agent chat or open Files in Glass.
Observe the worktree creation toast: “Setup script failed” / “Canceled”.
Check logs (see below).
Control case: repeat steps 1–2 but stay on the same agent chat for ~60s. Setup completes successfully.

Expected Behavior

Worktree setup should continue in the background even if I switch agent chats.
Or setup should auto-resume / offer retry if canceled mid-flight.
UI should clearly warn: “Stay on this chat until setup finishes (~60s)”.
A failed setup should not look like a disposable empty worktree when the user already has edits there.

Screenshots / Screen Recordings

Operating System

MacOS

Version Information

Version: 3.9.16
VS Code Extension API: 1.105.1
Commit: 042b3c1a4c53f2c3808067f519fbfc67b72cad80
Date: 2026-06-27T06:41:01.941Z
Layout: glass
Build Type: Stable
Release Track: Default
Electron: 40.10.3
Chromium: 144.0.7559.236
Node.js: 24.15.0
V8: 14.4.258.32-electron.0
xterm.js: 6.1.0-beta.256
OS: Darwin arm64 25.5.0

Additional Information

Actual behavior
Setup is canceled in ~6ms when Glass agent focus moves.
No shell-exec session is started.
No Worktrees Setup output channel appears in Output dropdown (only Window, Terminal, MCP, etc.).
Worktree directory persists in a half-provisioned state (no .envrc, no runtime, but user/agent edits may exist).
Related opposite bug already filed: agent steals focus back to worktree chat when setup finishes.

Log evidence
From ~/Library/Application Support/Cursor/logs/20260628T121549/window1_wb7/renderer.log:

Failed run (7ddc, agent e7dd3df4):

2026-06-29 19:20:57.699 [info] [WorktreeManager] Created worktree at …/7ddc for agent e7dd3df4-… in 1505ms
2026-06-29 19:20:57.700 [info] [worktree-setup] executing UNIX setup script file
2026-06-29 19:20:57.706 [error] [worktree-setup] failed executing setup script: Canceled
2026-06-29 19:20:58.232 [warning] [GlassTabPersistenceService] migration_tab_transition … e7dd3df4 → c94c2abf … “reason”:“file_launcher”
Note: no started shell-exec session line on the failed run.

Successful run 79 seconds later (hbiv, agent ece6a546, same repo):

2026-06-29 19:22:16.925 [info] [worktree-setup] started shell-exec session
2026-06-29 19:23:21.870 [info] [worktree-setup] setup script finished {“durationMs”:64948,“exitCode”:0}
Same failure pattern also seen on worktree qpy1 (2026-06-26 00:27:01, canceled in 4ms, then immediate GlassTabPersistenceService agent switch).

Impact
Worktree appears created but environment is broken (no runtime, no .envrc).
User may continue working in the agent assuming setup succeeded.
Data loss risk when treating failed-setup worktrees as disposable.
Docs reference Output → Worktrees Setup channel, but it does not appear in Glass UI Output dropdown in 3.9.16.

Requested fix
Decouple setup lifecycle from Glass agent focus (run to completion in background).
If cancel is unavoidable, show Retry setup in UI and block agent edits until setup succeeds or user confirms.
Expose worktree / Worktrees Setup logs consistently in Glass Output.
Show explicit in-progress setup state with time estimate (~60s).

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey @Shareef_H!

Thanks for sharing this. I haven’t been able to reproduce it on my own. The setup script always succeeds, even when I move to another window.

  • Can you confirm that the only action it takes to trigger this is moving focus to another chat?
  • Would you be able to share a minimal worktree setup script .cursor/setup-worktree-unix.sh that reproduces this? Here’s the one I’ve been trying that hasn’t been successful in reproducing.
#!/bin/bash
set -e

# Minimal, observable, long-running worktree setup script used to reproduce
# https://forum.cursor.com/t/worktree-setup-canceled-when-switching-glass-agent-chats-leaves-broken-worktree-with-no-recovery-ui/164358
#
# It writes progress to a log file INSIDE the worktree so you can prove whether
# setup actually ran/finished, and simulates the ~10s runtime of a real setup.

LOG=".cursor/repro-setup.log"
mkdir -p .cursor
{
  echo "[repro-setup] START $(date -u +%FT%TZ) pwd=$PWD"
  for i in $(seq 1 10); do
    echo "[repro-setup] working $i/10 $(date -u +%FT%TZ)"
    sleep 1
  done
  # Marker file that only exists if setup ran to completion.
  echo "ok" > .cursor/repro-setup-complete
  echo "[repro-setup] DONE  $(date -u +%FT%TZ)"
} | tee -a "$LOG"

Hey Colin,

Honestly, I am not 100% sure what the source of the issue is, but worktree setup is intermittently failing. It seems totally random, so I had my agent investigate in the same session where it failed. The description/evidence above is based on my agent’s investigation.

I also have not been able to consistently reproduce. Not sure if others have reported this before.

I would start a new session using a new worktree and it would fail a couple of seconds later. If I try it again, it works just fine.

Thanks for your help, I understand that without a proper reproduction you won’t be able to do anything, but perhaps surfacing this will encourage others facing the same issue to provide further evidence.