Repository navigation
aitools: typed fetch, state and agent CLI timeout errors #7475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * `databricks aitools install --output json` reports more specific `error_category` values: `SKILLS_FETCH_FAILED`, `RELEASE_LOOKUP_FAILED`, `RATE_LIMITED`, `MANIFEST_INVALID`, `STATE_INVALID` and `PLUGIN_CLI_TIMEOUT`. A coding agent CLI that does not answer in time is now reported as `timed out after <duration>`, followed by any stderr it wrote before it was stopped. ([#7475](https://github.com/databricks/cli/pull/7475)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package aitools | |
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "io/fs" | ||
| "net" | ||
|
|
@@ -57,6 +58,14 @@ func classifyInstallError(err error) protos.AitoolsErrorCategory { | |
| if skill, ok := errors.AsType[*installer.SkillError](err); ok { | ||
| return skillErrorCategory(skill) | ||
| } | ||
| // FetchError is checked before the standard library types: a response | ||
| // that arrived carries a status the net error types know nothing about. | ||
| if fetch, ok := errors.AsType[*installer.FetchError](err); ok { | ||
| return fetchErrorCategory(fetch) | ||
| } | ||
| if _, ok := errors.AsType[*installer.StateError](err); ok { | ||
| return protos.AitoolsErrorCategoryStateInvalid | ||
| } | ||
| if tagged, ok := errors.AsType[*categorizedError](err); ok { | ||
| return tagged.category | ||
| } | ||
|
|
@@ -71,11 +80,11 @@ func classifyInstallError(err error) protos.AitoolsErrorCategory { | |
| } | ||
|
|
||
| // stdlibErrorCategory classifies errors by their standard library type, which | ||
| // the installer wraps with %w: network and timeout errors from fetching the | ||
| // manifest or skill files, and filesystem errors from writing skills or the | ||
| // install state. JSON decode errors stay UNCATEGORIZED: the manifest, the | ||
| // release payload and the install state all decode JSON, so only typed | ||
| // installer errors can tell MANIFEST_INVALID from STATE_INVALID. | ||
| // the installer wraps with %w: filesystem errors from writing skills or the | ||
| // install state, and network and timeout errors, including those of a | ||
| // FetchError that got no response. JSON decode errors stay UNCATEGORIZED: the | ||
| // manifest, the release payload and the install state all decode JSON, so only | ||
| // typed installer errors can tell MANIFEST_INVALID from STATE_INVALID. | ||
| func stdlibErrorCategory(err error) protos.AitoolsErrorCategory { | ||
| switch { | ||
| case errors.Is(err, huh.ErrUserAborted): | ||
|
|
@@ -133,7 +142,52 @@ func skillErrorCategory(e *installer.SkillError) protos.AitoolsErrorCategory { | |
| } | ||
| } | ||
|
|
||
| // fetchErrorCategory maps a FetchError to its category. The first matching | ||
| // case wins, so the order matters: an interrupted command is never a fetch | ||
| // failure, a transport failure keeps its NETWORK or TIMEOUT category, and the | ||
| // release stage is checked before the decode check. | ||
| func fetchErrorCategory(e *installer.FetchError) protos.AitoolsErrorCategory { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit]
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in af32385: a doc comment on |
||
| // The command was interrupted while the request was in flight: the fetch | ||
| // did not fail on its own. | ||
| if errors.Is(e, context.Canceled) { | ||
| return protos.AitoolsErrorCategoryCommandInterrupted | ||
| } | ||
| // No response arrived (DNS, refused connection, proxy, TLS, client | ||
| // timeout), or reading the body failed on the transport (a timeout or a | ||
| // reset mid-body): the user cannot reach the host, which NETWORK and | ||
| // TIMEOUT already report. | ||
| if c := stdlibErrorCategory(e.Err); e.StatusCode == 0 || c == protos.AitoolsErrorCategoryNetwork || c == protos.AitoolsErrorCategoryTimeout { | ||
| return c | ||
| } | ||
| switch { | ||
| case e.RateLimited: | ||
| return protos.AitoolsErrorCategoryRateLimited | ||
| case errors.Is(e, clicompat.ErrNotFound): | ||
| return protos.AitoolsErrorCategoryManifestNotFound | ||
| // Before the decode check: a release payload that does not decode is a | ||
| // failed release lookup, not an invalid manifest. | ||
| case e.Stage == installer.FetchStageRelease: | ||
| return protos.AitoolsErrorCategoryReleaseLookupFailed | ||
| // The response arrived but was not a manifest: content, not transport. | ||
| case isManifestDecodeError(e) || errors.Is(e, installer.ErrManifestTooLarge): | ||
| return protos.AitoolsErrorCategoryManifestInvalid | ||
| default: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] Every installer fetch now wraps its transport error in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in af32385: |
||
| return protos.AitoolsErrorCategorySkillsFetchFailed | ||
| } | ||
| } | ||
|
|
||
| // isManifestDecodeError reports whether the response arrived but was not a | ||
| // valid manifest. | ||
| func isManifestDecodeError(err error) bool { | ||
| _, syntax := errors.AsType[*json.SyntaxError](err) | ||
| _, typ := errors.AsType[*json.UnmarshalTypeError](err) | ||
| return syntax || typ | ||
| } | ||
|
|
||
| func blockedErrorCategory(e *installer.BlockedError) protos.AitoolsErrorCategory { | ||
| if e.TimedOut { | ||
| return protos.AitoolsErrorCategoryPluginCLITimeout | ||
| } | ||
| switch e.Reason { | ||
| case installer.ReasonCLINotOnPath: | ||
| return protos.AitoolsErrorCategoryCLINotOnPath | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] The comment above these categories in
libs/telemetry/protos/aitools_install.go:55-56says "The typed installer errors (release lookup, skills fetch) win over the generic network/timeout classification." With this PR it is the other way round: aFetchErrorwith a transport cause reports NETWORK or TIMEOUT, and the typed categories apply only once a response arrived. Someone reading the enum would expect every failed release lookup to be RELEASE_LOOKUP_FAILED. Update that comment to match.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 57c5e35. The comment above the fetch categories in
libs/telemetry/protos/aitools_install.gonow says that a fetch failing on the transport (no response, or a timeout or reset while reading the body) reports NETWORK or TIMEOUT, and the other categories apply once a response arrived.