runner: keep export handoffs nonterminal through recovery

This commit is contained in:
2026-10-20 21:19:26 +01:00
parent ca78b24f47
commit ec3eda9e05
28 changed files with 370 additions and 82 deletions
+5 -5
View File
@@ -1461,16 +1461,16 @@ func (a App) wait(ctx context.Context, pos []string, o *options, call callFunc)
return nil
}
// awaitRuns polls every run that active reports as unfinished until each is
// terminal, using the same GetRun reattachment the run --wait path uses, and
// calls onTerminal for each as it finishes (including runs already terminal at
// awaitRuns polls unfinished runs using GetRun reattachment. Export waits remain
// unfinished even for run --wait, whose status-only predicate intentionally stops
// at human decisions. It calls onTerminal for each as it finishes (including runs already terminal at
// entry, in the order supplied). A deadline that passes first returns a
// *waitLimitError naming the runs still active; ctx ending first returns
// ctx.Err(). It never cancels, retries or otherwise changes a run.
func (a App) awaitRuns(ctx context.Context, runs []protocol.Message, deadline <-chan time.Time, call callFunc, active func(string) bool, onTerminal func(protocol.Message) error) error {
remaining := make([]protocol.Message, 0, len(runs))
for _, r := range runs {
if active(r.RunDetail.Status) {
if active(r.RunDetail.Status) || (r.RunDetail.Status == protocol.RunStatusWaiting && r.RunDetail.ExportPendingSequence > 0) {
remaining = append(remaining, r)
continue
}
@@ -1495,7 +1495,7 @@ func (a App) awaitRuns(ctx context.Context, runs []protocol.Message, deadline <-
if refreshed.RunDetail == nil {
return fmt.Errorf("server did not return run detail for %d", r.RunDetail.ID)
}
if active(refreshed.RunDetail.Status) {
if active(refreshed.RunDetail.Status) || (refreshed.RunDetail.Status == protocol.RunStatusWaiting && refreshed.RunDetail.ExportPendingSequence > 0) {
next = append(next, refreshed)
continue
}
+40
View File
@@ -0,0 +1,40 @@
package cli
import (
"context"
"testing"
"time"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func TestRunAndExplicitWaitDoNotReturnDuringExportRecovery(t *testing.T) {
for _, mode := range []string{"run --wait", "wait"} {
t.Run(mode, func(t *testing.T) {
active := runInProgress
if mode == "wait" {
active = runUnfinished
}
initial := protocol.Message{RunDetail: &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 7, Status: protocol.RunStatusWaiting, ExportPendingSequence: 2}}}
polls, finished := 0, false
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
err := (App{}).awaitRuns(ctx, []protocol.Message{initial}, nil, func(request protocol.Message) (protocol.Message, error) {
polls++
if request.Type != protocol.GetRun || request.RunID != 7 {
t.Errorf("unexpected request: %+v", request)
}
return protocol.Message{RunDetail: &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 7, Status: "succeeded"}}}, nil
}, active, func(message protocol.Message) error {
if message.RunDetail.Status != "succeeded" {
t.Errorf("wait returned before actual terminal: %+v", message.RunDetail)
}
finished = true
return nil
})
if err != nil || polls != 1 || !finished {
t.Fatalf("export wait ended early: polls=%d finished=%v error=%v", polls, finished, err)
}
})
}
}