From 07d20bd0620ce9c1c75fc16eef13ee861bdcefdb Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:43:42 +0000 Subject: [PATCH 1/4] air: Shorten MLflow run names and IDs the same way in `air list` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MLflow column of `air list` cut a long run name to its first characters, but showed the last characters of the run ID when the run had no name. Rows with long names sharing a prefix looked identical. The column now shows the run's name, or its ID when the name is unknown, and shortens either one the same way: a label that doesn't fit keeps its end behind a leading "…". Co-authored-by: Isaac --- cmd/air/list.go | 4 ++-- cmd/air/mlflow.go | 25 +++++++++++++++++-------- cmd/air/mlflow_test.go | 34 ++++++++++++++++++++++++++++------ cmd/air/render.go | 3 ++- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/cmd/air/list.go b/cmd/air/list.go index cc2b27c99d4..50108b85c83 100644 --- a/cmd/air/list.go +++ b/cmd/air/list.go @@ -350,9 +350,9 @@ func setMLflowLinks(ctx context.Context, w *databricks.WorkspaceClient, host str } entries[i].row.MLflowURL = mlflowLogsURL(host, ids) name := fetchMLflowRunName(ctx, w, ids.RunID) - // Shorten the name, not the retry note, to fit the column. + // Shorten the label, not the retry note, to fit the column. note := ids.retryNote() - entries[i].row.MLflowLabel = truncate(mlflowRunLabel(name, ids.RunID), mlflowColWidth-len(note)) + note + entries[i].row.MLflowLabel = mlflowRunLabel(name, ids.RunID, mlflowColWidth-len(note)) + note entries[i].row.ExperimentURL = mlflowExperimentURL(host, ids) // The ETA needs a progress-metric history fetch, so it's computed only // for running rows (the only ones that can have one). diff --git a/cmd/air/mlflow.go b/cmd/air/mlflow.go index 7cf9f867630..5f9bc99de5d 100644 --- a/cmd/air/mlflow.go +++ b/cmd/air/mlflow.go @@ -6,6 +6,7 @@ import ( "slices" "strings" + "github.com/charmbracelet/lipgloss" "github.com/databricks/cli/libs/log" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -156,14 +157,22 @@ func fetchMLflowRunName(ctx context.Context, w *databricks.WorkspaceClient, mlfl } // mlflowRunLabel is the text shown for the MLflow Run cell: the run's name, or -// "...{last 8 of run id}" when the name is unknown. Mirrors Python's -// _get_mlflow_run_name (cli_display.py). -func mlflowRunLabel(name, mlflowRunID string) string { - if name != "" { - return name +// its run ID when the name is unknown. A label wider than width keeps its end +// behind a leading "…", since run names and IDs tend to share a prefix and +// differ in their tail. A width of 0 or less means no limit. +func mlflowRunLabel(name, mlflowRunID string, width int) string { + label := name + if label == "" { + label = mlflowRunID } - if len(mlflowRunID) > 8 { - return "..." + mlflowRunID[len(mlflowRunID)-8:] + if width <= 0 || lipgloss.Width(label) <= width { + return label } - return "..." + mlflowRunID + // Drop leading runes until the rest fits beside the "…"; a wide rune takes + // two cells, so the cut is by display width, not rune count. + runes := []rune(label) + for len(runes) > 0 && lipgloss.Width(string(runes)) > width-1 { + runes = runes[1:] + } + return "…" + string(runes) } diff --git a/cmd/air/mlflow_test.go b/cmd/air/mlflow_test.go index 2f316acaf74..1728ab22111 100644 --- a/cmd/air/mlflow_test.go +++ b/cmd/air/mlflow_test.go @@ -5,6 +5,7 @@ import ( "net/http/httptest" "testing" + "github.com/charmbracelet/lipgloss" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/stretchr/testify/assert" @@ -175,12 +176,33 @@ func TestMLflowURLs(t *testing.T) { } func TestMLflowRunLabel(t *testing.T) { - // Uses the run name when it is known. - assert.Equal(t, "sunny-cat-42", mlflowRunLabel("sunny-cat-42", "0123456789abcdef")) - // Falls back to the last 8 characters of a long run id. - assert.Equal(t, "...9abcdef0", mlflowRunLabel("", "0123456789abcdef0")) - // A short run id is shown in full behind the ellipsis. - assert.Equal(t, "...short", mlflowRunLabel("", "short")) + const runID = "0123456789abcdef0123456789abcdef" + tests := []struct { + name string + runName string + runID string + width int + want string + }{ + {name: "long name keeps its end", runName: "qwen-finetune-2026-10-23-lr-3e-5", runID: runID, width: 22, want: "…ne-2026-10-23-lr-3e-5"}, + {name: "short name is shown whole", runName: "sunny-cat-42", runID: runID, width: 22, want: "sunny-cat-42"}, + {name: "name at the width is shown whole", runName: "exactly-twenty-two-chr", runID: runID, width: 22, want: "exactly-twenty-two-chr"}, + {name: "unnamed run keeps the end of its ID", runID: runID, width: 22, want: "…bcdef0123456789abcdef"}, + {name: "short ID is shown whole", runID: "short", width: 22, want: "short"}, + {name: "wide characters count as two cells", runName: "训练运行-实验-第一百二十三次", runID: runID, width: 8, want: "…十三次"}, + {name: "width of one leaves only the ellipsis", runName: "sunny-cat-42", runID: runID, width: 1, want: "…"}, + {name: "no width limit shows the whole name", runName: "qwen-finetune-2026-10-23-lr-3e-5", runID: runID, want: "qwen-finetune-2026-10-23-lr-3e-5"}, + {name: "no width limit shows the whole ID", runID: runID, want: runID}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := mlflowRunLabel(tt.runName, tt.runID, tt.width) + assert.Equal(t, tt.want, got) + if tt.width > 0 { + assert.LessOrEqual(t, lipgloss.Width(got), tt.width) + } + }) + } } func TestFetchMLflowRunName(t *testing.T) { diff --git a/cmd/air/render.go b/cmd/air/render.go index 3985ab57588..755e8540fb9 100644 --- a/cmd/air/render.go +++ b/cmd/air/render.go @@ -124,7 +124,8 @@ func renderRunText(ctx context.Context, out io.Writer, w *databricks.WorkspaceCl } if ids != nil { - view.mlflowLabel = mlflowRunLabel(fetchMLflowRunName(ctx, w, ids.RunID), ids.RunID) + ids.retryNote() + // The box grows to fit its fields, so the label is shown whole. + view.mlflowLabel = mlflowRunLabel(fetchMLflowRunName(ctx, w, ids.RunID), ids.RunID, 0) + ids.retryNote() view.mlflowURL = mlflowRunURL(w.Config.Host, ids) } From 14d7e6372a391e6ced78a51501d1eeffc0b77fa0 Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Thu, 12 Nov 2026 23:44:07 +0000 Subject: [PATCH 2/4] Add changelog fragment Co-authored-by: Isaac --- .nextchanges/air/7582.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/air/7582.md diff --git a/.nextchanges/air/7582.md b/.nextchanges/air/7582.md new file mode 100644 index 00000000000..41c227969f2 --- /dev/null +++ b/.nextchanges/air/7582.md @@ -0,0 +1 @@ +* `air list` shortens a long MLflow run name the same way as a run ID, keeping its end behind a leading `…`, so runs whose names share a prefix stay distinguishable. ([#7582](https://github.com/databricks/cli/pull/7582)) From 9d6ace2ea111268fce74c04de09e49ae076f29bd Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:00:55 +0000 Subject: [PATCH 3/4] air: Test the unnamed-run MLflow label with a retry note Covers the list row's width budget when a retry note follows a shortened label, and the whole run ID in the info pane. Also corrects the label's doc comment and widens the changelog entry to cover run IDs. Co-authored-by: Isaac --- .nextchanges/air/7582.md | 2 +- cmd/air/list_detail_test.go | 50 +++++++++++++++++++++++++++++++++++++ cmd/air/mlflow.go | 7 +++--- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/.nextchanges/air/7582.md b/.nextchanges/air/7582.md index 41c227969f2..b275116fbca 100644 --- a/.nextchanges/air/7582.md +++ b/.nextchanges/air/7582.md @@ -1 +1 @@ -* `air list` shortens a long MLflow run name the same way as a run ID, keeping its end behind a leading `…`, so runs whose names share a prefix stay distinguishable. ([#7582](https://github.com/databricks/cli/pull/7582)) +* `air list` shortens MLflow run names and unnamed-run IDs by keeping their end behind a leading `…`, and `air get` shows an unnamed run's full MLflow run ID. ([#7582](https://github.com/databricks/cli/pull/7582)) diff --git a/cmd/air/list_detail_test.go b/cmd/air/list_detail_test.go index 8cbe2c8d3b6..997b8131c48 100644 --- a/cmd/air/list_detail_test.go +++ b/cmd/air/list_detail_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/charmbracelet/lipgloss" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/stretchr/testify/assert" @@ -95,3 +96,52 @@ func TestListRowAndPanesLinkTheSameOlderRetry(t *testing.T) { assert.Contains(t, info, "MLflow URL: "+srv.URL+"/ml/experiments/E1/runs/R1\n") assert.Contains(t, logs, "\nMLflow URL (retry 1): "+wantURL+"\n") } + +func TestUnnamedOlderRetryLabelFitsTheListColumnAndIsWholeInTheInfoPane(t *testing.T) { + // Given a failed run whose retry 0 logged to an MLflow run with no name and + // whose last retry failed before it started. + t.Setenv("DATABRICKS_CACHE_DIR", t.TempDir()) + const mlflowRunID = "0123456789abcdef0123456789abcdef" + run := indexRun(7, 1000_000) + run.State.ResultState = jobs.RunResultStateFailed + task := run.Tasks[0] + run.Tasks = nil + for attempt, taskRunID := range []int64{70, 71} { + task.RunId, task.AttemptNumber = taskRunID, attempt + run.Tasks = append(run.Tasks, task) + } + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case aiTrainingWorkflowsPath: + _, _ = w.Write([]byte(`{"training_workflows": [{"job_run_id": "7", "submit_time": {"seconds": 1000}}]}`)) + case "/api/2.2/jobs/runs/get": + _ = json.NewEncoder(w).Encode(run) + case "/api/2.2/jobs/runs/get-output": + if r.URL.Query().Get("run_id") == "70" { + _, _ = w.Write([]byte(`{"ai_runtime_task_output": {"mlflow_experiment_id": "E1", "mlflow_run_id": "` + mlflowRunID + `"}}`)) + return + } + _, _ = w.Write([]byte(`{}`)) + default: + _, _ = w.Write([]byte(`{}`)) + } + })) + t.Cleanup(srv.Close) + ctx := cmdio.MockDiscard(t.Context()) + w := newTestWorkspaceClient(t, srv.URL) + + // When the list and the info pane render the run. + rows, err := newRunFetcher(ctx, w, listQuery{ + userFilter: "me@example.com", currentUser: "me@example.com", limit: 10, fetchMLflow: true, + }).next(10) + require.NoError(t, err) + info, err := runDetailText(ctx, w, 7) + require.NoError(t, err) + + // Then the list row keeps the end of the ID and the whole retry note within + // the column, and the info pane shows the whole ID. + require.Len(t, rows, 1) + assert.Equal(t, "…56789abcdef (retry 0)", rows[0].MLflowLabel) + assert.Equal(t, mlflowColWidth, lipgloss.Width(rows[0].MLflowLabel)) + assert.Contains(t, info, mlflowRunID+" (retry 0)") +} diff --git a/cmd/air/mlflow.go b/cmd/air/mlflow.go index 5f9bc99de5d..9294552abd1 100644 --- a/cmd/air/mlflow.go +++ b/cmd/air/mlflow.go @@ -158,8 +158,8 @@ func fetchMLflowRunName(ctx context.Context, w *databricks.WorkspaceClient, mlfl // mlflowRunLabel is the text shown for the MLflow Run cell: the run's name, or // its run ID when the name is unknown. A label wider than width keeps its end -// behind a leading "…", since run names and IDs tend to share a prefix and -// differ in their tail. A width of 0 or less means no limit. +// behind a leading "…", because run names often share a prefix and differ at +// the end. A width of 0 or less means no limit. func mlflowRunLabel(name, mlflowRunID string, width int) string { label := name if label == "" { @@ -168,8 +168,7 @@ func mlflowRunLabel(name, mlflowRunID string, width int) string { if width <= 0 || lipgloss.Width(label) <= width { return label } - // Drop leading runes until the rest fits beside the "…"; a wide rune takes - // two cells, so the cut is by display width, not rune count. + // A wide rune takes two cells, so cut by display width, not rune count. runes := []rune(label) for len(runes) > 0 && lipgloss.Width(string(runes)) > width-1 { runes = runes[1:] From 60bd00e18bc91aeaee1c3e708c939a9994c94def Mon Sep 17 00:00:00 2001 From: dimk0 <4886215+dimk0@users.noreply.github.com> Date: Fri, 13 Nov 2026 07:45:03 +0000 Subject: [PATCH 4/4] air: Cut `air list` cells by display width truncate measured display width but cut by character count, so a cell with wide (for example CJK) text overflowed its column. It now cuts by display width. truncateStart is the keep-the-end variant, and the MLflow label uses it instead of its own loop. Co-authored-by: Isaac --- .nextchanges/air/7582.md | 2 +- cmd/air/list_tui_render.go | 23 +++++++++++++++++++++-- cmd/air/list_tui_test.go | 31 +++++++++++++++++++++++++++++++ cmd/air/mlflow.go | 10 ++-------- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/.nextchanges/air/7582.md b/.nextchanges/air/7582.md index b275116fbca..a6306817810 100644 --- a/.nextchanges/air/7582.md +++ b/.nextchanges/air/7582.md @@ -1 +1 @@ -* `air list` shortens MLflow run names and unnamed-run IDs by keeping their end behind a leading `…`, and `air get` shows an unnamed run's full MLflow run ID. ([#7582](https://github.com/databricks/cli/pull/7582)) +* `air list` shortens MLflow run names and unnamed-run IDs by keeping their end behind a leading `…`, and its columns no longer overflow on wide (for example CJK) text; `air get` shows an unnamed run's full MLflow run ID. ([#7582](https://github.com/databricks/cli/pull/7582)) diff --git a/cmd/air/list_tui_render.go b/cmd/air/list_tui_render.go index 3f23535a8e2..7b9add62f47 100644 --- a/cmd/air/list_tui_render.go +++ b/cmd/air/list_tui_render.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/ansi" "github.com/muesli/termenv" ) @@ -241,11 +242,29 @@ func pad(s string, n int, right bool) string { // truncate shortens s to a visible width of n, appending "…" on overflow. func truncate(s string, n int) string { - if lipgloss.Width(s) <= n { + return ansi.Truncate(s, n, "…") +} + +// truncateStart shortens s to a visible width of n, keeping its end behind a +// leading "…" on overflow. +func truncateStart(s string, n int) string { + width := lipgloss.Width(s) + if width <= n { return s } if n <= 1 { + return truncate(s, n) + } + // TruncateLeft never splits a character, so a cut that lands inside a + // two-cell character leaves the result one cell too wide. + cut := width - (n - 1) + out := ansi.TruncateLeft(s, cut, "…") + if lipgloss.Width(out) > n { + out = ansi.TruncateLeft(s, cut+1, "…") + } + // TruncateLeft drops the "…" when nothing of s is left. + if out == "" { return "…" } - return string([]rune(s)[:n-1]) + "…" + return out } diff --git a/cmd/air/list_tui_test.go b/cmd/air/list_tui_test.go index f195006f222..89964d14619 100644 --- a/cmd/air/list_tui_test.go +++ b/cmd/air/list_tui_test.go @@ -338,6 +338,37 @@ func TestListModelDetailLateMsgDropped(t *testing.T) { assert.NotContains(t, m.View(), "late result") } +func TestTruncateFitsDisplayWidth(t *testing.T) { + // A CJK character takes two cells and a combining mark none, so the cut is + // by display width and never splits a character. + const wide = "/Users/张伟/大模型微调实验第一百二十三次评估" + const accented = "xxxxxxxxxxxxxxxxxxxx\u0301yz" + tests := []struct { + name string + s string + n int + wantEnd string // truncate + wantStart string // truncateStart + }{ + {name: "fits", s: "abc", n: 5, wantEnd: "abc", wantStart: "abc"}, + {name: "exactly fits", s: "abcde", n: 5, wantEnd: "abcde", wantStart: "abcde"}, + {name: "one cell over", s: "abcdef", n: 5, wantEnd: "abcd…", wantStart: "…cdef"}, + {name: "wide characters", s: wide, n: 11, wantEnd: "/Users/张…", wantStart: "…十三次评估"}, + {name: "cut inside a wide character", s: wide, n: 12, wantEnd: "/Users/张伟…", wantStart: "…十三次评估"}, + {name: "wide character at width two", s: "评估评估", n: 2, wantEnd: "…", wantStart: "…"}, + {name: "combining mark stays with its letter", s: accented, n: 4, wantEnd: "xxx…", wantStart: "…x\u0301yz"}, + {name: "combining mark is dropped with its letter", s: accented, n: 3, wantEnd: "xx…", wantStart: "…yz"}, + {name: "width of one", s: "abcdef", n: 1, wantEnd: "…", wantStart: "…"}, + {name: "width of zero", s: "abcdef", n: 0, wantEnd: "", wantStart: ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.wantEnd, truncate(tt.s, tt.n)) + assert.Equal(t, tt.wantStart, truncateStart(tt.s, tt.n)) + }) + } +} + func TestPadAndTruncate(t *testing.T) { assert.Equal(t, "ab ", pad("ab", 5, false)) assert.Equal(t, " ab", pad("ab", 5, true)) diff --git a/cmd/air/mlflow.go b/cmd/air/mlflow.go index 9294552abd1..82a0a96ca3e 100644 --- a/cmd/air/mlflow.go +++ b/cmd/air/mlflow.go @@ -6,7 +6,6 @@ import ( "slices" "strings" - "github.com/charmbracelet/lipgloss" "github.com/databricks/cli/libs/log" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -165,13 +164,8 @@ func mlflowRunLabel(name, mlflowRunID string, width int) string { if label == "" { label = mlflowRunID } - if width <= 0 || lipgloss.Width(label) <= width { + if width <= 0 { return label } - // A wide rune takes two cells, so cut by display width, not rune count. - runes := []rune(label) - for len(runes) > 0 && lipgloss.Width(string(runes)) > width-1 { - runes = runes[1:] - } - return "…" + string(runes) + return truncateStart(label, width) }