From cd91efeab3a9ea93c02a9a9e4e8fc25097e8021a Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 16 Nov 2026 04:30:49 +0000 Subject: [PATCH 1/2] air logs: add --no-follow to print an active run's logs and exit `air logs` always follows an active run until it finishes, so a coding agent that wants to check progress has to kill it with `timeout` and guess the state from partial output. --no-follow reuses the one-shot view already used for past retries: print the tail so far, exit 0. Co-authored-by: Isaac --- .nextchanges/air/logs-no-follow.md | 1 + acceptance/air/help/output.txt | 5 ++++- cmd/air/logs.go | 7 ++++++- cmd/air/logs_test.go | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .nextchanges/air/logs-no-follow.md diff --git a/.nextchanges/air/logs-no-follow.md b/.nextchanges/air/logs-no-follow.md new file mode 100644 index 00000000000..e8c48edd20b --- /dev/null +++ b/.nextchanges/air/logs-no-follow.md @@ -0,0 +1 @@ +* `databricks air logs --no-follow` prints the logs so far from an active run and exits, instead of following the run until it finishes. diff --git a/acceptance/air/help/output.txt b/acceptance/air/help/output.txt index 7b37a4c83ac..d7039d134e4 100644 --- a/acceptance/air/help/output.txt +++ b/acceptance/air/help/output.txt @@ -195,7 +195,8 @@ Global Flags: Stream logs from an active run until it completes, or fetch logs from a completed run. -JOB_RUN_ID is the job run ID returned by "databricks air run". +JOB_RUN_ID is the job run ID returned by "databricks air run". Use --no-follow +to print the logs so far from an active run and exit. Usage: databricks air logs JOB_RUN_ID [flags] @@ -203,12 +204,14 @@ Usage: Examples: databricks air logs 123456789 databricks air logs 123456789 --node 1 --retry 0 + databricks air logs 123456789 --no-follow --tail 50 databricks air logs 123456789 --download-to ./logs Flags: --download-to string Download all logs to this directory instead of printing -h, --help help for logs --minutes int Fetch only logs from the last N minutes + --no-follow Print the logs so far and exit instead of following an active run --node int Fetch logs from this node --retry int View logs from a specific retry attempt; -1 means latest (default -1) --tail int Print the last N existing lines before following, or from a completed run (default 10000) diff --git a/cmd/air/logs.go b/cmd/air/logs.go index 33dd4d67366..41c6e22581e 100644 --- a/cmd/air/logs.go +++ b/cmd/air/logs.go @@ -26,6 +26,7 @@ func newLogsCommand() *cobra.Command { retry int downloadTo string review bool + noFollow bool ) cmd := &cobra.Command{ @@ -35,9 +36,11 @@ func newLogsCommand() *cobra.Command { Long: `Stream logs from an active run until it completes, or fetch logs from a completed run. -JOB_RUN_ID is the job run ID returned by "databricks air run".`, +JOB_RUN_ID is the job run ID returned by "databricks air run". Use --no-follow +to print the logs so far from an active run and exit.`, Example: ` databricks air logs 123456789 databricks air logs 123456789 --node 1 --retry 0 + databricks air logs 123456789 --no-follow --tail 50 databricks air logs 123456789 --download-to ./logs`, } @@ -45,6 +48,7 @@ JOB_RUN_ID is the job run ID returned by "databricks air run".`, cmd.Flags().IntVar(&tail, "tail", 0, "Print the last N existing lines before following, or from a completed run (default 10000)") cmd.Flags().IntVar(&minutes, "minutes", 0, "Fetch only logs from the last N minutes") cmd.Flags().IntVar(&retry, "retry", -1, "View logs from a specific retry attempt; -1 means latest") + cmd.Flags().BoolVar(&noFollow, "no-follow", false, "Print the logs so far and exit instead of following an active run") cmd.Flags().StringVar(&downloadTo, "download-to", "", "Download all logs to this directory instead of printing") cmd.Flags().BoolVar(&review, "review", false, "Download logs from all nodes and filter for error signatures") cmd.Flags().MarkHidden("review") @@ -130,6 +134,7 @@ JOB_RUN_ID is the job run ID returned by "databricks air run".`, boundInitialLogs: minutes == 0, downloadTo: downloadTo, jsonOutput: root.OutputType(cmd) == flags.OutputJSON, + staticView: noFollow, }) if downloadTo != "" || root.OutputType(cmd) == flags.OutputJSON { return err diff --git a/cmd/air/logs_test.go b/cmd/air/logs_test.go index 224df3e374b..3d5e9734cf0 100644 --- a/cmd/air/logs_test.go +++ b/cmd/air/logs_test.go @@ -500,3 +500,22 @@ func TestRunLogsPreservesSubmittedRunURL(t *testing.T) { require.NoError(t, err) assert.True(t, strings.HasSuffix(buf.String(), "\n\nView job run at: "+runURL+"\n"), buf.String()) } + +func TestLogsNoFollowPrintsActiveRunOnce(t *testing.T) { + var getRunHits int + srv := activeRunPastRetryServer(t, &getRunHits) + var buf bytes.Buffer + // The run never finishes, so following it would block until the deadline. + ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second) + defer cancel() + ctx = cmdio.InContext(ctx, cmdio.NewIO(ctx, flags.OutputText, nil, &buf, &buf, "", "")) + ctx = cmdctx.SetWorkspaceClient(ctx, newTestWorkspaceClient(t, srv.URL)) + cmd := withOutput(newLogsCommand(), flags.OutputText) + cmd.SetContext(ctx) + cmd.SetOut(&buf) + require.NoError(t, cmd.Flags().Set("no-follow", "true")) + + require.NoError(t, cmd.RunE(cmd, []string{"9"})) + assert.Equal(t, "retry 0 log\n", buf.String()) + assert.Equal(t, 1, getRunHits) +} From d26907faaa8b83f8979091197be9324130370b07 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 16 Nov 2026 04:58:01 +0000 Subject: [PATCH 2/2] Add PR link to changelog fragment Co-authored-by: Isaac --- .nextchanges/air/logs-no-follow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/air/logs-no-follow.md b/.nextchanges/air/logs-no-follow.md index e8c48edd20b..046d640cc9b 100644 --- a/.nextchanges/air/logs-no-follow.md +++ b/.nextchanges/air/logs-no-follow.md @@ -1 +1 @@ -* `databricks air logs --no-follow` prints the logs so far from an active run and exits, instead of following the run until it finishes. +* `databricks air logs --no-follow` prints the logs so far from an active run and exits, instead of following the run until it finishes. ([#7654](https://github.com/databricks/cli/pull/7654))