batchstore: surface backend errors from Submit as failed job status

executeJob was only capturing 'assistant' events from core.Submit.
Backend errors emit an 'error' event that was silently dropped,
causing jobs with nonexistent models to show status=done with empty
result instead of status=failed.
This commit is contained in:
Levi Neely 2026-04-16 20:46:45 +02:00
parent 9a51d287f7
commit 181e629009
1 changed files with 8 additions and 2 deletions

View File

@ -288,10 +288,13 @@ func (s *BatchStore) executeJob(ctx context.Context, job *batchJob) (string, err
prompt += "\n\nRespond with valid JSON only, no prose."
}
var replyBuf strings.Builder
var replyBuf, errBuf strings.Builder
core.Submit(ctx, prompt, func(ev agent.Event) {
if ev.Role == "assistant" {
switch ev.Role {
case "assistant":
replyBuf.WriteString(ev.Content)
case "error":
errBuf.WriteString(ev.Content)
}
})
@ -306,6 +309,9 @@ func (s *BatchStore) executeJob(ctx context.Context, job *batchJob) (string, err
if ctx.Err() != nil {
return "", ctx.Err()
}
if errBuf.Len() > 0 {
return "", fmt.Errorf("%s", strings.TrimSpace(errBuf.String()))
}
return replyBuf.String(), nil
}