Skip to content

Cut background polling CPU churn with read caches and fetch backoff#648

Merged
h0x91b merged 1 commit into
mainfrom
chore/dev3-log-noise-audit
Jun 11, 2026
Merged

Cut background polling CPU churn with read caches and fetch backoff#648
h0x91b merged 1 commit into
mainfrom
chore/dev3-log-noise-audit

Conversation

@h0x91b

@h0x91b h0x91b commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

A one-hour log audit showed ~8,200 subprocess spawns/hour and ~6,400 full re-parses of tasks.json (1.4 MB) driven by background pollers. This PR adds four independent, targeted caches:

  • data.ts — mtime/size stat-validated read cache for loadProjects()/loadTasks(). Cache hits return shallow copies, mutator paths bypass the cache, saves invalidate it. Cross-process safe: validation is a per-read stat(), so external writes are always picked up.
  • git.ts fetchOrigin — exponential backoff for failing fetches (2 min base, doubling to a 30 min cap) per projectPath:branch. Previously the cooldown was only set on success, so repos with an unreachable remote were re-fetched on every poller tick forever (one repo logged 213 failed fetches/hour).
  • git.ts detectDefaultCompareRef — 10 min TTL promise cache. It runs git shortlog over two weeks of history and was invoked by every getResolvedProject RPC (renderer polls every 10 s → 260 shortlogs/hour).
  • github.tsgh auth status cached for 60 s (only the authenticated result, so a fresh gh auth login is visible immediately) and gh auth token cached for 5 min, instead of spawning three subprocesses per GitHub call.

Details and trade-offs in decisions/067-background-polling-read-caches.md.


This PR was authored by Claude (the AI assistant working on this branch).

Log audit showed ~8,200 subprocess spawns and 6,400 full tasks.json
re-parses per hour driven by background pollers. Four targeted fixes:

- data.ts: mtime/size stat-validated cache for loadProjects/loadTasks;
  cache hits return shallow copies, mutators bypass, saves invalidate
- git.ts fetchOrigin: exponential backoff (2min..30min) for failing
  fetches — cooldown was previously only set on success, so repos with
  a dead remote were re-fetched on every poller tick forever
- git.ts detectDefaultCompareRef: 10min TTL cache (runs git shortlog
  over two weeks of history, was invoked by every getResolvedProject)
- github.ts: cache gh auth status (60s, authenticated only) and
  gh auth token (5min) instead of 3 subprocesses per GitHub call

See decisions/067-background-polling-read-caches.md.
@h0x91b h0x91b enabled auto-merge (squash) June 11, 2026 15:18
@h0x91b h0x91b merged commit a846759 into main Jun 11, 2026
4 checks passed
@h0x91b h0x91b deleted the chore/dev3-log-noise-audit branch June 11, 2026 15:19
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.

1 participant