Repository navigation
aitools: store the consent to install AI tools automatically - #8112
Conversation
## Changes The auto-install state file (`~/.databricks/aitools/auto-install.json`) now records the user's consent alongside the opt-out, as a new `consented` field. The two values together give one answer per machine: unknown, given or opted out (`autoinstall.Consent`). ```diff State opted_out + consented # never set together with opted_out -SetOptedOut(ctx, bool) error +SetConsent(ctx, Consent) (previous Consent, err error) +GiveConsentIfUnknown(ctx) (previous Consent, err error) -Decline(ctx) error +Decline(ctx) (previous Consent, err error) ``` Writers of the consent: | Action | Stores | |---|---| | `databricks aitools auto-install enable` | consent; replaces an opt-out, as before | | `databricks aitools auto-install disable`, a global uninstall, a "no" to a prompt | opt-out, as before | | a global-scope `databricks aitools install` that set at least one agent up | consent, unless the user answered before | | a "yes" to the skills prompt of `databricks apps init` | consent, unless the user answered before | | a run of the auto-install hook that finds global install state written by the CLI | consent, unless the user answered before | `GiveConsentIfUnknown` is for actions that imply consent without asking for it, so it never replaces an earlier opt-out. For the same reason it fails on a state file it can't parse instead of replacing it, because that file may hold an opt-out. `SetConsent` keeps replacing an unreadable file, as `SetOptedOut` did, because it records an explicit choice. The hook infers consent only from install state in the global skills directory. These cases don't count: skills without install state (they may be the user's own copies), a project-scope installation, install state that records only MCP servers, and runs in CI, with the environment opt-out set, or on a development build. `Decide` doesn't change. Auto-install runs, skips and prompts exactly as it did before. ## Why Before this change the state could hold only an opt-out. A machine whose user ran `auto-install enable`, answered "yes", or installed the tools globally looked the same as one whose user had never answered, and `enable` just cleared the opt-out without writing anything. Storing the answer explicitly lets the CLI tell these machines apart. The file stays readable by older CLI versions. A consent is a separate field that they ignore, and an opt-out is still `opted_out: true`, so they read it as before. If the file has both fields set, which only a hand edit can cause, it reads as opted out. ### Note for reviewers: changed expectations in existing tests - `TestAutoInstallFinishesAMixedInstallRefusedTheSkills` (`cmd/aitools/autoinstall_run_test.go`) now expects `Consented: true` in the state after the second and third runs. The first run leaves CLI-written install state in the global skills directory, and later runs now read that as consent. Only the expected `State` values changed. The outcomes and the install assertions are the same as before. - `TestAutoInstallRetriesAnAgentThatGotNoSkills` changed the same way, for the same reason. - The acceptance outputs under `acceptance/cmd/aitools/auto-install/` (`enable-disable`, `skipped`, `upgrade`) now show `"consented": true` where the CLI stores it. - Callers of the old API (`SetOptedOut`, and `Decline`, which now also returns the previous answer) were updated, including `cmd/apps/init_test.go`. ## Tests - `libs/aitools/autoinstall`: `Consent()` covers all combinations of the two fields. Also tested: `SetConsent` transitions and the previous answer it returns, `GiveConsentIfUnknown` (unknown, given, opt-out kept, unreadable file left as is), state files as earlier versions write them, and an older reader decoding the new file. `Decide` has a new case: the environment opt-out wins over a stored consent. - `cmd/aitools`: `TestAutoInstallStoresTheConsentOfAnExistingInstall` covers each case in which the hook does or doesn't infer consent. In every case nothing else in the state changes and no telemetry is sent. `TestInstallStoresTheConsent` checks that a global install stores consent, an opt-out is kept, a project install stores nothing, and an install that set no agent up stores nothing. - `libs/aitools/agents`: a "yes" at the `apps init` prompt stores consent and keeps an earlier opt-out. - Acceptance: `enable-disable` adds the project, global and opt-out-kept install cases, and `upgrade` shows that the consent is stored on the run after the first auto-install. - `go test ./libs/aitools/... ./cmd/aitools/...` and `go test ./acceptance -run TestAccept/cmd/aitools/auto-install` pass locally. Co-authored-by: Isaac <no-reply@databricks.com>
Regression test report ✅Commit: Selected 6 changed tests (limit=20, 0 not selected) 6 tests: regression=6 unreleased=0 coverage=0 failing=0
TestAccept/cmd/aitools/auto-install/enable-disable: branch ✅ | main (b7f1abc) ❌ | latest (v1.28.0) ❌main (b7f1abc): latest (v1.28.0): TestAccept/cmd/aitools/auto-install/first-run: branch ✅ | main (b7f1abc) ❌ | latest (v1.28.0) ❌main (b7f1abc): latest (v1.28.0): TestAccept/cmd/aitools/auto-install/no-terminal: branch ✅ | main (b7f1abc) ❌ | latest (v1.28.0) ❌main (b7f1abc): latest (v1.28.0): TestAccept/cmd/aitools/auto-install/retries: branch ✅ | main (b7f1abc) ❌ | latest (v1.28.0) ❌main (b7f1abc): latest (v1.28.0): TestAccept/cmd/aitools/auto-install/skipped: branch ✅ | main (b7f1abc) ❌ | latest (v1.28.0) ❌main (b7f1abc): latest (v1.28.0): TestAccept/cmd/aitools/auto-install/upgrade: branch ✅ | main (b7f1abc) ❌ | latest (v1.28.0) ❌main (b7f1abc): latest (v1.28.0): |
There was a problem hiding this comment.
Automated review at a8da9d1. Each finding was verified against the code.
Not ready yet: 1 blocking issue(s), tagged [blocking].
This PR adds a consented field to the auto-install state, alongside the opt-out. enable, global installs, the apps init "yes" and the auto-install hook now write it. The blocking problem is that the hook also counts install state written by auto-install's own silent install as consent. After one unprompted run under a coding agent, the next run stores consented: true for a user who was never asked, and that wrong value stays in the file. Also below: the auto-install prompt's own "yes" stores nothing, a dead assignment, and an extra file read on every command.
| if existing == nil { | ||
| return | ||
| } | ||
| previous, err := autoinstall.GiveConsentIfUnknown(ctx) |
There was a problem hiding this comment.
[blocking] Here consentExistingInstall treats any CLI-written global .state.json as consent, including state written by auto-install itself. Under a coding agent, autoInstallAsks() is false, so auto-install runs without asking. The upgrade golden shows the result: the 1.30.0 run installs without asking and stores no consent, and the 1.31.0 run stores "consented": true. TestAutoInstallRetriesAnAgentThatGotNoSkills and TestAutoInstallFinishesAMixedInstallRefusedTheSkills show the same for state left by an unfinished first install. That contradicts the State.Consented doc ("the user agreed"), and once written, the value can't be told apart from a real answer. Can we skip install state that auto-install wrote? For example, infer consent only when no auto-install run has happened yet (in.State.LastVersion == ""), or record when the install state came from an explicit install.
| // "no" to the skills prompt of `databricks apps init`. | ||
| OptedOut bool `json:"opted_out,omitempty"` | ||
|
|
||
| // Consented records that the user agreed to installing the tools and |
There was a problem hiding this comment.
[nice to have] The auto-install prompt is the one question that asks about auto-install directly, but its "yes" (autoInstallRun.ask in cmd/aitools/autoinstall_run.go) only calls Accept, while its "no" now goes through Decline and stores the opt-out. A "yes" followed by a failed or refused install leaves consent unknown, while the apps init "yes" stores it before installing. Should the "yes" branch call GiveConsentIfUnknown too, and should this doc list it as a writer?
| log.Debugf(ctx, "auto-install: skipped: %v", err) | ||
| return nil | ||
| } | ||
| consentExistingInstall(ctx, &in) |
There was a problem hiding this comment.
[nice to have] This now runs before the !reason.Due() return. On a settled machine (ReasonAlreadyRan) whose consent is unknown, every command also resolves GlobalSkillsDir and reads the global .state.json, which the base skipped. Machines that never installed globally stay unknown forever, so they pay this on every command. Can this move after the Due() check, or is inferring consent on runs that do nothing worth the cost?
| // An opt-out stored since the state was read stays, and the run finds it | ||
| // when it reads the state again under the run lock. | ||
| if previous != autoinstall.ConsentOptedOut { | ||
| in.State.Consented = true |
There was a problem hiding this comment.
[nit] Nothing reads this. Decide doesn't look at Consented, and in.State is reloaded under the run lock (line 219) before the run acts on it. Drop the assignment, along with "in.State gets the stored consent" in the doc comment, unless something is meant to read it.
✅ Integration test reportCommit: 6175820
Top 6 slowest tests (at least 2 minutes):
|
Auto-install marks a first install it starts before the user answered, and the consent inference skips install state it wrote that way or left unfinished. A "yes" at the install prompt now stores the consent too. Co-authored-by: Isaac <no-reply@databricks.com>
| if in.CI || in.EnvOptOut || in.State.Consent() != autoinstall.ConsentUnknown { | ||
| return | ||
| } | ||
| if in.State.Installing || in.State.InstalledWithoutConsent { |
There was a problem hiding this comment.
[non-blocking] CLI 1.27 and 1.28 ship auto-install but never write installed_without_consent, so if the gate is ever turned on for a range that includes them, the install state their coding-agent runs leave is read here as the user's consent on the next upgrade. Either skip the inference when LastVersion predates the flag, or make sure the gate is only ever turned on from the version that records it.
| // An opt-out stored since the state was read stays, and the run finds it | ||
| // when it reads the state again under the run lock. | ||
| if previous != autoinstall.ConsentOptedOut { | ||
| in.State.Consented = true |
There was a problem hiding this comment.
[non-blocking] I agree with #8112 (comment). Nothing reads in.State.Consented between this assignment and the reload under the run lock, so the assignment, the previous-answer branch around it and the "in.State gets the stored consent" sentence in the doc comment are dead.
simonfaltum
left a comment
There was a problem hiding this comment.
Reviewed 6175820aa74eab1ff48d3367cc9a6b7c46cf7875. This merged before I posted, so these are follow-up findings.
Two scenarios can still record consented: true without a user agreeing:
- Concurrent automatic installation: the new inline comment describes a stale-state race that bypasses the provenance markers.
- Legacy automatic installation: already raised by @rclarey in #8112 (comment). A successful unprompted install from a CLI without
installed_without_consentis indistinguishable from a manual install here. This matters if auto-install is enabled for those older versions, or an older writer drops the marker.
Both scenarios reproduced in temporary tests: consent should have stayed unknown, but the stored value was ConsentGiven. The concurrency reproduction also cleared InstalledWithoutConsent while Installing remained true.
The existing non-blocking observations about the extra install-state read and unused assignment remain covered by #8112 (comment) and #8112 (comment). The prompt's “yes” now saving consent is fixed.
Validation: the autoinstall and agents library tests passed. The command suite had an unrelated picker-layout failure that also reproduced in isolation. Four of five review sources completed; the independent Codex review was unavailable.
| if existing == nil { | ||
| return | ||
| } | ||
| previous, err := autoinstall.GiveConsentIfUnknown(ctx) |
There was a problem hiding this comment.
[blocking] Recheck provenance atomically before inferring consent. The checks above use state loaded before the run lock. Process A can read an unknown state with neither marker set; process B can then start an unprompted install, set Installing and InstalledWithoutConsent, and save global install state. A now finds that install state and calls GiveConsentIfUnknown, which reloads the file but checks only Consent(): it writes Consented=true and clears InstalledWithoutConsent, even though nobody agreed.
I reproduced this interleaving with a temporary test; the resulting state was Consented:true, Installing:true, InstalledWithoutConsent:false.
Please recheck both provenance markers under the state lock in an inference-specific update, or acquire the run lock and reload before inferring. Explicit installation and prompt writers should still be able to clear the marker.
| home := t.TempDir() | ||
| ctx := env.WithUserHomeDir(t.Context(), home) | ||
| path := filepath.Join(home, ".databricks", "aitools", stateFileName) | ||
| readOlder := func() olderState { |
There was a problem hiding this comment.
[nit] .agents/rules/style-guide-go.md asks for a regular named function instead of an inline closure used only to name a repeated operation. Could readOlder be a test helper taking testing.T and the state path?
Changes
The auto-install state file (
~/.databricks/aitools/auto-install.json) now records the user's consent alongside the opt-out, as a newconsentedfield. The two values together give one answer per machine: unknown, given or opted out (autoinstall.Consent).Writers of the consent:
databricks aitools auto-install enabledatabricks aitools auto-install disable, a global uninstall, a "no" to a promptdatabricks aitools installthat set at least one agent updatabricks apps initGiveConsentIfUnknownis for actions that imply consent without asking for it, so it never replaces an earlier opt-out. For the same reason it fails on a state file it can't parse instead of replacing it, because that file may hold an opt-out.SetConsentkeeps replacing an unreadable file, asSetOptedOutdid, because it records an explicit choice.The hook infers consent only from install state in the global skills directory. These cases don't count: skills without install state (they may be the user's own copies), a project-scope installation, install state that records only MCP servers, and runs in CI, with the environment opt-out set, or on a development build.
Decidedoesn't change. Auto-install runs, skips and prompts exactly as it did before.Why
Before this change the state could hold only an opt-out. A machine whose user ran
auto-install enable, answered "yes", or installed the tools globally looked the same as one whose user had never answered, andenablejust cleared the opt-out without writing anything. Storing the answer explicitly lets the CLI tell these machines apart.The file stays readable by older CLI versions. A consent is a separate field that they ignore, and an opt-out is still
opted_out: true, so they read it as before. If the file has both fields set, which only a hand edit can cause, it reads as opted out.Note for reviewers: changed expectations in existing tests
TestAutoInstallFinishesAMixedInstallRefusedTheSkills(cmd/aitools/autoinstall_run_test.go) now expectsConsented: truein the state after the second and third runs. The first run leaves CLI-written install state in the global skills directory, and later runs now read that as consent. Only the expectedStatevalues changed. The outcomes and the install assertions are the same as before.TestAutoInstallRetriesAnAgentThatGotNoSkillschanged the same way, for the same reason.acceptance/cmd/aitools/auto-install/(enable-disable,skipped,upgrade) now show"consented": truewhere the CLI stores it.SetOptedOut, andDecline, which now also returns the previous answer) were updated, includingcmd/apps/init_test.go.Tests
libs/aitools/autoinstall:Consent()covers all combinations of the two fields. Also tested:SetConsenttransitions and the previous answer it returns,GiveConsentIfUnknown(unknown, given, opt-out kept, unreadable file left as is), state files as earlier versions write them, and an older reader decoding the new file.Decidehas a new case: the environment opt-out wins over a stored consent.cmd/aitools:TestAutoInstallStoresTheConsentOfAnExistingInstallcovers each case in which the hook does or doesn't infer consent. In every case nothing else in the state changes and no telemetry is sent.TestInstallStoresTheConsentchecks that a global install stores consent, an opt-out is kept, a project install stores nothing, and an install that set no agent up stores nothing.libs/aitools/agents: a "yes" at theapps initprompt stores consent and keeps an earlier opt-out.enable-disableadds the project, global and opt-out-kept install cases, andupgradeshows that the consent is stored on the run after the first auto-install.go test ./libs/aitools/... ./cmd/aitools/...andgo test ./acceptance -run TestAccept/cmd/aitools/auto-installpass locally.