From edd8c1ea949207afed2fa60e85c4086d6db75de0 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:53:11 +0000 Subject: [PATCH] aitools: keep installing plugins when the skills install fails `databricks aitools install` no longer stops when installing skill files fails. Agents that get a plugin (Claude Code) don't depend on the skill files, so their plugin is still installed. The skills error is still the command's error. The plugin is recorded in the install state without advancing `state.Release`, because the skill files on disk are still at the old release; otherwise `aitools version` and a pinned `aitools update` would report them as up to date. If skills from an install that predates state tracking are on disk with no state file, the plugin is not recorded at all, so `aitools update` and the install's legacy checks still see those skills. ```diff executePlan install skills for skills agents - on error: return error # plugin agents never attempted + on error: remember skillsErr install plugins for plugin agents - on state write error: return err + on state write error: return errors.Join(skillsErr, err) + record plugins; if skillsErr, keep state.Release # skills on disk are still at the old release + if skillsErr and untracked legacy skills on disk: don't create a plugin-only state file + if skillsErr: return skillsErr # stays the top-level error if per-agent errors: return agentErrors ``` Changelog fragment: `.nextchanges/cli/aitools-install-skills-failure-keeps-plugins.md`. Co-authored-by: Isaac --- ...ls-install-skills-failure-keeps-plugins.md | 1 + cmd/aitools/install.go | 44 +++++-- cmd/aitools/install_test.go | 123 +++++++++++++++++- libs/aitools/installer/plugin.go | 3 +- libs/aitools/installer/update.go | 21 +++ 5 files changed, 176 insertions(+), 16 deletions(-) create mode 100644 .nextchanges/cli/aitools-install-skills-failure-keeps-plugins.md diff --git a/.nextchanges/cli/aitools-install-skills-failure-keeps-plugins.md b/.nextchanges/cli/aitools-install-skills-failure-keeps-plugins.md new file mode 100644 index 00000000000..60777a1b217 --- /dev/null +++ b/.nextchanges/cli/aitools-install-skills-failure-keeps-plugins.md @@ -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)) diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index 3e4bccc5271..bb9ffe5ab8f 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -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}) + } } } @@ -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 { + return outcomes, errors.Join(skillsErr, err) } } } @@ -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...)} } @@ -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)) diff --git a/cmd/aitools/install_test.go b/cmd/aitools/install_test.go index 1df2df8eb71..abd9a491537 100644 --- a/cmd/aitools/install_test.go +++ b/cmd/aitools/install_test.go @@ -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) { @@ -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) diff --git a/libs/aitools/installer/plugin.go b/libs/aitools/installer/plugin.go index b7a777116b9..5801cbc95d5 100644 --- a/libs/aitools/installer/plugin.go +++ b/libs/aitools/installer/plugin.go @@ -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 { diff --git a/libs/aitools/installer/update.go b/libs/aitools/installer/update.go index e8a5cc7b88d..30f1d98ab48 100644 --- a/libs/aitools/installer/update.go +++ b/libs/aitools/installer/update.go @@ -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 { + 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) {