Repository navigation
fix(git): rebuild a cached delta bundle once the mirror tip moves - #466
Draft
stuartwdouglas wants to merge 2 commits into
Draft
stuartwdouglas wants to merge 2 commits into
stuartwdouglas wants to merge 2 commits into
Conversation
stuartwdouglas
requested review from
joshfriend
and removed request for
a team
November 24, 2026 21:45
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
stuartwdouglas
marked this pull request as draft
November 25, 2026 06:28
stuartwdouglas
added a commit
that referenced
this pull request
Nov 25, 2026
…#467) ## Problem When an upload-pack request's haves aren't covered by a bitmap, git first fills one in by walking the whole tree on the haves side (`haves/boundary` → `boundary-fill-in`). On a large monorepo mirror, that costs about the same for a 47-commit gap as for weeks of history. It affects two paths: - **Incremental fetches served from the mirror.** On Roxy workstations, git reads to github.com are redirected to cachew. A clone's catch-up fetch (want new HEAD, have the snapshot commit) lands in `serveReadyRepo` → `git http-backend` → upload-pack. - **Delta bundle builds** (`git bundle create HEAD ^base`), which a clone waits on when the bundle isn't cached yet. ## Change - `serveReadyRepo` already buffers the request body for the "not our ref" replay. A `/git-upload-pack` request whose body has `have` lines is now marked incremental. Detection uses the same gzip-aware 64 KiB inspect window as clone counting; `decodeUploadPackPrefix` is factored out of `inspectUploadPackBody`. - Incremental requests run http-backend with `GIT_CONFIG_COUNT=1`, `pack.useBitmaps=false`. This is command-scope config, and the mirror's own config is unchanged. The "not our ref" replay gets the same override. - Clones (wants only), v2 `ls-refs` and `info/refs` keep bitmaps, because a full object walk benefits from them. v0 and v2 requests both take this path. - A fetch whose first `have` falls past the 64 KiB window is treated as a clone and keeps bitmaps. That is today's behaviour. - Bundles are built with `-c pack.useBitmaps=false`. ## Measurements These were taken on the bb-block staging cash-server mirror (git 2.52.1, MIDX bitmap fresh and covering HEAD, boundary traversal on). Each fetch is a protocol v2 `fetch` through `git http-backend` with the CGI env cachew uses, two runs each: | have | bitmaps on | bitmaps off | |---|---|---| | HEAD~47 | 13–15s, 4.3 MB | <1s, 1.1 MB | | HEAD~2000 (~6 days) | 24s, 72 MB | 8s, 42 MB | `pack-objects` runs on the same mirror: - HEAD~5: 13s on vs <1s off. - HEAD~150: 14s vs 1s. - ~1 month (10,859 commits): 51s and 316 MB vs 32s and 204 MB. - A 47-commit delta bundle build: 14s vs about 1s. Production baseline for a cold bundle build: `snapshot.bundle?base=<main~47>` against bb-block prod took 37.2s to first byte (4.49 MB). Part of that may be time spent waiting behind a mirror fetch under `WithFetchExclusion`. Not measured: a client advertising many unrelated branch tips as haves. If that proves slow, a cap on `have` lines is the limit to add. ## Testing - `TestUploadPackSkipsBitmapsOnlyForIncrementalFetches` drives the real POST handler and a real `git http-backend` on the fixture mirror. A PATH wrapper records the `pack.usebitmaps` value each backend run sees. There are six cases: - v2 fetch with haves - v0 fetch with haves - gzipped v0 fetch with haves - fetch replayed after "not our ref" (both runs `false`) - v0 clone - v2 ls-refs The clone and ls-refs cases expect the value unset. With detection forced off, the three with-haves cases fail. - The fake-git bundle test now matches `bundle create` anywhere in argv, because `-c` shifts the arguments. - `go test -race ./internal/strategy/git/ ./internal/gitclone/` passes and `tsk` is clean. Follow-up: #466, now a draft, will carry the bundle staleness fix and the `tip=` hint after this merges. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Delta bundles are cached under the snapshot base alone for bundle-cache-ttl (2h). The first bundle built after a snapshot was served to every later clone, so each clone fetched the rest of the gap from upstream. On cash-server that GitHub freshen took 18-22s per clone, because GitHub took 18s to build a 47-commit pack. Cached bundles now record the mirror HEAD they were built to. A plain GET whose replica mirror has moved past that tip rebuilds through the existing bundleBuilds coalescing. Ranged resumes keep the entry they started on. A tip this replica lacks came from a newer replica and is served as-is, so replicas don't rebuild each other's bundles. Rebuilds are synchronous. They stay cheap because bundles are built without bitmaps: about 1s for 47 commits on the staging mirror. Co-authored-by: Sleeper Service <a6659a6442a259afd31da6e85f71b9e9f3fe127dd3cc88d2ae9fb544922bcb3c>
A client's ensure-refs and its delta bundle GET can reach different replicas, so the bundle replica's mirror may still be behind the HEAD ensure-refs just fetched, and the stale-tip check then misses. The bundle URL now accepts an optional tip=<sha>, the HEAD the client's ensure-refs resolved. A cached bundle that already contains tip is served as-is. Otherwise, a replica whose mirror lacks tip runs freshenMirror before deciding, the same fetch the unknown-base path uses. Its ref-check gate (10s) and the fetch timeout bound that work, so a bogus or unreachable tip costs at most one fetch per interval. A tip that isn't a full commit SHA is ignored. Older clients send no tip and are unaffected. Co-authored-by: Sleeper Service <a6659a6442a259afd31da6e85f71b9e9f3fe127dd3cc88d2ae9fb544922bcb3c>
stuartwdouglas
force-pushed
the
sleeper/bundle-stale-on-tip-move
branch
from
November 25, 2026 07:07
45df1f6 to
7b64399
Compare
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.
Follows #467 (bitmaps off for incremental upload-pack and bundle builds), now on main.
Problem
Delta bundles are cached under the snapshot base alone (
bundleCacheKey=upstreamURL + ".bundle." + base) forbundle-cache-ttl(default 2h). The first bundle built after a snapshot is served to every later clone, so each clone fetches the rest of the gap in its freshen step. On cash-server, three cold clones all got the same 718 KB bundle, and freshen then took 18–22s per clone. That fetch is served by cachew's mirror (Roxy redirects git reads to cachew), and before #467 it paid the bitmap fill-in. #467 makes that fetch cheap; this PR makes the gap it has to cover small.Change
X-Cachew-Bundle-Tip).merge-base --is-ancestor), the bundle is rebuilt through the existingbundleBuildscoalescing.pregenerateBundleuses the same check.The tip is checked on lookup rather than added to the key. The key is computed before
GetOrCreate: with the tip in the key, a pod with no local mirror would have to clone before it could serve from the shared cache, and every tip would leave a 2h object behind.Build cost
Builds run with bitmaps off since #467, so a rebuild scales with the delta (on the bb-block staging mirror a 47-commit bundle took about 1s, against 14s with bitmaps).
Build rate
At most one build is in flight per (repo, base) per replica, because
bundleBuildscoalesces them. A rebuild needs a bundle request and a new mirror HEAD since the last build. Mirror fetches are gated byref-check-interval(10s), ensure-refs and the 15m periodic fetch, so the worst case is one build per mirror fetch, not one per clone.Client tip hint (
?tip=<sha>, second commit)The client waits for ensure-refs before requesting the bundle, but the GET can land on a different replica (at least 3 sit behind
cachew.mesh), whose mirror may be behind. The bundle request now accepts an optionaltip=<sha>, sent by bloxlet in squareup/blox#5600:tipis validated withcommitSHARe. Anything else is ignored rather than rejected, so older clients are unaffected.tip, it's served as-is.tipcallsfreshenMirror(the same one the unknown-base path uses), then takes the stale-tip path. The miss/build path does the same beforecreateBundle.tipcosts at most one upstream fetch perref-check-interval(10s) per replica.Production 0.8.5 predates #452, so its ensure-refs returns an empty
HEADand clients send no tip until a release that includes #452 is deployed.Testing
TestBundleRebuiltWhenMirrorTipMovesfails with the check stubbed out and passes with it.TestBundleFromNewerReplicaIsKeptpasses.TestBundleTipFreshensMirrorBehindClientandTestBundleBogusTipFetchesAtMostOncePerIntervalfail with the freshen stubbed out and pass with it.go test -race ./internal/strategy/git/ ./internal/gitclone/passes andtskis clean.🤖 Generated with Claude Code