gate

package
v0.175.0-rc.511 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gate is the merge and promotion gate: lane admission, the queue, overlap and pair checks, takeover and preemption of a running child, urgent cut-ins, child runs and release confirmation, and central lane turns.

The command package holds the CLI commands, the detached child entrypoint and the lane views, and is its Host. What this package still needs of the command crosses two seams, each named in one file:

  • host.go: Host, the app's configuration, state, clock and output and the app's own steps; and Cmd, the command package's functions.
  • vocabulary.go: the command's names and exit codes the gate writes and reads, kept equal by the command's TestGateVocabulary.

A seam entry goes when what it names has moved to a package this one can import.

Index

Constants

View Source
const (
	KeptOutputs = "merge-output"
	KeptFor     = 7 * 24 * time.Hour
)

KeptOutputs is the directory under the state directory that keeps each finished merge run's output (keptOutput), KeptFor how long.

View Source
const (
	FollowPoll = 200 * time.Millisecond
	ChildStart = 30 * time.Second
)

FollowPoll is how often the gate copies devctl's new stderr lines and looks for its exit code; ChildStart how long the merge's child may take to start.

View Source
const (
	DevctlReleaseFailed = 6

	DevctlAuth        = 8
	DevctlUnconfirmed = 9
)

devctl pr merge's exit codes the unit's exit tells apart.

View Source
const (
	// RunInfoExt is the extension of what gate runs shows of a detached run
	// (RunInfo), which its merge-child writes before it starts the command.
	RunInfoExt = ".run"
	// StoppedExt marks a run gate stop stopped, with who did.
	StoppedExt = ".stopped"
)
View Source
const (
	VerdictUnconfirmed = "unconfirmed"
	VerdictAvailable   = "available"
)

VerdictUnconfirmed is a merge whose release nobody could confirm.

View Source
const (
	ExitCentral = 69
)

The command's names the gate writes and reads. They are the command's; its TestGateVocabulary keeps each equal to the command's own.

View Source
const ExitGateDuplicate = 3

ExitGateDuplicate: the pull request's merge already runs, devctl's "not applicable".

View Source
const ExitGateQueued = 76

ExitGateQueued: the merge waits on for its turn, or for the GitHub budget's reset, in a run of its own, which wakes its owner with the outcome.

View Source
const ExitGateRefused = 77

ExitGateRefused: a hold, a GitHub budget unknown or an unreadable installation; nothing is queued.

View Source
const ExitGateUnread = 74

ExitGateUnread: the GitHub budget read failed in transit on every try (sysexits' EX_IOERR); the merge was neither judged nor queued, the same command runs again once GitHub answers.

View Source
const GateCmdName = "gate"

GateCmdName is the gate's command, which a queued run and a brokered gate run, and which re-executes a replaced binary by itself.

View Source
const GateFromEnv = "BEEKEEPER_GATE_FROM"

GateFromEnv names the gate a queued run took the merge's place from.

View Source
const GateLimitEnv = "BEEKEEPER_GATE_LIMIT"

GateLimitEnv carries a call's tool limit (merge.toolLimit) across the re-exec of a replaced binary: the time the call leaves, RFC 3339.

View Source
const GatePrefix = "beekeeper gate: "

GatePrefix starts every line the gate prints.

View Source
const GateRunningEnv = "BEEKEEPER_GATE_RUNNING"

GateRunningEnv carries a running merge's devctl across the re-exec of a replaced binary: its merge-child's pid and how far its stderr was copied, "<pid>:<offset>".

View Source
const LeftExt = ".left"

LeftExt marks a wait its gate left to run on outside the call (its caller's timeout, the tool limit): its merge-child goes on without the gate and hands the outcome to the owner.

View Source
const MergeBudgetReserve = 200

MergeBudgetReserve leaves room for the reads and writes of one gated PR.

View Source
const MergeChildCmd = "merge-child"

MergeChildCmd is the hidden command that runs one gated devctl command for the gate.

View Source
const NoneWarranted = "none warranted"

NoneWarranted is a merge's release when its commits warranted none.

View Source
const PairFresh = 30 * time.Second

PairFresh is how recently a paired merge's gate must have found only the pair holding it back for its sibling to start: a gate polls every 5s.

View Source
const RebaseReads = 3

RebaseReads is how often the gate reads a pull request whose rebase GitHub has not computed yet.

View Source
const TerminationExt = ".termination"

TerminationExt survives merge file cleanup so a later invocation can explain the previous failed run even when its runner could not write an exit record.

View Source
const TimeoutComm = "timeout"

TimeoutComm is coreutils' timeout as the process table names it.

View Source
const UnknownState = "unknown"

UnknownState is GitHub's mergeable_state while it computes it.

View Source
const VerbMerging = "merging"
View Source
const VerbPromoting = "promoting"

Variables

View Source
var (
	// ReleasesPoll is how often a merge that waits for its lane's releases
	// reads the state.
	ReleasesPoll = 5 * time.Second
	// ReleasesWait bounds that wait: past the confirming gate's own release
	// wait (ReleasePRWait), its settle and a margin, a gate that still
	// confirms is wedged.
	ReleasesWait = func(settle time.Duration) time.Duration { return ReleasePRWait + settle + 5*time.Minute }
)

Seams for the tests.

View Source
var BaseChecks = func(ctx context.Context, repo, base string) (github.BaseChecks, error) {
	return github.ReadBaseChecks(ctx, github.RunGH, repo, base)
}
View Source
var BusyPauses = merge.BusyPauses

BusyPauses are the pauses before a busy base's next devctl run; a seam for the tests.

View Source
var DevctlAcceptsRed = toolAcceptsRed
View Source
var DevctlVersion = toolVersion
View Source
var InfraReds = func(ctx context.Context, doc []byte) []merge.Infra {
	return merge.InfraReds(ctx, github.RunGH, doc)
}

InfraReds are the red checks of a document that died on a transient infrastructure failure, read from their jobs' logs.

View Source
var JudgeWait = 10 * time.Second
View Source
var MergeExts = []string{".progress.tmp", ".progress", ".json", ".log", ".rc", ".pid", ".spec", RunInfoExt, ".kept", StoppedExt, LeftExt}

MergeExts are the extensions of a merge's files.

View Source
var PluginTagPoll = 10 * time.Second

PluginTagPoll is how often the gate looks for a merged plugin's tag, pluginTagWait how long it awaits the tags of one merge.

View Source
var PluginTags = func(ctx context.Context, repo, sha string) ([]string, error) {
	return github.PluginTags(ctx, github.RunGH, repo, sha)
}
View Source
var PrWarmWait = func(ctx context.Context, repo string, n int) {
	c := proc.CommandContext(ctx, merge.Tool, "pr", "wait", repo, strconv.Itoa(n))
	c.Env = Cmd.DevctlCommandEnv("")
	c.Stdout, c.Stderr = io.Discard, os.Stderr
	_ = c.Run()
}

PrWarmWait runs devctl pr wait for repo#n, its progress on the gate's stderr: a warm-up whose verdict the merge's own devctl run judges.

View Source
var PromoteCandidate = func(ctx context.Context, repo string) (string, error) {
	ctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
	defer cancel()
	var stderr bytes.Buffer
	c := proc.CommandContext(ctx, merge.Tool, "release", "promote", repo, "--dry-run", "--progress")
	c.Env = Cmd.DevctlCommandEnv("")
	c.Stderr = &stderr
	out, err := c.Output()
	if candidate, ok := merge.ParsePromoteCandidate(out); ok {
		return candidate, nil
	}
	if err == nil {
		err = errors.New("no document")
	}

	if cause := ctx.Err(); cause != nil {
		err = fmt.Errorf("%w (%w)", err, cause)
	}
	if tail := cmp.Or(Cmd.LastOf(stderr.String()), merge.PromoteFailure(out)); tail != "" {
		err = fmt.Errorf("%w: %s", err, tail)
	}
	return "", fmt.Errorf("%s release promote %s --dry-run: %w", merge.Tool, repo, err)
}

PromoteCandidate is the release candidate devctl release promote would dispatch for repo now (its --dry-run), "" when there is none.

View Source
var PullBase = func(ctx context.Context, repo string, n int) (github.PullBase, error) {
	return github.ReadPullBase(ctx, github.RunGH, repo, n)
}
View Source
var PullMergeCommits = func(ctx context.Context, repo string, n int) ([]string, error) {
	return github.MergeCommits(ctx, github.RunGH, repo, n)
}
View Source
var PullRebase = func(ctx context.Context, repo string, n int) (github.Rebase, error) {
	return github.ReadRebase(ctx, github.RunGH, repo, n)
}
View Source
var PullState = github.PullState
View Source
var ReadBackoff = []time.Duration{10 * time.Second, 30 * time.Second, 80 * time.Second}

ReadBackoff are the pauses between the tries of a gate read that failed in transit: four tries over about two minutes, so a short network or Teleport outage does not refuse a merge, nor cost it its lane place.

View Source
var ReadHelmReleases = func(ctx context.Context, lane config.Lane) ([]merge.HelmRelease, error) {
	ctx, cancel := context.WithTimeout(ctx, time.Minute)
	defer cancel()
	kctx, err := kubeContext(ctx, lane)
	if err != nil {
		return nil, err
	}
	out, err := kubectlList(ctx, kctx, "helmreleases.helm.toolkit.fluxcd.io")
	if err != nil {
		return nil, err
	}
	hrs, err := merge.ParseHelmReleases(out)
	if err != nil {
		return nil, err
	}
	if out, err = kubectlList(ctx, kctx, "ocirepositories.source.toolkit.fluxcd.io"); err != nil {
		return nil, err
	}
	return hrs, merge.AttachRanges(hrs, out)
}

ReadHelmReleases reads the lane installation's HelmReleases with kubectl, each with the range its OCIRepository follows.

View Source
var RebaseRetry = 2 * time.Second

RebaseRetry is how long the gate waits for GitHub to compute whether a pull request rebases before it reads again.

View Source
var ReleaseAt = func(ctx context.Context, repo, base, ref string) (github.BaseRelease, error) {
	return github.ReadReleaseAt(ctx, github.RunGH, repo, base, ref)
}
View Source
var ReleasePRWait = 35 * time.Minute

ReleasePRWait bounds the wait for a release pull request's tag pipeline: devctl release wait's own default timeout and a margin.

View Source
var ReleaseWait = func(ctx context.Context, repo string, target ...string) []byte {
	var out bytes.Buffer
	c := proc.CommandContext(ctx, merge.Tool, append([]string{"release", "wait", repo}, target...)...)
	c.Env = Cmd.DevctlCommandEnv("")
	c.Stdout, c.Stderr = &out, os.Stderr
	_ = c.Run()
	return out.Bytes()
}

ReleaseWait runs devctl release wait for repo's release named by target (a version, or --pr and a number), its progress on the gate's stderr, and returns its document.

View Source
var ReviewGuard = func(ctx context.Context, repo string, n int) (string, error) {
	why, _, err := github.ReviewGuard(ctx, github.RunGH, repo, n)
	return why, err
}

ReviewGuard is the pull request's review read (github.ReviewGuard).

View Source
var SelfExe = os.Executable
View Source
var ServerRetries = []time.Duration{10 * time.Second, 30 * time.Second, time.Minute}

ServerRetries are the pauses before the gate sends a merge again whose merge call GitHub answered with a 5xx (merge.ServerError), one per retry.

View Source
var StopWait = 5 * time.Second

StopWait is how long a TaskStop waits for an ended devctl's merge-child to exit before it asks GitHub how the merge stands.

View Source
var TagExists = func(ctx context.Context, repo, tag string) (bool, error) {
	return github.TagExists(ctx, github.RunGH, repo, tag)
}
View Source
var TimedCaller = func() bool {
	t, err := Cmd.Plat().Machine.Processes()
	return err == nil && UnderTimeout(t, os.Getpid())
}

TimedCaller says whether the gate runs under a timeout (coreutils' timeout between it and the Claude Code CLI it runs under, if any), whose SIGTERM is the caller giving up on the call, never a stop aimed at the run; a seam for the tests.

Functions

func ExitCode

func ExitCode(rc int) error

func ExitText

func ExitText(rc int, reason string) string

ExitText is "exit <rc>", with the run's reason when it gave one.

func FinishedRun

func FinishedRun(base string) (doc []byte, rc int)

FinishedRun reads how a merge's run ended from its files once its runner is gone: its document and exit code, 137 (killed) without one.

func GateLine

func GateLine(format string, args ...any)

func GateRefused

func GateRefused(format string, args ...any) error

func GateRefusedWith

func GateRefusedWith(code int, format string, args ...any) error

GateRefusedWith prints the gate's line and exits code: "refused, …", or "unread, …" for a read that failed in transit, which judged nothing.

func JudgeRun

func JudgeRun(ctx context.Context, repo string, pr, tries int) (merge.Outcome, error)

JudgeRun asks GitHub, up to tries times, whether repo#pr merged, as its run left no document to say it; the caller's context may be gone, the gate's is not.

func KeepOutput

func KeepOutput(base string, doc []byte, now time.Time) string

KeepOutput keeps a finished run's stderr and document for its owner in <state>/merge-output/<repo>-<n>-<UTC time>.log, as its files under merges/ are removed with the run, and prunes the kept outputs older than KeptFor. It returns the kept file, "" when there was nothing to keep.

func LaunchChild

func LaunchChild(spec ChildSpec, base string) (int, error)

LaunchChild writes spec, with this process's environment, directory and pid as its gate, to base.spec, starts merge-child on it and returns its pid.

func MergeBase

func MergeBase(stateDir, repo string, pr int) string

MergeBase is the base of a merge's files in the state directory: devctl's document (.json) and stderr (.log), its exit code (.rc), its runner's pid (.pid), the command it runs (.spec), what gate runs shows of it (.run), the file its output is kept in (.kept), who stopped it with gate stop (.stopped) and, for a wait, the gate's mark that it left the run to run on (.left). A termination diagnostic (.termination) survives cleanup for the next invocation. Not the caller's pipes, which close with the caller's session.

func MergeKillReason

func MergeKillReason(log []byte) string

MergeKillReason preserves the wrapper's confirmed cap report when present. SIGKILL alone cannot identify its sender and must never be called an OOM.

func NothingDone

func NothingDone(pr int, out merge.Outcome) string

NothingDone is the outcome line's "nothing merged", "nothing promoted" for a promotion, with devctl's state of it when its document named one.

func OnlyLockBusy

func OnlyLockBusy(err error) bool

OnlyLockBusy says every leaf of err, through wrapping and joining, is a LockBusyError or coordinator lease commit lock contention.

func ParseRunOutcome

func ParseRunOutcome(pr int, doc []byte, rc int) (merge.Outcome, bool, int)

ParseRunOutcome treats promote's usage exit as a certain refusal, even without a JSON document. No GitHub mutation can have happened.

func PruneUrgent

func PruneUrgent(st *state.State, now time.Time, ttl time.Duration)

PruneUrgent drops the urgent merges whose reset window ended and the marks whose merge has not reached its gate within ttl.

func RecordMergeTermination

func RecordMergeTermination(base, reason string)

func RemoveMergeFiles

func RemoveMergeFiles(base string)

RemoveMergeFiles removes a merge's files.

func ShortSHA

func ShortSHA(sha string) string

ShortSHA is a commit's short form.

func SignalPID

func SignalPID(pid int, s os.Signal)

SignalPID sends s to pid.

func SquashArgv

func SquashArgv(self, repo string, pr int, devctlArgv []string) []string

SquashArgv is the gate's command for repo#pr on the plain squash merge route, with the caller's --timeout.

func StaleMerge

func StaleMerge(st *state.State, m state.Merge) string

StaleMerge is local evidence that a running place has lost its writer. Unknown versions are not evidence of staleness.

func ToolKey

func ToolKey(h state.Hold) string

ToolKey names the merge or promotion that opened the tool-release window h.

func UnderTimeout

func UnderTimeout(t *proc.Table, pid int) bool

UnderTimeout says whether a timeout is among pid's ancestors below the Claude Code CLI, if any.

func UnsavedBudget

func UnsavedBudget(err error) error

UnsavedBudget is a budget read's error without the failures to save the reading: when every failure in err is the state lock being busy, GitHub answered and only keeping the reading lost to another beekeeper process holding the lock for a moment. The reading is known and stands, and the next read saves it; any other failure keeps the budget unknown (#3411).

func UrgentTaken

func UrgentTaken(a Host, st *state.State, key string) string

UrgentTaken is why another merge than key cannot be urgent now: one ran under the floor in this reset window, or one is marked and waits; "" when none.

func Vocabulary

func Vocabulary() map[string]any

Vocabulary is the constants above by name, for the command's test.

func WaitGone

func WaitGone(pid int, d time.Duration) bool

WaitGone says whether pid exits within d.

Types

type Binary

type Binary interface {
	Path() string
	Replaced() bool
	Exec(env ...string) error
}

Binary is the executable a gate call or a merge-child runs: whether another file was renamed over its path since it started (beekeeper self-update, install) and its re-exec, which carries the call on under the installed release with the same pid, arguments and stdio.

type ChildRun

type ChildRun struct {
	Doc []byte
	Rc  int

	Unheard  bool
	Replaced bool
	Offset   int64

	// left says the follow reached its leave time while the run went on;
	// cut that it left as its caller's timeout cut the connection
	// (TimedCaller), merged that it left at the merge, the run awaiting
	// its release (leaveMerged).
	Left bool
	// ended says the follow returned as its caller went away, for a run that
	// ends with it (withCaller): its merge-child stops the command.
	Ended bool
	// contains filtered or unexported fields
}

ChildRun is how a detached run ended for its gate: devctl's document and exit code (128+n for a signal), the file its output is kept in, and whether a write to the caller's pipes failed. replaced says the gate's binary was replaced while the run went on, which runs on: offset is how far its stderr was copied, for the re-executed gate to follow it from.

func FollowChild

func FollowChild(base string, pid int, offset int64, bin Binary, hold func(doc []byte) bool, leave time.Time, withCaller bool, sig <-chan os.Signal) ChildRun

FollowChild follows the devctl that merge-child pid runs outside its caller: a harness that ends the caller kills its process tree, and a session run as a unit takes its cgroup down with it. merge-child (this binary) runs devctl in a transient user service of its own (systemd-run), or where there is no user service manager as a child in a session of its own: its stdout goes to base.json, its stderr to base.log, which the gate copies onto its own stderr from offset on, and its exit code to base.rc. The gate writes the document to its stdout once devctl ended; a child gone without an exit code counts as killed (137). SIGINT, a person's Ctrl-C, reaches devctl at once. SIGTERM reaches it when it is a stop aimed at the gate: its caller still there stopGrace later. A caller going away (SIGHUP, or the gate's parent gone with the SIGTERM, a harness killing its command's process tree) does not stop devctl (outliveCaller keeps it from ending the gate), unless withCaller: then the follow returns at once with ended set, and the run's merge-child stops devctl as the gate is gone. A SIGTERM from a timeout the gate runs under (TimedCaller) cuts the connection, not the run: the follow returns at once with left and cut set, the run's files in place for its merge-child, which hands the outcome to its owner. bin, when given, is the gate's binary: replaced while the run goes on, the follow returns at once with replaced set and the offset reached, the run's files in place, for the gate to re-execute the installed binary and follow on from there. hold, when given, keeps a document it takes off the stdout (held), for the gate to decide. leave, when set, is when the follow returns with left set while the run goes on (the gate's tool limit), its files in place for its merge-child and the watch. sig, when given, hears the signals from before devctl started (GateRun.followSignals); else the follow hears them from its start on.

func FollowChildUntil

func FollowChildUntil(base string, pid int, offset int64, bin Binary, hold func(doc []byte) bool, leave time.Time, leaveMerged, withCaller bool, sig <-chan os.Signal) (r ChildRun)

FollowChildUntil is FollowChild that, with leaveMerged, also returns with Left and merged set once the run merged and awaits its release (Cmd.AwaitsRelease): its merge-child confirms the release and records the run without the caller (the gate's --until-merged).

type ChildSpec

type ChildSpec struct {
	Argv    []string    `json:"argv"`
	Command []string    `json:"command,omitempty"`
	Env     []string    `json:"env"`
	Dir     string      `json:"dir"`
	Owner   state.Party `json:"owner,omitzero"`
	Gate    int         `json:"gate,omitempty"`
	Config  string      `json:"config,omitempty"`
	HandCut string      `json:"handCut,omitempty"`
	// WithCaller is set for a wait, never for a merge or a queued merge's run.
	WithCaller bool `json:"withCaller,omitempty"`
	// BusyBudget, set for a merge with --update-branch, is how long from its
	// first run merge-child runs devctl again after a run ends on a busy base
	// (merge.BusyBase), BusyPauses its pauses before them (merge.BusyNext);
	// zero: once.
	BusyBudget time.Duration   `json:"busyBudget,omitempty"`
	BusyPauses []time.Duration `json:"busyPauses,omitempty"`
}

ChildSpec is what merge-child runs: the gate's command, environment and working directory, in base.spec (0600: the environment carries tokens). Owner is the session the outcome goes to, Gate the pid of the gate that hands it over while its caller listens, Config the configuration a wake of the owner loads, Command the devctl command Argv stands for when Argv is beekeeper's own (a queued merge, a wait that follows another's poller), HandCut a merge's base branch that no Auto-release run tags. WithCaller says the run ends with its gate (a wait): merge-child stops the command once the gate is gone without leaving the run to run on (LeftExt).

type Command

type Command struct {
	AwaitsRelease         func(base string) bool
	BinaryVersion         func(ctx context.Context, file string) string
	Clock                 func(now time.Time, t time.Time) string
	DevctlCommandEnv      func(configPath string) []string
	EndChild              func(pid int) error
	Event                 func(by state.Party, verb string, format string, a ...any) state.Event
	HandOver              func(base string, r ChildRun, cli int)
	HoldTarget            func(h state.Hold) string
	LastLine              func(path string) string
	LastOf                func(s string) string
	MergeAuthority        func(ctx context.Context, a Host, repo string, pr int, targetHead string) (string, bool, error)
	NewExitError          func(code int, msg string, err error) error
	OutliveCaller         func() func()
	OwnedBase             func(stateDir string, argv []string, pid int) string
	ParseRef              func(s string) (github.PR, bool)
	Plat                  func() platform.Platform
	ReadBudget            func(a Host, ctx context.Context) (github.Budget, error)
	ReadPID               func(base string) int
	RecordDeliveryRelease func(st *state.State, repo string, pr int, out merge.Outcome, handCut string, now time.Time) []state.Event
	RecordRun             func(st *state.State, i int, lane config.Lane, by state.Party, r RunOutcome, now time.Time, note string) []state.Event
	ReplacedBinary        func(pid int) (platform.Install, bool)
	RunFailure            func(doc []byte, last string, handCut string) string
	StoredGraphQL         func(g *github.GraphQL, at time.Time) *state.GraphQL
	UntilText             func(a Host, h state.Hold) string
	UserSystemd           func() bool
	WakeID                func(p state.Party) string
	WithInfra             func(reason string, infra []merge.Infra) string
}

Command is the command package's functions the gate calls. They stay there until their own packages exist; a field goes when its function has moved to a package the gate can import.

var Cmd Command

Cmd is the command's functions, set by the command at its start.

type GateRun

type GateRun struct {
	ReviewedHead string
	Host         Host
	Ctx          context.Context
	Argv         []string
	Repo         string
	Pr           int
	Lane         config.Lane
	Me           state.Party
	Pid          int
	Cli          int // the caller's CLI (callerCLI)
	LastWhy      string

	Queued bool // the merge's own run, which waits on after exit 76
	From   int  // the gate a queued run took the merge's place from
	// placed says the merge had its place in the lane: a step that finds
	// none, its place was taken out (lanes drop).
	Placed bool
	// passive says a live predecessor owns the lane's checks. This step
	// only read the queue and may sleep longer without refreshing its place.
	Passive bool
	// candidate is the release candidate a promotion is for; read says this
	// call read it (a fresh promote), else it is its place's.
	Candidate     string
	CandidateRead bool
	// pinned says the promotion names its candidate (--version).
	Pinned bool
	// central says the merge's lane queues in the central instance: joined
	// once the merge has its place there, centralWhy what it waits for
	// there as of centralAsked.
	Central bool

	CentralAsked time.Time
	// release is how the pull request's base branch releases, read once
	// before devctl's turn.
	Release *github.BaseRelease

	// bin is the executable this call runs, re-executed once replaced.
	Bin Binary
	// output is the file this call's stdout writes to (gateOutput), the
	// background task a TaskStop names.
	Output string
	// leaveAt is when the call leaves its merge to run on outside it, exit
	// 76 (merge.toolLimit); zero: never.
	LeaveAt time.Time
	// untilMerged ends the call once the merge landed and its merge-child
	// only awaits the release (--until-merged, the supervisor loop's).
	UntilMerged bool

	// requeued says a hold took the running merge back out of its lane
	// (requeue): its wait for the turn starts again.
	Requeued bool
	// sig hears the signals aimed at the gate from before devctl starts
	// (followSignals), so that none sent while it starts is lost.
	Sig <-chan os.Signal
	// contains filtered or unexported fields
}

GateRun is one gated merge.

func (*GateRun) AwaitReleases

func (g *GateRun) AwaitReleases() error

AwaitReleases runs before the merge's devctl in a lane without an installation: while a release of the lane is being confirmed it warms the pull request up (warmUp, beside the wait), then waits until that release is known and the lane settled, so the merge lands after the previous release's verdict. The wait is the merge's, its place running without a devctl: a stop (SIGINT, a SIGTERM aimed at the run, the gate's context ending, beekeeper gate stop) ends it with nothing merged and the place out of the lane; a hold that preempts the merge puts it back to waiting (PreemptedError); a place taken out of the lane refuses; a release still unknown past ReleasesWait refuses rather than merging ahead of its verdict. The reviews are read again before devctl starts.

func (*GateRun) CapWait

func (g *GateRun) CapWait(st *state.State, me state.Merge) string

CapWait is what the merge me, its lane's next, waits for under merge.cap, "" when it may start: the machine's devctl merges and promotes count, the waits never, except in the merge's reset window (merge.resetFirst): only the running merges count, and the older merges queued for the reset that are free to start take their slots first.

func (*GateRun) CapWaitFor

func (g *GateRun) CapWaitFor(st *state.State, me state.Merge, need int) string

CapWaitFor is capWait for a start that takes need slots: two for the first merge of a pair, which starts its sibling too (pairTurn), none for that sibling.

func (*GateRun) CentralLeave

func (g *GateRun) CentralLeave(why string)

CentralLeave takes the merge out of its central lane once it joined.

func (*GateRun) CentralRecord

func (g *GateRun) CentralRecord(settles bool, why string)

CentralRecord tells the central lane how the merge's run ended: merged, the lane settles until the machine's watch saw its release roll; otherwise it leaves the lane. A failure is said, never fatal: devctl ran.

func (*GateRun) CentralStart

func (g *GateRun) CentralStart() (string, error)

CentralStart makes the merge, running here, its central lane's running one. When another merge of the lane started there first, the merge waits again here (unstart) and it returns what it waits for.

func (*GateRun) CentralTurn

func (g *GateRun) CentralTurn() (string, error)

CentralTurn queues the merge in its central lane, or keeps its place there, and returns what it waits for there: "" on its turn. A hold the central instance names refuses the merge, as a local hold does; an unreachable central instance refuses it with ExitCentral.

func (*GateRun) CheckMergeRoute

func (g *GateRun) CheckMergeRoute() error

CheckMergeRoute refuses branch updates on every merge route, before queuing and again before launch for runs resumed from an earlier version.

func (*GateRun) CheckRebase

func (g *GateRun) CheckRebase() error

CheckRebase refuses a rebase merge GitHub reports conflicting with its base, or whose head carries a merge commit, before it takes a lane place: devctl would refuse the first only at its turn (exit 3, "This branch can't be rebased"), and a base merged into the branch hides the conflict from the pull request and breaks the line's linear history. GitHub not answering refuses; a rebase GitHub has not computed after RebaseReads reads queues, devctl judging it at its turn.

func (*GateRun) CheckReviews

func (g *GateRun) CheckReviews(refuse func(code int, format string, args ...any) error) error

CheckReviews refuses a pull request merge a reviewer holds, through refuse: a request for changes that is the reviewer's latest verdict, or unanswered feedback newer than the head. Reviews GitHub does not answer for refuse too (74 in transit): nothing merges unread.

func (*GateRun) ConfirmRelease

func (g *GateRun) ConfirmRelease(out *merge.Outcome, rc int) (string, int)

ConfirmRelease confirms the release of the merge devctl ended at the merge (overlaps), its lane place releasing meanwhile, within ReleasePRWait: an available release or none warranted frees the place; a failed release keeps its verdict for settling without a roll, and an unconfirmed one settles the lane by the settle rule from now. It records the release in out and returns the gate's line and the exit devctl pr merge would have ended with.

func (*GateRun) DeclarePair

func (g *GateRun) DeclarePair(arg string) error

DeclarePair records the pair the merge's --pair names, sibling as owner/repo#n or its URL, before the merge takes its place. A declaration that names no pull request, the merge itself, or a merge already paired with another is refused with nothing queued. The pair's merge refused before declares it anew; its sibling refused before leaves the refusal for the step, which refuses this merge with it.

func (*GateRun) Enqueue

func (g *GateRun) Enqueue(why string) error

Enqueue hands the merge's wait to a run of its own outside the caller (LaunchChild), the same gate under --queued: it keeps the merge's place, merges when its turn comes and wakes the owner with the outcome (tellOwner), as this gate leaves without its heard marker. It returns exit 76, for a merge that waited its turn and for one under the budget floor alike. An unpinned promotion is refused instead (77): its turn, later, would promote a candidate nobody chose.

func (*GateRun) Follow

func (g *GateRun) Follow(base string, pid int, offset int64) error

Follow copies the merge's devctl (its merge-child pid) stderr on from offset to its end and records the run (record). A binary replaced meanwhile re-executes the installed one first (reexec), which follows the same devctl on from there (resumeMerge), so the installed release records the outcome; one that does not start is followed on under this one.

func (*GateRun) GateBudget

func (g *GateRun) GateBudget() (state.Budget, error)

GateBudget is the last budget reading when it is younger than merge.budgetFresh and its reset has not come, else a fresh one (a conditional request, free on 304): a merge queued for the reset reads the new window at once. Neither needs the state lock: the last reading is read without it (a write replaces the state in one rename), and a fresh reading that only lost its save to a busy lock stands (#3411).

func (*GateRun) Key

func (g *GateRun) Key() string

Key names the merge, owner/repo#n or owner/repo promote.

func (*GateRun) LanePending

func (g *GateRun) LanePending() string

LanePending says what the merge's lane waits for before its next merge lands, "" when nothing (merge.Lane.Unsettled without the overlap).

func (*GateRun) LaneReady

func (g *GateRun) LaneReady(q merge.Lane) ([]merge.HelmRelease, string, error)

LaneReady reads the lane's installation: why is what the lane waits for, "" when it is free, which needs each of its settling merges settled. A lane without an installation has nothing to roll, but a merge whose release is unknown (its run lost, merged without a confirmed release) settles it by the settle rule all the same: its release may be cutting now, and a promotion behind it would race that. A merge whose release its gate confirms (merge.Confirming) lets an overlapping merge start (overlaps), which merges only once that release is known (awaitReleases). An installation that cannot be read refuses.

func (*GateRun) MergeArgv

func (g *GateRun) MergeArgv() ([]string, error)

MergeArgv is the command the merge's merge-child runs: the gated devctl command bounded by the gate's CI timeout, with --no-release-wait into a hand-cut base, or the plain squash merge for a repository devctl does not serve.

func (*GateRun) MergeFiles

func (g *GateRun) MergeFiles() (string, error)

MergeFiles is the base of the merge's files (MergeBase), its directory created.

func (*GateRun) Mine

func (g *GateRun) Mine(st *state.State, phase string) int

Mine is the index of this merge's entry in that phase, -1 when none.

func (*GateRun) OutcomeTo

func (g *GateRun) OutcomeTo() string

OutcomeTo says where the outcome of a merge that runs on outside the call goes: a wake of its owner's session, on the roster or off it, else the log.

func (*GateRun) OverlapLane

func (g *GateRun) OverlapLane() bool

OverlapLane says whether the merge's lane lets it start while the lane's previous merge confirms its release: a pull request devctl merges, in a local lane without an installation, not devctl's own (its release window reads the merge's release).

func (*GateRun) Overlaps

func (g *GateRun) Overlaps() bool

Overlaps says whether the merge, once merged, confirms its release in its gate after devctl ended at the merge, freeing its lane for the next merge meanwhile: an overlapLane merge whose release devctl would await, its base tagged by Auto-release (no hand cut, no per-plugin tags, no release-PR flow, which the gate handles on their own).

func (*GateRun) PairTurn

func (g *GateRun) PairTurn(st *state.State) (why string, need int)

PairTurn decides a paired merge at its lane turn: why is what it waits for, "" when it starts; need is the merge.cap and merge.sessionCap slots its start takes: two for the first of the pair, none for its sibling, whose slot the first took. An unpaired merge needs one.

func (*GateRun) PreemptChild

func (g *GateRun) PreemptChild() (state.Hold, bool)

PreemptChild ends the running merge's devctl when a hold preempts it.

func (*GateRun) ReadRelease

func (g *GateRun) ReadRelease() (string, error)

ReadRelease reads the pull request's release tree once before merging. Commit reads bypass the branch cache because the PR may change workflows. A post-merge refresh reads the tree that actually landed.

func (*GateRun) ReadRetrying

func (g *GateRun) ReadRetrying(what string, read func() error) error

ReadRetrying runs read, the gate's read of what (the GitHub budget, an installation's HelmReleases, a pull request), again after each ReadBackoff pause while it fails in transit (merge.Transient), a line per retry. Any other failure returns at once. The error after the last try names the last failure and the tries.

func (*GateRun) Record

func (g *GateRun) Record(base string, run ChildRun) error

Record records the run's outcome: a merge settles its lane, one that warranted no release or whose lane has no installation to roll leaves it once its release is known, and so does one with nothing merged. A run without its document or ended by a signal is GitHub's to judge: merged, its release is recovered with release wait; unanswered, the lane settles by the settle rule as for a lost merge. The run's files go with the record; a save the newer release that wrote the state refuses leaves them, document and exit code, for the watch, which records the run from them at its next poll.

func (*GateRun) Reexec

func (g *GateRun) Reexec(when string, env ...string)

Reexec replaces this process with the binary installed at its path, with env for the new one, and says so; it returns only when the new binary does not start, and the call carries on under this one.

func (*GateRun) Refuse

func (g *GateRun) Refuse(format string, args ...any) error

Refuse removes the merge from its queue, logs the refusal and refuses it.

func (*GateRun) RefuseRunningWith

func (g *GateRun) RefuseRunningWith(code int, format string, args ...any) error

RefuseRunningWith is refuseRunning with exit code code.

func (*GateRun) RefuseWith

func (g *GateRun) RefuseWith(code int, format string, args ...any) error

RefuseWith is refuse with exit code code.

func (*GateRun) ReloadQueueConfig

func (g *GateRun) ReloadQueueConfig() error

ReloadQueueConfig lets waiting gates observe edits without replacing the binary. An incomplete edit keeps the last valid settings until the next poll.

func (*GateRun) Requeue

func (g *GateRun) Requeue(base string, h state.Hold) error

Requeue puts a preempted merge back to waiting in its place, unless GitHub reports it merged all the same (devctl merged before it ended), or does not answer: then its run is recorded as any other.

func (*GateRun) ResumeMerge

func (g *GateRun) ResumeMerge(running string) error

ResumeMerge carries a running merge on after the re-exec of a replaced binary: running names its merge-child and how far its stderr was copied (GateRunningEnv). The merge keeps its place, its devctl runs on, and this release follows and records it; a merge the state no longer runs is followed to its end all the same, its outcome the caller's.

func (*GateRun) ReviewHold

func (g *GateRun) ReviewHold() (string, error)

ReviewHold reads the pull request's reviews and comments afresh (github.ReviewGuard): the reason a reviewer holds its merge, "" when none does. devctl pr merge's own guard drops a request for changes once a commit or a reply is newer, so the gate reads before devctl runs.

func (*GateRun) RunMerge

func (g *GateRun) RunMerge() error

RunMerge runs devctl once, detached from its caller (LaunchChild), its document and exit code unchanged, and follows it to its end (follow). A run that does not start is recorded as one without a document.

func (*GateRun) RunsDevctl

func (g *GateRun) RunsDevctl() bool

RunsDevctl says whether the gated command runs devctl: a promotion, or a merge of a repository devctl serves; any other merge takes the plain squash merge.

func (*GateRun) SessionWaitFor

func (g *GateRun) SessionWaitFor(st *state.State, need int) string

SessionWaitFor is sessionWait for a start that takes need of the party's slots (capWaitFor): a pair's first keeps one free for its sibling.

func (*GateRun) StaleRefused

func (g *GateRun) StaleRefused(stale *state.StaleWriterError) error

StaleRefused refuses the call whose save the newer release that wrote the state refused and that could not re-execute: nothing ran, the lane is untouched, and the installed beekeeper gates the same command again.

func (*GateRun) Start

func (g *GateRun) Start(settling string, hrs []merge.HelmRelease) (string, error)

Start makes the merge the lane's running one, when it still is first, its lane's settling merges are the ones it checked, the machine runs fewer than merge.cap devctl merges and promotes and its party may start one more (sessionWait), and runs devctl.

func (*GateRun) Started

func (g *GateRun) Started(pid int)

Started records the merge's devctl, which runs on when the gate is gone.

func (*GateRun) Step

func (g *GateRun) Step() (string, error)

Step joins or refreshes the merge's queue entry and starts devctl when it is the merge's turn. It returns what the merge waits for, or "" and the run's outcome once devctl ran or the merge was refused.

func (*GateRun) Takeover

func (g *GateRun) Takeover() (bool, error)

Takeover checks GitHub before trusting a duplicate's running place. Reads happen outside the lock; the exact owner and phase are checked again when claiming it so concurrent retries cannot both take it over.

func (*GateRun) ToolMerge

func (g *GateRun) ToolMerge() bool

ToolMerge says whether the gate merges or promotes the merge tool's own repository, which opens the tool-release window.

func (*GateRun) WarmUp

func (g *GateRun) WarmUp(ctx context.Context)

WarmUp waits for the existing head's CI within the configured timeout. It never updates the branch; the merge judges the wait's outcome.

type Host

type Host interface {
	As() string
	CallCentralRaw(ctx context.Context, me state.Party, tool string, args map[string]any, v any) (string, error)
	Cfg() *config.Config
	CfgPath() string
	CheckPlaces(ctx context.Context, by state.Party, now time.Time, lane string, repo string, pr int, every time.Duration) error
	CheckRepositoryVisibility(ctx context.Context, repo string) error
	CloseToolWindow(ctx context.Context, by state.Party)
	ExplicitConfig() string
	FatalPublicationBarrier(ctx context.Context, st *state.State, repo string, pr int) error
	InstallTool(ctx context.Context, by state.Party, verb string, what string) error
	LeaveCentral(ctx context.Context, merges []state.Merge, why string)
	LoadedCfg() string
	MergeEvents(evs []state.Event) ([]state.Event, error)
	Now() time.Time
	PollToolWindow(ctx context.Context, by state.Party)
	Present(m state.Merge) bool
	RecordGone(ctx context.Context) ([]string, []string, []state.Merge)
	SetCfg(v *config.Config)
	SetNow(v time.Time)
	Store() state.Store
	TeleportCause(ctx context.Context) string
}

Host is the command the gate runs in: its configuration, state, clock and output, and the command's own steps. The command's app is the one implementation.

type LaneTurn

type LaneTurn struct {
	Lane     string   `json:"lane"`
	Merge    string   `json:"merge"`
	Phase    string   `json:"phase"`
	Position int      `json:"position"`
	Turn     bool     `json:"turn"`
	Ahead    []string `json:"ahead"`
}

LaneTurn is where a merge stands in its lane.

type PreemptedError

type PreemptedError struct{ Why string }

PreemptedError ends a merge's run that a hold took back out of its lane before devctl merged: the merge waits on in its place, why says for what.

func (*PreemptedError) Error

func (e *PreemptedError) Error() string

type RunInfo

type RunInfo struct {
	Command        string      `json:"command"`
	Owner          state.Party `json:"owner,omitzero"`
	Gate           int         `json:"gate,omitempty"`
	Started        time.Time   `json:"started"`
	ProcessStarted time.Time   `json:"processStarted,omitzero"`
}

RunInfo is what gate runs shows of a detached run: the command (never its environment, which carries tokens), its owner, its gate and its start.

func ReadRunInfo

func ReadRunInfo(base string) (RunInfo, bool)

ReadRunInfo reads what the run at base left for gate runs, false when it left nothing (a run started by an older release).

type RunOutcome

type RunOutcome struct {
	Out        merge.Outcome
	Rc         int
	Reason     string
	Unanswered error
	// confirming marks a merge whose release its gate confirms after the
	// merge (GateRun.overlaps): the verdict follows as merge.release.
	Confirming bool
}

RunOutcome is how one merge's devctl run ended: its outcome, its exit code, its reason (runReason), and GitHub's error when nothing could judge it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL