Repository navigation
fix(windows): reduce idle agent detection CPU - #2651
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughWindows process tracking now uses indexed ChangesWindows process tracking
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant PaneDetection
participant ForegroundObservation
participant ProcessSnapshot
participant ForegroundSelectionCache
PaneDetection->>PaneDetection: build shared process-probe input
PaneDetection->>ForegroundObservation: observe when required
ForegroundObservation->>ProcessSnapshot: enumerate and index processes
ProcessSnapshot->>ForegroundSelectionCache: validate or create selection
ForegroundSelectionCache-->>ForegroundObservation: return cached or fresh selection
ForegroundObservation-->>PaneDetection: provide foreground process group
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/platform/windows.rs (1)
1012-1017: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winRun the process-handle syscalls before taking the cache lock.
rememberexecutes under the globalFOREGROUND_SELECTION_CACHEmutex. It callsProcessIdentity::openfor the shell, the selected process, and every descendant.remember_with_identitiesthen callsentry.command(), which can triggerread_process_command(anOpenProcessplus remote memory reads). One global mutex therefore serializes those syscalls across all panes on the 250 ms detection cadence.Collect the signatures and identities first, then take the lock only for the map mutation.
remember_with_identitiesalready accepts prepared identities, so the split is small.As per coding guidelines: "Avoid unnecessary work in multiplicative paths such as rendering, layout, PTY parsing, detection, resizing, and client frame fanout; ... minimize terminal-core lock duration".
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5061130e-8979-4d41-bb32-918daa02e2f5
📒 Files selected for processing (1)
src/platform/windows.rs
61f4102 to
ad901d6
Compare
Greptile SummaryThe PR reduces Windows idle agent-detection overhead by separating lightweight process snapshots from lazy command-line inspection and caching validated foreground selections.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/pane.rs | Adds Windows-only scheduling for foreground observations while preserving immediate and periodic lifecycle checks. |
| src/platform/windows.rs | Introduces lightweight indexed snapshots, lazy command inspection, and validated foreground-selection caching for Windows process detection. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
Tick[Pane detection tick] --> Gate{Foreground observation due?}
Gate -->|No| Previous[Reuse last foreground process group]
Gate -->|Yes| Snapshot[Obtain lightweight Windows process snapshot]
Snapshot --> Cache{Validated selection cached?}
Cache -->|Yes| Job[Return cached foreground job]
Cache -->|No| Select[Traverse indexed process topology]
Select --> Lazy[Read command metadata lazily as needed]
Lazy --> Validate[Open identities and validate creation times]
Validate --> Remember[Cache eligible foreground selection]
Remember --> Job
Previous --> Probe{Process probe required?}
Job --> Probe
Probe -->|Yes| Agent[Update detected agent state]
Probe -->|No| Sleep[Wait for next tick]
Reviews (2): Last reviewed commit: "fix(windows): gate agent process discove..." | Re-trigger Greptile
|
Also went performance diving with a bit of profiling and some help from 5.6 pro after filing the issue, going to test this branch head to head, will report back. Edit: I ran both current heads against the same baseline on the same machine. The fixture used real Pi 0.84.1 sessions in offline mode, with every pane detected as Idle. Each result is the median of seven 15-second samples after a 20-second warm-up. I also removed the Git sidebar tokens so the separate Git polling issue did not affect the result.
The other approach I cooked up with 5.6 Pro uses scheduler gates in the pane runtime. It avoids running Windows foreground process discovery on stable idle ticks, while preserving immediate checks for acquisition and restore paths plus the periodic lifecycle safety check. That is why it does especially well with one idle pane. The tradeoff is that it does not make process discovery itself cheaper, so the remaining safety checks still scale with the number of panes. Your branch tackles the other side. It keeps the existing observation schedule but makes each observation cheaper through lightweight snapshots, lazy command-line reads, indexed process trees and cached foreground selections. That scales better at 15 panes and keeps the optimization inside the Windows platform layer. The tradeoff is that scheduled observations still happen, and the cache needs identity and invalidation handling. Both approaches reduced Windows process I/O from roughly 1,580 ops/s to around 120 ops/s with 15 panes. So this does not look like a clean either/or. The scheduler gates win the common one-pane idle case, while your snapshot and selection changes scale better across many panes. They touch different layers and look potentially stackable. I linked the branch so you can pick whichever parts make sense for the final PR. I can also mix and match this a bit and iterate on a combined approach, if it's too annoying to test with a VM on your side. Edit2: Curiosity got the better of me and since both integrated easily, I tested a fused approach, updated table below. Pretty cool results ngl.
|
ad901d6 to
f2c62bc
Compare
commented
Aug 11, 2026
|
@Pimpmuckl I integrated your scheduler-gate commit and kept your authorship. I also reproduced the fused result on the Windows VM: 0.208% median with one idle Pi pane and 0.729% with 15, versus 1.042% and 2.708% for the process optimization alone. Full-lifecycle exit, forced-death detection, and relaunch transitions still passed. Thank you for profiling this and putting together the complementary approach. |
commented
Aug 11, 2026
|
@Pimpmuckl could you test this version too? it looks much better |
commented
Aug 11, 2026
Tested the current PR head: Same fixture as before: Pi 0.84.1 offline, every pane detected as Idle, non-Git cwd, Git sidebar tokens removed, 20-second warm-up, then seven 15-second samples.
The current ranges were 0.31-0.94% for one pane and 1.98-3.02% for 15 panes. Process I/O stayed flat at roughly 21 ops/s and 120 ops/s. This is firmly in range of fluctuation, I don't run fixed CPU frequency so a couple percent up/down are expected, looks good to me. |
commented
Aug 11, 2026
|
ty!! |
Summary
Performance
Windows 11 VM, release build, CPU reported as percent of one logical core. Adding the scheduler gate on top of the process-discovery optimization produced:
The earlier process-discovery benchmark reduced 15 idle Codex panes from 7.917% to 1.979% and idle server I/O operations by roughly 93%. A separate Git Bash fallback control measured 1.875% median CPU before scheduler gating.
Validation
just checkRefs #2642
Thanks @Pimpmuckl for the scheduler approach, benchmark matrix, and Windows verification.