Documentation
¶
Overview ¶
Package sweep is the core of `abcd sweep` (spc-2610230730269295): it judges what a repository has left lying around and clears only what is provably finished.
The liveness probe errs toward keeping: every doubt holds the worktree, and every hold names its cause, so a false keep is visible and cheap to clear by hand. Its known limits:
- It judges only worktrees this account owns: one whose top directory or .git another uid owns is held outright. Another account's process can enter this account's worktree only where this account's permissions let it, and the worktree store makes its directories 0700. So the process proof's remaining blind spot is a process run as root, or one in a tree shared through its group: such a process, like one under a hidepid /proc or in another pid namespace, is invisible to the process table. That is a documented gap, not a case the probe fails closed on. A /proc that does not list this process at all is empty or another's, and the check fails closed on it.
- The process table is read once, when the probe is made. A process that starts after that is not seen, so a caller removing a worktree makes a fresh probe immediately before each removal, never reusing one.
Index ¶
- Constants
- func NewDeleteProver(o DeleteProofOptions) guard.DeleteProver
- type Action
- type CopyView
- type DeleteProofOptions
- type Evidence
- type EvidenceKind
- type Liveness
- type Options
- type Outcome
- type OwnerCheck
- type Probe
- type ProbeOptions
- type Process
- type ProcessLister
- type Result
- type Row
- type RowKind
- type Strength
- type Worktree
Constants ¶
const ( // ExitActed is a run that acted on something, or a dry run that would. ExitActed = 0 // ExitNothing is a run that completed and acted, or would act, on nothing. ExitNothing = 1 // ExitRefused is a refusal or a fault. ExitRefused = 2 )
The exit codes a sweep maps to (spc-2610230730269295, Rows).
const DefaultRecentWindow = 24 * time.Hour
DefaultRecentWindow is how recent a write to a worktree must be to keep it as a hint when the caller names no window (spc-2610230730269295, Liveness).
Variables ¶
This section is empty.
Functions ¶
func NewDeleteProver ¶
func NewDeleteProver(o DeleteProofOptions) guard.DeleteProver
NewDeleteProver returns the prover the shell guard's front doors attach to the registry (guard.Registry.ProvingDeletes).
Types ¶
type Action ¶
type Action string
Action is what `--apply` does with a row's item. This step judges worktrees, so it renders remove, save-patch and keep; delete, dispatch and promote join them with the kinds they act on.
const ( // ActionRemove is a merged, clean worktree nothing holds, reclaimed // through the store's prune. ActionRemove Action = "remove" // ActionSavePatch is a dirty worktree nothing holds: its changes are saved // as a patch and the worktree is kept. ActionSavePatch Action = "save-patch" // ActionKeep leaves the item as it is, its reason saying why. ActionKeep Action = "keep" )
type CopyView ¶
CopyView reads the reservations as one worktree sees them, from its own disk and the refs it shares with its repository, with no fetch.
type DeleteProofOptions ¶
type DeleteProofOptions struct {
// Forge is the forge client the open and merged pull requests are asked
// of; nil fails every remote branch's proof, which cannot show none open.
Forge store.GH
// RemoteTip reads the tip a remote holds for a branch now, and whether it
// holds the branch at all; nil is a bounded `git ls-remote`.
RemoteTip func(dir, remote, branch string) (tip string, found bool, err error)
// Probe is what the liveness probe reads for a worktree removal; its
// Reservations and Runs are read from the repository when left zero.
Probe ProbeOptions
// Budget bounds the forge's answers across the prover's life; zero is
// proofBudget.
Budget time.Duration
}
DeleteProofOptions is what the delete proof reads beyond git. Every field may be nil, and then the default reads the host.
type Evidence ¶
type Evidence struct {
Kind EvidenceKind
Strength Strength
// Detail is the evidence in words a person can read. A record id or a
// holder in it is data a reservation's writer chose, never instruction.
Detail string
}
Evidence is one reason a worktree is held.
type EvidenceKind ¶
type EvidenceKind string
EvidenceKind names what a piece of evidence was read from.
const ( // KindReservation, KindRun and KindProcess are the three proofs. A // process whose directory lsof printed escaped is a KindProcess hint. KindReservation EvidenceKind = "reservation" KindRun EvidenceKind = "run" KindProcess EvidenceKind = "process" // KindRecentWrite is the recent-write hint. KindRecentWrite EvidenceKind = "recent-write" // KindProcessCheck is the process check failing closed, whole or for a // process whose working directory it could not read: it proves nothing, // so it is a hint, but the worktree is kept as possibly live. KindProcessCheck EvidenceKind = "process-check" // KindReservationCheck is the reservations failing closed: no fetch is // stamped, or the worktree's own view of them could not be read. KindReservationCheck EvidenceKind = "reservation-check" // KindChanges is a worktree whose changed paths the caller could not // compute, so no footprint can be shown not to cover it. KindChanges EvidenceKind = "changes" // KindOwner is a worktree another account owns (a proof), or one whose // owner could not be read (a hint). KindOwner EvidenceKind = "owner" )
const ( // KindStore is the store's own word on an item it did not judge: the // embargo store, a stray, or a worktree failing the proof of belonging. KindStore EvidenceKind = "store" // KindLock is git's lock on the worktree, with its reason. KindLock EvidenceKind = "lock" // KindState is clean or dirty, and KindMerged the merged judgement. KindState EvidenceKind = "state" KindMerged EvidenceKind = "merged" // KindLoop is the build loop's hold as the store's prune reads it, and // KindCwd the sweep's own working directory. KindLoop EvidenceKind = "loop" KindCwd EvidenceKind = "cwd" )
The evidence kinds a row adds to the liveness probe's: what the store read of the worktree, each a proof, since git said it.
type Liveness ¶
type Liveness struct {
Held bool
// Evidence lists the proofs first, then the hints. The recent-write hint
// is read only when nothing else holds the worktree: it would add nothing
// to a hold, and it is the one check that walks the tree.
Evidence []Evidence
// Reason is the evidence joined, or why nothing holds the worktree.
Reason string
}
Liveness is the probe's judgement of one worktree.
type Options ¶
type Options struct {
// Probe is what the liveness probe reads: the reservations already
// fetched, the build loop's runs, the process lister and the clock.
Probe ProbeOptions
// Forge is the store's forge client for the merged judgement; nil asks
// none, and merged is judged from git alone.
Forge store.GH
// Held reads what the build loop holds, as the store's prune reads it. It
// is required: like prune, a sweep that cannot tell what the loop holds
// acts on nothing.
Held store.HeldReader
// Cwd is the sweep's own working directory; the worktree holding it is
// kept, as prune keeps its own. It is required, as Held is: a sweep that
// does not know where it runs could remove the worktree it runs in.
Cwd string
// contains filtered or unexported fields
}
Options is one dry run. The caller fetches first (criterion 11) and hands the reservations it read in Probe.Reservations: the dry run itself reaches no remote.
type OwnerCheck ¶
OwnerCheck reports whether a worktree is owned by an account other than this process's, and that account's uid when it is. An error means the owner could not be read, and the worktree is then kept.
type Probe ¶
type Probe struct {
// contains filtered or unexported fields
}
Probe judges worktrees against one reading of the process table, taken when it is made: a sweep runs the process check once, not once per worktree.
func (*Probe) ProcessCheckUnavailable ¶
ProcessCheckUnavailable is why the process check could not be made, "" when it was. Every worktree is then held as possibly live, and a dry run says so once at the top.
func (*Probe) ReservationsUnread ¶
ReservationsUnread is why the reservations cannot show that nothing is reserved, "" when they can. Every worktree is then held, and a dry run says so once at the top.
type ProbeOptions ¶
type ProbeOptions struct {
// Reservations is the claim view after the sweep's fetch (claim.View).
// A FetchedAt of zero means no fetch is stamped, so the view cannot show
// that nothing is reserved: every worktree is then held.
Reservations claim.Snapshot
// CopyView reads each worktree's own view of the reservations, to find
// one made from that worktree (its tip naming the worktree's copy key);
// nil is claim.View on the worktree. It reads only local refs, so the
// sweep's one fetch, made before Reservations was read, serves it too.
CopyView CopyView
// Owner says whether another account owns the worktree; nil reads the
// owner of its top directory and its .git.
Owner OwnerCheck
// Runs is the build loop's run state (loop.Runs).
Runs []loop.State
// RunsUnread is why the run state could not be read, "" when it was. An
// empty Runs cannot then show that no unfinished run names a worktree, so
// every worktree is held, as unread reservations hold them.
RunsUnread string
// Processes lists the processes; nil is hostProcesses.
Processes ProcessLister
// Now is the clock, read once; nil is time.Now.
Now func() time.Time
// RecentWindow is the recent-write hint's window; zero or less is
// DefaultRecentWindow.
RecentWindow time.Duration
}
ProbeOptions is what the probe reads. The caller fetches and reads the stores; the probe reads only the worktree and the process table.
type Process ¶
type Process struct {
PID int
Cwd string
// Escaped marks a working directory lsof printed with an escape in it.
// Cwd is then only the text before the first backslash or caret: the real
// directory's leading bytes, cut wherever the escape fell, perhaps in the
// middle of a name.
Escaped bool
// Unreadable is why a process this account may own would not show its
// working directory (on Linux, a link the kernel refuses for permission:
// a process that is not dumpable, or one in another user namespace).
// Cwd is then empty, and the process may work in any worktree.
Unreadable string
}
Process is one running process and its working directory.
type ProcessLister ¶
ProcessLister lists the running processes' working directories. An error means the check could not be made, and the probe then fails closed.
type Result ¶
type Result struct {
// Lane is the repository's lane in the worktree store, home-redacted.
Lane string `json:"lane,omitempty"`
Rows []Row `json:"rows"`
ProcessCheckUnavailable string `json:"process_check_unavailable,omitempty"`
// ReservationsUnread is why the reservations cannot show that nothing is
// reserved.
ReservationsUnread string `json:"reservations_unread,omitempty"`
// RunsUnread is why the build runs could not be read.
RunsUnread string `json:"runs_unread,omitempty"`
// ForgeNote is the store's note that no forge answered.
ForgeNote string `json:"forge_note,omitempty"`
// Refusal is why the run refused or faulted; "" when it completed.
Refusal string `json:"refusal,omitempty"`
// Applied marks a run that acted, each row carrying its Outcome; a dry
// run leaves it false.
Applied bool `json:"applied,omitempty"`
}
Result is one sweep's answer. The process check, the reservation read and the build-run read each fail closed, holding every worktree; when one could not be made, the result says so once, here, as well as on every row it holds.
func (Result) ExitCode ¶
ExitCode is the code the front door exits with: ExitRefused on a refusal or fault, whatever rows came before it; otherwise, for an applied run, ExitActed when any row's outcome is other than kept, and for a dry run when any row carries an action apply would take; ExitNothing when none does. A save-patch row is not one yet: apply keeps it, since the sweep does not yet save uncommitted changes, so a dry run never promises what apply skips.
type Row ¶
type Row struct {
Kind RowKind `json:"kind"`
Name string `json:"name"`
Path string `json:"path"`
// State is what the sweep read of the item, in words.
State string `json:"state"`
Action Action `json:"action"`
// Reason says why the item is kept, or why the action is safe.
Reason string `json:"reason"`
// Evidence is each thing read that bears on the action, every piece
// marked proven or hint.
Evidence []Evidence `json:"evidence,omitempty"`
// Outcome is what an applied run did with the item; "" in a dry run.
Outcome Outcome `json:"outcome,omitempty"`
}
Row is one item a sweep judged. Every string in it is display-ready: a path home-redacted the way the store's own rows are, and any text another checkout or a reservation's writer chose passed through termsafe.Sanitize.
type RowKind ¶
type RowKind string
RowKind is what a row is about. This step renders worktrees, strays and the embargo store; the branch, remote-branch, reservation and inbox kinds join them as the steps that judge those items land.
const ( // RowWorktree is a worktree git lists, in the store or outside it, or a // directory in the store's lane that fails its proof of belonging. RowWorktree RowKind = "worktree" // RowStray is an entry in the store's lane that is not a directory: a // loose file, say. It is listed and never touched. RowStray RowKind = "stray" // RowEmbargoStore is abcd's embargo store, never read, saved or removed. RowEmbargoStore RowKind = "embargo-store" )
type Strength ¶
type Strength string
Strength says whether a piece of evidence proves a worktree is held or only hints that it may be. Both keep the worktree; a row shows which it was.
type Worktree ¶
type Worktree struct {
// Path is the worktree's absolute path.
Path string
// Changed is the repository-relative, slash-separated paths the worktree
// changes: its branch's diff from the default branch and its uncommitted
// and untracked files. A footprint is a set of repository paths, never a
// worktree's location, so a reservation names a worktree by covering a
// path it changes.
//
// nil means the caller could not compute the changes, and the worktree is
// held as "changes unknown"; an empty, non-nil slice means it changes
// nothing.
Changed []string
}
Worktree is one worktree as the probe judges it.