Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions acceptance/cmd/aitools/auto-install/enable-disable/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ Automatic installation of Databricks AI tools is disabled.
"opted_out": true
}

=== enable clears it
=== enable stores the consent in its place

>>> [CLI] aitools auto-install enable
Automatic installation of Databricks AI tools is enabled.

>>> auto_install_state
{}
{
"consented": true
}

=== enable says when the environment still turns it off

Expand All @@ -46,7 +48,9 @@ Error: no skills or plugins installed
Exit code: 1

>>> auto_install_state
{}
{
"consented": true
}

=== a global uninstall of a mistyped skill leaves it on

Expand All @@ -56,7 +60,9 @@ Error: skill "databricks-tset" is not installed
Exit code: 1

>>> auto_install_state
{}
{
"consented": true
}

=== a global uninstall turns it off

Expand All @@ -74,4 +80,25 @@ Uninstalled 1 skill.
Uninstalled 1 skill.

>>> auto_install_state
{}
{
"consented": true
}

=== a project install stores no consent

>>> auto_install_state
(no auto-install state)

=== a global install stores the consent

>>> auto_install_state
{
"consented": true
}

=== a global install keeps an opt-out

>>> auto_install_state
{
"opted_out": true
}
16 changes: 15 additions & 1 deletion acceptance/cmd/aitools/auto-install/enable-disable/script
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ title "disable stores the opt-out"
trace $CLI aitools auto-install disable
trace auto_install_state

title "enable clears it"
title "enable stores the consent in its place"
trace $CLI aitools auto-install enable
trace auto_install_state

Expand Down Expand Up @@ -41,3 +41,17 @@ cd "${USERPROFILE:-$HOME}/project"
$CLI aitools install --skills-only --scope=project --agents=claude-code &> LOG.install-project
trace $CLI aitools uninstall --scope=project
trace auto_install_state

title "a project install stores no consent"
rm "${USERPROFILE:-$HOME}/.databricks/aitools/auto-install.json"
$CLI aitools install --skills-only --scope=project --agents=claude-code &> LOG.install-project-2
trace auto_install_state

title "a global install stores the consent"
$CLI aitools install --skills-only --scope=global --agents=cursor &> LOG.install-global-2
trace auto_install_state

title "a global install keeps an opt-out"
$CLI aitools auto-install disable &> LOG.disable
$CLI aitools install --skills-only --scope=global --agents=cursor &> LOG.install-global-3
trace auto_install_state
3 changes: 2 additions & 1 deletion acceptance/cmd/aitools/auto-install/first-run/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ databricks-test
>>> auto_install_state
{
"last_version": "1.30.0",
"installed_without_consent": true,
"id": "treatment-machine"
}

Expand Down Expand Up @@ -56,7 +57,7 @@ SKILL.md
my own skill

>>> settled_version
{"last_version":"1.30.0"}
{"last_version":"1.30.0","installed_without_consent":true}

=== first run with the user's own skill under another name in an agent's skills directory: installs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ databricks-test
>>> auto_install_state
{
"last_version": "1.30.0",
"installed_without_consent": true,
"id": "treatment-machine"
}
2 changes: 2 additions & 0 deletions acceptance/cmd/aitools/auto-install/retries/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"attempts": 1,
"last_attempt": "[LAST_ATTEMPT]",
"installing": true,
"installed_without_consent": true,
"id": "treatment-machine"
}

Expand Down Expand Up @@ -51,5 +52,6 @@ Installed Databricks AI tools for Cursor. Disable: databricks aitools auto-insta
>>> auto_install_state
{
"last_version": "1.31.0",
"installed_without_consent": true,
"id": "treatment-machine"
}
2 changes: 2 additions & 0 deletions acceptance/cmd/aitools/auto-install/skipped/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Automatic installation of Databricks AI tools is enabled.
>>> auto_install_state
{
"last_version": "1.32.0",
"consented": true,
"id": "treatment-machine"
}

Expand All @@ -68,6 +69,7 @@ Automatic installation of Databricks AI tools is enabled.
>>> auto_install_state
{
"last_version": "1.33.0",
"consented": true,
"id": "treatment-machine"
}

Expand Down
17 changes: 17 additions & 0 deletions acceptance/cmd/aitools/auto-install/upgrade/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ databricks-dropped
databricks-edited
databricks-kept

>>> auto_install_state
{
"last_version": "1.30.0",
"installed_without_consent": true,
"id": "treatment-machine"
}

=== upgrade to 1.31.0 with release 0.4.0: updates like aitools update, keeping the edited skills

>>> DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.31.0 DATABRICKS_CLI_GITHUB_API_URL=[DATABRICKS_URL]/newer [CLI] jobs list
Expand All @@ -37,6 +44,13 @@ my notes
edited 1.0.0
my notes

>>> auto_install_state
{
"last_version": "1.31.0",
"installed_without_consent": true,
"id": "treatment-machine"
}

=== upgrade to 1.32.0 while the latest release is 0.2.0: no downgrade, nothing printed, not retried

>>> DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.32.0 DATABRICKS_CLI_GITHUB_API_URL=[DATABRICKS_URL]/older [CLI] jobs list
Expand All @@ -50,6 +64,7 @@ kept 2.0.0
>>> auto_install_state
{
"last_version": "1.32.0",
"installed_without_consent": true,
"id": "treatment-machine"
}

Expand All @@ -62,6 +77,7 @@ kept 2.0.0
>>> auto_install_state
{
"last_version": "1.32.0",
"installed_without_consent": true,
"id": "treatment-machine"
}

Expand All @@ -88,5 +104,6 @@ kept 2.0.0
>>> auto_install_state
{
"last_version": "1.33.0",
"consented": true,
"id": "treatment-machine"
}
4 changes: 4 additions & 0 deletions acceptance/cmd/aitools/auto-install/upgrade/script
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ title "first run of 1.30.0 installs skills release 0.3.0"
trace $CLI jobs list
trace print_telemetry
trace cursor_skills
trace auto_install_state

# The user edits a skill that the next release drops, and one that it updates.
echo "my notes" >> "$skills_dir/databricks-dropped/SKILL.md"
Expand All @@ -25,6 +26,9 @@ trace cursor_skills
trace skill_file databricks-kept
trace skill_file databricks-dropped
trace skill_file databricks-edited
# Auto-install made the installation without asking, so it is not the user's
# consent.
trace auto_install_state

title "upgrade to 1.32.0 while the latest release is 0.2.0: no downgrade, nothing printed, not retried"
trace DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.32.0 DATABRICKS_CLI_GITHUB_API_URL=$DATABRICKS_HOST/older $CLI jobs list
Expand Down
6 changes: 5 additions & 1 deletion cmd/aitools/autoinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func newAutoInstallToggleCmd(enable bool) *cobra.Command {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
if err := autoinstall.SetOptedOut(ctx, !enable); err != nil {
consent := autoinstall.ConsentOptedOut
if enable {
consent = autoinstall.ConsentGiven
}
if _, err := autoinstall.SetConsent(ctx, consent); err != nil {
return fmt.Errorf("failed to save the auto-install setting: %w", err)
}
printAutoInstallSetting(ctx, enable)
Expand Down
52 changes: 49 additions & 3 deletions cmd/aitools/autoinstall_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func autoInstall(ctx context.Context, skippedCommand bool) os.Signal {
log.Debugf(ctx, "auto-install: skipped: %v", err)
return nil
}
consentExistingInstall(ctx, &in)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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?

reason := autoinstall.Decide(in)
if !reason.Due() {
log.Debugf(ctx, "auto-install: skipped: %s", reason)
Expand Down Expand Up @@ -402,6 +403,47 @@ func installStateSaved(globalDir string) bool {
return err != nil || existing != nil
}

// consentExistingInstall stores the consent of a machine whose user never
// answered but has a global installation that the CLI made (one with install
// state): the user installed the tools, so auto-install keeps them up to date.
// Skills without install state may be the user's own copies, and a project
// installation belongs to the project, so neither counts. Nor does install
// state that auto-install wrote itself without consent (a coding agent's run,
// or a first install that did not finish). in is a run past stateFreeSkips;
// one in CI or with auto-install turned off in the environment stores nothing.
// in.State gets the stored consent.
func consentExistingInstall(ctx context.Context, in *autoinstall.Inputs) {
if in.CI || in.EnvOptOut || in.State.Consent() != autoinstall.ConsentUnknown {
return
}
if in.State.Installing || in.State.InstalledWithoutConsent {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

return
}
globalDir, err := installer.GlobalSkillsDir(ctx)
if err != nil {
log.Debugf(ctx, "auto-install: could not look for an installation: %v", err)
return
}
existing, err := installer.LoadState(globalDir)
if err != nil {
log.Debugf(ctx, "auto-install: could not look for an installation: %v", err)
return
}
if existing == nil {
return
}
previous, err := autoinstall.GiveConsentIfUnknown(ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread
anton-107 marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

if err != nil {
log.Debugf(ctx, "auto-install: could not save the state: %v", err)
return
}
// 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

}
}

// saveInstallStateDigest records the digest of the install state that a first
// install that did not finish saved, so that a later run can tell it from
// install state that anything else wrote. Without the digest, a later run
Expand Down Expand Up @@ -468,8 +510,8 @@ const skippedNotice = "Skipped. To install Databricks AI tools later, run: datab
// version even when it is never answered: the process is killed, stdin is
// closed, Ctrl+C is pressed, nobody answers within promptTimeout (an
// unrecognized agent in a pseudo-terminal), or the answer is neither yes nor
// no. "Yes" is recorded so that the version's retries do not ask again; only
// "no" stores the opt-out.
// no. "Yes" is recorded so that the version's retries do not ask again, and
// stores the consent; "no" stores the opt-out.
func (r autoInstallRun) ask(ctx context.Context, names []string) (bool, os.Signal) {
if err := cmdio.DiscardInput(ctx); err != nil {
log.Debugf(ctx, "auto-install: could not discard the pending input: %v", err)
Expand Down Expand Up @@ -504,6 +546,10 @@ func (r autoInstallRun) ask(ctx context.Context, names []string) (bool, os.Signa
// The install goes ahead; a retry of it asks again.
log.Debugf(ctx, "auto-install: could not save the answer: %v", err)
}
// The consent stays even if the install then fails or is refused.
if _, err := autoinstall.GiveConsentIfUnknown(ctx); err != nil {
log.Debugf(ctx, "auto-install: could not save the consent: %v", err)
}
return true, nil
case "n", "no":
r.decline(ctx)
Expand All @@ -519,7 +565,7 @@ func (r autoInstallRun) ask(ctx context.Context, names []string) (bool, os.Signa
// asks again.
func (r autoInstallRun) decline(ctx context.Context) {
r.settle(ctx, protos.AitoolsAutoInstallOutcomeDeclined)
if err := autoinstall.Decline(ctx); err != nil {
if _, err := autoinstall.Decline(ctx); err != nil {
log.Warnf(ctx, "Could not save the answer, so a later CLI version asks again: %v", err)
cmdio.LogString(ctx, skippedNotice)
return
Expand Down
Loading
Loading