feat(agent-manager): reduce GitStatsPoller load by polling active worktree only#8809
Open
Githubguy132010 wants to merge 5 commits intoKilo-Org:mainfrom
Open
feat(agent-manager): reduce GitStatsPoller load by polling active worktree only#8809Githubguy132010 wants to merge 5 commits intoKilo-Org:mainfrom
Githubguy132010 wants to merge 5 commits intoKilo-Org:mainfrom
Conversation
…ktree only Poll only the active worktree's diff stats on most ticks; do a full sync of all worktrees every FULL_SYNC_EVERY (6) ticks (~30 s at the default 5 s interval). This mirrors the existing PRStatusPoller pattern and reduces HTTP traffic and memory pressure when a worktree has a large diff. - Add setActiveWorktreeId() to GitStatsPoller; triggers an immediate poll when the active worktree changes so the user sees fresh stats without waiting for the next scheduled tick - Wire the call in AgentManagerProvider's loadMessages / clearSession handlers alongside the existing prBridge.poller call - Emit a full stats snapshot on every onStats callback (using cached lastStats for non-polled worktrees) so the webview contract is unchanged - Add 5 new unit tests covering partial-tick skipping, full-sync cadence, complete snapshot emission, and immediate-poll behaviour Closes Kilo-Org#8653 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.4-20260305 · 511,166 tokens |
1. Queue pending active-worktree refresh when a poll is already in flight instead of silently dropping the request. The queued refresh fires immediately after the in-flight fetch completes. 2. Keep periodic full-sync cadence when activeWorktreeId is undefined (e.g. after clearSession) instead of reverting to every-tick full sync, which would re-introduce the load this PR aims to avoid. 3. Add tests for both fixes.
Contributor
Author
|
Addressed both review warnings in 4745efe: 1. Busy-poll race — 2. clearSession load spike — Added tests for both fixes. |
When activeWorktreeId is undefined, non-full-sync ticks now skip polling entirely instead of polling all worktrees (which would re-introduce the every-tick load). Stats from the last full sync remain cached for the webview. Fix failing test to match the new behaviour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Closes #8653.
A worktree with a large diff (e.g. 20 k lines) causes unnecessarily high RAM usage and HTTP traffic because
GitStatsPollercalledclient.worktree.diffSummary()for every worktree on every 5-second tick, regardless of whether the user was looking at it.PRStatusPolleralready solves the same problem: it polls the active worktree every tick and does a full sync of all worktrees only every ~2 minutes. This PR applies the same pattern toGitStatsPoller.Implementation
GitStatsPollergains asetActiveWorktreeId(id)method (mirroringPRStatusPoller):diffSummary.FULL_SYNC_EVERY = 6ticks (~30 s at the default 5 s interval), all non-missing worktrees are polled so inactive badges stay reasonably fresh.setActiveWorktreeIdwith a new ID immediately triggers an out-of-band poll for that worktree, so the user sees fresh stats the moment they switch sessions — no extra wait.onStatsalways receives a complete snapshot: fresh data for polled worktrees + cachedlastStatsfor non-polled ones. The webview contract is unchanged.tickCountis reset onstop()so restarted pollers always begin with a full sync.AgentManagerProviderwires up the new call in theloadMessagesandclearSessionhandlers, alongside the existingprBridge.poller.setActiveWorktreeId()call.Screenshots
No UI changes — the stats numbers in the Agent Manager panel are unaffected; they just update with lower CPU/network overhead.
How to Test
diffSummaryis called only for the active worktree most of the time, and for all worktrees ~every 30 s.cd packages/kilo-vscode && bun test tests/unit/git-stats-poller.test.ts(15 tests, 0 failures).Get in Touch