Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

Phase 4: a new tip cancels the old build, and the lease serves the quiet repo

760b523a7dbb6fc1c1210a16bf44232a7c592b1b · Keenan Nemetz · 17d ago · parent 34afc569

Phase 4: a new tip cancels the old build, and the lease serves the quiet repo

Two ways a single repository could monopolise the instance's runner pool. A push
series queued a build per commit, so ten pushes in a minute ran ten builds of nine
dead commits — `StatusCanceled` existed, the gate knew how to report it, and nothing
ever wrote it. And the lease ordered by age across every eligible repository, so the
oldest job won wherever it lived: one busy repository's queue was served before a
quiet repository's, no matter how many runners were busy with the first.

Cancellation is now decided where the workflow's own trigger is decided: a push that
owes at least one run retires the *queued* runs of that repo+ref whose sha it
replaces, and nothing else — a running job is never interrupted, since a build
canceled mid-flight is a different promise from one nobody started, and a push that
queues nothing (no matching workflow) cancels nothing. The count is logged, because a
run that stops for no findable reason reads exactly like a run that vanished.

The lease orders by in-flight count per repository first and age within a repository
second, which needs no new config key and no operator tuning: the burst still runs,
it just cannot occupy every runner while another repository waits.

Measured: TestCancelSupersededOnlyTouchesWaitingRunsOfTheSameRef (1 canceled, another
ref untouched, the running job still running), TestLeaseServesTheLeastBusyRepoFirst
(the busy repository's older second job is passed over for the quiet repository), and
TestANewerTipCancelsTheQueuedBuildOfTheOlderOne end to end through the reconciler.

Canceled runs are queue state, not history — they never happened, so they have no
record and `vole index rebuild` drops them rather than inventing one.

internal/server/ci.go +27−8

@@ -98,6 +98,10 @@ func (s *Server) enqueue(ev runs.Event) {
98 98 s.Log.Warn("ci: workflows in a pushed commit do not validate", "repo", ev.Repo, "problems", len(problems))
99 99 return
100 100 }
101 // What this push owes: one run per job of every workflow that applies to it. The
102 // list is built before anything is queued, because a push that owes nothing must
103 // not cancel the previous tip's builds.
104 var owing []runs.Run
101 105 for _, wf := range wfs {
102 106 switch {
103 107 case branch != "" && !wf.Applies(branch):
@@ -123,14 +127,29 @@ func (s *Server) enqueue(ev runs.Event) {
123 127 Created: time.Now().UTC(),
124 128 }
125 129 run.ID, _ = id.New(time.Now())
126 created, err := s.Runs.Enqueue(run)
127 if err != nil {
128 s.Log.Warn("ci: cannot queue a run", "repo", ev.Repo, "job", job.ID, "err", err)
129 continue
130 }
131 if created {
132 s.Log.Info("ci: queued", "repo", ev.Repo, "job", job.ID, "sha", commit[:8], "run", run.ID)
133 }
130 owing = append(owing, run)
131 }
132 }
133 if len(owing) == 0 {
134 return
135 }
136 // A newer tip supersedes the queued builds of the older one: pushing twice in a
137 // minute must not build the first commit twice. Running jobs are left alone, and
138 // the cancellation is logged because a run that stopped for a reason nobody can
139 // find is the same as a run that vanished.
140 if n, err := s.Runs.CancelSuperseded(ev.Repo, ev.Ref, commit, time.Now().UTC()); err != nil {
141 s.Log.Warn("ci: cannot cancel superseded runs", "repo", ev.Repo, "ref", ev.Ref, "err", err)
142 } else if n > 0 {
143 s.Log.Info("ci: canceled superseded runs", "repo", ev.Repo, "ref", ev.Ref, "runs", n)
144 }
145 for _, run := range owing {
146 created, err := s.Runs.Enqueue(run)
147 if err != nil {
148 s.Log.Warn("ci: cannot queue a run", "repo", ev.Repo, "job", run.Job, "err", err)
149 continue
150 }
151 if created {
152 s.Log.Info("ci: queued", "repo", ev.Repo, "job", run.Job, "sha", commit[:8], "run", run.ID)
134 153 }
135 154 }
136 155 }