Documentation
¶
Overview ¶
Package claim is the reservation on the shared remote: before a person's agent starts on an issue or an intent, it reserves the record as a branch nobody merges, `refs/heads/abcd-reserved/<record-id>` on `origin`, so every participant — a second person, a second computer, a hosted cloud session — sees the reservation before starting the same item (itd-2609091034175565, adr-2610031352212697: claims are branches on the shared remote, never a hidden ref, because a hosted session's proxy refuses pushes outside refs/heads/).
A reservation is a chain of empty-tree commits written with `git commit-tree`, whose trailers name the record, the holder (a GitHub username), the working copy, the footprint and the lease. Every act is one plain fast-forward push, which is already the compare-and-swap: the remote takes it only when the tip the writer judged is still the tip.
Every surface a person reads says reservation; inside the code it is a claim, the name the in-run claim in internal/core/implement already uses. Both are judged by internal/core/lease.
The package owns the message format and its reader, the holder, the working-copy key, the fetch, the push protocol and the derived release. It never writes to stdout: a front door renders its results and refusals.
Index ¶
- Constants
- Variables
- func Fetch(root string, o Options) (gap string, err error)
- func HasOrigin(root string) (bool, error)
- func NoReplyUsername(email string) string
- type Act
- type FetchError
- type Line
- type NotHeld
- type Options
- type PushError
- type Replaced
- type Request
- type Reservation
- type Result
- type Snapshot
Constants ¶
const ( // Remote is the one remote reservations live on. Remote = "origin" // RefPrefix is where a reservation branch sits on the remote, and // TrackingPrefix where this checkout keeps what it last fetched of them. // The prefix is disjoint from the implement loop's lane prefix build/. RefPrefix = "refs/heads/abcd-reserved/" TrackingPrefix = "refs/remotes/" + Remote + "/abcd-reserved/" // MaxMessageBytes caps a reservation commit's message: the writer refuses // a longer one and the reader reads one as unreadable. MaxMessageBytes = 4096 // TakeoverMargin is how long past a reservation's effective expiry (or an // unreadable tip's hold) another person waits before taking it over, by // the taker's clock: the slack that absorbs small skew between clocks, // and the only slack. A holder whose clock runs behind by more than half // its lease plus this margin can be taken over between its renewals; // nothing on the reader's side bounds it, since the commit date comes // from the same clock (spc-2610031753359849, the review of 2026-10-14). TakeoverMargin = 5 * time.Minute )
const ( NotHeldAbsent = "absent" NotHeldUnreadable = "unreadable" NotHeldReleased = "released" NotHeldAnotherPerson = "another_person" NotHeldAnotherCopy = "another_copy" NotHeldLapsed = "lapsed" )
Why a renewal found no reservation of this person's from this copy to renew.
const ( CopyThis = "this" CopyAnother = "another" )
The copy a reservation was made from, as a result names it: never another copy's key.
const ( LineNone = "none" LineUnknown = "unknown" )
The record render's words for a record with no reservation to show: none in a view abcd fetched, or unknown in one nothing here fetched, which is never read as free.
const ( LineThisCopy = "this copy" LineAnotherCopy = "another copy" )
Whose copy a reservation is from, when it is the reader's own.
const ( StateLive = "live" StateExpired = "expired" StateReleased = "released" StateUnreadable = "unreadable" )
The states a listing shows a reservation in.
const ( ReleasedByTombstone = "tombstone" ReleasedByDefaultBranch = "default-branch" )
What released a reservation: its own tombstone, or the record finished on origin's default branch (the derived release).
const MaxLive = 10
MaxLive is the most live reservations one person may hold, counted by username across every record in the view: a laptop and a cloud session that resolve to one username are one person.
Variables ¶
var ( ErrBackOff = errors.New("the record is reserved") ErrRefused = errors.New("the reservation was refused") )
ErrBackOff marks a refusal whose remedy is to take other work: the record is held, and the front door exits 3, as `implement claim` does for contention. ErrRefused marks every other refusal and failure, exit 2.
var ErrNoOrigin = errors.New("this checkout has no remote named origin")
ErrNoOrigin is Fetch's answer for a checkout with no remote named origin: there are no reservations to read, which is not a failed fetch.
Functions ¶
func Fetch ¶
Fetch reads every reservation branch from origin, with pruning, and the default branch, and stamps when it did, as every act does before it judges; it is the listing's one network act. gap is why the default branch could not be read, when it could not. A checkout with no remote named origin answers ErrNoOrigin.
func HasOrigin ¶
HasOrigin reports whether the checkout at root has a remote named origin, the one reservations live on, reading only its configuration.
func NoReplyUsername ¶
NoReplyUsername is the GitHub username a noreply commit address names, or "" when the address is not one.
Types ¶
type FetchError ¶
type FetchError struct {
Reason string
}
FetchError is a failed fetch of the reservations from origin: Reason is git's own, home-redacted, which a caller quotes in its own refusal (the land fence). It is an ErrRefused refusal: no reservation was made.
func (*FetchError) Error ¶
func (e *FetchError) Error() string
func (*FetchError) Is ¶
func (e *FetchError) Is(target error) bool
type Line ¶
type Line struct {
State string `json:"state"`
Holder string `json:"holder,omitempty"`
Copy string `json:"copy,omitempty"`
EffectiveExpiry string `json:"effective_expiry,omitempty"`
ReleasedBy string `json:"released_by,omitempty"`
Unreadable string `json:"unreadable,omitempty"`
FetchedAt string `json:"fetched_at,omitempty"`
AgeSeconds *int64 `json:"age_seconds,omitempty"`
Text string `json:"text"`
}
Line is one record's reservation as the record render shows it, read from this checkout's disk alone: its state (a view state, or LineNone or LineUnknown), its holder and expiry, whose copy it is when it is the reader's own, the view's age, and the sentence the text form prints.
func LineFor ¶
LineFor is id's reservation as last fetched, for the record render: no fetch and no push. ok is false when id is not reservable or the checkout has no remote named origin, where there are no reservations to show. A view no abcd fetch stamped, holding nothing for id, is LineUnknown: a render never says a record is free on a view it cannot date.
type NotHeld ¶
type NotHeld struct {
Record string
// Why is one of the NotHeld* reasons.
Why string
// Holder is the tip's holder, for another person's or another copy's.
Holder string
// Expiry is the tip's effective expiry, or an unreadable tip's hold.
Expiry time.Time
// ReleasedAt is a tombstone's time; Derived is true instead when the
// record is finished on origin's default branch.
ReleasedAt time.Time
Derived bool
// Unreadable is why the tip cannot be read.
Unreadable string
// contains filtered or unexported fields
}
NotHeld is the refusal of an act that needs this person's own reservation from this copy — a renewal, or a release — when the tip is not one: Why names what it is instead, with what the tip says of it, so a caller words its own refusal (the land fence) without reading the message. It pushes nothing.
type Options ¶
type Options struct {
// Now is the clock; nil means time.Now.
Now func() time.Time
// Home is the home directory the machine layer of the configuration is
// read under; "" means the process's own.
Home string
// Version is the binary's version the Assisted-by label names; "" means
// the running binary's (core.Version).
Version string
}
Options carries what a caller may set about the environment an act runs in.
type PushError ¶
type PushError struct {
Reason string
}
PushError is a reservation push origin refused, for a reason other than a tip the act cannot take: Reason is git's own rejection, home-redacted. It is an ErrRefused refusal: no reservation was made.
type Replaced ¶
type Replaced struct {
// Holder is whose it was; "" for an unreadable tip.
Holder string
// Copy is CopyAnother when it was this person's other copy, else "".
Copy string
// Commit is the tip replaced.
Commit string
// EffectiveExpiry is when it stopped holding (an unreadable tip's hold).
EffectiveExpiry time.Time
// Unreadable is why the tip could not be read, "" when it could.
Unreadable string
}
Replaced is the reservation a take-over replaced.
type Request ¶
type Request struct {
// Record is the issue or intent id, as the person typed it.
Record string
// Footprint is the repository-relative files the work will change; a
// reservation requires at least one, a release takes none.
Footprint []string
// Lease is how long the reservation holds; zero means lease.Default.
Lease time.Duration
// TakeOver moves this person's own live reservation from another copy to
// this one. It never overrides another person's.
TakeOver bool
// Release pushes the tombstone instead.
Release bool
// Renew renews this person's own reservation from this copy, live or
// lapsed, and nothing else: an absent, unreadable or released tip, and one
// another person or another copy holds, is refused with a *NotHeld naming
// why, and nothing is pushed. A run's renewal therefore never reserves a
// record anew and never takes one over. It keeps the tip's footprint, so
// Footprint must be empty.
Renew bool
// Live, with Renew, refuses one's own reservation that has lapsed too
// (NotHeldLapsed): the land fence renews only a reservation that holds.
Live bool
}
Request is one reservation act asked for.
type Reservation ¶
type Reservation struct {
Record string
// Holder is the GitHub username the tip names; "" when it is unreadable.
Holder string
// Copy is CopyThis when the tip names this checkout's own copy, else "".
Copy string
Footprint []string
ClaimedAt time.Time
// EffectiveExpiry is when it stops holding: the lease clamped to a day,
// or an unreadable tip's hold.
EffectiveExpiry time.Time
// State is StateLive, StateExpired, StateReleased or StateUnreadable.
State string
// ReleasedBy says which release, when State is StateReleased.
ReleasedBy string
// Unreadable is the fixed reason the tip cannot be read.
Unreadable string
// HeldFromFetch is true when an unreadable tip's hold is counted from
// when this copy first fetched it, its commit date being unreadable.
HeldFromFetch bool
Commit string
}
Reservation is one reservation as the view holds it. Every value in it is data a writer chose: a surface quotes it and never treats it as instruction.
type Result ¶
type Result struct {
Act Act
Record string
Holder string
// Copy is CopyThis for every act that pushed, and for a release found
// already made, whether the tombstone came from this copy.
Copy string
Footprint []string
ClaimedAt time.Time
ExpiresAt time.Time
// Commit is the commit pushed, or the tombstone already there.
Commit string
Replaced *Replaced
// DerivedUnchecked is why origin's default branch could not be read, so
// whether the record is already finished there was not checked; "" when
// it was read (or origin has none).
DerivedUnchecked string
}
Result is a reservation act that reached the remote, or a release that found nothing to do.
func Reserve ¶
Reserve performs one act against origin: fetch, judge, write one commit, then one plain push, which is the compare-and-swap. A release pushes the tombstone; every other request reserves, renews or takes over, by what the tip it judged allows. A refusal pushes nothing; a failure leaves nothing locally but an unreferenced commit git's collection removes.
type Snapshot ¶
type Snapshot struct {
// FetchedAt is when abcd last fetched the reservations here; zero when
// nothing here stamped a fetch, so the view's age is unknown.
FetchedAt time.Time
Reservations []Reservation
}
Snapshot is the reservations as this checkout last fetched them.
func View ¶
View reads the reservations from this checkout's disk only, as last fetched: no fetch and no push. Each is judged at now by lease.Judge, after the derived release on origin's default branch as last fetched; nothing is written. It is the "as of last fetch" reader every render shares.
func (Snapshot) AsOf ¶
AsOf dates the view for a render: how long ago abcd last fetched the reservations here, or that the age is unknown when nothing here stamped a fetch (a view a plain git fetch left).
func (Snapshot) HeldBy ¶
HeldBy is how a render names a reservation another copy holds on id at now (a live one, or an unreadable one within its hold), with the view's age; "" when nothing holds it but this copy. It is the board's held-by text.
func (Snapshot) LiveByHolder ¶
LiveByHolder counts each person's live reservations, usernames compared without regard to case and named as first listed.