Skip to content

Commit 7123aae

Browse files
anton-107Isaac
andcommitted
aitools: refresh only the Databricks marketplace, and do not fail the install on it
Claude Code's `plugin marketplace update` with no name refreshes every marketplace the user has added, so one unreachable third-party marketplace failed the Databricks plugin install. The refresh now names the marketplace the Databricks plugin is listed in, and a failed refresh no longer stops the install or the update: both go on from the local copy of the marketplace and, once that succeeds, warn and record the plugin version as unknown. Codex's `plugin marketplace upgrade` in `aitools update` names the marketplace too. ```diff InstallPluginForAgent (libs/aitools/installer/plugin.go) marketplace add (if absent) - claude plugin marketplace update - on error: remove the marketplace we added, return install-failed + claude plugin marketplace update <marketplace> + on error: keep the error, continue claude plugin install databricks@<marketplace> on error: remove the marketplace we added - return install-failed with the install error + return install-failed with the install error + + "(refreshing the marketplace also failed: <refresh error>)" if the refresh failed - record Version = <ref> + if the refresh failed and the marketplace was not just added by us: + warn that the plugin came from the local copy (with the agent's stderr) + record Version = "" (version unknown) + else record Version = <ref> UpdatePluginForAgent (aitools update) - claude plugin marketplace update + claude plugin marketplace update <recorded marketplace, or the agent's current one> - on error: return install-failed + on error: keep the error, continue claude plugin update ... - codex plugin marketplace upgrade + codex plugin marketplace upgrade <recorded marketplace, or the agent's current one> + on error: same as above codex plugin add ... on update error: return install-failed + + "(refreshing the marketplace also failed: <refresh error>)" if the refresh failed - record Version = <ref> + if the refresh failed: warn as above, record Version = "" (version unknown) + else record Version = <ref> ``` Changelog fragment: `.nextchanges/cli/aitools-marketplace-refresh.md`. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 9d4b058 commit 7123aae

7 files changed

Lines changed: 286 additions & 64 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `databricks aitools install` and `databricks aitools update` refresh only the marketplace the Databricks plugin is listed in, so another unreachable marketplace no longer blocks them. When that refresh fails, both commands warn, install or update the plugin from the local copy of the marketplace, and record the plugin version as unknown. ([#7473](https://github.com/databricks/cli/pull/7473))

‎cmd/aitools/list.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,17 @@ func renderSkillTable(skills []skillEntry, bothScopes bool) string {
384384
// are skipped: this line reports the plugin, and their versions would otherwise
385385
// decide the status of an agent that also has a plugin in another scope.
386386
func agentStatusLabel(a agentEntry, release string) string {
387-
version, upToDate := "", true
387+
// picked is separate from version because an empty version ("version
388+
// unknown") is a real pick, not "nothing picked yet".
389+
version, picked, upToDate := "", false, true
388390
for _, scope := range []string{installer.ScopeProject, installer.ScopeGlobal} {
389391
info, ok := a.Installed[scope]
390392
if !ok || info.Delivery != deliveryPlugin.String() {
391393
continue
392394
}
393395
stale := info.Version != release
394-
if version == "" || (upToDate && stale) {
395-
version = info.Version
396+
if !picked || (upToDate && stale) {
397+
version, picked = info.Version, true
396398
}
397399
if stale {
398400
upToDate = false

‎cmd/aitools/list_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ func TestBuildAgentEntriesRecordsPerScopeVersions(t *testing.T) {
348348
assert.Equal(t, "databricks plugin · v0.2.5 · update available", agentStatusLabel(cc, "0.2.6"))
349349
}
350350

351+
func TestAgentStatusLabelKeepsUnknownStaleScope(t *testing.T) {
352+
// The project record has no version (its last install could not refresh the
353+
// marketplace), the global one is current. The unknown scope is stale and
354+
// must not be hidden behind the up-to-date version.
355+
a := agentEntry{Installed: map[string]installInfo{
356+
installer.ScopeProject: {Delivery: deliveryPlugin.String(), Version: ""},
357+
installer.ScopeGlobal: {Delivery: deliveryPlugin.String(), Version: "0.2.7"},
358+
}}
359+
assert.Equal(t, "databricks plugin · version unknown · update available", agentStatusLabel(a, "0.2.7"))
360+
}
361+
351362
func TestRenderListJSONScopeFiltersSummary(t *testing.T) {
352363
out := listOutput{
353364
Release: "0.1.0",

‎libs/aitools/installer/detect.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import (
1313
// agent's own plugin cache (ground truth, catches installs made directly through
1414
// the agent), falling back to the version recorded in the CLI install state when
1515
// the plugin is not found on disk. An agent with no resolvable version is
16-
// omitted rather than reported without one.
16+
// omitted rather than reported without one. That includes an agent without a
17+
// plugin cache reader (Codex) whose record has no version because its last
18+
// install or update ran from a marketplace copy that could not be refreshed.
1719
func InstalledTools(ctx context.Context) []string {
1820
recorded := recordedPluginVersions(ctx)
1921

‎libs/aitools/installer/plugin.go‎

Lines changed: 87 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ func recordedInstallTarget(agent *agents.Agent, rec PluginRecord) string {
105105
if plugin == "" {
106106
plugin = agent.Plugin.ID
107107
}
108-
marketplace := rec.Marketplace
109-
if marketplace == "" {
110-
marketplace = agent.Plugin.Marketplace
111-
}
112-
return plugin + "@" + marketplace
108+
return plugin + "@" + recordedMarketplace(agent, rec)
113109
}
114110

115111
// marketplaceAddArgs builds the `plugin marketplace add <source>` argv (sans binary).
@@ -137,19 +133,27 @@ func marketplaceRemoveArgs(spec *agents.PluginSpec) []string {
137133
}
138134

139135
func marketplaceRemoveArgsForRecord(agent *agents.Agent, rec PluginRecord) []string {
140-
marketplace := rec.Marketplace
141-
if marketplace == "" {
142-
marketplace = agent.Plugin.Marketplace
136+
return []string{"plugin", "marketplace", "remove", recordedMarketplace(agent, rec)}
137+
}
138+
139+
// recordedMarketplace is the marketplace a recorded install came from, or the
140+
// agent's current one for records written before it was stored.
141+
func recordedMarketplace(agent *agents.Agent, rec PluginRecord) string {
142+
if rec.Marketplace != "" {
143+
return rec.Marketplace
143144
}
144-
return []string{"plugin", "marketplace", "remove", marketplace}
145+
return agent.Plugin.Marketplace
145146
}
146147

147148
// marketplaceUpdateArgs builds the marketplace refresh command for agents whose
148149
// plugin CLI supports it. Claude's official marketplace can be stale locally,
149150
// causing install/update to report that a published plugin does not exist.
150-
func marketplaceUpdateArgs(agent *agents.Agent) []string {
151+
// The refresh names the marketplace: without a name Claude refreshes every
152+
// marketplace the user has added, and one unreachable third-party marketplace
153+
// then fails the databricks install.
154+
func marketplaceUpdateArgs(agent *agents.Agent, marketplace string) []string {
151155
if agent.Name == agents.NameClaudeCode {
152-
return []string{"plugin", "marketplace", "update"}
156+
return []string{"plugin", "marketplace", "update", marketplace}
153157
}
154158
return nil
155159
}
@@ -172,24 +176,58 @@ func pluginInstallArgs(agent *agents.Agent, scope string) []string {
172176
}
173177
}
174178

175-
// pluginUpdateSteps builds the ordered per-agent update argv sets (sans binary).
176-
// Codex updates in two steps: refresh the marketplace, then re-add.
177-
func pluginUpdateSteps(agent *agents.Agent, rec PluginRecord) [][]string {
179+
// pluginRefreshArgs builds the marketplace refresh that runs before an update
180+
// (sans binary), or nil for agents without one. Both agents name the
181+
// marketplace, so an unreachable marketplace the user added for another plugin
182+
// does not fail the update.
183+
func pluginRefreshArgs(agent *agents.Agent, rec PluginRecord) []string {
184+
if agent.Name == agents.NameCodex {
185+
return []string{"plugin", "marketplace", "upgrade", recordedMarketplace(agent, rec)}
186+
}
187+
return marketplaceUpdateArgs(agent, recordedMarketplace(agent, rec))
188+
}
189+
190+
// pluginUpdateArgs builds the per-agent update argv (sans binary). Codex
191+
// updates by re-adding the plugin.
192+
func pluginUpdateArgs(agent *agents.Agent, rec PluginRecord) []string {
178193
target := recordedInstallTarget(agent, rec)
179194
switch agent.Name {
180195
case agents.NameCodex:
181-
return [][]string{
182-
{"plugin", "marketplace", "upgrade"},
183-
{"plugin", "add", target},
184-
}
196+
return []string{"plugin", "add", target}
185197
case agents.NameClaudeCode:
186-
return [][]string{
187-
marketplaceUpdateArgs(agent),
188-
appendScopeArg([]string{"plugin", "update", target}, rec.Scope),
189-
}
198+
return appendScopeArg([]string{"plugin", "update", target}, rec.Scope)
190199
default:
191-
return [][]string{{"plugin", "update", target}}
200+
return []string{"plugin", "update", target}
201+
}
202+
}
203+
204+
// refreshMarketplace runs the marketplace refresh (args may be nil for agents
205+
// without one). A failed refresh is not fatal: the local copy of the marketplace
206+
// usually still lists the plugin, so the caller goes on with it, and either
207+
// warns with warnLocalMarketplaceCopy once that succeeds or adds the refresh
208+
// error to its own error with withRefreshError.
209+
func refreshMarketplace(ctx context.Context, bin string, args []string) error {
210+
if args == nil {
211+
return nil
212+
}
213+
_, err := runAgentCmd(ctx, pluginCmdTimeout, prepend(bin, args))
214+
return err
215+
}
216+
217+
// warnLocalMarketplaceCopy tells the user that a successful install or update
218+
// used a local marketplace copy that could not be refreshed, so the plugin may
219+
// be out of date.
220+
func warnLocalMarketplaceCopy(ctx context.Context, agent *agents.Agent, marketplace string, refreshErr error) {
221+
log.Warnf(ctx, "Could not refresh the %s marketplace, so the %s plugin came from its local copy and may be out of date; run `databricks aitools update` later: %s", marketplace, agent.DisplayName, stderrOf(refreshErr))
222+
}
223+
224+
// withRefreshError appends a failed refresh to the detail of a failed install
225+
// or update, since a stale local marketplace copy may be the cause.
226+
func withRefreshError(blocked *BlockedError, refreshErr error) *BlockedError {
227+
if refreshErr != nil {
228+
blocked.Detail += " (refreshing the marketplace also failed: " + stderrOf(refreshErr) + ")"
192229
}
230+
return blocked
193231
}
194232

195233
// pluginUninstallArgs builds the per-agent uninstall argv (sans binary).
@@ -258,16 +296,7 @@ func InstallPluginForAgent(ctx context.Context, agent *agents.Agent, nativeScope
258296
_, addErr := runAgentCmd(ctx, pluginCmdTimeout, prepend(bin, marketplaceAddArgs(agent.Plugin)))
259297
installedMarketplace = addErr == nil && !alreadyPresent
260298
}
261-
if args := marketplaceUpdateArgs(agent); args != nil {
262-
if _, err := runAgentCmd(ctx, pluginCmdTimeout, prepend(bin, args)); err != nil {
263-
if installedMarketplace {
264-
if _, rmErr := runAgentCmd(ctx, pluginCmdTimeout, prepend(bin, marketplaceRemoveArgs(agent.Plugin))); rmErr != nil {
265-
log.Warnf(ctx, "%s plugin marketplace refresh failed and the marketplace could not be de-registered: %v", agent.DisplayName, rmErr)
266-
}
267-
}
268-
return PluginRecord{}, &BlockedError{Agent: agent.Name, Reason: ReasonInstallFailed, Detail: stderrOf(err)}
269-
}
270-
}
299+
refreshErr := refreshMarketplace(ctx, bin, marketplaceUpdateArgs(agent, agent.Plugin.Marketplace))
271300

272301
if _, err := runAgentCmd(ctx, pluginCmdTimeout, prepend(bin, pluginInstallArgs(agent, nativeScope))); err != nil {
273302
// Roll back a marketplace we just added so a failed install doesn't
@@ -277,35 +306,49 @@ func InstallPluginForAgent(ctx context.Context, agent *agents.Agent, nativeScope
277306
log.Warnf(ctx, "%s plugin install failed and the marketplace could not be de-registered: %v", agent.DisplayName, rmErr)
278307
}
279308
}
280-
return PluginRecord{}, &BlockedError{Agent: agent.Name, Reason: ReasonInstallFailed, Detail: stderrOf(err)}
309+
return PluginRecord{}, withRefreshError(&BlockedError{Agent: agent.Name, Reason: ReasonInstallFailed, Detail: stderrOf(err)}, refreshErr)
281310
}
282311

312+
// A marketplace we just added is a fresh copy, so a failed refresh right
313+
// after it changes nothing. Otherwise we can't tell which version the local
314+
// copy held, so the record says "version unknown" until the next successful
315+
// update.
316+
version := DisplaySkillsVersion(ref)
317+
if refreshErr != nil && !installedMarketplace {
318+
warnLocalMarketplaceCopy(ctx, agent, agent.Plugin.Marketplace, refreshErr)
319+
version = ""
320+
}
283321
return PluginRecord{
284322
Marketplace: agent.Plugin.Marketplace,
285323
Plugin: agent.Plugin.ID,
286324
Scope: nativeScope,
287-
Version: DisplaySkillsVersion(ref),
325+
Version: version,
288326
InstalledMarketplace: installedMarketplace,
289327
}, nil
290328
}
291329

292330
// UpdatePluginForAgent updates the plugin through the agent's own CLI. The
293331
// plugin's own update handles content the release dropped, so there is no
294-
// per-skill prune for plugin agents.
295-
func UpdatePluginForAgent(ctx context.Context, agent *agents.Agent, rec PluginRecord) error {
332+
// per-skill prune for plugin agents. It reports whether the marketplace refresh
333+
// succeeded: after a failed refresh the update runs from the local copy, so the
334+
// installed version is unknown.
335+
func UpdatePluginForAgent(ctx context.Context, agent *agents.Agent, rec PluginRecord) (refreshed bool, err error) {
296336
if agent.Plugin == nil {
297-
return &BlockedError{Agent: agent.Name, Reason: ReasonNoPlugin}
337+
return false, &BlockedError{Agent: agent.Name, Reason: ReasonNoPlugin}
298338
}
299339
bin, err := resolveAgentBinary(agent)
300340
if err != nil {
301-
return &BlockedError{Agent: agent.Name, Reason: ReasonCLINotOnPath, Detail: err.Error()}
341+
return false, &BlockedError{Agent: agent.Name, Reason: ReasonCLINotOnPath, Detail: err.Error()}
302342
}
303-
for _, args := range pluginUpdateSteps(agent, rec) {
304-
if _, err := runAgentCmd(ctx, pluginCmdTimeout, prepend(bin, args)); err != nil {
305-
return &BlockedError{Agent: agent.Name, Reason: ReasonInstallFailed, Detail: stderrOf(err)}
306-
}
343+
refreshErr := refreshMarketplace(ctx, bin, pluginRefreshArgs(agent, rec))
344+
if _, err := runAgentCmd(ctx, pluginCmdTimeout, prepend(bin, pluginUpdateArgs(agent, rec))); err != nil {
345+
return false, withRefreshError(&BlockedError{Agent: agent.Name, Reason: ReasonInstallFailed, Detail: stderrOf(err)}, refreshErr)
307346
}
308-
return nil
347+
if refreshErr != nil {
348+
warnLocalMarketplaceCopy(ctx, agent, recordedMarketplace(agent, rec), refreshErr)
349+
return false, nil
350+
}
351+
return true, nil
309352
}
310353

311354
// UninstallPluginForAgent removes the plugin through the agent's own CLI, and

0 commit comments

Comments
 (0)