Propagate cancellation and preserve resumable state

This commit is contained in:
2026-11-20 05:53:49 +00:00
parent a6c6f1e4ab
commit c7a5ff316d
21 changed files with 356 additions and 27 deletions

View File

@@ -46,6 +46,9 @@ type analyzeExecutionContext struct {
}
func (analyzeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*StageResult, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
if env == nil || env.Config == nil {
return nil, fmt.Errorf("analyze: stage environment config is required")
}
@@ -138,6 +141,9 @@ func (analyzeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
}
for _, item := range workPlan.ExecutionOrder {
if err := ctx.Err(); err != nil {
return nil, err
}
artifactCfg := env.Config.ConcreteArtifacts()[item.Key]
fingerprint, _, _, err := computeAnalyzeArtifactFingerprint(
item.Key,

View File

@@ -3,6 +3,7 @@ package stage
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
@@ -86,6 +87,9 @@ func (transcribeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest)
group, groupCtx := errgroup.WithContext(ctx)
group.SetLimit(concurrency)
for _, job := range jobs {
if groupCtx.Err() != nil {
break
}
job := job
group.Go(func() error {
if err := groupCtx.Err(); err != nil {
@@ -116,13 +120,10 @@ func (transcribeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest)
return nil
})
}
groupErr := group.Wait()
if err := state.checkpointFailure(); err != nil {
return nil, err
}
groupErr := errors.Join(group.Wait(), state.checkpointFailure())
completedCount := state.completedCount()
if err := ctx.Err(); err != nil {
return nil, fmt.Errorf("transcribe: canceled after completing %d of %d audio jobs: %w", completedCount, len(jobs), err)
return nil, errors.Join(fmt.Errorf("transcribe: canceled after completing %d of %d audio jobs: %w", completedCount, len(jobs), err), groupErr)
}
if groupErr != nil {
return nil, groupErr