Repository navigation
fix(terminal): don't report agent exit on a degraded foreground scan - #9244
Conversation
On Windows/ConPTY the foreground scan (a Get-CimInstance Win32_Process PowerShell fork) can exceed its 3s budget under load, and there is no wmic fallback on Win11 24H2+. A timed-out scan returned the shell name, which the completion coordinator reads as "agent exited" and fires a false "agent done" notification while the agent is still working. Prefer the last positively-recognized agent across a degraded (available:false) scan so a transient failure no longer looks like an exit. An authoritative (available:true) scan still refreshes/clears the memory, so a genuine exit or crash is still detected. No-op on macOS, where the scan is always available.
|
Warning Review limit reached
Next review available in: 4 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/providers/local-pty-provider.ts (1)
1210-1214: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse an explicit
nullcheck.Since
lastRecognizedAgentis typed asstring | null, it's generally safer and more idiomatic to explicitly check for!== nullrather than relying on truthiness, even though agent process names are not expected to be empty strings.♻️ Proposed refactor
- if (stable.lastRecognizedAgent) { + if (stable.lastRecognizedAgent !== null) { ptyLastRecognizedForeground.set(id, stable.lastRecognizedAgent) } else { ptyLastRecognizedForeground.delete(id) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9d661d41-6bf2-42f9-9e1d-a6e8919ff452
📒 Files selected for processing (3)
src/main/providers/local-pty-provider.tssrc/main/providers/stable-foreground-process.test.tssrc/main/providers/stable-foreground-process.ts
Validation on real Windows 11 24H2 (branch head c96b4c3)Validated by an agent on a real Windows box with the CIM-timeout load rig. PASS (authoritative):
Caveat (honest): the pre-fix false completion could not be reproduced in that exact rig — the process-exit backstop didn't engage as the completion driver there (hooks dominated), so live end-to-end causation isn't fully proven. The fix's correctness rests on the (authoritative) unit test plus the confirmed timeout behavior. Known limitation surfaced (follow-up candidate, not addressed here): under pathological self-load (~12 |
|
Cross-reference for the record: this fix lives in the local PTY provider, which on Windows is only the daemon-unavailable fallback path — Windows PTYs are hosted by the terminal daemon, so this change is inert on the default Windows configuration (it's a correct, no-regression improvement to the fallback path, just not the primary one). #9258 carries the equivalent fix on the daemon foreground path, which is what actually lands the Windows false-"agent done" fix. |
…tablyai#9244) * fix(terminal): don't report agent exit on a degraded foreground scan On Windows/ConPTY the foreground scan (a Get-CimInstance Win32_Process PowerShell fork) can exceed its 3s budget under load, and there is no wmic fallback on Win11 24H2+. A timed-out scan returned the shell name, which the completion coordinator reads as "agent exited" and fires a false "agent done" notification while the agent is still working. Prefer the last positively-recognized agent across a degraded (available:false) scan so a transient failure no longer looks like an exit. An authoritative (available:true) scan still refreshes/clears the memory, so a genuine exit or crash is still detected. No-op on macOS, where the scan is always available. * fix(terminal): drop stale foreground scan results
Problem
Windows users running many Claude agents across ~10+ worktrees report too many "agent done" notifications, and notifications that fire while the agent is still working — clicking one navigates to the worktree and the agent is mid-task.
Root cause (false "agent done")
The completion coordinator runs three parallel completion sources (hook / title / process-exit). The process-exit backstop declares "done" when the foreground process is no longer a recognized agent for two consecutive samples.
On Windows/ConPTY there is no foreground process group, so foreground detection forks
powershell.exe … Get-CimInstance Win32_Process … ConvertTo-Jsonwith a hard 3s timeout (windows-foreground-process-rows.ts). Measured on a real Win11 24H2 box under load (concurrent scans + CPU pressure), that fork+scan took 2.94–4.57s — repeatedly over the 3s budget. When it times out it's killed → returns null → and thewmicfallback is removed on Win11 24H2+, sogetForegroundProcessdrops to node-pty's.process, which transiently reads the shell name. The coordinator reads that shell as "the agent exited" and fires a false completion while the agent is still working.Notably this does not require dead hooks — the process-exit suppressor is same-agent-blind (it only vetoes a different agent), and a "working" hook status stays fresh for 30 minutes, so neither protects a working agent from a flaky inspection. macOS is unaffected because its
ps-based inspection is fast and never times out.Fix
Make a degraded (
available: false) foreground scan report the last positively-recognized agent instead of the shell fallback, so a transient scan failure no longer looks like an exit:src/main/providers/stable-foreground-process.ts(resolveStableForegroundProcess).LocalPtyProvider.getForegroundProcessvia a per-PTYptyLastRecognizedForegroundcache (cleared on teardown / when the PTY is gone).An authoritative (
available: true) scan still refreshes or clears the memory, so a genuine exit or crash is still detected. This is a no-op on macOS, where the scan is always available — the change only engages on the Windows timeout path.Trade-off: under sustained scan timeouts, a real exit registers slightly later (once a scan succeeds) — the safe direction vs. a false completion, and the hook
Stopstill fires the real completion on a Git-for-Windows box.Testing
stable-foreground-process.test.ts— 5/5, including a regression guard that a real exit is still detected (authoritative scan clears the memory).src/main/providersdir;typecheck:nodeclean; oxlint/oxfmt clean.Scope
This fixes only the false completion. The flood half — no global notification rate cap (cooldown is per-worktree),
suppressWhenFocusedcovering only the active worktree, and the parked-watcher second completion path — is platform-independent and a separate follow-up PR.Live validation on real Windows (the CIM-timeout load rig) is in progress against this branch.