@@ -63,17 +63,22 @@ func preflightValidate(ctx context.Context, w *databricks.WorkspaceClient, cfg *
6363 return err
6464}
6565
66- // validateConfig performs the current backend validation without client-side
67- // availability fallbacks. The legacy response reports field errors only; it
68- // cannot yet distinguish complete success from skipped backend dependencies.
66+ // validateConfig performs backend validation without submission's fail-open
67+ // behavior. One exact old-backend parse error triggers a legacy-body retry.
6968func validateConfig (ctx context.Context , w * databricks.WorkspaceClient , cfg * runConfig , commandPath string , containers []submittedContainer , idempotencyToken string ) error {
7069 apiClient , err := client .New (w .Config )
7170 if err != nil {
7271 return fmt .Errorf ("failed to create API client: %w" , err )
7372 }
7473
74+ request := validateConfigRequest (ctx , cfg , commandPath , containers , idempotencyToken )
7575 var resp validateConfigResponse
76- err = apiClient .Do (ctx , http .MethodPost , validateConfigPath , auth .WorkspaceIDHeaders (w .Config ), nil , validateConfigRequest (cfg , commandPath , containers , idempotencyToken ), & resp )
76+ err = apiClient .Do (ctx , http .MethodPost , validateConfigPath , auth .WorkspaceIDHeaders (w .Config ), nil , request , & resp )
77+ if rejectsValidateConfigEnvironment (err ) {
78+ delete (request , "environment" )
79+ resp = validateConfigResponse {}
80+ err = apiClient .Do (ctx , http .MethodPost , validateConfigPath , auth .WorkspaceIDHeaders (w .Config ), nil , request , & resp )
81+ }
7782 if err != nil {
7883 validationErr := fmt .Errorf ("failed to validate config: %w" , err )
7984 if unavailable , retryable := classifyValidationFailure (err ); unavailable {
@@ -87,6 +92,18 @@ func validateConfig(ctx context.Context, w *databricks.WorkspaceClient, cfg *run
8792 return errors .New (formatConfigErrors (resp .Errors ))
8893}
8994
95+ const unsupportedEnvironmentMessage = "Cannot find field: environment in message databricks.aicomputemanager.ValidateConfigRequest"
96+
97+ // rejectsValidateConfigEnvironment identifies the one old-backend response for
98+ // which retrying without the additive environment field is safe.
99+ func rejectsValidateConfigEnvironment (err error ) bool {
100+ apiErr , ok := errors.AsType [* apierr.APIError ](err )
101+ return ok &&
102+ apiErr .StatusCode == http .StatusBadRequest &&
103+ apiErr .ErrorCode == "MALFORMED_REQUEST" &&
104+ apiErr .Message == unsupportedEnvironmentMessage
105+ }
106+
90107// classifyValidationFailure separates service failures from caller errors and
91108// reports whether retrying the same request may succeed.
92109func classifyValidationFailure (err error ) (unavailable , retryable bool ) {
@@ -113,11 +130,11 @@ func classifyValidationFailure(err error) (unavailable, retryable bool) {
113130 return false , false
114131}
115132
116- // validateConfigRequest builds the {task, run_options} body from the user's config. commandPath is
133+ // validateConfigRequest builds the {task, run_options, environment } body from the user's config. commandPath is
117134// the workspace path where the command script will be uploaded; the caller computes it before this
118135// call so the server can validate the real path. `parameters` is intentionally omitted: it is
119136// free-form nested hyperparameters uploaded as a YAML file at submit, not the proto's string map.
120- func validateConfigRequest (cfg * runConfig , commandPath string , containers []submittedContainer , idempotencyToken string ) map [string ]any {
137+ func validateConfigRequest (ctx context. Context , cfg * runConfig , commandPath string , containers []submittedContainer , idempotencyToken string ) map [string ]any {
121138 compute := map [string ]any {}
122139 if cfg .Compute != nil {
123140 compute ["accelerator_type" ] = cfg .Compute .AcceleratorType
@@ -156,10 +173,13 @@ func validateConfigRequest(cfg *runConfig, commandPath string, containers []subm
156173 if image := cfg .unityCatalogImagePath (); image != "" {
157174 task ["unity_catalog_image_path" ] = image
158175 }
176+ runtimeVersion , _ := cfg .runtimeVersion ()
177+ dependencies , _ := cfg .inlineDependencies ()
159178
160179 return map [string ]any {
161180 "task" : task ,
162181 "run_options" : validateConfigRunOptions (cfg , idempotencyToken ),
182+ "environment" : buildRunEnvironment (dlRuntimeImage (ctx , runtimeVersion ), dependencies ),
163183 }
164184}
165185
0 commit comments