package runner import ( "context" "errors" "amadan.net/oficina/equipo/internal/equipo/team" "amadan.net/oficina/equipo/internal/runner/provider" ) func infrastructureOnly(err error, r *attemptState) bool { if joined, ok := err.(interface{ Unwrap() []error }); ok { for _, cause := range joined.Unwrap() { if !infrastructureOnly(cause, r) { return false } } return true } if wrapped, ok := err.(interface{ Unwrap() error }); ok { return infrastructureOnly(wrapped.Unwrap(), r) } switch err { case context.Canceled, context.DeadlineExceeded: return r.ServiceInterrupted case ErrTransient: return true case provider.ErrClosed: switch r.Phase { case "claimed", "creating-workspace", "workspace": return true } } return false } func attemptFailureReason(err error) string { var refusal *RefusalError if errors.As(err, &refusal) { return refusal.Reason } for _, item := range []struct { err error reason string }{ {provider.ErrAccountMismatch, "account_mismatch"}, {ErrPromptTooLarge, "runner.prompt_too_large"}, {team.ErrEvidence, "runner.evidence"}, {team.ErrBudget, "runner.budget"}, {team.ErrQuota, "runner.quota"}, {team.ErrReplayUnsafe, "runner.replay"}, } { if errors.Is(err, item.err) { return item.reason } } if joined, ok := err.(interface{ Unwrap() []error }); ok { for _, cause := range joined.Unwrap() { if !errors.Is(cause, context.Canceled) && !errors.Is(cause, context.DeadlineExceeded) { return attemptFailureReason(cause) } } causes := joined.Unwrap() if len(causes) > 0 { return attemptFailureReason(causes[0]) } } reason, _ := Diagnostic(err) return reason }