Repository navigation
Conversation
✅ Integration test reportCommit: 4bf8228
Top 17 slowest tests (at least 2 minutes):
|
631f0c9 to
134e5bc
Compare
simonfaltum
left a comment
There was a problem hiding this comment.
Can you add a .nextchanges/cli/ fragment for the reduced CLI startup time?
|
@simonfaltum I figured this is not user facing so doesn't deserve a changelog entry. We had a regression a while back that added 20ms and nobody noticed... :D |
simonfaltum
left a comment
There was a problem hiding this comment.
LGTM. Rechecked the full stack and the completion rationale fix. CI and the focused root/sync/bundle tests pass, and 22 before/after CLI checks matched apart from build-version metadata. The changelog explanation makes sense.
This review was generated with GitHub MCP.
| // Hand-written commands that replace a generated workspace command of the | ||
| // same name. Cobra resolves duplicate names by position after an unstable | ||
| // sort, so the generated command must not be added at all. | ||
| name := func(spec root.CommandSpec) string { return strings.Fields(spec.Use)[0] } |
There was a problem hiding this comment.
[nit] Could this be a named helper or a CommandSpec.Name() method, as the Go style guide requests, instead of an inline function for a repeated operation? A follow-up is fine.
18c2d3d to
bb9eeca
Compare
Every invocation built the whole command tree (~1,750 commands and ~3,300 flags) before parsing its args, which took about 4 ms per run. Top-level commands are now declared as root.CommandSpec values. A root.Tree holds a placeholder built from each spec's fields, which are all its parent shows in help, completion, and suggestions, and Tree.Execute builds the commands that the args resolve to before running cobra. The tree owns the root command, and the functions that create and run a bare root command are now unexported, so commands can only be added as specs and the CLI can only run through Tree.Execute. root.NewCommand panics if building a command changes the fields its spec declares. Co-authored-by: Isaac <no-reply@databricks.com>
## Changes `root.Execute` now takes the args to run instead of reading them from the command, where cobra falls back to `os.Args` if they were never set. `nil` means no arguments. `main` passes `os.Args[1:]`, and tests pass their args directly instead of calling `SetArgs` first. ## Why databricks#7487 builds top-level commands lazily, so it has to resolve the command from the args before cobra runs. That requires `Execute` to receive the args. ## Tests New unit test `TestExecuteWithNilArgsRunsWithoutArgs` checks that nil means no arguments; existing unit and acceptance tests cover the callers. This pull request and its description were written by Isaac. Co-authored-by: Isaac <no-reply@databricks.com>
## Changes Users, and agents acting for them, can't report a CLI problem from the CLI. This adds `databricks feedback [--command "<command>"] MESSAGE`, which sends the message to Databricks from the authenticated workspace. It supersedes databricks#7567 and keeps its behavior. - `--command` names the command the feedback is about, as a free string. Its first word picks the owning team: `air` goes to `ModelTraining.AIRuntime`, `bundle` to `DeveloperEcosystem.CoreDabs`, anything else to `DeveloperEcosystem.DatabricksCLI`. Its words may only use command-name characters, which rejects flags and paths, and it is at most 200 characters. `origin` is the words joined with underscores (`bundle_deploy`). - Each submission is one `fast_feedback_log` event (the in-product feedback widget's) posted to `/telemetry-ext`, using existing fields only; the agent and `--run-id` ride in the user agent. - A detected AI agent needs the user's approval: a prompt when stdin and stderr are terminals, or `--yes` otherwise. The prompt shows the message with invisible characters escaped, the workspace, and every choice sent with it. Declining, including Ctrl-D, prints "Feedback not sent." and exits 1. Humans are not prompted. - The message, flags and approval are checked before authenticating. `--target` is rejected, because the bundle is never loaded. An unquoted message or `--command` gets an error that says what to quote. - The send makes one attempt with SDK retries off and is bounded by 30 s, including a token refresh; the login before it works as for any command. Success prints a reference ID (JSON with `-o json`). A failure names the ID and says whether the feedback was definitely not sent: it failed before a connection was set up or while authenticating, or the server answered 4xx or accepted none of it. - Feedback is sent even with `DATABRICKS_CLI_DISABLE_TELEMETRY` set; the help says so. - `telemetry.Send`, `telemetry.NotSent` and `cmdio.IsErrorTTY` are new, and `DatabricksCliLog` is tagged `omitzero` so a feedback entry carries only `fast_feedback_log` (existing events always set it). ## Why Feedback text is retained centrally, so an agent's text needs the user's approval before it is sent. A retry after an ambiguous failure could file the feedback twice, so the command makes one attempt and reports the ID on failure. ## Decisions to review - `--command` is not looked up in the command tree, which would mean building every command (the tree is lazy since databricks#7487). A typo, an argument or a `databricks` prefix reaches `origin` as typed, and a misspelled `bundle` goes to the CLI team. Keeping only the first word would drop details like `bundle_deploy`. - `Text` is user-authored, which telemetry normally never carries. That is the point of the event, and an agent's text needs the user's approval first. - The prompt reads a plain line and needs only stdin and stderr to be terminals, not `cmdio.IsPromptSupported`, so it also works with `TERM=dumb` and MSYS2 pipes. It escapes invisible characters instead of stripping them like `cmd/air`'s `stripControl`, so the user sees exactly what is sent. - `feedback` is exempt from the aitools install hint, like other one-shot commands. - The single-attempt client repeats the setup in `cmd/air/validateconfig.go`; sharing it would touch `cmd/air` and `experimental/ssh`. ## Tests - `acceptance/cmd/feedback`: routing, the JSON receipt, agent refusal and `--yes`, input errors (including without a login), telemetry disabled, and a broken bundle. - `TestSendMakesOneAttempt`: one request each for success, `numProtoSuccess: 0`, HTTP 403, 500 and 503, and a TCP reset. `TestSendFailingBeforeConnectingIsNotSent`: a refused connection and an untrusted certificate count as not sent. `TestSendTimeoutBoundsTokenAcquisition`: a blocked token source stops at the deadline. - Unit tests cover input checks and quoting hints, approval with `NO_COLOR`, `TERM=dumb` and stderr redirected, escaping, and that a declined or ended prompt sends nothing. The full unit and acceptance suites, `./task lint` and `./task checks` pass locally. - One real submission to a Databricks staging workspace was stored with every field as sent. The acceptance test stays local, because a cloud run would file real feedback on every CI run. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
Changes
Every invocation builds the whole command tree (~1,750 commands and ~3,300 flags) before parsing args. That takes about 4ms of every run, including
databricks version.Top-level commands are now declared as a
root.CommandSpec. The spec holds the fields the root shows in help, completion, and suggestions, plus aBuildfunction. Aroot.Treeadds a placeholder for each spec.Tree.Executeresolves the args and builds only the command they resolve to before running cobra.helpand shell completion still build the full tree.This is enforced by the API:
root.Treeowns the root command. The functions that create and run a bare root command are now private, so commands can only be added as specs and the CLI can only run throughTree.Execute.root.NewCommandpanics ifBuildchanges a field the spec declares, so a placeholder always matches its command.databricks versiondrops from ~11ms to ~6ms (1,000 runs, Linux).Tests
This pull request and its description were written by Isaac.