S08-07 - Repository Lifecycle
Purpose: When objects leave export.git and landing.git, and the
locks that order that work against fetches and pushes.
Design
Section titled “Design”No automatic garbage collection
Section titled “No automatic garbage collection”Git never collects garbage in export.git or landing.git by itself:
- both have
gc.auto=0andmaintenance.auto=false; landing.gitalso hasreceive.autogc=false.
So every repack and prune runs under the locks below: the export lock
for export.git, and the landing lock for landing.git
(S08-05-push-limitsS08-05-push-limits: Push LimitsCleanup after a push that failed, the size cap of landing.git, and the time and memory bounds of the git gateway., “Landing lock”).
Discard
Section titled “Discard”wb land leaves the session’s refs in landing.git, so wb diff and
another wb land --branch still work. No cleanup follows wb land.
wb discard <session>:
- On a lost session, first ends the session with no recovery push, under the landing lock (S06-11-reconnect-and-recoveryS06-11-reconnect-and-recovery: Reconnect, Loss and RecoveryWhat happens when the host-guest link drops, when a session is lost, and how a lost session's work is recovered or discarded., “Discarding a lost session”).
- Deletes the session’s refs under
refs/heads/wb/<session-id>/fromlanding.git. - Has
wb-guestddelete the session’s guest worktree and its history link (S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does.). When the VM isn’t running, that happens at its next start.
After each wb discard, wb-hostd runs the landing cleanup, repack and
prune, under the landing lock (S08-05-push-limitsS08-05-push-limits: Push LimitsCleanup after a push that failed, the size cap of landing.git, and the time and memory bounds of the git gateway., “Cleanup after a
failed push”). The audit log keeps the session’s entries.
Export lock
Section titled “Export lock”Each project has an export lock in wb-hostd.
wbtakes it alone, throughwb-hostd’s local IPC. It takes it for the export update at session start, and for every repack or prune ofexport.git.- Each
upload-packfromexport.gitto the guest holds it shared. No object then disappears under a running fetch. - The git gateway’s connection deadline (S08-05-push-limitsS08-05-push-limits: Push LimitsCleanup after a push that failed, the size cap of landing.git, and the time and memory bounds of the git gateway., “Bounds”)
ends such an
upload-pack. A guest can’t hold the lock past it.
The lock is one streaming call on wb-hostd’s local IPC endpoint,
named with the project ID.
wb-hostdgrants it once noupload-packof the project holds it shared.- From the moment
wbasks,wb-hostddoesn’t start anotherupload-packof that project untilwblets go. The guest’s fetches then can’t keepwbwaiting past one connection deadline. - The grant lists the sessions of the project that are no longer live. The ref lists and the acknowledgment of a shrink (“Shrinking the selection”) travel on the same call.
wbholds the lock as long as the call is open.wb-hostdreleases it whenwbcloses the call or its connection ends.- The lock is only in
wb-hostd’s memory, so a restart ofwb-hostddoesn’t leave a stale lock.
The call can end while wb holds the lock, because wb-hostd stopped
or wb lost the connection. wb then stops its git child, and refuses
the session start with that reason (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
A fetch, delete or prune that stops part way leaves objects and refs in
export.git. The next update replaces, deletes, or prunes them. A
prune, finished or not, removes only objects that no ref of
export.git reaches.
The lock orders work and is not a control. A compromised wb-hostd
that grants it while an upload-pack runs only breaks that guest’s
fetch. One that never grants it only stops session starts. What it
says can’t make wb write anything but the selected refs, the deletes
of names it checked, and the prune.
Borrowed objects
Section titled “Borrowed objects”landing.git borrows from export.git. receive-pack advertises the
tips of export.git to the pushing guest (core.alternateRefsCommand
in git-config(1)). A push leaves out the objects those refs reach. A
session branch can then depend on any object that export.git’s refs
reached at the time of the push.
Shrinking the selection
Section titled “Shrinking the selection”An export update deletes the refs of sessions that are no longer live,
and moves the plain names. It shrinks the selection when some object is
then no longer reachable from any ref of export.git.
wb finds a shrink with git rev-list --objects of the old tips, with
--not and the new ones. Any output is a shrink. The refs of every
live session stay (S08-02-export-repositoryS08-02-export-repository: Export RepositoryWhich refs and objects the guest can fetch from export.git, and how wb, its one writer, keeps it safe to run git in., “Parallel sessions”). So
only objects that no live session selected can go.
Without a shrink, wb only deletes the refs. With one, wb holds the
export lock, and wb-hostd the landing lock, from the first of these
steps to the last. Neither a push nor a landing cleanup starts before
the prune ends.
wbsendswb-hostdthe exact list of refs to delete. The fetch has already moved the plain names. The objects their old tips reach stay inexport.gituntil the prune.wb-hostdchecks each name withgit check-ref-format.wb-hostdcopies intolanding.gitthe objects that its session refs reach and the remaining refs don’t. It runsgit rev-list --objectsof the session refs, with--notand every ref ofexport.gitnot on the list, piped intogit pack-objectswithout--local.landing.gitthen holds every object its refs need that the prune can remove.wb-hostdacknowledges the list.wbdeletes exactly the refs on the list. Then it runsgit repack -a -dandgit prune --expire=nowonexport.git.
The objects of a ref that left the selection are then gone from
export.git. A later session can’t fetch them by ID. A guest that
fetched them earlier still has them in the project user’s clone,
because pruning only stops later fetches (T12-shared-exportT12-shared-export: Sessions of a project share what they can
fetchA project's export.git holds the refs that any live session of the project selected (S08-02-export-repository).).
The copy adds to landing.git’s size only the objects of deselected
refs that a session branch still reaches. It counts toward the cap
(S08-05-push-limitsS08-05-push-limits: Push LimitsCleanup after a push that failed, the size cap of landing.git, and the time and memory bounds of the git gateway., “Landing size cap”). export.git has no size cap,
because what it holds comes from the user’s own repository.
Cost of a shrink
Section titled “Cost of a shrink”The prune runs on the session start path, before the new session’s
guest fetches. That costs NFR01-startupNFR01-startup: StartupGoals: a warm VM reaches the Claude prompt in about 4 s and a suspended VM in about 7 s, and no start takes more than 10 s (p95), excluding first-time project setup and the first boot after a host restart. a full repack of export.git
whenever the selection shrinks. The project’s pushes wait for the
landing lock meanwhile.
The cost isn’t measured. As a rough guide, building export.git for
the Go repository took about 16 s (X07-git-round-tripX07-git-round-trip: Git round tripRemote helper over vsock, read-only upload-pack, restricted receive-pack into the landing repository, flagging of risky paths.).
When the user stays on one branch and only adds commits to it, the base of an ended session is an ancestor of the new tip. Deleting its refs then isn’t a shrink, and the update doesn’t prune.
Decisions
Section titled “Decisions”Repack and prune only under the locks
Section titled “Repack and prune only under the locks”- Why: a prune that runs while a fetch or push is in flight can remove objects that the fetch or push needs.
- Decided: B41-git-data-scopeB41-git-data-scope: Which git data may reach the guest, and how far does the host trust its own git?Serve the guest from a host-side export repository holding only the session's branch, scan carried-in files, clean remote URLs, and require a minimum git version., item 6.
Status: Draft