fix: serve cached snapshots immediately, regenerate in background#193
Merged
fix: serve cached snapshots immediately, regenerate in background#193
Conversation
The snapshot request path was fetching from upstream synchronously, then invalidating the cached snapshot because its Last-Modified predated the fetch that just ran. On active repos this created a regeneration loop where every request rebuilt the snapshot. Instead, always serve a cached snapshot if one exists and move the upstream fetch to a background goroutine. The workstation's git-fetch after extracting the snapshot goes through cachew's git http-backend path, which forwards to upstream when refs are stale, so the workstation always ends up fully up to date. Also reduce the default mirror-snapshot-interval from 6h to 2h so that new pods restore a fresher mirror snapshot and the post-restore delta fetch is smaller. Amp-Thread-ID: https://ampcode.com/threads/T-019cf8fc-dbea-761b-8933-a781adb473bb Co-authored-by: Amp <amp@ampcode.com>
stuartwdouglas
approved these changes
Mar 17, 2026
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.
Problem
The snapshot request path was fetching from upstream synchronously, then checking if the cached snapshot's
Last-ModifiedpredatedlastFetch. Since the fetch just ran, the snapshot was always invalidated, causing a regeneration loop on active repos. Every workstation request triggered a fullgit clone → tar → zstdcycle instead of serving the cached snapshot.Fix
Always serve a cached snapshot if one exists. The workstation's
git fetchafter extracting the snapshot goes through cachew's git http-backend path, which forwardsinfo/refsdirectly to upstream when refs are stale. The workstation always ends up fully up to date — the snapshot just provides a fast ~95% head start.Move the upstream fetch to a background goroutine so it keeps the mirror fresh for
git fetch/git pulloperations without blocking snapshot serving.Reduce default
mirror-snapshot-intervalfrom 6h to 2h so new pods restore a fresher mirror snapshot and the post-restore delta fetch is smaller.Observed impact on staging
Before: every snapshot request on active repos logged
Cached snapshot predates last fetch, regenerating— clone times were 2-10x expected.After: cached snapshots served immediately,
Refs stale for snapshot request, fetching in backgroundlogged instead. Clone times back to expected levels.