Harden prepare and transcribe transitions

This commit is contained in:
2026-08-10 21:53:54 +00:00
parent 9da2c1e144
commit 702f622e18
8 changed files with 165 additions and 22 deletions

View File

@@ -112,6 +112,7 @@ func (transcribeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest)
jobCh = make(chan job)
mu sync.Mutex
firstErr error
completed int
perFile = map[string]map[string]any{}
outputRef = map[string]artifacts.Ref{}
)
@@ -175,6 +176,7 @@ func (transcribeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest)
SessionID: sessionID,
AbsolutePath: j.outPath,
}
completed++
mu.Unlock()
}
}
@@ -184,12 +186,14 @@ func (transcribeStage) Run(ctx context.Context, env *Env, m *manifest.Manifest)
go worker()
}
dispatched := 0
dispatch:
for _, j := range jobs {
select {
case <-stageCtx.Done():
break dispatch
case jobCh <- j:
dispatched++
}
}
close(jobCh)
@@ -198,6 +202,12 @@ dispatch:
if firstErr != nil {
return nil, firstErr
}
if err := ctx.Err(); err != nil {
return nil, fmt.Errorf("transcribe: canceled after dispatching %d of %d audio jobs and completing %d: %w", dispatched, len(jobs), completed, err)
}
if completed != len(jobs) {
return nil, fmt.Errorf("transcribe: completed %d of %d planned audio jobs after dispatching %d", completed, len(jobs), dispatched)
}
speakers := make([]string, 0, len(perFile))
for speaker := range perFile {