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
+17 -4
View File
@@ -18,8 +18,12 @@ func TestSessionExportGateCheckpointAndSuccessorAreAtomic(t *testing.T) {
if err := s.BeginStep(ctx, id, 2, "two", nil); err == nil {
t.Fatal("successor started while export was incomplete")
}
if err := s.FinishRun(ctx, id, "failed", "error", "export gate", step.Output); err != nil {
t.Fatal(err)
paused, err := s.GetRun(ctx, id)
if err != nil || paused.Status != "waiting" || paused.ExportPendingSequence != 1 || paused.FinishedAt != "" {
t.Fatalf("gate became terminal: %+v %v", paused, err)
}
if _, _, err := s.ResolveDecision(ctx, id, "one", "success", ""); err == nil {
t.Fatal("model export wait accepted human decision")
}
job, _ := s.SessionExportJob(ctx, id, 1)
claimed, err := s.ClaimSessionExportJob(ctx, time.UnixMilli(job.NextAt), time.Minute)
@@ -40,8 +44,17 @@ func TestSessionExportGateCheckpointAndSuccessorAreAtomic(t *testing.T) {
}
// A crash after reserving the continuation but before starting its next
// executor must retain the checkpoint for startup's interrupted run.
if _, err := s.db.Exec(`UPDATE pipeline_runs SET status='interrupted' WHERE id=?`, id); err != nil {
t.Fatal(err)
for _, prior := range []string{"failed", "interrupted", "running", "queued"} {
if _, err := s.db.Exec(`UPDATE pipeline_runs SET status=?,finished_at=CURRENT_TIMESTAMP WHERE id=?`, prior, id); err != nil {
t.Fatal(err)
}
if err := s.RecoverRuns(ctx); err != nil {
t.Fatal(err)
}
recovered, err := s.GetRun(ctx, id)
if err != nil || recovered.Status != "waiting" || recovered.ExportPendingSequence != 1 || recovered.FinishedAt != "" {
t.Fatalf("restart exposed a terminal export wait from %s: %+v %v", prior, recovered, err)
}
}
ready, err := s.ReadySessionExportGates(ctx)
if err != nil || ready[id] != 1 {