Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Automatic installation of Databricks AI tools no longer moves skills you installed from a newer release (for example with `DATABRICKS_SKILLS_REF`) back to the older release this CLI version is pinned to, and no longer reports that as "Updated"; it leaves them alone. `databricks aitools update` still installs the pinned release when you run it. ([#7888](https://github.com/databricks/cli/pull/7888))
7 changes: 4 additions & 3 deletions acceptance/cmd/aitools/auto-install/script.prepare
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ use_home() {
echo "{\"id\": \"${2:-treatment-machine}\"}" > "${USERPROFILE:-$HOME}/.databricks/aitools/auto-install.json"
}

# gate true|false writes a compatibility manifest into the CLI cache with that
# auto_install flag. A fresh cache file replaces the remote manifest.
# gate true|false [SKILLS] writes a compatibility manifest into the CLI cache
# with that auto_install flag and skills version SKILLS (default: latest). A
# fresh cache file replaces the remote manifest.
gate() {
"$mkdir_bin" -p "$DATABRICKS_CACHE_DIR"
echo "{\"0.0.0\": {\"appkit\": \"0.84.0\", \"skills\": \"latest\", \"auto_install\": $1}}" > "$DATABRICKS_CACHE_DIR/compat-manifest.json"
echo "{\"0.0.0\": {\"appkit\": \"0.84.0\", \"skills\": \"${2:-latest}\", \"auto_install\": $1}}" > "$DATABRICKS_CACHE_DIR/compat-manifest.json"
}

# cursor_skills lists the skills installed for Cursor.
Expand Down
26 changes: 26 additions & 0 deletions acceptance/cmd/aitools/auto-install/upgrade/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,29 @@ kept 2.0.0
"last_version": "1.32.0",
"id": "treatment-machine"
}

>>> DATABRICKS_SKILLS_REF=v0.4.0 [CLI] aitools install --skills-only --scope=global --agents=cursor
Installing Databricks skills for Cursor...
Using skills version 0.4.0
Fetching skills manifest...
Installed 2 skills in [TEST_TMP_DIR]/pinned-home/.databricks/aitools/skills.

=== upgrade to 1.33.0 pinned to 0.3.0 over an explicit 0.4.0 install: no downgrade, nothing printed, not retried

>>> DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.33.0 [CLI] jobs list

>>> print_telemetry
{"command":"jobs_list","exit_code":0,"aitools_auto_install_event":{"outcome":"KEPT","holdout_arm":"TREATMENT","interactive":false}}

>>> cursor_skills
databricks-edited
databricks-kept

>>> skill_file databricks-kept
kept 2.0.0

>>> auto_install_state
{
"last_version": "1.33.0",
"id": "treatment-machine"
}
15 changes: 15 additions & 0 deletions acceptance/cmd/aitools/auto-install/upgrade/script
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ title "an older CLI on the same machine (e.g. one an IDE ships) does nothing"
trace DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.31.0 $CLI jobs list
trace print_telemetry
trace auto_install_state

# The user pinned release 0.4.0 with an explicit install. The compatibility
# manifest pins this CLI to the older 0.3.0, as it pins released CLIs.
use_home pinned-home
skills_dir="${USERPROFILE:-$HOME}/.databricks/aitools/skills"
trace DATABRICKS_SKILLS_REF=v0.4.0 $CLI aitools install --skills-only --scope=global --agents=cursor
print_telemetry > /dev/null

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] .agents/rules/testing.md says to send output you don't want in the golden to LOG.<name>, not /dev/null. As written, the telemetry from the setup install is lost even under go test -v. print_telemetry > LOG.install_telemetry still clears it and keeps it out of output.txt.

gate true 0.3.0

title "upgrade to 1.33.0 pinned to 0.3.0 over an explicit 0.4.0 install: no downgrade, nothing printed, not retried"
trace DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.33.0 $CLI jobs list
trace print_telemetry
trace cursor_skills
trace skill_file databricks-kept
trace auto_install_state
2 changes: 2 additions & 0 deletions acceptance/cmd/aitools/auto-install/upgrade/test.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Ignore = ["pinned-home"]

# Skills releases: the latest release is v0.3.0, under /newer it is v0.4.0 and
# under /older it is v0.2.0 (DATABRICKS_CLI_GITHUB_API_URL picks one).

Expand Down
46 changes: 46 additions & 0 deletions cmd/aitools/autoinstall_plan_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package aitools

import (
"context"
"errors"
"maps"
"os"
"path/filepath"
Expand All @@ -9,6 +11,7 @@ import (
"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/libs/aitools/autoinstall"
"github.com/databricks/cli/libs/aitools/installer"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/telemetry/protos"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -161,3 +164,46 @@ func TestSkipsAutoInstall(t *testing.T) {
assert.False(t, skipsAutoInstall(cmd), cmd.CommandPath())
}
}

// The update runs the plugin updates before it refuses the raw skills, so a
// refusal still reports the plugins it updated.
func TestUpdateToolsReportsPluginsUpdatedBeforeARefusal(t *testing.T) {
autoInstallHome(t)
noTelemetryAuth(t)
t.Setenv("DATABRICKS_SKILLS_REF", "v0.3.0")
resetUpdatePluginSeams(t)
dir := saveGlobalState(t, map[string]string{"databricks-sql": "0.1.0"})
before, err := installer.LoadState(dir)
require.NoError(t, err)

origUpdateSkills := updateSkillsFn
t.Cleanup(func() { updateSkillsFn = origUpdateSkills })
updateSkillsFn = func(context.Context, installer.ManifestSource, []*agents.Agent, installer.UpdateOptions) (*installer.UpdateResult, error) {
return nil, &installer.RefusedError{Err: errors.New("keeping the installed skills")}
}
pluginUpdated := false
updatePluginsFn = func(context.Context, string, string) ([]installer.PluginUpdate, error) {
if !pluginUpdated {
return nil, nil
}
state, err := installer.LoadState(dir)
require.NoError(t, err)
rec := state.Plugins[agents.NameClaudeCode]
rec.Version = "0.3.0"
state.Plugins[agents.NameClaudeCode] = rec
require.NoError(t, installer.SaveState(dir, state))
return []installer.PluginUpdate{{Agent: "Claude Code", Version: "0.3.0"}}, nil
}
ctx := cmdio.MockDiscard(t.Context())

// Nothing changed: the refusal is returned, which auto-install reports
// as kept.
_, err = updateTools(ctx, dir, before)
assert.ErrorAs(t, err, new(*installer.RefusedError))

pluginUpdated = true
result, err := updateTools(ctx, dir, before)
require.NoError(t, err)
assert.Equal(t, protos.AitoolsAutoInstallOutcomeInstalled, result.outcome)
assert.Equal(t, []string{"Claude Code"}, result.agents)
}
22 changes: 16 additions & 6 deletions cmd/aitools/autoinstall_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,9 @@ func (t toolsPlan) fresh() bool {
// planTools plans what `databricks aitools install --scope=global` runs
// without prompts, for the agents whose config directory exists. An existing
// global installation is updated as `databricks aitools update --scope=global`
// does instead, which keeps its downgrade guard, keeps the skills whose files
// the user modified at their version, and does not migrate skills to plugins.
// does instead, which keeps its downgrade guard, also keeps an installed
// release newer than a pinned one, keeps the skills whose files the user
// modified at their version, and does not migrate skills to plugins.
// Planning reads only local state; prior is the auto-install state.
func planTools(ctx context.Context, prior autoinstall.State) (toolsPlan, error) {
globalDir, err := installer.GlobalSkillsDir(ctx)
Expand Down Expand Up @@ -627,8 +628,12 @@ func updateTools(ctx context.Context, globalDir string, before *installer.Instal
uctx := telemetry.WithNewLogger(ctx)
uctx = context.WithValue(uctx, funnelKey{}, &commandFunnel{command: protos.AitoolsCommandUpdate})
uctx = context.WithValue(uctx, telemetryAuthKey{}, &telemetryAuth{})
if err := runUpdate(uctx, updateFlags{scope: installer.ScopeGlobal, keepModified: true}); err != nil {
return installResult{}, err
updateErr := runUpdate(uctx, updateFlags{scope: installer.ScopeGlobal, keepModified: true})
// The update refuses the raw skills after it updated the plugins, so a
// refusal still reports the plugins it changed.
_, refused := errors.AsType[*installer.RefusedError](updateErr)
if updateErr != nil && !refused {
return installResult{}, updateErr
}
after, err := installer.LoadState(globalDir)
if err != nil {
Expand All @@ -638,9 +643,14 @@ func updateTools(ctx context.Context, globalDir string, before *installer.Instal
if after != nil {
result.agents = changedAgents(ctx, before, after)
}
if len(result.agents) > 0 {
result.outcome = protos.AitoolsAutoInstallOutcomeInstalled
if len(result.agents) == 0 {
// Nothing changed: the caller reports a refusal as kept.
return result, updateErr
}
if refused {
log.Debugf(ctx, "auto-install: kept the installed skills: %v", updateErr)
}
result.outcome = protos.AitoolsAutoInstallOutcomeInstalled
return result, nil
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/aitools/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ type updateFlags struct {
project, global bool
// keepModified is not a flag: auto-install sets it (see
// installer.UpdateOptions.KeepModified). It also keeps the raw skills of
// agents that have, or could get, the plugin.
// agents that have, or could get, the plugin, and refuses a downgrade
// (installer.UpdateOptions.NoDowngrade).
keepModified bool
}

Expand Down Expand Up @@ -219,6 +220,7 @@ func runUpdate(ctx context.Context, f updateFlags) error {
Scope: scope,

KeepModified: f.keepModified,
NoDowngrade: f.keepModified,

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] NoDowngrade only reaches the raw-skills reconcile, but updatePluginsFn(ctx, scope, ref) (line 182) runs first with the same pinned ref and no downgrade check. Take a mixed global install where Claude Code has the plugin and Cursor has raw skills from v0.4.0, with the manifest pinning this CLI to 0.3.0. Auto-install runs the plugin update, UpdateInstalledPlugins saves the record as 0.3.0 and line 195 prints it. Then UpdateSkills returns RefusedError and the run is reported as KEPT. Can the refusal be decided before the plugin step when keepModified is set (compare ref with the installed release up front), so a refused run changes nothing?

}
opts.Skills = skills

Expand Down
2 changes: 1 addition & 1 deletion internal/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ An entry can also set `"auto_install": true` to turn on the automatic installati

This skills fallback only applies to raw-file delivery. Version checks omit update availability when latest is unknown, and plugin operations don't substitute the fallback version.

Raw-skills updates and reinstalls reject automatic downgrades, including with `--force`: the fallback must be at least as new as the installed release. Existing installs without a comparable release require a successful latest-release fetch. Explicit `DATABRICKS_SKILLS_REF` overrides and compatibility pins can still select an older release.
Raw-skills updates and reinstalls reject automatic downgrades, including with `--force`: the fallback must be at least as new as the installed release. Existing installs without a comparable release require a successful latest-release fetch. Explicit `DATABRICKS_SKILLS_REF` overrides and compatibility pins can still select an older release, except in automatic installation: it keeps an installed release newer than the pinned one, which `databricks aitools update` still installs.

CLIs before `1.6.0` reject the whole remote manifest when any entry uses `"latest"`, even an entry they never resolve to. They use a valid cached manifest or their embedded manifest without returning a parse error. These CLIs stop receiving remote compatibility updates for both AppKit and skills.

Expand Down
13 changes: 13 additions & 0 deletions libs/aitools/installer/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type UpdateOptions struct {
// no record to check against), instead of replacing it. Automatic updates
// set it: they must never overwrite what the user changed.
KeepModified bool

// NoDowngrade refuses a release older than the installed one even when
// the ref is pinned (by DATABRICKS_SKILLS_REF or the compatibility
Comment thread
anton-107 marked this conversation as resolved.
Resolved
// manifest). A pinned branch or commit SHA is still installed. Automatic
// updates set it: a newer release the user installed is theirs to roll
// back.
NoDowngrade bool
}

// UpdateResult describes what UpdateSkills did (or would do in check mode).
Expand Down Expand Up @@ -109,6 +116,12 @@ func UpdateSkills(ctx context.Context, src ManifestSource, targetAgents []*agent
return &UpdateResult{Unchanged: slices.Sorted(maps.Keys(state.Skills))}, nil
}

// A pinned ref is the ref installed, so it is compared before fetching its
// manifest. A branch or commit SHA has no release order to compare.
if explicit && opts.NoDowngrade && semver.IsValid(latestTag) && semver.Compare(latestTag, installedRef) < 0 {
return nil, &RefusedError{Err: fmt.Errorf("keeping the installed skills %s, which are newer than the pinned %s; run 'databricks aitools update' to install %s", DisplaySkillsVersion(installedRef), DisplaySkillsVersion(latestTag), DisplaySkillsVersion(latestTag))}
}

manifest, latestTag, err := FetchSkillsManifestWithFallback(ctx, src, latestTag, allowFallback && !explicit)
if err != nil {
if opts.Check {
Expand Down
68 changes: 68 additions & 0 deletions libs/aitools/installer/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package installer
import (
"bytes"
"context"
"errors"
"io/fs"
"log/slog"
"os"
Expand Down Expand Up @@ -163,6 +164,73 @@ func TestUpdateKeepModifiedKeepsEditedSkill(t *testing.T) {
assert.Equal(t, "0.2.0", state.Skills["databricks-jobs"])
}

func TestUpdateNoDowngradeRefusesAnOlderPinnedRelease(t *testing.T) {
Comment thread
anton-107 marked this conversation as resolved.
Resolved
tmp := setupTestHome(t)
ctx := cmdio.MockDiscard(t.Context())
setupFetchMock(t)
t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.0")

src := &mockManifestSource{manifest: testManifest()}
agent := testAgent(tmp)
require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{agent}, InstallOptions{}))

// A pinned older release, as the compatibility manifest pins one. It is
// refused before its manifest is fetched.
t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef)
unfetchable := &mockManifestSource{fetchErr: errors.New("the manifest was fetched")}
_, err := UpdateSkills(ctx, unfetchable, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true})
assert.ErrorAs(t, err, new(*RefusedError))
assert.ErrorContains(t, err, "keeping the installed skills 0.2.0, which are newer than the pinned 0.1.5; run 'databricks aitools update' to install 0.1.5")
globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills")
state, err := LoadState(globalDir)
require.NoError(t, err)
assert.Equal(t, "v0.2.0", state.Release)

// Without it, the pinned ref is the user's choice.
_, err = UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{})
require.NoError(t, err)
state, err = LoadState(globalDir)
require.NoError(t, err)
assert.Equal(t, testSkillsRef, state.Release)
}

func TestUpdateNoDowngradeInstallsANewerPinnedRelease(t *testing.T) {
tmp := setupTestHome(t)
ctx := cmdio.MockDiscard(t.Context())
setupFetchMock(t)
t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef)

src := &mockManifestSource{manifest: testManifest()}
agent := testAgent(tmp)
require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{agent}, InstallOptions{}))

t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.0")
_, err := UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true})
require.NoError(t, err)
state, err := LoadState(filepath.Join(tmp, ".databricks", "aitools", "skills"))
require.NoError(t, err)
assert.Equal(t, "v0.2.0", state.Release)
}

func TestUpdateNoDowngradeInstallsAPinnedBranch(t *testing.T) {
tmp := setupTestHome(t)
ctx := cmdio.MockDiscard(t.Context())
setupFetchMock(t)
t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.0")

src := &mockManifestSource{manifest: testManifest()}
agent := testAgent(tmp)
require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{agent}, InstallOptions{}))

// A branch has no release order, so it is not a downgrade.
t.Setenv("DATABRICKS_SKILLS_REF", "main")
_, err := UpdateSkills(ctx, src, []*agents.Agent{agent}, UpdateOptions{NoDowngrade: true})
require.NoError(t, err)
state, err := LoadState(filepath.Join(tmp, ".databricks", "aitools", "skills"))
require.NoError(t, err)
assert.Equal(t, "main", state.Release)
}

func TestUpdateCheckDryRun(t *testing.T) {
tmp := setupTestHome(t)
ctx := cmdio.MockDiscard(t.Context())
Expand Down
Loading