Skip to content

Write the deploy's error class to a result file for auto-deploy - #7856

Open
atreyadbrx wants to merge 3 commits into
mainfrom
dabs-ad-d3-result-file
Open

atreyadbrx wants to merge 3 commits into
mainfrom
dabs-ad-d3-result-file

Conversation

@atreyadbrx

@atreyadbrx atreyadbrx commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Changes

When DATABRICKS_AUTO_DEPLOY_RESULT_FILE is set, bundle deploy writes a JSON file on every exit:

  • {} on success;
  • {"error_class": "SERVICE"} when the first error logged is an API error with status 5xx, 429 or 408, or the CLI panicked;
  • {"error_class": "USER"} for any other failure, network errors included.

A deferred function in ProcessBundleRet writes it; only bundle deploy turns it on (ProcessOptions.WriteDeployResult), because other deploying commands keep working after ProcessBundle returns. On a panic it writes SERVICE and re-panics. To classify an error after it's rendered, diag.FromErr now keeps it as Diagnostic.Cause, and logdiag remembers the first error's cause next to its summary. A failed write logs a warning and doesn't change the exit code. Without the variable nothing changes.

Why

The DABs auto-deploy runner runs bundle deploy and reports failures to the customer. Today it treats every CLI failure as the customer's, so platform failures are blamed on customers and don't reach our alerts. The runner sets this variable and will use error_class to tell the two apart. When the CLI can't tell, it reports USER, so the customer still sees the error.

A file rather than -o json leaves deploy's output unchanged and covers every exit path. There's no changelog entry: the variable is an interface for the runner, not for users.

Tests

  • Unit: the classifier, a panic reported as SERVICE, and logdiag keeping the first error's cause.
  • Acceptance bundle/deploy/result-file: a deploy that succeeds ({}), a job create that keeps returning 500 (SERVICE), a reference to an undefined variable (USER), and bundle validate (no file).
  • Two cmd/root tests compared whole diagnostics; they now check severity and summary. load_dbalert_files.go lists every Diagnostic field for exhaustruct, so it sets Cause too.

This pull request and its description were written by Isaac.

@github-actions github-actions Bot added the DABs DABs related issues label Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Commit: 4e0055a2b | Workflow run

Regression test report

Selected 1 changed tests (limit=20, 0 not selected)

2 tests: regression=2 unreleased=0 coverage=0 failing=0
test branch main (c639f9d) latest (v1.28.0)
TestAccept/bundle/deploy/result-file/DMS= ✅ ❌ ❌
TestAccept/bundle/deploy/result-file/DMS=true ✅ ❌ ❌
TestAccept/bundle/deploy/result-file/DMS=: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌

main (c639f9d):

acceptance_test.go:1402: Diff:
        --- bundle/deploy/result-file/output.txt
        +++ /tmp/TestAcceptbundledeployresult-fileDMS=975064445/002/output.txt
        @@ -8,33 +8,6 @@
         Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
         
         >>> jq -c . result.json
        -{}
        +jq: error: Could not open file result.json: No such file or directory
         
        -=== A deploy that fails because the service does is SERVICE
        -
        ->>> musterr [CLI] bundle deploy -t outage
        -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/result-file/outage/files...
        -Error: cannot create resources.jobs.foo: Fault injected by test. (500 INTERNAL_ERROR)
        -
        -Endpoint: POST [DATABRICKS_URL]/api/2.2/jobs/create
        -HTTP Status: 500 Internal Server Error
        -API error_code: INTERNAL_ERROR
        -API message: Fault injected by test.
        -
        -Files: 2 uploaded, 0 deleted
        -
        ->>> jq -c . result.json
        -{"error_class":"SERVICE"}
        -
        -=== A deploy that fails because of the bundle is USER
        -
        ->>> musterr [CLI] bundle deploy -t broken
        -Error: reference does not exist: ${var.missing}
        -
        -
        ->>> jq -c . result.json
        -{"error_class":"USER"}
        -
        -=== bundle validate does not write the file
        -
        ->>> assert_not_exists.py result.json
        +Exit code: 2

latest (v1.28.0): same output as main (c639f9d)

TestAccept/bundle/deploy/result-file/DMS=true: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌

main (c639f9d):

acceptance_test.go:1402: Diff:
        --- bundle/deploy/result-file/output.txt
        +++ /tmp/TestAcceptbundledeployresult-fileDMS=true3772225443/002/output.txt
        @@ -8,33 +8,6 @@
         Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
         
         >>> jq -c . result.json
        -{}
        +jq: error: Could not open file result.json: No such file or directory
         
        -=== A deploy that fails because the service does is SERVICE
        -
        ->>> musterr [CLI] bundle deploy -t outage
        -Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/result-file/outage/files...
        -Error: cannot create resources.jobs.foo: Fault injected by test. (500 INTERNAL_ERROR)
        -
        -Endpoint: POST [DATABRICKS_URL]/api/2.2/jobs/create
        -HTTP Status: 500 Internal Server Error
        -API error_code: INTERNAL_ERROR
        -API message: Fault injected by test.
        -
        -Files: 2 uploaded, 0 deleted
        -
        ->>> jq -c . result.json
        -{"error_class":"SERVICE"}
        -
        -=== A deploy that fails because of the bundle is USER
        -
        ->>> musterr [CLI] bundle deploy -t broken
        -Error: reference does not exist: ${var.missing}
        -
        -
        ->>> jq -c . result.json
        -{"error_class":"USER"}
        -
        -=== bundle validate does not write the file
        -
        ->>> assert_not_exists.py result.json
        +Exit code: 2
        
FAIL

latest (v1.28.0): same output as main (c639f9d)

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 4e0055a

Run: 45511454206

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 272 20 5:05
💚​ aws-windows-latest-4core-16gb 1 274 18 4:20
💚​ azure linux-2core-8gb 1 271 20 5:02
💚​ azure-windows-latest-4core-16gb 1 273 18 4:09
💚​ gcp linux-2core-8gb 1 272 20 5:23
💚​ gcp-windows-latest-4core-16gb 1 274 18 4:04
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 6 slowest tests (at least 2 minutes):
duration env testname
4:17 aws-windows-latest-4core-16gb TestAccept
4:15 gcp linux-2core-8gb TestAccept
4:07 azure-windows-latest-4core-16gb TestAccept
4:02 gcp-windows-latest-4core-16gb TestAccept
3:58 aws linux-2core-8gb TestAccept
3:57 azure linux-2core-8gb TestAccept

@atreyadbrx
atreyadbrx requested a review from pietern November 21, 2026 00:04
@atreyadbrx
atreyadbrx force-pushed the dabs-ad-d3-result-file branch from b33418c to 7ad3f2e Compare November 23, 2026 18:52
@atreyadbrx atreyadbrx changed the title Write a deploy result file for the auto-deploy runner Write the deploy's error class to a result file for auto-deploy Nov 23, 2026
@atreyadbrx
atreyadbrx marked this pull request as ready for review November 23, 2026 23:38
@atreyadbrx
atreyadbrx requested review from a team as code owners November 23, 2026 23:38

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at 7ad3f2e. Each finding was verified against the code.

Not ready yet: 1 blocking issue(s), tagged [blocking].

This PR has bundle deploy and pipelines deploy write a result file with {} or an error_class of USER or SERVICE when DATABRICKS_AUTO_DEPLOY_RESULT_FILE is set. The classification now uses the first error's cause, which diag.Diagnostic and logdiag keep. The approach is small and the unit and acceptance tests cover the main cases. The file doesn't hold up on some exit paths, though: a panic writes {}, and pipelines deploy can fail after the file says success. Treating every *url.Error as SERVICE also goes against the "if unsure, USER" rule.

Comment thread cmd/bundle/utils/process.go Outdated
if opts.Deploy {
defer func() {
// Ahead of the nil check: the result file is written on every exit.
phases.WriteDeployResult(ctx, retErr)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] This defer also runs while a panic unwinds. At that point retErr is still nil and logdiag usually has no error, so WriteDeployResult writes {}. Then root.execute recovers the panic and exits 1. So a nil dereference in a mutator or in phases.Deploy leaves a file that says the deploy succeeded, which contradicts "a missing file means the CLI crashed" in bundle/phases/deploy_result.go:31. Can we recover() here and re-panic, then either skip the write or write SERVICE when there was a panic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ba3592d. WriteDeployResultOnExit is now its own deferred function: it calls recover(), writes SERVICE (a panic is a CLI bug, not the bundle's) and re-panics, so telemetry and root.execute's recovery still run. Covered by TestWriteDeployResultOnExitReportsPanicAsService.

Comment thread cmd/bundle/utils/process.go Outdated
if opts.Deploy {
defer func() {
// Ahead of the nil check: the result file is written on every exit.
phases.WriteDeployResult(ctx, retErr)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] The file is written when ProcessBundleRet returns, not when the command exits. After that, pipelines deploy (cmd/pipelines/deploy.go:69) runs mutator.InitializeURLs(), which calls CurrentWorkspaceID. If that call fails, the command exits 1 with root.ErrAlreadyPrinted, but the file already says {}. Should pipelines deploy write the result again after that step, or should the write move to a place that covers the whole command?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ba3592d. Only bundle deploy writes the file now, through ProcessOptions.WriteDeployResult. pipelines deploy and the apps commands keep working after ProcessBundle returns, and the runner only runs bundle deploy.

Comment thread bundle/phases/deploy_result.go Outdated
}
return errorClassUser
}
if _, ok := errors.AsType[*url.Error](err); ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] net/http wraps nearly every client-side failure in *url.Error. That includes a DNS failure for a mistyped workspace.host, TLS or proxy misconfiguration, and context.Canceled/DeadlineExceeded when the run is interrupted. All of these come out as SERVICE, so the runner hides a message the customer needs. That's the opposite of the stated "when unsure, USER" fallback, and libs/retry/retry.go:84-90 explains why the repo doesn't treat every *url.Error as the platform's fault. Can this reuse or align with retry.IsTransient/IsTransientRead, or at least return USER for context cancellation and DNS/x509 errors, with a unit case for each?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in ba3592d. Only an API error with status 5xx, 429 or 408 is SERVICE; network errors are USER. retry.IsTransient doesn't fit here, because it leaves out errors the SDK already retried, such as a 429. The unit table now has a network error as USER.


data, err := json.Marshal(result)
if err == nil {
err = os.WriteFile(path, data, 0o644)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] The file is written only from the defer in ProcessBundleRet. A flag-parsing error or a PersistentPreRunE failure (cmd/root/root.go:57-72) never gets there, so no file is written, and the runner reads that as a crash. Nothing removes an old file either, so if the runner reuses the path it reads the previous run's {} (the acceptance script has to rm result.json by hand). Should the runner contract require deleting the file before each run, or should the CLI remove it early, with the doc comment on WriteDeployResult updated to match?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runner passes fixed flags and gives each run a fresh temporary directory, so the path never exists when the CLI starts. A failure before ProcessBundleRet (output or logger setup) leaves no file, and the runner then keeps its current behavior. The doc comment now says a missing file means the deploy never got far enough to write it (ba3592d).

atreyadbrx and others added 3 commits November 24, 2026 23:30
When DATABRICKS_AUTO_DEPLOY_RESULT_FILE is set, bundle deploy writes a
JSON file on every exit: {} on success, otherwise
{"error_class": "SERVICE"} or {"error_class": "USER"}. SERVICE means the
first error logged is an API error with status 5xx, 429 or 408, or a
request that got no response. Everything else is USER. Without the
variable nothing changes.

diag.FromErr now keeps the error a diagnostic was made from as
Diagnostic.Cause, and logdiag remembers the first error's cause, so the
class can be read after the error is rendered.

Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
load_dbalert_files.go lists every diag.Diagnostic field, so it needs
the new Cause field: the error for the read and parse failures, nil
for the others.

Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
- A panic wrote {}, as if the deploy had succeeded. WriteDeployResultOnExit
  is now its own deferred function: it reports a panic as SERVICE, because
  a panic is a CLI bug, and re-panics.
- Only bundle deploy writes the file (ProcessOptions.WriteDeployResult).
  pipelines deploy and the apps commands keep working after ProcessBundle
  returns, so a file written there could say {} for a command that then
  fails.
- Network errors are USER: a wrong host, proxy or certificate causes them
  too, and USER is the default when the CLI can't tell.

Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@atreyadbrx
atreyadbrx force-pushed the dabs-ad-d3-result-file branch from ba3592d to 4e0055a Compare November 24, 2026 23:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants