fabro/lib
Bryan Helmkamp 7f9b31074c
perf(server): cache bare GitHub clones for automation materialization
Materializing an automation run cloned the full repo fresh into a
tempdir on every click — 5–15s of git activity on the HTTP request
thread, paid in full for every run, then thrown away.

Add a per-`(owner, repo)` bare-clone cache under
`<Storage::cache_dir>/automation-repos/<owner>/<repo>.git`, and replace
the per-call clone+fetch+checkout dance with:

1. `KeyedMutex` lock on `(owner, repo)` so concurrent calls serialize
   per repo and parallelize across repos.
2. If the bare clone is missing, `git clone --bare --depth 1`. Otherwise
   `git worktree prune` to clean up any admin entries leaked by previous
   `TempDir` drops.
3. `git fetch --depth 1 origin <ref>` against the bare clone.
4. `git rev-parse FETCH_HEAD` for the SHA.
5. `git worktree add --detach --force <temp>/repo FETCH_HEAD` into the
   per-call scratch dir, then build the manifest as today.

First run for a repo still pays the clone cost. Every subsequent run
for any ref or automation against that repo pays only the fetch delta
plus a near-free worktree add (~100–500ms).

Corruption recovery: if the bare clone's `HEAD` file is missing or
zero-length after a failure, the cache wipes the directory and retries
once before surfacing `CloneFailed` as before. Auth and network errors
do not trigger a wipe.

Promote `fabro_store::KeyedMutex` and its guard to `pub` so the
server can reuse the existing primitive instead of duplicating it.

Tests:
- `bare_clone_reused_across_calls` seeds a local upstream, runs
  `prepare_worktree` twice, and asserts the bare clone's `objects/`
  tree is identical before and after the second call (i.e., no
  re-clone).
- `bare_clone_recovers_from_corruption` truncates `HEAD` between
  calls and asserts the cache rebuilds and succeeds.
- The existing plan-builder argv/timeout assertions are updated to
  cover the new bare-clone, bare-fetch, worktree-add, worktree-prune,
  and rev-parse FETCH_HEAD plans.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 08:29:58 -04:00
..
crates perf(server): cache bare GitHub clones for automation materialization 2026-05-29 08:29:58 -04:00
packages/fabro-api-client refactor: Remove inbound IP allowlisting (#443) 2026-05-27 22:29:08 -04:00