Skip to content

fix(vscode): cache and bound change badge file reads - #13728

Merged
marius-kilocode merged 2 commits into
mainfrom
investigate-reported-issue
Sep 3, 2026
Merged

fix(vscode): cache and bound change badge file reads#13728
marius-kilocode merged 2 commits into
mainfrom
investigate-reported-issue

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Addresses the badge-polling part of #13720. A change to one tracked or untracked file invalidates the aggregate Git statistics cache. Previously, the next scan could read every eligible untracked text file again through an unbounded Promise.all, even when those files had not changed.

Why This Change Was Made

Keep the fix within the existing badge readers:

  • Cache numeric line counts for up to 10,000 paths, keyed by the same precise file metadata used by the existing fingerprint. Do not retain file contents or failed reads.
  • Limit filesystem counting to 16 concurrent operations across badge readers. This gate is separate from the Git subprocess semaphore and is not acquired around nested Git commands.
  • Reuse the reader in the no-base-branch fallback instead of maintaining a second unbounded implementation.

The shared gate deliberately trades some badge-update latency between projects for bounded filesystem pressure. A slow project can queue ahead of another project, and a filesystem operation that never settles can retain a slot. This change does not add filesystem timeouts or cancellation, and prompt submission does not use this gate.

User Impact

Repeated badge scans no longer reread stable untracked files when a neighboring file changes. The normal branch-comparison totals are preserved. The fallback now uses the same binary, symlink, empty-file, and trailing-newline rules as the normal badge path.

The initial scan still reads eligible files. Workloads with constant changes to every file or more paths than the cache can retain still require reads, but concurrent reads remain bounded. There are no CLI, SSE, or cloud synchronization changes. The separate 7.5.9 prompt-send failure was not reproduced, so this PR does not claim to resolve that part of #13720.

Evidence

Paired local measurement

Measured the actual GitStatsSnapshot.status() and diff() implementation under Node 25.2.1 on macOS ARM64, using the same disposable Git repository before and after the patch:

  • 2,048 untracked text files, each 160 KiB with 8,192 lines, totaling 320 MiB.
  • One tracked file changed before every scan. All untracked files stayed unchanged.
  • Separate before/after bundles, executed sequentially with VS Code closed and no concurrent build or test commands.
  • The first scan starts with a fresh in-process cache. Warm results are medians of the next three scans. The filesystem cache was not flushed.
  • CPU profiles were captured with node --cpu-prof. CPU time is process user plus system time; event-loop delay was measured with monitorEventLoopDelay.
Measurement Before After
Warm scan elapsed time, median 577 ms 114 ms
Warm scan CPU time, median 888 ms 67 ms
Maximum event-loop delay across warm scans 150 ms 11 ms
First scan elapsed time 585 ms 567 ms
First scan maximum event-loop delay 179 ms 16 ms

The warm median elapsed time fell by about 80%. Every measured normal-path scan returned the same totals: 2,049 files, +16,777,217, -1. This is a small local sample, not a cross-platform benchmark or a reproduction of all 55 reported worktrees. The timing improvement is from the Node reproduction, not the webview renderer profile.

Regression and manual checks

The new regression test failed before the fix because changing a tracked file reread both unchanged untracked files. It now passes and also covers same-size changes, replacement/deletion, shared fallback reuse, failed reads, and bounded real filesystem probes.

91 focused tests passed. Extension compile, lint, typecheck, Knip, formatting, and the Kilo change-marker guard passed.

In isolated VS Code, the 2,048-file fixture remained usable during repeated tracked-file churn. Adding an untracked file and editing an already-counted untracked file updated the badges correctly. The cropped screenshot below shows the final live update; it is not performance evidence.

Agent Manager local badge after tracked and untracked file updates

@kilo-code-bot

kilo-code-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/kilo-vscode/src/agent-manager/git-stats-snapshot.ts
  • packages/kilo-vscode/tests/unit/git-stats-snapshot.test.ts
Previous Review Summary (commit 0c72ddd)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 0c72ddd)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • .changeset/quiet-badge-scans.md
  • packages/kilo-vscode/src/agent-manager/GitOps.ts
  • packages/kilo-vscode/src/agent-manager/git-stats-snapshot.ts
  • packages/kilo-vscode/tests/unit/git-stats-snapshot.test.ts

Reviewed by grok-4.6 · Input: 138.2K · Output: 6.8K · Cached: 133.5K

Review guidance: REVIEW.md from base branch main

Comment thread packages/kilo-vscode/src/agent-manager/git-stats-snapshot.ts Outdated
Comment thread packages/kilo-vscode/src/agent-manager/git-stats-snapshot.ts
Comment thread packages/kilo-vscode/src/agent-manager/git-stats-snapshot.ts
@marius-kilocode

Copy link
Copy Markdown
Collaborator Author

@WebReflection thanks, I cleaned that up

@marius-kilocode
marius-kilocode merged commit f0da86e into main Sep 3, 2026
25 checks passed
@marius-kilocode
marius-kilocode deleted the investigate-reported-issue branch September 3, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants