From d825a49400baf40909bb2bc1d658d3626dce717d Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 20:20:15 +0000 Subject: [PATCH 1/4] [CNXT-2531] air run: include ?o= in the job run URL `air run` built the run URL by hand, without the `?o=` suffix that `air get` and `air list` add through dashboardURL(). The two commands printed different URLs for the same run, and the `air run` one does not deep-link to the right workspace on multi-workspace accounts. submitWorkload now resolves the workspace ID and uses the same helper. The run already exists at that point, so a failed lookup falls back to the URL without the suffix instead of failing the submit. Co-authored-by: Isaac --- acceptance/air/run-submit-databricks-ai/output.txt | 2 +- acceptance/air/run-submit-deps/output.txt | 2 +- acceptance/air/run-submit-overrides/output.txt | 2 +- acceptance/air/run-submit/output.txt | 6 +++--- cmd/air/runsubmit.go | 13 ++++++++++--- cmd/air/runsubmit_test.go | 8 ++++++-- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/acceptance/air/run-submit-databricks-ai/output.txt b/acceptance/air/run-submit-databricks-ai/output.txt index 0635ef3d307..5e19f717249 100644 --- a/acceptance/air/run-submit-databricks-ai/output.txt +++ b/acceptance/air/run-submit-databricks-ai/output.txt @@ -4,7 +4,7 @@ >>> [CLI] air run -f run.yaml Submitting experiment: databricks-ai-v5-smoke Submitted workload with Job Run ID: 555 -View job run at: [DATABRICKS_URL]/jobs/runs/555 +View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID] Tip: use --watch when submitting a run to stream logs to your terminal. Stream logs after submission using: diff --git a/acceptance/air/run-submit-deps/output.txt b/acceptance/air/run-submit-deps/output.txt index 68f58e64c65..ae716c0bdfd 100644 --- a/acceptance/air/run-submit-deps/output.txt +++ b/acceptance/air/run-submit-deps/output.txt @@ -4,7 +4,7 @@ >>> [CLI] air run -f run.yaml Submitting experiment: deps-smoke Submitted workload with Job Run ID: 555 -View job run at: [DATABRICKS_URL]/jobs/runs/555 +View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID] Tip: use --watch when submitting a run to stream logs to your terminal. Stream logs after submission using: diff --git a/acceptance/air/run-submit-overrides/output.txt b/acceptance/air/run-submit-overrides/output.txt index f3acef3852d..3e1f5e69ed3 100644 --- a/acceptance/air/run-submit-overrides/output.txt +++ b/acceptance/air/run-submit-overrides/output.txt @@ -7,7 +7,7 @@ Override: changing parameters.model.hidden_size from 1024 to 2048 Override: setting parameters.optimizer.learning_rate to 0.001 Submitting experiment: overrides-smoke Submitted workload with Job Run ID: 555 -View job run at: [DATABRICKS_URL]/jobs/runs/555 +View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID] Tip: use --watch when submitting a run to stream logs to your terminal. Stream logs after submission using: diff --git a/acceptance/air/run-submit/output.txt b/acceptance/air/run-submit/output.txt index 3119c788b51..1ca32b0df45 100644 --- a/acceptance/air/run-submit/output.txt +++ b/acceptance/air/run-submit/output.txt @@ -5,7 +5,7 @@ Submitting experiment: submit-smoke Uploading [SNAPSHOT_TARBALL]... Submitted workload with Job Run ID: 555 -View job run at: [DATABRICKS_URL]/jobs/runs/555 +View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID] Tip: use --watch when submitting a run to stream logs to your terminal. Stream logs after submission using: @@ -112,7 +112,7 @@ Stream logs after submission using: >>> [CLI] air run -f b300.yaml Submitting experiment: b300-submit-smoke Submitted workload with Job Run ID: 555 -View job run at: [DATABRICKS_URL]/jobs/runs/555 +View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID] Tip: use --watch when submitting a run to stream logs to your terminal. Stream logs after submission using: @@ -163,7 +163,7 @@ Stream logs after submission using: >>> [CLI] air run -f rtx6000.yaml Submitting experiment: rtx6000-submit-smoke Submitted workload with Job Run ID: 555 -View job run at: [DATABRICKS_URL]/jobs/runs/555 +View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID] Tip: use --watch when submitting a run to stream logs to your terminal. Stream logs after submission using: diff --git a/cmd/air/runsubmit.go b/cmd/air/runsubmit.go index f01198d2b7a..de16c0b1044 100644 --- a/cmd/air/runsubmit.go +++ b/cmd/air/runsubmit.go @@ -17,6 +17,7 @@ import ( "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/env" "github.com/databricks/cli/libs/filer" + "github.com/databricks/cli/libs/log" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/client" "github.com/databricks/databricks-sdk-go/service/compute" @@ -332,7 +333,7 @@ func stageRunArtifacts(ctx context.Context, launchWriter fileWriter, items []upl // payload, and submit it. It // returns the new run_id and its dashboard URL. showProgress enables the stderr // staging spinner (text mode only). -func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *runConfig, configPath, idempotencyKey string, showProgress bool) (runID int64, dashboardURL string, err error) { +func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *runConfig, configPath, idempotencyKey string, showProgress bool) (runID int64, runURL string, err error) { start := time.Now() var snap snapshotResult defer func() { logRunEvent(ctx, cfg, snap, runID, time.Since(start), err) }() @@ -446,8 +447,14 @@ func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *run return 0, "", err } - dashboardURL = strings.TrimRight(w.Config.Host, "/") + "/jobs/runs/" + strconv.FormatInt(runID, 10) - return runID, dashboardURL, nil + // The run already exists, so a failed workspace id lookup must not fail the + // submit: fall back to the link without the ?o= workspace hint. + workspaceID, err := w.CurrentWorkspaceID(ctx) + if err != nil { + log.Debugf(ctx, "air run: could not fetch workspace ID for the dashboard link: %v", err) + return runID, strings.TrimRight(w.Config.Host, "/") + "/jobs/runs/" + strconv.FormatInt(runID, 10), nil + } + return runID, dashboardURL(w.Config.Host, runID, workspaceID), nil } func submittedContainers(cfg *runConfig, funcDir string) []submittedContainer { diff --git a/cmd/air/runsubmit_test.go b/cmd/air/runsubmit_test.go index 441a1c12d26..d2be7a048ee 100644 --- a/cmd/air/runsubmit_test.go +++ b/cmd/air/runsubmit_test.go @@ -7,6 +7,7 @@ import ( "io/fs" "path" "path/filepath" + "strconv" "strings" "sync" "sync/atomic" @@ -382,7 +383,7 @@ func TestSubmitWorkload(t *testing.T) { runID, dashboardURL, err := submitWorkload(t.Context(), w, cfg, cfgPath, "idem-key", false) require.NoError(t, err) assert.Equal(t, int64(777), runID) - assert.Contains(t, dashboardURL, "/jobs/runs/777") + assert.Equal(t, server.URL+"/jobs/runs/777?o="+strconv.Itoa(testserver.TestWorkspaceID), dashboardURL) assert.Equal(t, "idem-key", validatedToken) // The submitted payload is a native ai_runtime_task pointing at the uploaded @@ -728,7 +729,10 @@ func TestSubmitWorkloadWithCodeSource(t *testing.T) { }) var meCalls atomic.Int32 server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any { - meCalls.Add(1) + // The dashboard link's workspace id lookup also hits /Me, without attributes. + if req.URL.Query().Get("attributes") == "userName" { + meCalls.Add(1) + } return req.Workspace.MeUser(req.Token) }) stubValidateConfig(server) From 5cbeeffa383d58578c1bde6fd42b0ad5a58d3abd Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 20:20:50 +0000 Subject: [PATCH 2/4] Add changelog fragment Co-authored-by: Isaac --- .nextchanges/air/run-url-workspace-id.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/air/run-url-workspace-id.md diff --git a/.nextchanges/air/run-url-workspace-id.md b/.nextchanges/air/run-url-workspace-id.md new file mode 100644 index 00000000000..24d56f03501 --- /dev/null +++ b/.nextchanges/air/run-url-workspace-id.md @@ -0,0 +1 @@ +* `air run` now prints the job run URL with the `?o=` suffix, matching `air get` and `air list`. ([#7573](https://github.com/databricks/cli/pull/7573)) From 30a3e56719c2fb6c298fd51ddda8da97ce7433ea Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:46:55 +0000 Subject: [PATCH 3/4] air run: resolve the workspace ID before submitting The workspace ID lookup for the run link sat between creating the run and printing its ID, so a slow or retrying lookup could hold back the ID of a run that already existed. Resolve it alongside validation and staging instead, bounded by a short timeout, and prefer the ID already on the client config so the common case makes no extra request. dashboardURL now omits ?o= for an unknown workspace ID, which replaces the hand-built fallback URL and stops `air list` linking to ?o=0 when its own lookup fails. Co-authored-by: Isaac --- .nextchanges/air/run-url-workspace-id.md | 2 +- cmd/air/format.go | 9 ++++- cmd/air/format_test.go | 1 + cmd/air/runsubmit.go | 38 +++++++++++++++---- cmd/air/runsubmit_test.go | 48 ++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 14 deletions(-) diff --git a/.nextchanges/air/run-url-workspace-id.md b/.nextchanges/air/run-url-workspace-id.md index 24d56f03501..9b82e2af64d 100644 --- a/.nextchanges/air/run-url-workspace-id.md +++ b/.nextchanges/air/run-url-workspace-id.md @@ -1 +1 @@ -* `air run` now prints the job run URL with the `?o=` suffix, matching `air get` and `air list`. ([#7573](https://github.com/databricks/cli/pull/7573)) +* `air run` now prints the job run URL with the `?o=` suffix, matching `air get` and `air list`; `dashboard_url` in `air run -o json` and the `--watch` events gains it too. ([#7573](https://github.com/databricks/cli/pull/7573)) diff --git a/cmd/air/format.go b/cmd/air/format.go index 89e2420fd3b..68c956ad4c0 100644 --- a/cmd/air/format.go +++ b/cmd/air/format.go @@ -254,9 +254,14 @@ func roundMillisToSeconds(ms int64) int64 { // dashboardURL builds {host}/jobs/runs/{id}?o={workspace_id}, matching Python // (cli_entrypoint.py:1911). The ?o= workspace id deep-links to the right -// workspace on multi-workspace accounts. +// workspace on multi-workspace accounts; an unknown (zero) workspace id omits +// it rather than linking to ?o=0. func dashboardURL(host string, runID, workspaceID int64) string { - return fmt.Sprintf("%s/jobs/runs/%d?o=%d", strings.TrimRight(host, "/"), runID, workspaceID) + url := fmt.Sprintf("%s/jobs/runs/%d", strings.TrimRight(host, "/"), runID) + if workspaceID == 0 { + return url + } + return fmt.Sprintf("%s?o=%d", url, workspaceID) } // formatDuration turns a number of seconds into a compact human string such as diff --git a/cmd/air/format_test.go b/cmd/air/format_test.go index 7b4bbc80154..c76260d28cb 100644 --- a/cmd/air/format_test.go +++ b/cmd/air/format_test.go @@ -170,6 +170,7 @@ func TestDurationSeconds(t *testing.T) { func TestDashboardURL(t *testing.T) { // The ?o= workspace id and a trailing-slash-trimmed host, matching Python. assert.Equal(t, "https://example.test/jobs/runs/123?o=42", dashboardURL("https://example.test/", 123, 42)) + assert.Equal(t, "https://example.test/jobs/runs/123", dashboardURL("https://example.test/", 123, 0)) } func TestLatestAttemptNumber(t *testing.T) { diff --git a/cmd/air/runsubmit.go b/cmd/air/runsubmit.go index de16c0b1044..7f617b11213 100644 --- a/cmd/air/runsubmit.go +++ b/cmd/air/runsubmit.go @@ -331,7 +331,8 @@ func stageRunArtifacts(ctx context.Context, launchWriter fileWriter, items []upl // submitWorkload runs the submit happy path: validate the config while uploading // the launch artifacts, ensure the experiment directory, assemble the Jobs // payload, and submit it. It -// returns the new run_id and its dashboard URL. showProgress enables the stderr +// returns the new run_id and its dashboard URL, which carries the ?o= workspace +// hint only when the workspace ID could be resolved. showProgress enables the stderr // staging spinner (text mode only). func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *runConfig, configPath, idempotencyKey string, showProgress bool) (runID int64, runURL string, err error) { start := time.Now() @@ -388,6 +389,13 @@ func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *run return stageErr }) }) + // Resolved here, not after submission: once the run exists nothing may delay + // showing its ID. + var workspaceID int64 + group.Go(func() error { + workspaceID = workspaceIDForRunLink(stagingCtx, w) + return nil + }) if err := group.Wait(); err != nil { return 0, "", err } @@ -447,14 +455,30 @@ func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *run return 0, "", err } - // The run already exists, so a failed workspace id lookup must not fail the - // submit: fall back to the link without the ?o= workspace hint. - workspaceID, err := w.CurrentWorkspaceID(ctx) + return runID, dashboardURL(w.Config.Host, runID, workspaceID), nil +} + +// workspaceIDLookupTimeout bounds the workspace ID lookup for the run link, so +// an unresponsive lookup cannot hold up submission for the SDK's retry window. +const workspaceIDLookupTimeout = 10 * time.Second + +// workspaceIDForRunLink returns the workspace ID for the run link's ?o= hint, +// or 0 when it cannot be resolved: the link is a convenience and must never +// fail or stall a submission. +func workspaceIDForRunLink(ctx context.Context, w *databricks.WorkspaceClient) int64 { + ctx, cancel := context.WithTimeout(ctx, workspaceIDLookupTimeout) + defer cancel() + id, err := auth.ResolveWorkspaceID(ctx, w) if err != nil { - log.Debugf(ctx, "air run: could not fetch workspace ID for the dashboard link: %v", err) - return runID, strings.TrimRight(w.Config.Host, "/") + "/jobs/runs/" + strconv.FormatInt(runID, 10), nil + log.Debugf(ctx, "air run: could not resolve workspace ID for the run link: %v", err) + return 0 } - return runID, dashboardURL(w.Config.Host, runID, workspaceID), nil + workspaceID, err := strconv.ParseInt(id, 10, 64) + if err != nil { + log.Debugf(ctx, "air run: workspace ID %q for the run link is not numeric", id) + return 0 + } + return workspaceID } func submittedContainers(cfg *runConfig, funcDir string) []submittedContainer { diff --git a/cmd/air/runsubmit_test.go b/cmd/air/runsubmit_test.go index d2be7a048ee..f1e0dc44c4b 100644 --- a/cmd/air/runsubmit_test.go +++ b/cmd/air/runsubmit_test.go @@ -354,6 +354,8 @@ func TestStageRunArtifactsOverlapsLaunchAndSnapshot(t *testing.T) { } func TestSubmitWorkload(t *testing.T) { + // A workspace ID in the developer's environment would replace the test server's in the run link. + t.Setenv("DATABRICKS_WORKSPACE_ID", "") server := testserver.New(t) t.Cleanup(server.Close) @@ -715,6 +717,47 @@ containers: } } +// The run link's workspace ID is best-effort: when it cannot be resolved the +// submit still succeeds with a link that omits ?o=. The lookup must also be +// done before the run is created, so nothing delays showing a new run's ID. +func TestSubmitWorkloadWithoutWorkspaceID(t *testing.T) { + server := testserver.New(t) + t.Cleanup(server.Close) + + // Register before AddDefaultHandlers: the router is first-wins, so these must claim the routes ahead of the default handlers. + var workspaceIDLookups, lookupsBeforeSubmit atomic.Int32 + server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any { + // The workspace ID lookup is the /Me call without attributes; answering it + // without the X-Databricks-Org-Id header makes the lookup fail. + if req.URL.Query().Get("attributes") == "" { + workspaceIDLookups.Add(1) + } + return req.Workspace.MeUser(req.Token) + }) + server.Handle("POST", "/api/2.2/jobs/runs/submit", func(req testserver.Request) any { + lookupsBeforeSubmit.Store(workspaceIDLookups.Load()) + return jobs.SubmitRunResponse{RunId: 777} + }) + stubValidateConfig(server) + testserver.AddDefaultHandlers(server) + + w, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "token"}) + require.NoError(t, err) + // The test server's host metadata supplies a workspace ID; drop it to force the lookup. + w.Config.WorkspaceID = "" + + cfgPath := writeConfigFile(t, "run.yaml", minimalConfig) + cfg, err := loadRunConfig(cfgPath) + require.NoError(t, err) + + runID, runURL, err := submitWorkload(t.Context(), w, cfg, cfgPath, "idem-key", false) + require.NoError(t, err) + assert.Equal(t, int64(777), runID) + assert.Equal(t, server.URL+"/jobs/runs/777", runURL) + assert.Equal(t, int32(1), lookupsBeforeSubmit.Load(), "the workspace ID must be resolved before the run is created") + assert.Equal(t, int32(1), workspaceIDLookups.Load()) +} + // A working-tree code_source is packaged into a tarball, uploaded via libs/filer, // and its remote code_source_path attached to the submitted task. func TestSubmitWorkloadWithCodeSource(t *testing.T) { @@ -729,10 +772,7 @@ func TestSubmitWorkloadWithCodeSource(t *testing.T) { }) var meCalls atomic.Int32 server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any { - // The dashboard link's workspace id lookup also hits /Me, without attributes. - if req.URL.Query().Get("attributes") == "userName" { - meCalls.Add(1) - } + meCalls.Add(1) return req.Workspace.MeUser(req.Token) }) stubValidateConfig(server) From 82c1f84e79d3fe911d7600d62d5b2d95bf1d7563 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:44:57 +0000 Subject: [PATCH 4/4] Address review: trim repeated comments, note the air list change Co-authored-by: Isaac --- .nextchanges/air/run-url-workspace-id.md | 2 +- cmd/air/runsubmit.go | 10 ++++------ cmd/air/runsubmit_test.go | 4 +--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.nextchanges/air/run-url-workspace-id.md b/.nextchanges/air/run-url-workspace-id.md index 9b82e2af64d..aad532732f5 100644 --- a/.nextchanges/air/run-url-workspace-id.md +++ b/.nextchanges/air/run-url-workspace-id.md @@ -1 +1 @@ -* `air run` now prints the job run URL with the `?o=` suffix, matching `air get` and `air list`; `dashboard_url` in `air run -o json` and the `--watch` events gains it too. ([#7573](https://github.com/databricks/cli/pull/7573)) +* `air run` now prints the job run URL with the `?o=` suffix, matching `air get` and `air list`; `dashboard_url` in `air run -o json` and the `--watch` events gains it too. When `air list` cannot resolve the workspace ID, its links now omit `?o=` instead of ending in `?o=0`. ([#7573](https://github.com/databricks/cli/pull/7573)) diff --git a/cmd/air/runsubmit.go b/cmd/air/runsubmit.go index 7f617b11213..df79fc3a9ca 100644 --- a/cmd/air/runsubmit.go +++ b/cmd/air/runsubmit.go @@ -389,8 +389,6 @@ func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *run return stageErr }) }) - // Resolved here, not after submission: once the run exists nothing may delay - // showing its ID. var workspaceID int64 group.Go(func() error { workspaceID = workspaceIDForRunLink(stagingCtx, w) @@ -458,13 +456,13 @@ func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *run return runID, dashboardURL(w.Config.Host, runID, workspaceID), nil } -// workspaceIDLookupTimeout bounds the workspace ID lookup for the run link, so -// an unresponsive lookup cannot hold up submission for the SDK's retry window. +// workspaceIDLookupTimeout caps workspaceIDForRunLink. const workspaceIDLookupTimeout = 10 * time.Second // workspaceIDForRunLink returns the workspace ID for the run link's ?o= hint, -// or 0 when it cannot be resolved: the link is a convenience and must never -// fail or stall a submission. +// or 0 when it cannot be resolved. The link is a convenience, so the lookup +// never fails a submission; it is capped, and callers run it before creating +// the run, so that it cannot hold back a new run's ID either. func workspaceIDForRunLink(ctx context.Context, w *databricks.WorkspaceClient) int64 { ctx, cancel := context.WithTimeout(ctx, workspaceIDLookupTimeout) defer cancel() diff --git a/cmd/air/runsubmit_test.go b/cmd/air/runsubmit_test.go index f1e0dc44c4b..e101bbc28af 100644 --- a/cmd/air/runsubmit_test.go +++ b/cmd/air/runsubmit_test.go @@ -717,9 +717,7 @@ containers: } } -// The run link's workspace ID is best-effort: when it cannot be resolved the -// submit still succeeds with a link that omits ?o=. The lookup must also be -// done before the run is created, so nothing delays showing a new run's ID. +// An unresolved workspace ID yields a link without ?o=, looked up before the run is created. func TestSubmitWorkloadWithoutWorkspaceID(t *testing.T) { server := testserver.New(t) t.Cleanup(server.Close)