Windows: agent extension hosts and the main process spin ~1 core each, indefinitely, after an agent's worktree is deleted (archive / move to cloud / pruneStaleWorktrees)

Where does the bug appear (feature/product)?

Cursor IDE: Agents window (local agents running in git worktrees)

Describe the Bug

Sometimes Cursor deletes a local agent’s git worktree while that agent’s workbench and its local extension host are still alive. This happened when archiving the agent, when moving it to the cloud, and when Cursor’s own GitProvider.pruneStaleWorktrees removed the .git\worktrees\<id> gitdir. After that, the extension host is never disposed. One of its threads spins indefinitely at about 0.5-0.9 of a core.

The Cursor main process spins about one more core with the same fingerprint. It holds 17 directory-watch handles that resolve to C:\$Extend\$Deleted\..., meaning the directories are pending deletion.

On my machine, 3 zombie extension hosts plus the main process used about 3.8 cores, roughly 19% of a 20-thread CPU, for about 11 hours. Only a full restart stopped it.

Measured on a zombie extension host (Cursor.exe --type=utility --utility-sub-type=node.mojom.NodeService):

  • 500k+ “other” (non-read/write) I/O operations per 10 s, about 80% kernel time. Healthy hosts do 1-3k per 10 s.
  • One hot thread. Handle count stays flat, so this is a spin, not a leak.

What the logs show:

  • Each zombie host maps (through exthost.log) to a worktree that no longer exists. The worktree folder and its .git\worktrees\<id> are both gone.
  • The renderer logged [Worktree] Removing worktree at ... for them. For two of them, git worktree remove --force actually failed (validation failed ... .git does not exist / Permission denied), yet Cursor logged success. The same removal was also issued from several workbenches, the zombie ones included.
  • One spin started 87 ms after Cursor’s own git worktree prune (GitProvider.pruneStaleWorktrees) deleted the gitdir of a worktree whose workbench was still open.
  • A sibling worktree removed at the same time got Scheduled service disposal and was disposed 30 s later. The zombie ones never got a disposal line.

Root cause (libuv, Windows):

  • Up to libuv 1.52.x, a watched directory that becomes delete-pending makes ReadDirectoryChangesW fail with ERROR_ACCESS_DENIED.
  • libuv then emits rename and immediately re-queues the read, which fails again at once. This repeats until the app closes the watcher.
  • libuv 1.53.0 fixes it (libuv/libuv#5013). Node has not picked it up yet (nodejs/node#66282, tracking nodejs/node#61398).
  • Even with that fix, the app still has to close the watcher and dispose the workbench.

Minimal repro of the loop (plain Node v24.5.0 / libuv 1.51.0 on the same machine):

const fs = require('fs'), os = require('os'), path = require('path');
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'watch-repro-'));
let n = 0;
const w = fs.watch(dir, () => n++);
setTimeout(() => {
  fs.rmdirSync(dir);
  const t = process.cpuUsage(), s = Date.now(), n0 = n;
  setTimeout(() => {
    const c = process.cpuUsage(t), ms = Date.now() - s;
    console.log({ eventsPerSec: Math.round((n - n0) * 1000 / ms), cores: ((c.user + c.system) / 1000 / ms).toFixed(2) });
    w.close();
  }, 2000);
}, 300);

Output: { eventsPerSec: 155398, cores: '0.97' }. Every event is a rename that carries the full \\?\C:\... path.

Steps to Reproduce

  1. On Windows, in the Agents window, start a local agent that runs in a worktree.
  2. While its workbench/tab is still open, archive the agent or move it to the cloud. Alternatively, let pruneStaleWorktrees remove its gitdir.
  3. In Task Manager or Process Explorer, the agent’s extension host (Cursor.exe --type=utility ... NodeService) stays alive and pegs about one core. The main process may peg another.

Expected Behavior

  • Before deleting or pruning a worktree, dispose the agent’s workbench and extension host and close every file watcher on the worktree and its gitdir.
  • Close a watcher when its own root gets rename or an error.
  • Do not prune a gitdir that an open workbench is still watching.
  • Do not report a worktree removal as successful when git failed.

Operating System

Windows 11 Pro 25H2 (build 26200)

Version Information

Cursor 3.24.12. Update 3.24.18 had been downloaded but was not installed when this was observed, so whether 3.24.18 behaves differently is untested.

Additional Information

Related, but not the same root cause: forum topics 168643 (Windows extension host burning CPU while idle) and 155821 (orphaned extension hosts after window close).

Does this stop you from using Cursor?

No. Cursor works, but it silently burns several cores until it is restarted.

Hey, thanks for such a detailed breakdown. The logs, process measurements, and especially the minimal Node repro really helped us trace what’s happening. I’ve passed it on to the team.

In short, from what we can see: the cleanup that runs after archive, and also during move to cloud, can delete the agent worktree while its workspace is still loaded. On Windows, file watchers on the remote folder don’t close after that, and that’s the spin you measured. You’re also right that removal is being logged as successful even when there’s actually a git error. This definitely isn’t something caused by your setup.

For now, the only reliable way to clear the stuck processes is to fully quit Cursor and start it again.

A couple of questions so we can check the logs on our side:

  1. Is the email you use to log into Cursor different from your forum email? We don’t see recent Cursor activity on the forum account, and the right account would help us find the logs.
  2. If you get a chance to install 3.24.18, does archiving the agent with the tab still open cause the same spin?

I’ll post here once I have an update.

Thanks! It happened again overnight, and this time I traced the exact trigger in the code. The spinning processes were still 3.24.12 (3.24.18 was downloaded at 18:08 but only applied at a restart at 01:36), but the relevant code is unchanged in the installed 3.24.18 workbench.glass.main.js.

Where it comes from

  • WorktreeArchiveCleanup runs in every workbench of the Agents window. On onDidArchiveAgent each workbench calls scheduleRemoval.
  • Its guard isOpenWorkspaceFolder() only checks this.workspaceContextService.getWorkspace().folders, i.e. the folders of that workbench.
  • So the workbench that owns the worktree logs [WorktreeArchiveCleanup] Skipping removal of ...: currently open as a workspace folder. Exactly 30.0 s later (the 3e4 grace timer) every other workbench runs Worktree.remove (git worktree remove --force plus a recursive delete), with no cleanup lease. Up to 5 workbenches removed the same folder at the same time (35-39 s each, with Permission denied).
  • The owning workbench and its extension host are never disposed, so their watchers stay on the delete-pending folder and spin.

Four timestamped pairs from last night (skip in the owning workbench, then removal 30 s later from other workbenches, local time): 18:09:49.511 / 18:10:19.827, 18:11:08.760 / 18:11:38.761, 18:21:23.274 / 18:21:53.277, 19:49:53.061 / 19:50:23.061.

Two more things worth knowing

  1. In two of these cases there was no manual archive. The skip line came 92-191 ms after an AgentHostChildSessionMirror watchSessions.deleted event for the agent that was still running in that worktree. In one case the worktree was deleted while its agent was still writing turns: it kept going for ~30 s and held its agent-loop wakelock for 3 more minutes. So this is a data-loss risk too, not only CPU.
  2. A workbench whose folder is gone is never closed: GlassDiffService kept retrying spawn git.exe ENOENT on the deleted folder for about 7 hours.

Impact overnight: two extension hosts at ~0.5-0.8 core each for 5.8 h and 7.3 h, plus the main process at ~1 core, until the restart.

What would fix it:

  • Answer isOpenWorkspaceFolder from the main-process workspace collection (all workbenches).
  • Run the archive removal once in main, under the existing cleanup lease.
  • Dispose the owning workspace, its extension host and its watchers before removing the folder.
  • Don’t treat a session-mirror deletion of a running agent as an archive.

About 3.24.18: no archive has happened on it yet, so I can’t confirm a repro on that build, but the code path above is the same.

Hey, thanks for the follow-up. The timestamps and the breakdown of exactly where cleanup gets triggered are really helpful. I’ve passed everything along to the team and called out the case where the worktree got deleted without a manual archive while the agent was still running. That seems separate from the CPU issue, so I flagged it on its own.

Until we have an update, here are a couple things that may help:

  • If important work is happening in the worktree, commit more often, especially before archive or move to cloud. That way, if the folder gets deleted unexpectedly, the changes will still be in git.
  • If the processes have already spun up, like before, the only thing that helps right now is fully quitting Cursor and launching it again.

Repeating the first question from my last message: are you signed into Cursor with a different email than the one on the forum? We don’t see recent activity on the forum account, and if we have the right account, it’ll be easier for us to check what shows up on our side. Also, if this happens again on 3.24.18, with archive or without, please send the timestamps the same way you did this time.

I’ll reply here when there’s an update.