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 @@
* A coding agent no longer gets the "Databricks skills are not installed" hint on a command after which the automatic installation of Databricks AI tools installs them for that agent, so its output no longer tells it to install what the same command installs. When that installation does not happen, for example because the command failed, the hint appears once the command ends. ([#7890](https://github.com/databricks/cli/pull/7890))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
51 changes: 51 additions & 0 deletions acceptance/cmd/aitools/auto-install/agent-hint/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

=== a failing command: no install, the hint once the command ends

>>> CLAUDECODE=1 [CLI] jobs get abc
Error: invalid JOB_ID: abc
Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install

Exit code: 1

>>> print_telemetry
{"command":"jobs_get","exit_code":1,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}}

=== first run of a new version: the install notice, no install hint

>>> CLAUDECODE=1 [CLI] jobs list
Installed Databricks AI tools for Claude Code, Cursor. Disable: databricks aitools auto-install disable

>>> print_telemetry
{"command":"jobs_list","exit_code":0,"aitools_install_event":{"agents":["CLAUDE_CODE","CURSOR"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED","agent_results":[{"agent":"CLAUDE_CODE","error_category":"CLI_NOT_ON_PATH"}],"trigger":"AUTO_FIRST_RUN"}}
{"command":"jobs_list","exit_code":0,"aitools_auto_install_event":{"outcome":"INSTALLED","holdout_arm":"TREATMENT","interactive":false}}

=== second run: the tools are installed, nothing

>>> CLAUDECODE=1 [CLI] jobs list

>>> print_telemetry

=== gate off: no install, the hint once the command ends, and on the next

>>> CLAUDECODE=1 [CLI] jobs list
Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install

>>> print_telemetry
{"command":"jobs_list","exit_code":0,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}}

>>> CLAUDECODE=1 [CLI] jobs list
Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install

>>> print_telemetry
{"command":"jobs_list","exit_code":0,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}}

=== an agent the install skips is still hinted: Claude Code has no config dir

>>> CLAUDECODE=1 [CLI] jobs list
Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install
Installed Databricks AI tools for Cursor. Disable: databricks aitools auto-install disable

>>> print_telemetry
{"command":"jobs_list","exit_code":0,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}}
{"command":"jobs_list","exit_code":0,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED","trigger":"AUTO_FIRST_RUN"}}
{"command":"jobs_list","exit_code":0,"aitools_auto_install_event":{"outcome":"INSTALLED","holdout_arm":"TREATMENT","interactive":false}}
34 changes: 34 additions & 0 deletions acceptance/cmd/aitools/auto-install/agent-hint/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Claude Code calls the CLI: its config dir exists and its CLI is not on PATH,
# so auto-install gives it skill files. The install hint must not tell it to
# install what the same run installs.
unset AGENT CLAUDE_CODE_SESSION_ID CLAUDE_CODE_CHILD_SESSION
use_home home
"$mkdir_bin" -p "${USERPROFILE:-$HOME}/.claude"
gate true

title "a failing command: no install, the hint once the command ends"
errcode trace CLAUDECODE=1 $CLI jobs get abc

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.

[nit] This case expects jobs get abc to fail. .agents/rules/testing.md says to assert an expected failure with musterr CMD and keep errcode for tolerated non-zero exits. Use musterr trace CLAUDECODE=1 $CLI jobs get abc.

trace print_telemetry

title "first run of a new version: the install notice, no install hint"
trace CLAUDECODE=1 $CLI jobs list
trace print_telemetry

title "second run: the tools are installed, nothing"
trace CLAUDECODE=1 $CLI jobs list
trace print_telemetry

title "gate off: no install, the hint once the command ends, and on the next"
use_home no-agents-home
"$mkdir_bin" -p "${USERPROFILE:-$HOME}/.claude"
gate false
trace CLAUDECODE=1 $CLI jobs list
trace print_telemetry
trace CLAUDECODE=1 $CLI jobs list
trace print_telemetry

title "an agent the install skips is still hinted: Claude Code has no config dir"
use_home holdout-home
Comment on lines +22 to +31

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.

[nit] use_home no-agents-home (line 22) gets .cursor (from use_home) and .claude. use_home holdout-home (line 31) stores the default treatment-machine ID. Neither home is what its name says; the names are reused only because the parent test.toml ignores them. Ignore lists append to the parent's, so a leaf agent-hint/test.toml with names such as gate-off-home and cursor-only-home would let the names match the cases.

gate true
trace CLAUDECODE=1 $CLI jobs list
trace print_telemetry
49 changes: 49 additions & 0 deletions cmd/aitools/autoinstall_hint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package aitools

import (
"slices"

"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/libs/aitools/autoinstall"
"github.com/spf13/cobra"
)

// AutoInstallsFor reports whether the auto-install after cmd may give the
// agent agentName tools (see autoinstall.InstallsFor). It decides as
// autoInstall does up to the gate lookup, which it skips: a run that would
// look the gate up counts as installing, so on a version whose gate is off the
// install hint moves to the end of the command. A machine whose stored ID puts
// it in the holdout never installs. A first install gives tools to the agents
// its plan names; an update gives skills to every agent with a config
// directory when a skill changed, which is only known after the manifest is
// fetched, so it counts as installing for each of them.
func AutoInstallsFor(cmd *cobra.Command, agentName string) bool {
ctx := cmd.Context()
in := autoInstallInputs(ctx, skipsAutoInstall(cmd))
if slices.Contains(stateFreeSkips, autoinstall.Decide(in)) {
return false
}
var err error
in.State, err = autoinstall.Load(ctx)
if err != nil || autoinstall.Decide(in) != autoinstall.ReasonGateOff {

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] Decide returns ReasonGateOff for any 0 < Attempts < MaxAttempts, so a retry after a failed attempt counts as installing (the "a retry installs too" case). A failed attempt prints "Could not install" only when asked, and coding agents are never asked. So with the gate on and the release download blocked or timing out, an agent can run up to 10 successful commands with neither the hint nor any install notice. Should this withhold the hint only on the version's first attempt (in.State.LastVersion != in.Version), so a failed attempt lets the hint through on the next command?

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] in.Bucket is never set here, and Decide checks the holdout only after the gate. So a holdout machine counts as installing, has its hint withheld, and is then settled as SKIPPED_HOLDOUT with nothing installed. On every new version the 10% control arm loses a hint the status quo would have shown, which skews the comparison the holdout exists for. When in.State.ID is set, the bucket is already known locally. Can this return false when autoinstall.InHoldout(autoinstall.Bucket(in.State.ID))?

Comment thread
anton-107 marked this conversation as resolved.
Resolved
return false
}
if in.State.ID != "" && autoinstall.InHoldout(autoinstall.Bucket(in.State.ID)) {
return false
}
tools, err := planTools(quietContext(ctx), in.State)
if err != nil || tools.skip != "" {
return false
}
if tools.existing != nil {
return slices.ContainsFunc(agents.DetectInstalled(ctx), func(a *agents.Agent) bool {
return a.Name == agentName
})
Comment on lines +38 to +41

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.

[nit] For an existing global install, this returns true for every agent with a config dir. But runUpdate reconciles file skills only when the state has skills (cmd/aitools/update.go:213); a plugin-only install updates just the recorded plugins. Example: only the Claude Code plugin is recorded, and Cursor calls with ~/.cursor and no skills. The hint then moves to the end of the first command of every version, and the update gives Cursor nothing. Return false when len(tools.existing.Skills) == 0, and correct the doc comment's "an update gives skills to every agent with a config directory".

}
for _, it := range tools.plan {

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] An update plan has no items, so this returns false when the global install predates the calling agent. With tools installed for Cursor only and ~/.claude created later, an upgrade that updates a skill still prints the hint followed by "Updated Databricks AI tools for Claude Code, Cursor" on the same command. Is the update path meant to be out of scope? If so, can the doc comment say it?

if it.agent.Name == agentName {
return slices.Contains(tools.newAgents(), it.agent.DisplayName)
}
}
return false
}
94 changes: 94 additions & 0 deletions cmd/aitools/autoinstall_hint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package aitools

import (
"context"
"os"
"path/filepath"
"strings"
"testing"

"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/libs/aitools/autoinstall"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/dbr"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// globalInstallState is a global install state file of an earlier install.
const globalInstallState = `{"schema_version": 2, "release": "v0.1.0", "skills": {"databricks-test": "0.1.0"}}`

func TestAutoInstallsFor(t *testing.T) {
tests := []struct {
name string
state string
// env is set on top of setupAutoInstallHome's environment.
env map[string]string
// installState replaces the global install state file.
installState string
agent string
command string
want bool
}{
{name: "first run of a version installs for a detected agent", want: true},
{name: "a retry installs too", state: `{"id": "treatment-machine", "last_version": "1.30.0", "attempts": 2}`, want: true},
{name: "a fresh machine with no state installs", state: "{}", want: true},
{name: "an agent without a config dir is not installed for", agent: agents.NameClaudeCode},
{name: "a settled version installs nothing", state: `{"id": "treatment-machine", "last_version": "1.30.0"}`},
{name: "a version whose retries ran out installs nothing", state: `{"id": "treatment-machine", "last_version": "1.30.0", "attempts": 10}`},
{name: "an opt-out installs nothing", state: `{"id": "treatment-machine", "opted_out": true}`},
{name: "the env opt-out installs nothing", env: map[string]string{"DATABRICKS_AITOOLS_AUTO_INSTALL": "false"}},
{name: "CI installs nothing", env: map[string]string{"CI": "true"}},
{name: "a development build installs nothing", env: map[string]string{"DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION": ""}},
{name: "a command that skips auto-install installs nothing", command: "aitools list"},
{name: "a failed plan installs nothing", installState: "not json"},
{name: "a holdout machine installs nothing", state: `{"id": "holdout-machine"}`},
{name: "an update may install for an agent with a config dir", installState: globalInstallState, want: true},
{name: "an update installs nothing for an agent without a config dir", installState: globalInstallState, agent: agents.NameClaudeCode},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
home := setupAutoInstallHome(t, tc.state, "CLAUDECODE", "1")
for k, v := range tc.env {
t.Setenv(k, v)
}
if tc.installState != "" {
dir := filepath.Join(home, ".databricks", "aitools", "skills")
require.NoError(t, os.MkdirAll(dir, 0o755))
require.NoError(t, os.WriteFile(filepath.Join(dir, ".state.json"), []byte(tc.installState), 0o600))
}
t.Cleanup(func() { gateOn = autoinstall.GateOn })
gateOn = func(context.Context, string) (bool, error) {
t.Error("the gate was looked up")
return true, nil
}
agent, command := tc.agent, tc.command
if agent == "" {
agent = agents.NameCursor
}
if command == "" {
command = "jobs list"
}
ctx := dbr.MockRuntime(cmdio.MockDiscard(t.Context()), dbr.Environment{})
stateBefore, _ := os.ReadFile(filepath.Join(home, ".databricks", "aitools", "auto-install.json"))
assert.Equal(t, tc.want, AutoInstallsFor(hintTestCommand(ctx, command), agent))
stateAfter, _ := os.ReadFile(filepath.Join(home, ".databricks", "aitools", "auto-install.json"))
assert.Equal(t, string(stateBefore), string(stateAfter), "the state is only read")
assert.NoDirExists(t, filepath.Join(home, ".cursor", "skills"))
})
}
}

// hintTestCommand returns the cobra command at path (two words) under a
// databricks root, with ctx set.
func hintTestCommand(ctx context.Context, path string) *cobra.Command {
group, name, _ := strings.Cut(path, " ")
root := &cobra.Command{Use: "databricks"}
parent := &cobra.Command{Use: group}
cmd := &cobra.Command{Use: name}
root.AddCommand(parent)
parent.AddCommand(cmd)
cmd.SetContext(ctx)
return cmd
}
14 changes: 10 additions & 4 deletions cmd/aitools/autoinstall_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,24 @@ func skipsAutoInstall(cmd *cobra.Command) bool {
return false
}

func autoInstall(ctx context.Context, skippedCommand bool) os.Signal {
version := autoinstall.Version(ctx)
in := autoinstall.Inputs{
// autoInstallInputs returns the decision inputs that need neither the state
// nor the gate.
func autoInstallInputs(ctx context.Context, skippedCommand bool) autoinstall.Inputs {
return autoinstall.Inputs{
SkippedCommand: skippedCommand,
OnRuntime: dbr.RunsOnRuntime(ctx),
CacheDisabled: autoinstall.CacheDisabled(ctx),
Version: version,
Version: autoinstall.Version(ctx),
RootInUserHome: rootInUserHome(ctx),
CI: agents.InCI(ctx),
// A "no" earlier in this process counts even if storing it failed.
EnvOptOut: autoinstall.EnvOptedOut(ctx) || autoinstall.Declined(),
}
}

func autoInstall(ctx context.Context, skippedCommand bool) os.Signal {
in := autoInstallInputs(ctx, skippedCommand)
version := in.Version
// What never auto-installs skips before the state is read, and without a
// log line: these are most runs. Root in a user's home is rare, and a user
// who always runs the CLI under sudo needs a way to see why nothing
Expand Down
20 changes: 19 additions & 1 deletion cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ func newRootCommand(ctx context.Context) *cobra.Command {
// when it drives the CLI without the tooling installed (best-effort: a
// stderr line and a telemetry event that is uploaded at exit). Only the
// global install state is read, as for the calling-agent User-Agent.
agents.MaybeHint(ctx, cmd, func(ctx context.Context, agentName string) bool {
deferred := agents.MaybeHint(ctx, cmd, func(ctx context.Context, agentName string) bool {
return installer.PluginRecorded(ctx, installer.ScopeGlobal, agentName)
})
// A hint withheld for auto-install prints once the command has ended.
// Commands run without execute have no slot, and then it is dropped.
if slot, ok := ctx.Value(deferredHintKey{}).(*func()); ok {
*slot = deferred
}
return nil
}

Expand Down Expand Up @@ -131,6 +136,11 @@ func newRootCommand(ctx context.Context) *cobra.Command {
// the context. It holds the signal that stopped auto-install, if one did.
type caughtSignalKey struct{}

// deferredHintKey is the context key of the *func() that execute puts in the
// context. It holds the agent hint withheld for auto-install, if one was (see
// agents.MaybeHint).
type deferredHintKey struct{}

// raise is process.Raise; tests replace it.
var raise = process.Raise

Expand Down Expand Up @@ -194,6 +204,8 @@ Stack Trace:
ctx = context.WithValue(ctx, logFileKey{}, &logFile)
var caught os.Signal
ctx = context.WithValue(ctx, caughtSignalKey{}, &caught)
var deferredHint func()
ctx = context.WithValue(ctx, deferredHintKey{}, &deferredHint)
// slog.SetDefault also redirects the standard log package, so both are restored.
prevLogger := slog.Default()
prevLogWriter, prevLogFlags := stdlog.Writer(), stdlog.Flags()
Expand Down Expand Up @@ -228,6 +240,12 @@ Stack Trace:
fmt.Fprintf(cmd.ErrOrStderr(), "Error: %s\n", err.Error())
}

// After auto-install, which runs only when the command succeeded, and
// before the telemetry upload, which sends its hint-shown event.
if deferredHint != nil {
deferredHint()
}
Comment on lines +243 to +247

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] The withheld hint prints only when ExecuteContextC returns to execute, so it is lost for runs that never get back there. Before this change those runs printed it first:

  • bundle run scripts, bundle run -- <cmd> and psql: libs/execv calls syscall.Exec on Unix and os.Exit on Windows.
  • A command that an agent's tool timeout kills.
  • ... 2>&1 | head -N when the output is longer than N lines: Go exits on SIGPIPE.

These runs never reach auto-install either, so the version stays pending and each such run withholds the hint again. While the gate is off, this happens on every machine for the first commands of each version. Options: print the withheld hint before execv hands off the process, and withhold only when the cached compatibility manifest already says the gate is on. That is a local read with no fetch, and gate-off versions keep the hint at the start.


exitCode := ExitStatus(err)

// Log exit status and error
Expand Down
Loading
Loading