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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `databricks aitools install` now installs plugins for the other coding agents even when installing skill files fails. ([#7479](https://github.com/databricks/cli/pull/7479))
44 changes: 32 additions & 12 deletions cmd/aitools/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,17 +607,18 @@ func executePlan(ctx context.Context, src installer.ManifestSource, plan []agent
var outcomes []agentOutcome
var explicitErrs []error

// A skills install runs as a group; its failure is the command's top-level
// error. Plugin agents don't depend on it, so they are still attempted.
var skillsErr error
if len(skillsAgents) > 0 {
if !quiet {
installer.PrintInstallingFor(ctx, skillsAgents)
}
// A skills install runs as a group; on failure the whole command fails and
// the top-level error category classifies it.
if err := installSkillsForAgentsFn(ctx, src, skillsAgents, opts); err != nil {
return outcomes, err
}
for _, a := range skillsAgents {
outcomes = append(outcomes, agentOutcome{agent: a, delivery: deliverySkills, status: outcomeInstalled})
skillsErr = installSkillsForAgentsFn(ctx, src, skillsAgents, opts)
if skillsErr == nil {
for _, a := range skillsAgents {
outcomes = append(outcomes, agentOutcome{agent: a, delivery: deliverySkills, status: outcomeInstalled})
}
}
}

Expand Down Expand Up @@ -664,9 +665,22 @@ func executePlan(ctx context.Context, src installer.ManifestSource, plan []agent
cmdio.LogString(ctx, fmt.Sprintf(" %s databricks plugin %s", it.agent.DisplayName, versionToken(rec.Version)))
}
}
if len(records) > 0 {
if err := recordPluginInstallsFn(ctx, opts.Scope, records, ref); err != nil {
return outcomes, err
if len(records) > 0 && skillsErr != nil && installer.HasUntrackedSkills(ctx, opts.Scope) {
// Skills with no state file are on disk (an install that predates
// state tracking, or an interrupted first install). A state file
// holding only these plugins would hide those skills from update and
// from the install's legacy checks, so leave recording to the next
// install whose skills step succeeds.
log.Debugf(ctx, "Not recording plugin installs: skills without install state are on disk")
} else if len(records) > 0 {
// After a skills failure the skills on disk stay at the old release,
// so record the plugins without advancing state.Release.
releaseRef := ref
if skillsErr != nil {
releaseRef = ""
}
if err := recordPluginInstallsFn(ctx, opts.Scope, records, releaseRef); err != nil {

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.

[nice to have] On a machine with raw skills from an install that predates state tracking (no .state.json), a skills failure now leads RecordPluginInstalls to create a state file holding only the plugin and an empty Skills map. After that, aitools update treats the scope as plugin-only (state == nil || len(state.Skills) > 0, cmd/aitools/update.go:171) and exits 0 with no output. Before this PR it printed "found skills from a previous install without state tracking; run 'databricks aitools install' to refresh before updating", so Cursor's legacy skills now silently stop being updated. The new state also turns off the legacyInstall guards in InstallSkillsForAgents (libs/aitools/installer/installer.go:367-373): the block on --skills installs and the ban on the embedded-manifest fallback.

Example: legacy skills on disk, aitools install --agents cursor,claude-code --scope global hits a manifest 503, then aitools update does nothing. I checked this with a scratch test: with the base install.go, update returns the legacy error; at this head it returns nil and never calls updateSkillsFn. A plugin-only install already has this gap, but with this PR a run that was asked to install skills for Cursor, and failed, ends up there too.

Suggest not creating a new state file from the skills-failure path when raw skills are already on disk without state (for example, an option on RecordPluginInstalls backed by hasLegacyInstall), or running the legacy check in update when the state has plugins but no skills. A test that starts from a legacy skills dir with no state file would pin this down.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed with your first suggestion. New installer.HasUntrackedSkills(ctx, scope) reports skills on disk from an install that predates state tracking (global scope, no state file, hasLegacyInstall). When the skills install failed and that is true, executePlan installs the plugins but doesn't call RecordPluginInstalls, so no plugin-only state file is created. aitools update then still returns the "found skills from a previous install without state tracking" error, and the --skills block and the embedded-manifest fallback ban in InstallSkillsForAgents stay in effect. The plugin is recorded by the next install whose skills step succeeds.

New test TestExecutePlanSkillsFailureKeepsUntrackedSkillsVisible starts from a legacy skills dir with no state file and a manifest 503. It checks that the plugin is installed, that no state file exists afterwards, and that HasUntrackedSkills is still true. Without the guard, it fails on the plugin-only state file.

I left the pre-existing plugin-only gap (a successful plugin-only install on a machine with legacy skills) unchanged, because it's outside this PR's change.

Commit: d0d5fc2

return outcomes, errors.Join(skillsErr, err)

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.

[nice to have] Skill files and plugin records share one state file per scope. When the skills install fails because that state file cannot be read or parsed, the plugin step still runs marketplace add and plugin install. Then this call fails on the same state file. The plugin is installed but not recorded, so update and uninstall do not manage it, and the JSON output reports it as installed. Before this PR, such a run changed nothing. Go on to the plugins only when the skills step failed on a fetch (*installer.FetchError). Add a test that does not stub recordPluginInstallsFn. In the legacy case at line 668 the plugin is also left unrecorded, on purpose, but only a debug log says so. Print a warning there that tells the user to re-run databricks aitools install.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, both parts are real gaps. This PR is already approved with the current behavior, so I'd like to handle them in a follow-up instead of changing the gate here:

  • Go on to the plugin step only when the skills step failed on a fetch (*installer.FetchError). That way an unreadable or invalid state file stops the run before marketplace add / plugin install. Add a test that runs the real RecordPluginInstalls.
  • Print a warning in the untracked-skills branch that tells the user to re-run databricks aitools install, instead of only a debug log.

For now, in the state-file case the command still fails: the returned error joins the skills error and the state error.

}
}
}
Expand Down Expand Up @@ -695,6 +709,11 @@ func executePlan(ctx context.Context, src installer.ManifestSource, plan []agent
cmdio.LogString(ctx, fmt.Sprintf("Installed the plugin for %d %s.", pluginCount, noun))
}

// The skills error has no per-agent entry, so it stays the top-level error;
// explicit per-agent failures are already in their outcomes.
if skillsErr != nil {
return outcomes, skillsErr
}
if len(explicitErrs) > 0 {
return outcomes, &agentErrors{err: errors.Join(explicitErrs...)}
}
Expand Down Expand Up @@ -740,8 +759,9 @@ func buildInstallOutput(scope string, outcomes []agentOutcome, runErr error) ins
}
// A top-level failure (skills-group install, plugin recording) has no
// per-agent entry, so surface it here too; otherwise the consumer sees a
// non-zero exit with an empty agents array and no reason. Per-agent failures
// stay in the agents entries above and are not repeated here.
// non-zero exit with no reason, and the agents array holds at most the
// plugin agents that were still installed. Per-agent failures stay in the
// agents entries above and are not repeated here.
if e := topLevelFailure(runErr); e != nil {
out.Error = e.Error()
out.ErrorCategory = string(classifyInstallError(e))
Expand Down
123 changes: 120 additions & 3 deletions cmd/aitools/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,122 @@ func TestExecutePlanPluginWithUnresolvedSkillsRelease(t *testing.T) {
assert.Empty(t, recordRef)
}

func TestExecutePlanSkillsFailureStillInstallsPlugins(t *testing.T) {
setupTestAgents(t) // temp HOME for the real state file below
t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6")
plugins := setupPluginMock(t)
recordPluginInstallsFn = installer.RecordPluginInstalls
origSkills := installSkillsForAgentsFn
origCleanup := cleanupLegacyFn
t.Cleanup(func() { installSkillsForAgentsFn = origSkills; cleanupLegacyFn = origCleanup })
cleanupLegacyFn = func(context.Context, *agents.Agent, string) error { return nil }
fetchErr := &installer.FetchError{Stage: installer.FetchStageManifest, StatusCode: 503, Err: errors.New("failed to fetch manifest: HTTP 503")}
installSkillsForAgentsFn = func(context.Context, installer.ManifestSource, []*agents.Agent, installer.InstallOptions) error {
return fetchErr
}

ctx := cmdio.MockDiscard(t.Context())
// Cursor's skills are at v0.2.5 from an earlier install.
dir, err := installer.GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, installer.SaveState(dir, &installer.InstallState{
SchemaVersion: 2,
Release: "v0.2.5",
Skills: map[string]string{"databricks": "0.2.5"},
}))

claude := testPluginAgent(agents.NameClaudeCode, "Claude Code", "claude")
cursor := &agents.Agent{Name: agents.NameCursor, DisplayName: "Cursor"}
plan := buildPlan([]*agents.Agent{cursor, claude}, installer.ScopeGlobal, false, false)
outcomes, err := executePlan(ctx, nil, plan, installer.InstallOptions{Scope: installer.ScopeGlobal}, false)

// The skills failure is still the command's error, but it no longer stops
// Claude Code's plugin install.
require.ErrorIs(t, err, fetchErr)
require.Len(t, *plugins, 1)
require.Len(t, outcomes, 1)
assert.Equal(t, agents.NameClaudeCode, outcomes[0].agent.Name)
assert.Equal(t, outcomeInstalled, outcomes[0].status)

// The plugin is recorded, but the release stays at the skills' v0.2.5 so
// version and update don't report the old skills as up to date.
state, err := installer.LoadState(dir)
require.NoError(t, err)
assert.Contains(t, state.Plugins, agents.NameClaudeCode)
assert.Equal(t, "v0.2.5", state.Release)
}

func TestExecutePlanSkillsFailureKeepsUntrackedSkillsVisible(t *testing.T) {
setupTestAgents(t)
t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6")
plugins := setupPluginMock(t)
recordPluginInstallsFn = installer.RecordPluginInstalls
origSkills := installSkillsForAgentsFn
origCleanup := cleanupLegacyFn
t.Cleanup(func() { installSkillsForAgentsFn = origSkills; cleanupLegacyFn = origCleanup })
cleanupLegacyFn = func(context.Context, *agents.Agent, string) error { return nil }
fetchErr := &installer.FetchError{Stage: installer.FetchStageManifest, StatusCode: 503, Err: errors.New("failed to fetch manifest: HTTP 503")}
installSkillsForAgentsFn = func(context.Context, installer.ManifestSource, []*agents.Agent, installer.InstallOptions) error {
return fetchErr
}

ctx := cmdio.MockDiscard(t.Context())
// Skills from an install that predates state tracking: on disk, no state file.
dir, err := installer.GlobalSkillsDir(ctx)
require.NoError(t, err)
require.NoError(t, os.MkdirAll(filepath.Join(dir, "databricks"), 0o755))
require.True(t, installer.HasUntrackedSkills(ctx, installer.ScopeGlobal))

claude := testPluginAgent(agents.NameClaudeCode, "Claude Code", "claude")
cursor := &agents.Agent{Name: agents.NameCursor, DisplayName: "Cursor"}
plan := buildPlan([]*agents.Agent{cursor, claude}, installer.ScopeGlobal, false, false)
outcomes, err := executePlan(ctx, nil, plan, installer.InstallOptions{Scope: installer.ScopeGlobal}, false)

require.ErrorIs(t, err, fetchErr)
require.Len(t, *plugins, 1)
require.Len(t, outcomes, 1)
assert.Equal(t, outcomeInstalled, outcomes[0].status)

// No plugin-only state file is created, so update still reports the
// untracked skills instead of treating the scope as plugin-only.
state, err := installer.LoadState(dir)
require.NoError(t, err)
assert.Nil(t, state)
assert.True(t, installer.HasUntrackedSkills(ctx, installer.ScopeGlobal))
}

func TestExecutePlanSkillsAndStateWriteFailuresAreJoined(t *testing.T) {
setupTestAgents(t) // temp HOME: the skills failure path reads the global skills dir
t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6")
setupPluginMock(t)
origSkills := installSkillsForAgentsFn
origCleanup := cleanupLegacyFn
t.Cleanup(func() { installSkillsForAgentsFn = origSkills; cleanupLegacyFn = origCleanup })
cleanupLegacyFn = func(context.Context, *agents.Agent, string) error { return nil }
skillsErr := errors.New("failed to write skill files")
installSkillsForAgentsFn = func(context.Context, installer.ManifestSource, []*agents.Agent, installer.InstallOptions) error {
return skillsErr
}
stateErr := &installer.StateError{Path: ".state.json", Err: errors.New("permission denied")}
recordPluginInstallsFn = func(context.Context, string, map[string]installer.PluginRecord, string) error {
return stateErr
}

claude := testPluginAgent(agents.NameClaudeCode, "Claude Code", "claude")
cursor := &agents.Agent{Name: agents.NameCursor, DisplayName: "Cursor"}
ctx := cmdio.MockDiscard(t.Context())
plan := buildPlan([]*agents.Agent{cursor, claude}, installer.ScopeGlobal, false, false)
_, err := executePlan(ctx, nil, plan, installer.InstallOptions{Scope: installer.ScopeGlobal}, false)

// Both failures reach the user, the skills one first.
require.ErrorIs(t, err, skillsErr)
require.ErrorIs(t, err, stateErr)
assert.Equal(t, skillsErr.Error()+"\n"+stateErr.Error(), err.Error())
// The category is picked by error type, not by order: the typed state
// error outranks the untyped skills error.
assert.Equal(t, protos.AitoolsErrorCategoryStateInvalid, classifyInstallError(err))
}

// --- RunE: skills-only path (config-dir detection, no plugin) ---

func TestInstallSkillsOnlyAllAgents(t *testing.T) {
Expand Down Expand Up @@ -597,12 +713,13 @@ func TestInstallOutputJSONTopLevelFailure(t *testing.T) {
cmd := newTestInstallCmd()
cmd.SetContext(ctx)
cmd.SetOut(&out)
// Cursor is skills-only, so this fails in the skills-group path, which returns
// before appending any per-agent outcome.
// Cursor is skills-only, so this fails in the skills-group path, which records
// no per-agent outcome.
cmd.SetArgs([]string{"--agents", "cursor", "--scope", "global", "--output", "json"})

// A top-level failure has no per-agent entry, so it must still be represented
// in the JSON (not just a bare non-zero exit with an empty agents array).
// in the JSON (not just a bare non-zero exit). With no plugin agent in the
// plan, the agents array is empty here.
err := cmd.Execute()
require.ErrorIs(t, err, root.ErrAlreadyPrinted)

Expand Down
3 changes: 2 additions & 1 deletion libs/aitools/installer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ func claudeAlreadyDisabled(err error) bool {
// RecordPluginInstalls persists plugin install records into the state file for
// the given CLI scope (global or project), creating state if none exists. ref
// is the resolved skills release the install corresponds to. An empty ref
// (release unresolved) keeps the existing state.Release.
// leaves state.Release unchanged: the release could not be resolved, or the
// skills install failed and the skills on disk are still at the old release.
func RecordPluginInstalls(ctx context.Context, cliScope string, records map[string]PluginRecord, ref string) error {
dir, err := skillsDir(ctx, cliScope)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions libs/aitools/installer/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,27 @@ func buildUpdateSkillSet(state *InstallState, manifest *Manifest, opts UpdateOpt
return skillSet
}

// HasUntrackedSkills reports whether the global scope has skills on disk but no
// state file: from an install that predates state tracking, or from a first
// install that failed before it saved state. Only the global scope is checked,
// so a first project install interrupted the same way is not detected. A state
// file that can't be read counts as no: the caller's next state load reports
// that error itself.
func HasUntrackedSkills(ctx context.Context, cliScope string) bool {
if cliScope != ScopeGlobal {

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.

[nit] This returns false for project scope, because "Project scope never had such installs". But InstallSkillsForAgents saves the state only after its loop, so a first project install that fails on the third skill leaves two skills on disk with no state. Then executePlan records the plugins, and the new project state has no skills. update treats that scope as plugin-only, and uninstall leaves those skill files. Check the project dir for skills without state too, and say in the doc that an interrupted install also leaves untracked skills.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the doc comment: it now says the check covers skills on disk with no state file from either an install that predates state tracking or a first install that failed before saving state. It also says only the global scope is checked, so an interrupted first project install isn't detected. I also aligned the comment at the call site in install.go.

I left the project-scope check itself for a follow-up. It changes when plugins get recorded in project scope, and this PR is already approved with the global-only behavior.

Commit: 1eca02f

return false
}
dir, err := GlobalSkillsDir(ctx)
if err != nil {
return false
}
state, err := LoadState(dir)
if err != nil {
return false
}
return state == nil && hasLegacyInstall(ctx, dir)
}

// hasLegacyInstall checks both canonical and legacy dirs for skills on disk without state.
func hasLegacyInstall(ctx context.Context, globalDir string) bool {
if hasSkillsOnDisk(globalDir) {
Expand Down
Loading