S08-03 - Pushes
Purpose: Where the guest’s pushes land, the settings receive-pack
runs with, which refs a push may write, and the push at session end.
Design
Section titled “Design”Landing repository
Section titled “Landing repository”Each project has a bare repository in Wraith Box’s state directory,
projects/<id>/landing.git. The guest pushes there, never to the
user’s repository.
landing.git borrows objects from the same project’s export.git. At
each session start wb-hostd rewrites its alternates file to exactly
that one entry. A push then sends only new objects.
The guest pushes to landing.git through the same transport as its
fetches (S08-01-into-the-guestS08-01-into-the-guest: Into the GuestHow the project's code reaches the guest: the clone, its transport, its remotes, and the uncommitted changes carried in at session start.).
Settings of receive-pack
Section titled “Settings of receive-pack”wb-hostd runs git receive-pack with these settings:
- Repository hooks are disabled.
core.hooksPathis the absolute path of a hooks directory in the read-only installed bundle. That directory holds only the pre-receive check (S08-04-push-checksS08-04-push-checks: Push ChecksThe checks that bound the memory and work of a push before git unpacks it: git's allocation limit, the pack scanner, and the pre-receive check.).receive.procReceiveRefsis unset. - Every object check (
fsck) is an error, including the checks git only reports by default. - Deletes, push options and signed pushes (
push-cert) are refused. receive.unpackLimit=1, so every push goes throughindex-pack.pack.threads=1.- A size limit,
receive.maxInputSize, of 256 MiB. That is the same value as the pack scanner’s wire-byte cap (S08-04-push-checksS08-04-push-checks: Push ChecksThe checks that bound the memory and work of a push before git unpacks it: git's allocation limit, the pack scanner, and the pre-receive check.). GIT_ALLOC_LIMITin its environment, at the per-object cap plus one byte (104857601). Its children inherit it. Git then refuses each allocation above it before making it (X28-git-alloc-limitX28-git-alloc-limit: git's allocation cap against delta bombsDoes GITALLOCLIMIT in receive-pack's environment make both host gits refuse each delta bomb of X26-pre-receive-check before allocating its result?, S08-04-push-checksS08-04-push-checks: Push ChecksThe checks that bound the memory and work of a push before git unpacks it: git's allocation limit, the pack scanner, and the pre-receive check.).
Git reads a GIT_ALLOC_LIMIT of 0 as no limit. So the value is never
computed from a setting that can be zero. The environment builder in
wb-hostd has a unit test that pins the value (C08-gitC08-git: GitThe test cases for the git round trip: the transport, the pack scanner and the pre-receive check, git's own limits behind them, and the data scope of what a session gets from the host repository.).
Ref restriction
Section titled “Ref restriction”A filter in wb-hostd reads the push’s command list before
receive-pack sees any of it. It refuses the whole push unless every
ref is under refs/heads/wb/<session-id>/, where <session-id> is:
- a live session: starting, running, paused, ending, or lost (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.);
- of the project the request names;
- in the VM the push came from.
A push to an ended or discarded session’s branch is refused and logged with the rule (SEC06-repo-writesSEC06-repo-writes: Repository-scoped writesGit pushes and repository-mutating API calls are allowed only for the repositories of the projects that have a session in the VM.). So is a push to another project’s or another VM’s branch.
The filter also checks the form of each command:
- Below the prefix, ref components use only
A-Z,a-z,0-9,-,_and.. - A component doesn’t start with
., doesn’t end with.or.lock, and holds no... - A component is at most 255 bytes, and a ref at most 1024.
- Object IDs must have the length of the landing repository’s hash.
shallowlines are refused.- The first command must ask for
side-band-64k. Git then sends its messages, and those ofindex-packand the pre-receive check, to the guest inside the protocol, not on its own standard error.
The filter reads no byte past the flush that ends the command list. The pack scanner then gets the pack from its first byte (S08-04-push-checksS08-04-push-checks: Push ChecksThe checks that bound the memory and work of a push before git unpacks it: git's allocation limit, the pack scanner, and the pre-receive check.).
The filter is a parser of guest bytes, so it has a fuzz target (C08-gitC08-git: GitThe test cases for the git round trip: the transport, the pack scanner and the pre-receive check, git's own limits behind them, and the data scope of what a session gets from the host repository.). It logs each ref it allows or refuses with the rule.
receive.hideRefs restricts the same refs inside git as a second
layer, and hides other sessions’ branches.
Git’s standard error
Section titled “Git’s standard error”With side-band-64k, receive-pack sends the messages of index-pack
and the hook to the guest inside the protocol. wb-hostd passes them
on without reading them.
What receive-pack still writes to its own standard error reaches
wb-hostd, such as a fatal: line. Its text depends on the pack, for
example an fsck message that quotes a tag name or a .gitmodules
value. So wb-hostd treats it as guest input:
- it keeps at most 4 KiB per push;
- it replaces control characters, escape sequences and invalid UTF-8 with U+FFFD;
- it logs the result as one quoted field next to the rule that ended the push (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter.).
Session end
Section titled “Session end”If the worktree has uncommitted changes, wb-guestd commits them to
the session branch as a WIP commit marked as such, then pushes. wb
can also push mid-session.
- The same happens whether
claudeexited by itself or after a hangup, because closing the terminal ends the session (S06-09-session-lifecycleS06-09-session-lifecycle: Session LifecycleA session's states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved.). wb-guestdcommits only afterclaudehas exited or was killed, and after the session’s processes were killed (S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes.).- A process that left the session while another session of the project runs can still write during the commit (S13-02-filesystem-profileS13-02-filesystem-profile: Layer 2: Seatbelt Filesystem Profile (v1)The Seatbelt profile each session's process tree runs under, where it comes from, its exceptions for Xcode builds, and its known gaps., “Known gaps”).
- The commit and the push run as the project user (S06-09-session-lifecycleS06-09-session-lifecycle: Session LifecycleA session's states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved., “As the project user”).
- A session that was lost gets the same commit and push at the next connection to its VM, unless it was discarded first.
When the commit or the push fails:
- the worktree keeps the changes;
- the summary says what failed;
wbexits with 255 (S05-02-exit-status-and-signalsS05-02-exit-status-and-signals: Exit Status and SignalsWhat wb claude exits with, and what it does with each signal.).
A later wb claude --continue starts from the host’s HEAD
(S08-01-into-the-guestS08-01-into-the-guest: Into the GuestHow the project's code reaches the guest: the clone, its transport, its remotes, and the uncommitted changes carried in at session start.). The old session’s uncommitted files reach a
new session only after the user lands its WIP commit and merges it, or
carries the files in by hand (FR04-carry-inFR04-carry-in: Uncommitted changes carried inUncommitted host changes (staged, unstaged, untracked-not-ignored) are carried into the session at start.).
Decisions
Section titled “Decisions”Borrow from export.git
Section titled “Borrow from export.git”- Why: without borrowing, a session’s first push sends the whole history (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.).
index-pack for every push
Section titled “index-pack for every push”receive.unpackLimit=1 sends every push through index-pack, never
unpack-objects.
- Why:
unpack-objects --strictkeeps the trees and commits of a push in memory until it ends, which only the per-push cap would bound. Andunpack-objectsresolves a delta as soon as its base has arrived.index-packwaits for the pack’s checksum, which the pack scanner holds back (X28-git-alloc-limitX28-git-alloc-limit: git's allocation cap against delta bombsDoes GITALLOCLIMIT in receive-pack's environment make both host gits refuse each delta bomb of X26-pre-receive-check before allocating its result?).
A filter in front of receive.hideRefs
Section titled “A filter in front of receive.hideRefs”- Why:
receive.hideRefscan’t be the only layer. It acceptsrefs/heads/wb/<session-id>itself, and applies the allowed half of a mixed push (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.).
Closing the terminal ends the session
Section titled “Closing the terminal ends the session”A hangup ends the session like an exit of claude. The same WIP
commit and push follow.
- Decided: I46I46 (closed): S05-cli, S06-vm-lifecycle: session lifecycle, detach, sleep and failureS05-cli and S06-vm-lifecycle describe starting a session and its summary at the end, but not what happens in between, or when things go wrong:, recorded in S06-09-session-lifecycleS06-09-session-lifecycle: Session LifecycleA session's states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved..
Status: Draft