Skip to content

Windows desktop 2.0.32: one core pinned at ~100% forever (kernel-mode) after removing a blocked grep permission request's working directory #56945

Open

Description

@helloSpookle

Description

On Windows (desktop 2.0.32, managed opencode-cli.exe), if a grep tool call is blocked on a permission
request that the API cannot list, and that session's working directory is then removed, the managed
service pins one core at ~100% forever (5/5 runs). Nothing recovers it except restarting the app:
no new log lines, no DB writes, no memory/handle growth, and /api/info keeps answering in 1 ms, so the
desktop liveness watchdog never fires.

The two ingredients:

  • a tool call blocked on a permission request that is invisible to every client: listing it answers
    400 with an empty body, and the service logs
    schema rejection ... ["data"][0]["metadata"]["include"] (the tool part carries "metadata": {}), and
  • removing that session's working directory while the call is still blocked (deleting the session is
    not needed).

Root cause, confirmed by A/B: the location's file watcher whose watched directory disappeared. With
the app started as OPENCODE_DISABLE_FILEWATCHER=true (watcher subscription lines 33 → 0) the identical
recipe does not spin at all (2/2 runs, 0.0% over 20 s), while the blocked request is unchanged. The
subscription is never released afterwards either: in three directory-removal runs the removed paths log
watcher stopped 0 times (97 such lines exist elsewhere in the log).

Measured while spinning:

  • exactly one thread burns (tid 4204): ~100% of one core, 92–94% of it kernel time; the other 32
    threads of the process are at 0
  • IO Other Operations/sec ≈ 316,000 (control-class, i.e. neither read nor write), read ≈ 0/s,
    write ≈ 0/s — i.e. one control-class syscall per iteration
  • zero new log lines, opencode.db/-wal +0 bytes, handles/threads/memory completely flat
  • /api/info 1 ms, /api/session 1 ms (the >6 s liveness watchdog can therefore never fire)

Control: the same sequence with { "permission": { "bash": "ask" } } (whose request is listable,
action=shell) gives 0.3–2.2% CPU, no spin; and creating + deleting an identical throwaway directory
without a blocked tool call does nothing at all (≤3.6%, zero watcher lines).

Related: #56712 (closest symptom: serve --service busy-looping one core, main thread R, no logs, API
alive — but theirs is intermittent/user-space, ours is continuous, kernel-time heavy and a deterministic
repro), #53811 (same subsystem: fs watcher churn), #47505 / #55679 (Windows + embedded @parcel/watcher
crash family, where OPENCODE_DISABLE_FILEWATCHER=1 is already the known workaround).

Plugins

None (only the bundled @opencode-ai/plugin; no plugin key in any opencode.json).

OpenCode version

2.0.32 desktop (managed opencode-cli.exe; log line: cli starting version=2.0.32 channel=latest args=["serve","--service"])

Steps to reproduce

  1. mkdir %TEMP%\opencode\oc-repro\work
    and write %TEMP%\opencode\oc-repro\work\opencode.json = { "permission": { "grep": "ask" } }

  2. POST /api/session
    { "location": { "directory": "%TEMP%\opencode\oc-repro\work" }, "title": "delete-me" }

  3. POST /api/session/{id}/prompt
    { "text": "Use the grep tool to find the word 'repro' in this directory." }
    -> the grep tool call starts and then blocks silently. While it is blocked the permission request is
    not listable: GET /api/permission/request?location[directory]=... -> 400, empty body, and the log says
    WARN message="schema rejection" kind=Body reason="Expected JSON value\n at ["data"][0]["metadata"]["include"]"

  4. while the call is still blocked, remove that directory (rmdir /s /q %TEMP%\opencode\oc-repro)
    -> opencode-cli.exe pins ~100% of one core within ~5 s and never stops.

Only step 4's "the watched directory goes away" matters: deleting just the session (keeping the directory)
gave max 10.8% over 20 s; deleting just the directory with the session still alive gave 100.1% within 5 s;
deleting a throwaway directory without a blocked tool call did nothing (<=3.6%, zero watcher lines).
Waiting does not help: with nothing deleted, 200 s of sampling never exceeded 7.8% and rg.exe was never
spawned (executed:false) - the request never times out.

Screenshot and/or share link

No response

Operating System

Windows 10 IoT Enterprise LTSC 21H2, 10.0.19044, x64, 6 cores / 12 threads.

Terminal

OpenCode Desktop (Electron) app; all API calls above were made with plain HTTP against the managed service.

Activity

  1. helloSpookle commented on Oct 19, 2026

    @helloSpookle
    Author

    Measurements, bisect and instrumentation notes for the repro above. Everything is from this machine
    (Windows 10 21H2 19044, x64, i5-12600K 6C/12T, no plugins), desktop 2.0.32, managed CLI at
    %APPDATA%\ai.opencode.desktop\cli\2.0.32-x64\opencode-cli.exe (cli starting version=2.0.32 channel=latest args=["serve","--service"]), spawned by the Electron app with
    stdio:['ignore','ignore','pipe'].

    Raw counters while spinning
    item value
    CPU 98.4–106.9% of one core (75 one-second samples over 5 runs)
    kernel vs user Win32_Process delta over 15.01 s: KernelModeTime +13.75 s (92%), UserModeTime +1.31 s; %priv 84–93 / %user 5–12
    I/O IO Other Operations/sec 311k–318k, IO Read ≈ 0/s, IO Write ≈ 0/s; cumulative over the spin: Other 58,722,150 vs Read 7,532 vs Write 1,080
    threads exactly one thread burns: tid 4204 = 6.02 CPU-seconds over a 6 s window (= a whole core), 92% of it kernel time, state Running; the other 32 threads at 0
    flat handles 269–292, threads 27–31, private ~519–525 MB, WS 305–368 MB, pool paged ~572 KB / nonpaged ~25 KB, page faults ≈ 0/s
    silence zero new opencode.log lines during the spin; opencode.db / -wal +0 bytes / 12 s; no new sockets
    API /api/info 1 ms, /api/session 1 ms, /api/permission/request 0 ms (deleted session's endpoints 404)
    onset dir removed 10:18:46.288 → first sample after it 101.9% (10:18:51.331); another run: delete 09:59:52.549, last sample before 0.0%, first after 100.1% (09:59:53.573)
    recreating the dir does not stop it (12 samples, 99.2–105.7%) — a recreated directory is a new object, so this is not evidence against a retrying handle
    The request is real — the API just cannot serialize it

    GET /api/session/{id}/message shows the stuck tool part:

    {"type":"tool","id":"call-fd09d374-…","name":"grep","executed":false,
     "state":{"status":"running","input":{"pattern":"repro","path":"C:\\…\\oc-r6-101335\\work"},
              "metadata":{}}}

    While it is pending (200 s window, polled every 2 s):

    call result
    GET /api/permission/request?location[directory]=<dir> 400, empty body
    GET /api/session/{id}/permission 400, empty body
    GET /api/permission/request (no filter) 200, but location resolves to the home dir → data: []

    The log for each poll:

    WARN  message="schema rejection" kind=Body reason="Expected JSON value\n  at [\"data\"][0][\"metadata\"][\"include\"]"
    INFO  message="Sent HTTP response" http.method=GET http.url=/api/permission/request http.status=400
    

    217 of the 229 schema rejection lines in the log point at exactly that path (one was
    ["data"][0]["metadata"]["path"] during another blocked run). So the request exists, but the response
    body fails its own schema — no client can see or answer it, and the turn stays stuck indefinitely.

    Bisect: which step actually triggers it
    run what was deleted result
    A only the session, directory left in place max 10.8% over 20 s — no spin
    B session first, then the directory 101.9% within 5 s
    C only the directory (session still alive) 100.1% within 5 s (max 112.7%)
    D throwaway dir, but no blocked tool call ≤3.6% — no spin, zero watcher log lines
    E nothing deleted, blocked for 200 s max 7.8% — no spin; rg.exe never spawned (executed:false)

    ⇒ the decisive ingredient is "the watched directory goes away while a call is blocked"; deleting the
    session is incidental, and nothing times out.

    Watcher evidence (A/B + lifecycle)
    launch watcher lines dir removed while blocked result
    default 33 (watcher subscribe … type=entries for every ancestor directory, type=file for each AGENTS.md, backend=node) yes spin 4/4 (100.1–112.7% of one core)
    OPENCODE_DISABLE_FILEWATCHER=true 0 (the location still boots) yes no spin 2/2 (0.0% over 20 s, max 1.6%)

    In both cases the blocked request was identical (both listings 400/empty, tool part metadata:{} /
    executed:false). In three directory-removal runs the subscriptions for the removed paths log
    watcher subscribe / watcher started = 4 each and watcher stopped = 0, while the log contains 97
    watcher stopped lines for other paths — i.e. this teardown path does not release the subscription.

    Instrumentation notes (why there is no .cpuprofile, and what was used instead)
    • no SIGPROF on Windows; the packaged desktop app rejects NODE_OPTIONS
      (node_bindings.cc:492] Most NODE_OPTIONs are not supported in packaged apps); the CLI rejects
      --inspect / --inspect-port as Unrecognized flag; Bun ignores NODE_OPTIONS / BUN_OPTIONS.
    • BUN_INSPECT=<host>:<port>/<path> does work (the managed service opens an inspector websocket).
      The path is mandatory: without it Bun serves a random token path which never surfaces (the app pipes the
      child's stderr), and Bun does not implement Node's /json discovery endpoint.
    • but this Bun build's inspector has no Profiler domain:
      {"error":{"code":-32601,"message":"'Profiler' domain was not found"}}. Only Runtime, Debugger,
      Console, Heap and Inspector exist, and Debugger.pause neither errors nor emits Debugger.paused.
      So cpu-profile.ts cannot produce a .cpuprofile here either.
    • what worked instead, live while it was spinning:
      • Runtime.evaluate answers in 1–2 ms, so the JS thread is not stuck (/api/info 1 ms throughout).
      • process.getActiveResourcesInfo() → [] (Bun has no Node-style resource tracking).
      • decisive: we ran a 3 s busy loop on the JS thread through Runtime.evaluate while sampling
        per-thread CPU. The looping thread and the spinning thread are the same tid, but the busy loop
        burns 0% kernel time while the spin burns 92% — i.e. a JS-driven loop that spends essentially
        all of its time in one control-class syscall per iteration and still yields back to the event loop
        (which is why the API stays at 1 ms and the watchdog never fires).
    • wpr.exe (ETW, needs elevation) is available here for a native .etl trace of the kernel side if you
      want one; it would contain local paths, so I'd only hand it over on request.
    Reproduction scripts

    The repro is driven by small PowerShell scripts on my side (create dir/session/prompt, sample CPU once a
    second, dump raw status codes). Happy to paste or attach them if that is useful.

  2. opencode-agent commented on Oct 19, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and the A/B against OPENCODE_DISABLE_FILEWATCHER, which was very useful.

    I tried your recipe on Linux with 2.0.32: grep set to ask, a grep call left waiting on its permission prompt, then the session's working directory deleted. The service stayed at about 2–5% CPU afterwards, so it didn't spin. That fits your measurements (mostly kernel time, ~316k control-class I/O operations/s), which point at the Windows backend of the file watcher (@parcel/watcher / ReadDirectoryChangesW) after its watched directory disappears. The watcher code also never seems to release a subscription when the watched directory itself goes away, which matches the missing watcher stopped lines in your log. A maintainer with Windows will need to confirm it.

    In the meantime, starting the app with OPENCODE_DISABLE_FILEWATCHER=true avoids the spin, as you found.

    Related issues:

  3. helloSpookle commented on Oct 19, 2026

    @helloSpookle
    Author

    Thanks — and your Linux run (2–5%, no spin) is exactly what our A/B predicts, so this really does look
    Windows-side. Two things from our side that may sharpen it, plus the raw logs.

    1. The dangling subscriptions in our runs are backend=node, not backend=windows. In our logs the
    backend appears to be chosen per subscription kind:

    subscription backend lines in our log
    type=directory (the config dir C:\Users\User\.config\opencode) backend=windows 19
    type=entries (every ancestor directory) and type=file (each AGENTS.md) backend=node 382

    The subscriptions left behind when the directory is removed are all type=entries → backend=node
    (e.g. watcher started path="…\oc-r11-112034" type=entries backend=node, same for …\work), and for
    those paths watcher subscribe / watcher started = 4 each with watcher stopped = 0 in three
    separate runs (97 watcher stopped lines exist elsewhere in the log). So if the backend is picked by
    subscription kind, the leak/hot-loop may be in the shared (node) path rather than only in the
    @parcel/watcher / ReadDirectoryChangesW one — worth checking before someone spends a day in the
    Windows backend.

    2. The 400 half is already covered. We found #37650 / PR #54090 ("drop undefined permission metadata
    values before publishing requests"), which is exactly our metadata.include 400 — so please don't spend
    time on that part of the report. The new part is only what happens to the location/watcher afterwards.
    (Once #54090 lands the first ingredient becomes avoidable, but step 4 — the watched directory
    disappearing while the server still holds the location — is the one that needs the fix. I have not yet
    tested whether the stuck request can be replaced by something else that keeps a location alive; happy to
    run that variant if useful: pin a location with a listable pending request (bash: ask, never answered),
    then delete the directory.)

    What we can provide on Windows if a maintainer wants it: per-thread sampling (we already have
    tid-level data — the spin is on the JS thread, 92–94% of its time in kernel mode, ~316k control-class
    syscalls/s, and it still yields to the event loop, which is why /api/info stays at 1 ms), ETW/.wpr
    traces of the kernel side (needs elevation), or extra logging in a local build of your choice. The repro
    takes ~90 s end to end.

    Raw evidence from the verification runs (PowerShell, one-second sampling):

    • spin-evidence-r11.log — full recipe run (spin starts ~5 s after the directory is removed)
    • spin-evidence-r11b.log, r11b-inspector-evidence.json — live inspector probes while it was spinning
    • spin-evidence-r11c.log — per-thread sampling and the JS-thread identity experiment
    • spin-evidence-r4.log, spin-evidence-r5.log, spin-evidence-r7.log — earlier runs incl. the bisect

    They contain local paths of the form C:\Users\User\…. Above, "run A/B/C/D/E" refers to the bisect table
    and "R4…R11c" to these files.

    r11b-inspector-evidence.json
    r11-inspector-evidence.json
    spin-evidence-r4.log
    spin-evidence-r5.log
    spin-evidence-r7.log
    spin-evidence-r11.log
    spin-evidence-r11b.log
    spin-evidence-r11c.log

  4. aurele-l commented on Oct 27, 2026

    @aurele-l

    Same fingerprint on a newer build, without the blocked-permission ingredient — the two ingredients in the title are not both required.

    Environment

    • opencode 2.2.0, CLI channel (@opencode/cli, opencode.exe serve --service)
    • Windows 11 26200, x64, NTFS
    • No plugins on the path this session used

    Measured while spinning (pid 18092, started 09:31:29, replaced 11:56)

    item value
    CPU over the process's whole life 7,617 CPU-s in 8,380 s of wall time = 90.9% of one core, i.e. it was spinning from boot, not from an event
    IO Other Operations/sec 369,094 (read ≈ 0/s, write ≈ 0/s) — same control-class storm you measured at ~316k
    context switches ~120/s
    new log lines 0 for 145 minutes (37 MB log, flat)
    /api/info, /api/session 1–2 ms, service fully usable, so the liveness watchdog could never fire
    permission requests none pending — nothing blocked in the session, no permission entries in the log

    What the log does have

    The only failed to watch directory entries in the whole log (5) are a removed worktree's directory:

    11:41:50, 11:42:29, 11:44:03, 11:45:24  path="...\worktree\549db2\docs-taxonomy"
    11:51:10                                path="...\worktree\d876f2\docs-taxonomy"
                                            error="ENOENT: no such file or directory, watch '...'"
    

    Both are git worktree removed directories that opencode still tried to arm on during a reload cycle, i.e. the same class as their type=entries (backend=node) dangling subscriptions — here the re-arm fails loudly, but nothing releases the subscriber that was armed while the path still existed.

    Re-creating the 18 missing watched directories (including those two, plus the three .git/worktrees/* entries) and force-rewriting a watched config file moved nothing: 96.9% → 101.6%. No recovery.

    Runtime half

    I can reproduce the loop without opencode: watch a directory with fs.watch, delete the directory, and Bun 1.4.4 on Windows delivers ~500 events/s while burning 88–97% of a core, ~90% of it kernel time; re-creating the directory at the same path does not stop it, w.close() stops it instantly. Filed at oven-sh/bun#47068 with the script, and it is the same defect nodejs/node#61398 describes (permanent delete → directory moves to $Extend\$Deleted, handle stays valid, ReadDirectoryChangesW returns the same record forever; libuv fix libuv/libuv#5013, released in libuv v1.53.0).

    What clears it

    opencode service restart — exit 0 in ~0.5 s, new pid, TUI reconnects, sessions survive. The fresh process: 129 watcher lines, 0 failures, 0.94–3.75% CPU, ioOther 33–148/s. A turn in flight dies, which is the only cost.

    Suggestion

    Release the subscription whose target disappeared, and log it, instead of leaving the handle armed: either drop it (the location's watch set is rebuilt per reload cycle anyway) or re-check the path with backoff before re-arming. Currently one removed worktree permanently costs a core until the process is restarted, and nothing in the logs, the API or the metrics reflects it.

  5. aurele-l commented on Oct 27, 2026

    @aurele-l

    Second run on the same machine and version, this time with a clean causal chain — and it shows that releasing the subscription is not enough.

    • 11:59:35.309 watcher subscribe + watcher started path="...\worktree\549db2\bump-1.0.0-10" type=entries backend=node
    • ~12:04:2x git worktree remove ...\worktree\549db2\bump-1.0.0-10 (worktree teardown, logged as a spawned process)
    • 12:04:45.353 watcher stopped path="...\worktree\549db2\bump-1.0.0-10" type=entries — the release path does run and does log
    • CPU accounting on the service (fresh pid from 11:56:21, 0.94–3.75% before this): the spin starts at ~12:04:21, and nine minutes later it holds 98–105% of one core with IO Other Operations/sec 322k–348k, read/s 0, write/s ~0.

    So: no permission request involved at all, and watcher stopped being logged does not stop the loop. The JS-side release happens, the native read loop keeps spinning. Closing a Bun fs.watch while its directory still exists stops it instantly (verified), so the state that matters is a handle armed on a directory that was deleted underneath it — it moves to $Extend\$Deleted, the handle stays valid and ReadDirectoryChangesW completes with the same record forever (nodejs/node#61398, libuv fix libuv/libuv#5013 released in libuv v1.53.0; Bun's own watcher still loops, oven-sh/bun#47068).

    That reorders the fix, and is the reason I would not close this as "leaked subscription":

    1. Runtime side: stop re-arming a handle whose directory is gone — on a completed read for a vanished directory, fail the watcher instead of looping (fs.watch (Windows): deleting the watched directory spins one core at ~500 events/s forever, and re-creating it does not stop it oven-sh/bun#47068).
    2. opencode side: type=entries subscriptions are armed on worktree directories that worktree_remove then deletes; re-check the path on teardown, or skip arming a type=entries watch on a worktree that is about to be removed. A release after the unlink is too late.
  6. shishouyuan commented on Nov 8, 2026

    @shishouyuan

    Adding a minimal, permission-free repro on 2.2.6 that lands in the same fingerprint, but with a type=file subscription instead of type=entries.

    Environment: opencode 2.2.6 (serve --stdio, bundled with OpenChamber 2.7.0), Windows 11 10.0.26300 x64, embedded Bun 1.4.4, Ryzen 7 7840HS, no plugins on the path used.

    Repro — no blocked permission, no worktree, no config change:

    1. In a session directory, create two images: probe_view\shot1.webp, shot2.webp.
    2. Open each in the side panel — that is what creates the watch (FileWatch, feat(core): watch files open in the side panel #57915). The log shows one watch per file:
      message="watcher subscribe" path="E:\agent_works\test\probe_view\shot1.webp" type=file ignores=0 role=server
      message="watcher started"   path="E:\agent_works\test\probe_view\shot1.webp" type=file backend=node ignores=0
      
    3. Remove-Item -Recurse -Force probe_view
    4. ~15 s later the service holds one core at ~100% and stays there.

    Measured on 2.2.6:

    item value
    CPU 99–102% of one core, 6 × 5 s samples
    kernel vs user 5.55 s kernel / 0.52 s user over 6 s = 91.5% kernel
    IO Other Operations/sec 462k–469k, read ≈ 0/s, write ≈ 0/s
    threads one thread Running, other 32 in Wait
    log 0 new lines; the type=file subscriptions never log watcher stopped
    RSS 342 MB → 335 MB (flat)
    recovery recreating the directory does not help; only a restart does

    Control: the same delete on a folder with no previewed file does not spin (0.2 s CPU/min afterwards).

    Reproduced twice on fresh 2.2.6 processes. The second run is the cleanest: the server had been up for one minute with 4.36 s of CPU, two side-panel watches existed, the directory was removed, and 10 s later the delta over 10 s was +10.02 s (100% of one core) — no ramp-up, no log line. Kernel share 90.0%, IO Other Operations/sec 460k–461k, and watcher stopped for the affected paths: 0.

    Two things that may narrow it:

    1. These dangling subscriptions are type=file → backend=node, i.e. the fs.watch(dirname(target), { recursive: false }) path in filesystem/watcher.ts, not @parcel/watcher. So backend=windows is not required for the spin — consistent with @helloSpookle's type=entries observation.
    2. Get-Process's cumulative Read/Write/OtherOperationCount reads 0 during the spin; only PerfMon's IO Other Operations/sec shows the ~465k storm. Anyone checking the cheap counters will wrongly conclude "no I/O".
    3. A plain read is not enough — the watch comes from the client opening the file in the side panel. And moving the file away afterwards does not release it either: after Move-Item b.webp out of the folder, watcher stopped for that path stayed 0, i.e. the handle is armed on the directory, not on the file. Deleting the now-empty directory would still be the fatal step.

    Same libuv/Bun conclusion as yours (nodejs/node#61398, libuv/libuv#5013, oven-sh/bun#47068). On the opencode side, the FileWatch registry (#57915) could drop a watch as soon as its directory disappears instead of keeping it until the 24 h expiry, and the watcher could stop re-arming on ENOENT.

  7. zhang-xzh commented on Nov 10, 2026

    @zhang-xzh

    Independent confirmation on Windows 11 (10.0.26300, 28 logical CPUs), desktop 2.2.6, managed opencode-cli.exe serve --service. Same subsystem, same signature — but no blocked permission request and no grep tool call was involved, so the "blocked + unlistable request" ingredient in the original recipe is not required.

    Trigger seen here

    Continuously ~100 % of one core ≈ 3 % total CPU in Task Manager while completely idle (10 005 s of thread CPU accumulated on a process 6 h old). It started after worktrees (M:\…\worktrees\wt-*) were removed while sessions on them were still open; the log has the matching location services evicted / watcher stopped pairs, but some watchers survive holding handles to directories that no longer exist.

    Measurements on the live process

    • Exactly one thread is hot (tid 23320): 4 984 ms CPU per 5 s; the other 42 threads are at 0.

    • Suspending that thread and sampling RIP/RCX lands almost exclusively in ntdll!NtNotifyChangeDirectoryFileEx+0x14 and ntdll!NtQueryInformationFile+0x14 — i.e. ReadDirectoryChangesW in a loop.

    • RCX (the handle argument) cycles over a fixed set of directory handles (0x854 / 0x6B8 / 0xC98 / 0x1098 / 0x1348 / 0xAC8). Enumerating the process handles shows several of them are deleted directories:

      0x1098 acc=0x100081 \??\M:\$Extend\$Deleted\000E00000009C5D748D4E115
      0x1348 acc=0x100081 \??\M:\$Extend\$Deleted\002C0000000989FF47FF469C
      0x6B8  acc=0x100081 \??\M:\$Extend\$Deleted\0018000000098993093C1ED9
      0xC98  acc=0x100081 \??\M:\$Extend\$Deleted\001D0000000989AA21DC2865
      
    • Probing those handles from outside (DuplicateHandle + ReadDirectoryChangesW): FALSE, GetLastError() == 5 (ERROR_ACCESS_DENIED), 0 ms — repeated, forever.

    • Control: a freshly started serve with a clean HOME idles at 0.5 % of one core, so this is state-dependent, not an unconditional loop.

    Minimal OS-level reproduction (no opencode, no blocked tool call)

    // rights identical to the watcher handles seen above (0x100081)
    h = CreateFileW(dir, 0x100081, FILE_SHARE_READ|WRITE|DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
    ReadDirectoryChangesW(h, buf, 1024, TRUE, FILTER, &ret, &ov, NULL, NULL);   // ok, pending
    DeleteFileW / RemoveDirectoryW(dir);                                        // directory removed while handle open
    WaitForSingleObject(ov.hEvent, 2000);  GetOverlappedResult(...)             // completes at once, err=5, transferred=0
    ReadDirectoryChangesW(h, ... /* synchronous */);                            // FALSE, err=5, elapsed 0 ms  (x N, forever)

    So a watch handle whose directory disappears makes ReadDirectoryChangesW fail immediately with ERROR_ACCESS_DENIED forever; the watcher retries with no backoff and the thread spins in kernel mode. That is the same mechanism as described above (92–94 % kernel time), and it needs neither an IO Other Operations/sec flood nor a blocked tool call to reach it.

    Suggested fix

    On ERROR_ACCESS_DENIED / ERROR_INVALID_HANDLE (handle gone or directory deleted), close the watch and drop the subscription instead of retrying; if a retry is wanted, back off (e.g. 1 s → 30 s) — never a zero-delay continue.

    Workaround

    Restart the desktop app (or the managed service) — the stale handles are released and CPU returns to ~0. OPENCODE_DISABLE_FILEWATCHER=1 also avoids it entirely (per #62687).

    Note: 2.2.7 was installed while I was diagnosing, and the service was restarted by the app, which released the stuck handles — I could not test whether 2.2.7 itself changes the retry behaviour. If it recurs on 2.2.7 I will follow up here.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions