Unify structured call completion and retain typed failures
This commit is contained in:
@@ -5,7 +5,6 @@ package proposal_generation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -129,15 +128,9 @@ func GenerateCandidates(ctx context.Context, req Request) (Result, error) {
|
||||
}
|
||||
|
||||
if callErr != nil {
|
||||
var failure *structuredoutput.Failure
|
||||
if errors.As(callErr, &failure) {
|
||||
operation.FailureReason = failure.Reason
|
||||
}
|
||||
if operation.FailureReason == "" {
|
||||
operation.FailureReason = outcomes.ReasonInternalFailure
|
||||
}
|
||||
structuredoutput.RecordFailure(&operation, callErr)
|
||||
result := Result{Operations: []outcomes.Operation{operation}, Artifacts: artifacts}
|
||||
if structuredoutput.IsRecoverable(callErr) && failure != nil && failure.Reason != "" {
|
||||
if operation.FailureClass == outcomes.FailureRecoverable {
|
||||
return result, nil
|
||||
}
|
||||
return result, fmt.Errorf("proposal generation completion failed: %w", callErr)
|
||||
|
||||
@@ -226,6 +226,20 @@ func TestGenerateCandidatesMalformedStructuredOutputReturnsFailedOperation(t *te
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateCandidatesUsesInternalReasonForUnspecifiedRecoverableFailure(t *testing.T) {
|
||||
cause := errors.New("underlying call failure")
|
||||
req := defaultRequest(t)
|
||||
req.LLMClient = &fakeStructuredClient{err: &structuredoutput.Failure{Class: outcomes.FailureRecoverable, Cause: cause}}
|
||||
result, err := GenerateCandidates(context.Background(), req)
|
||||
if err != nil || len(result.Operations) != 1 {
|
||||
t.Fatalf("recoverable proposal returned operations=%+v error=%v", result.Operations, err)
|
||||
}
|
||||
operation := result.Operations[0]
|
||||
if operation.FailureClass != outcomes.FailureRecoverable || operation.FailureReason != outcomes.ReasonInternalFailure || !errors.Is(operation.Cause, cause) {
|
||||
t.Fatalf("operation lost typed failure facts: %+v", operation)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateCandidatesFatalSetupPreservesCallFacts(t *testing.T) {
|
||||
client := &fakeStructuredClient{err: &structuredoutput.Failure{Class: structuredoutput.FailureFatal, Reason: outcomes.ReasonSetupFailure, Message: "structured model setup failed", Cause: errors.New("broken prompt")}, completion: structuredoutput.Response{Execution: outcomes.ExecutionCounts{Available: true, ProviderAttempts: 0}}}
|
||||
req := defaultRequest(t)
|
||||
|
||||
Reference in New Issue
Block a user