Skip to content

air: stop polling a finished run once its execution summary has settled - #8159

Open
qianhao-zhang-databricks wants to merge 2 commits into
mainfrom
air-watch-settled-summary
Open

qianhao-zhang-databricks wants to merge 2 commits into
mainfrom
air-watch-settled-summary

Conversation

@qianhao-zhang-databricks

Copy link
Copy Markdown
Contributor

Changes

databricks air run --watch and databricks air logs --follow exit about 2 s sooner after a run ends. Today, once the run is terminal, the log stream waits for three consecutive empty polls, one second apart, so that late-indexed records are not lost. It now exits on the first terminal poll when all of these hold:

  • the last lines the stream printed are the end of the AIR entry script's execution summary (Time in container: ..., then Completed at ... or ERROR: Script failed with exit code ..., then the closing rule), printed during the run's latest attempt;
  • at least three polls since then returned nothing new;
  • the summary was printed at least 5 s before this terminal poll started.

In every other case nothing changes. The rule is in one method, tailComplete (cmd/air/logstream.go); the summary matcher is summaryTracker (cmd/air/logstream_support.go).

Why

The entry script prints the summary as its last output on every attempt. Once it has been printed, three polls after it found nothing, and 5 s have passed, the three terminal polls repeat checks the stream has already made.

The summary never decides the outcome: the exit code, the final status and the closing -o json event still come from the Jobs run state, because user code can print the same lines. A summary from an earlier retry attempt, or any output after it, keeps the three terminal polls.

What this trades: the last look for late log records comes about 2 s earlier than today, at the first terminal poll instead of after three more. The 5 s floor keeps that look at least 5 s after the summary. In our test runs no log record became readable after the run was terminal on any run where the rule applied, and the slowest record took about 3 s from write to readable.

Known limitation, deliberate: when a run turns terminal less than 5 s after its summary, the rule does not apply and the CLI waits for today's three polls. So the saving shrinks as the server reports the end of a run faster. On test runs with a faster, not yet released server path, the summary came 2.7 to 4.1 s before the terminal poll on 6 of 8 runs, and the saving fell to 0.73 s median (n=8). The floor could be revisited (shortened or dropped) once there is more data on how late records arrive.

Tests

  • Unit tests in cmd/air/logstream_test.go:
    • TestStreamBricklensExitsOnFirstTerminalPollAfterSettledSummary fails without the change (7 log requests instead of 5).
    • TestStreamBricklensKeepsTerminalPollsWhenSummaryIsYoungerThanTheFloor fails without the 5 s floor (5 instead of 7).
    • TestStreamBricklensKeepsTerminalPollsWhenSummaryIsFromEarlierAttempt fails without the latest-attempt check (5 instead of 7).
    • TestStreamBricklensReturnsFailureOnFirstTerminalPollAfterSettledFailureSummary: a failed run whose summary has settled exits on the first terminal poll and still returns failure. It fails if the result is not taken from the Jobs run state, and without the change (7 log requests instead of 5).
    • Cases that keep the terminal polls (the run ends right after the summary, output after the summary), and four summaryTracker cases.
  • go test ./cmd/air/... and go test ./acceptance -run TestAccept/air/ pass. golangci-lint run ./..., golangci-lint fmt --diff, go vet ./cmd/air/..., go mod tidy (no diff), the dead-code check and tools/validate_nextchanges.py are clean.
  • Manual paired runs on single-GPU test runs, 2026-11-23, with this change on an earlier main. Since then the only upstream change to cmd/air/logstream*.go is the waiting-status text (#7899), which does not touch the poll loop or the exit decision, and this patch rebased onto it without a conflict. A second air run --watch with the same --idempotency-key attaches to the existing run, so the released CLI (v1.27.0) and this branch watched the same run:
    • This branch exited 1.98 s sooner, median (1.17 to 2.70 s), n=34 pairs on 17 runs (9 exit 0, 7 non-zero exit, 1 retried run; each run gave a text pair and an -o json pair). Against an unpatched build of the same base commit, the saving was 1.89 s median (n=17).
    • On all runs, stdout was identical line for line (-o json compared without timestamps; one watcher on two runs had an extra WAITING event because it attached earlier). Exit codes and the closing JSON event matched the Jobs result.
    • On two runs that printed 20,000 lines just before exiting, the summary arrived only after the run was terminal. The rule did not apply: both CLIs waited for the three terminal polls, as today.

This pull request and its description were written by Isaac.

After a watched run turns terminal, the Bricklens stream waits for three
consecutive empty polls, one second apart, so records indexed late are not
lost. When the stream already ended with the entry script's execution summary
(its last output on every attempt), the summary ended it at least 5 seconds
before the terminal poll, and at least three polls since then found nothing
new, those polls repeat evidence the stream already has. In that case exit on
the first terminal poll.

The decision is one function, tailComplete, that checks its evidence
strongest first and otherwise keeps today's three empty polls.

The summary lines only shorten the wait for late records. The exit code, the
final status and the closing -o json event still come from the Jobs run state,
because user code can print the same lines.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added the AIR Databricks AI Runtime CLI label Nov 28, 2026

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

AIR Databricks AI Runtime CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant