From 40bec0abd5a2ed6c19c6e089f229b166b5b18b95 Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:20:37 +0000 Subject: [PATCH 1/3] air: fill list limit past unavailable runs --- cmd/air/list_filter.go | 8 -------- cmd/air/list_index.go | 23 +++++++++++------------ cmd/air/list_index_test.go | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/cmd/air/list_filter.go b/cmd/air/list_filter.go index 9b5df111098..377d4668ed8 100644 --- a/cmd/air/list_filter.go +++ b/cmd/air/list_filter.go @@ -13,14 +13,6 @@ import ( // supportedFilterKeys are the keys accepted by `air list --filter KEY=VALUE`. var supportedFilterKeys = []string{"accelerator_type", "experiment", "num_accelerators", "user"} -// hasTaskFilter reports whether any filter is applied to a run's task fields -// (experiment or accelerators), i.e. matched after a run is fetched rather than -// while scanning. The index path uses this to skip its newest-N truncation, so a -// dropped match doesn't shrink the result below --limit. -func (f listFilters) hasTaskFilter() bool { - return f.Experiment != "" || f.AcceleratorType != "" || f.NumAccelerators != nil -} - // listFilters holds the parsed `--filter` values for `air list`. type listFilters struct { // User is an exact creator-email match diff --git a/cmd/air/list_index.go b/cmd/air/list_index.go index 3bd1839f7b6..d9cf6a568bc 100644 --- a/cmd/air/list_index.go +++ b/cmd/air/list_index.go @@ -11,7 +11,7 @@ import ( // indexStrategy serves the caller's own runs from the AiTrainingService index: // it fetches every run id up front (cheap id+timestamp pairs), orders them -// newest-first, keeps the newest `limit`, then hydrates them into full rows in +// newest-first, then hydrates them into full rows in // want-sized batches via Jobs runs/get. Terminal rows are cached so repeat calls // skip the network. Unlike the Jobs scan it can't lazy-page (it must sort the // whole id set first), but it still yields in batches so the table paints early. @@ -25,9 +25,10 @@ type indexStrategy struct { host string workspaceID int64 - ids []int64 // newest-first run ids to hydrate, resolved on first next() - pos int - loaded bool + ids []int64 // newest-first run ids to hydrate, resolved on first next() + pos int + returned int + loaded bool } func newIndexStrategy(ctx context.Context, w *databricks.WorkspaceClient, q listQuery, limit int) *indexStrategy { @@ -51,12 +52,6 @@ func (s *indexStrategy) load() error { return err } slices.SortFunc(refs, func(a, b workflowRef) int { return cmp.Compare(b.submitTimeMs, a.submitTimeMs) }) - // Keep only the newest `limit` ids so hydration is bounded — but skip that when - // a task filter is active, since it drops matches post-hydration and we'd - // otherwise return fewer than `limit`. The caller stops pulling at `limit`. - if s.limit > 0 && len(refs) > s.limit && !s.filters.hasTaskFilter() { - refs = refs[:s.limit] - } s.ids = make([]int64, len(refs)) for i, r := range refs { s.ids[i] = r.jobRunID @@ -71,6 +66,9 @@ func (s *indexStrategy) next(want int) ([]listedRun, error) { return nil, err } } + if s.limit > 0 { + want = min(want, s.limit-s.returned) + } var entries []listedRun for len(entries) < want && s.pos < len(s.ids) { @@ -84,14 +82,15 @@ func (s *indexStrategy) next(want int) ([]listedRun, error) { } entries = append(entries, rows...) } + s.returned += len(entries) return entries, nil } func (s *indexStrategy) done() bool { - return s.loaded && s.pos >= len(s.ids) + return s.loaded && ((s.limit > 0 && s.returned >= s.limit) || s.pos >= len(s.ids)) } -// truncated is always false: the index path is bounded by limit, not a scan cap. +// truncated is always false: the index path stops at the requested limit, not a scan cap. func (s *indexStrategy) truncated() bool { return false } // hydrate turns a batch of run ids into rows, serving cached terminal rows diff --git a/cmd/air/list_index_test.go b/cmd/air/list_index_test.go index 0d4f37887c0..c7495f2be66 100644 --- a/cmd/air/list_index_test.go +++ b/cmd/air/list_index_test.go @@ -143,6 +143,25 @@ func TestIndexStrategyDropsForbiddenAndMissing(t *testing.T) { assert.Equal(t, "3", rows[1].RunID) } +func TestIndexStrategyFillsLimitPastMissingRun(t *testing.T) { + refs := []workflowRef{ + {jobRunID: 1, submitTimeMs: 3000_000}, + {jobRunID: 2, submitTimeMs: 2000_000}, + } + runs := map[int64]jobs.Run{2: indexRun(2, 2000_000)} + srv, _ := indexAndGetServer(t, refs, runs, nil, map[int64]bool{1: true}) + t.Setenv("DATABRICKS_CACHE_ENABLED", "false") + + f := newRunFetcher(t.Context(), newTestWorkspaceClient(t, srv.URL), listQuery{ + currentUser: selfUser, + limit: 1, + }) + rows, err := f.next(1) + require.NoError(t, err) + require.Len(t, rows, 1) + assert.Equal(t, "2", rows[0].RunID) +} + func TestIndexStrategyPropagatesServerError(t *testing.T) { refs := []workflowRef{{jobRunID: 1, submitTimeMs: 1000_000}} srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { From fd36d9c4240410e083eb237966e3c148bdb54398 Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:22:09 +0000 Subject: [PATCH 2/3] changelog: add entry for PR 7735 --- .nextchanges/air/7735.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/air/7735.md diff --git a/.nextchanges/air/7735.md b/.nextchanges/air/7735.md new file mode 100644 index 00000000000..da722ea8c75 --- /dev/null +++ b/.nextchanges/air/7735.md @@ -0,0 +1 @@ +* `air list --all-status` now fills `--limit` past purged or inaccessible indexed runs. ([#7735](https://github.com/databricks/cli/pull/7735)) From e538ce2b763e66b3b5ea6e60ee15ca8d0dbb15ab Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:32:31 +0000 Subject: [PATCH 3/3] changelog: update entry for PR 7743 --- .nextchanges/air/7735.md | 1 - .nextchanges/air/7743.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 .nextchanges/air/7735.md create mode 100644 .nextchanges/air/7743.md diff --git a/.nextchanges/air/7735.md b/.nextchanges/air/7735.md deleted file mode 100644 index da722ea8c75..00000000000 --- a/.nextchanges/air/7735.md +++ /dev/null @@ -1 +0,0 @@ -* `air list --all-status` now fills `--limit` past purged or inaccessible indexed runs. ([#7735](https://github.com/databricks/cli/pull/7735)) diff --git a/.nextchanges/air/7743.md b/.nextchanges/air/7743.md new file mode 100644 index 00000000000..8c264bee04e --- /dev/null +++ b/.nextchanges/air/7743.md @@ -0,0 +1 @@ +* `air list --all-status` now fills `--limit` past purged or inaccessible indexed runs. ([#7743](https://github.com/databricks/cli/pull/7743))