Sign in

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

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

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

Self-hosted forge that lives in your Git repo.

Retire the queued runs of an event a newer one replaced

8ca8bbe04848a350f514eb956f70951b701bcd9c · Keenan Nemetz · 10d ago · parent 3031e357

Retire the queued runs of an event a newer one replaced

Opening a change request and then updating it queued two full sets of the
workflow's jobs for the same base commit. Neither superseded the other: the
occurrence is what makes event runs distinct, and CancelSuperseded only looks
at pushes. On a single-slot runner the newer event waited behind the older
event's identical work, and every edit added another set.

A run now records the subject of the event that queued it: a change-request
ID, an issue ID, or an entity and comment pair. When an event's batch is
queued, the queued runs of an older event for the same repository, trigger,
and subject are canceled. The batch's own occurrences are kept, so an edited
and an assigned action from one push do not cancel each other. Only queued
rows are touched: a handler that has started finishes, because it is already
acting on the event it received. Schedules and dispatches have no subject and
are unchanged.

The query needs no ref: the subject is a globally unique entity ID, so a base
branch that moved does not keep the older set alive, and another change
request's queue on the same branch is untouched.

Verified with go test ./server/, the store tests, and vole workflow run verify.

server/events_test.go +56

@@ -107,6 +107,62 @@ jobs:
107 107 }
108 108 }
109 109
110 // A newer event for the same change retires the queued runs of the event it replaced.
111 // The jobs are the same work on the same base commit, so leaving both sets queued is
112 // pure queue delay.
113 func TestANewerChangeRequestEventCancelsTheOlderQueuedSet(t *testing.T) {
114 t.Parallel()
115 f := newFixture(t)
116 f.publish(f.repo)
117 main := workRepo(t, workflowFile(`version: 1
118 on:
119 change-request:
120 jobs:
121 describe:
122 image: alpine:3.22
123 steps:
124 - run: echo "$VOLE_EVENT_ACTION"
125 `))
126 if _, errs, err := f.git(main, "push", f.sshURL(f.repo), "main:refs/heads/main"); err != nil {
127 t.Fatalf("push main: %s", errs)
128 }
129 feature, _ := f.cloneWithChange(t, map[string]string{"feature.txt": "a change\n"}, "feature")
130 if _, errs, err := f.git(feature, "push", f.sshURL(f.repo), "HEAD:refs/heads/feature"); err != nil {
131 t.Fatalf("push feature: %s", errs)
132 }
133 other, _ := f.cloneWithChange(t, map[string]string{"other.txt": "another change\n"}, "other")
134 if _, errs, err := f.git(other, "push", f.sshURL(f.repo), "HEAD:refs/heads/other"); err != nil {
135 t.Fatalf("push other: %s", errs)
136 }
137 out, errs, err := f.cli(feature, "change", "new", "--title", "A feature", "--base", "main", "--head", "feature", "-m", "body")
138 if err != nil {
139 t.Fatalf("change new: %v\n%s", err, errs)
140 }
141 changeID := strings.Fields(out)[0]
142 opened := f.waitForRun(t, 5*time.Second, func(r *runs.Run) bool {
143 return r.Trigger == "change_request" && r.TriggerAction == "opened"
144 })
145
146 // Moving the request to another head fires an updated event for the same change and
147 // the same base commit, while the opened event's job is still waiting.
148 if _, errs, err := f.cli(feature, "change", "update", changeID, "--head", "other"); err != nil {
149 t.Fatalf("change update: %v\n%s", err, errs)
150 }
151 updated := f.waitForRun(t, 5*time.Second, func(r *runs.Run) bool {
152 return r.Trigger == "change_request" && r.TriggerAction == "updated"
153 })
154 if updated.SHA != opened.SHA {
155 t.Fatalf("the updated event moved to %s, want the same base commit %s", updated.SHA, opened.SHA)
156 }
157 got, err := f.srv.Runs.Get(opened.ID)
158 if err != nil {
159 t.Fatal(err)
160 }
161 if got.Status != runs.StatusCanceled {
162 t.Fatalf("the superseded event run is %q, want %q", got.Status, runs.StatusCanceled)
163 }
164 }
165
110 166 func TestWorkflowDispatchCarriesInputs(t *testing.T) {
111 167 t.Parallel()
112 168 f := newFixture(t)