You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve aitools query: async polling, spinner, cancellation, --warehouse flag (#4612)
## Why
The existing `databricks experimental aitools tools query` command
blocks silently for up to 20 minutes with no user feedback, no way to
cancel a running query, and no way to override warehouse auto-detection.
This makes it frustrating for interactive use with long-running queries.
## Changes
**Before:** The command used `ExecuteAndWait` which blocks silently, has
no cancellation support, and always auto-detects the warehouse.
**Now:** The command submits queries asynchronously and polls with a
visible spinner, supports Ctrl+C cancellation that cleans up
server-side, and accepts a `--warehouse` flag.
Specifically:
- **Async polling with spinner**: Replaced `ExecuteAndWait` with a
two-step flow — `ExecuteStatement(WaitTimeout=0s)` to get the statement
ID immediately, then poll with `GetStatementByStatementId`. A background
ticker updates the spinner text every second showing elapsed time (`⣾
Executing query... (12s elapsed)`).
- **Ctrl+C cancellation**: Signal handler catches SIGINT/SIGTERM,
cancels the poll context, and calls `CancelExecution` to clean up the
running statement server-side. Prints `"Query cancelled."` to stderr.
- **`--warehouse` / `-w` flag**: Overrides the auto-detection chain (env
var → server default → first running warehouse).
- **Poll backoff**: Additive backoff 1s → 2s → 3s → 4s → 5s (capped)
between status polls.
- **Non-interactive debug logging**: `log.Debugf` on each poll iteration
for visibility when stderr is not a TTY.
- **Shell quoting hint**: When Databricks returns an
`UNRESOLVED_MAP_KEY` error (common when shell double-quote processing
strips inner quotes from map key access), the error message includes a
hint suggesting single quotes or `--file`.
## Test plan
- [x] Unit tests: 13 tests covering immediate success/failure, polling
state transitions, context cancellation with `CancelExecution`
assertion, warehouse flag resolution, result formatting, terminal state
detection, error hints.
- [x] Manual testing: ran queries against a live workspace with
`--profile`, verified spinner updates every second, verified Ctrl+C
cancels server-side, verified `--warehouse` override, verified
`UNRESOLVED_MAP_KEY` hint.
- [x] `go build ./...` clean
- [x] `go test ./experimental/aitools/cmd/ -count=1` passes (5s)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0 commit comments