Files
openchamber/packages/web/server/lib/fs
Bohdan Triapitsyn 0776aca9c4 perf(server): cache deterministic git rev-parse reads in fs exec route (#1399)
* perf(server): cache deterministic git rev-parse reads in fs exec route

A fresh client (e.g. immediately after a page reload) has an empty git
store and re-resolves every project's root from scratch, firing identical
`git rev-parse --absolute-git-dir` / `--git-common-dir` lookups against
`/api/fs/exec`. Each spawns a git subprocess server-side, so re-opening a
workspace recomputes everything.

Add a small TTL cache for an allowlist of deterministic, side-effect-free
git plumbing path queries, keyed by `(resolvedCwd, command)`:
- Only `git rev-parse` path lookups (absolute-git-dir, git-common-dir,
  show-toplevel) are cacheable; any other command — including any non-git
  command — always executes and is never stored.
- Only successful results are cached (failures may be transient).
- TTL is configurable via OPENCHAMBER_GIT_READ_CACHE_TTL_MS (default 30s,
  0 disables). The git directory layout is effectively static while the
  app runs, so a short TTL safely absorbs the post-reload burst.
- Expired entries are pruned alongside exec jobs.

Complements the client-side root-resolution cache: that one collapses the
in-session N² cascade, this one absorbs the cold-start burst on reload.

Adds tests covering cache hit, per-cwd keying, non-allowlisted commands,
failed-result bypass and the disable switch.

* fix(server): bound git-read cache with count + byte limits; test TTL expiry

Per the project caching policy (AGENTS.md: cap in-memory caches with both
count and byte limits), the git-read cache was unbounded between prunes.

Add dual-constraint LRU eviction (500 entries / 1MB, oldest-first) with
recency refresh on cache hits. Add tests for TTL expiry (fake timers) and
count-cap eviction.

* fix(server): dedupe in-flight git read cache hits
2026-05-24 13:21:09 +03:00
..