[BUG] Failed commands return only "exit status 1"; the command's error never reaches the agent
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 69/100
調査の方向性
internal/commands/builder.goから始め、特にCommandBuilder.executeCommandとExecuteを確認してください。internal/cmd.DefaultShellExecutor.Execが結合された出力をどのように返すか、またpkg/k8sがエラーをツールの結果にどのように変換するかを追ってください。既存のコマンドテストを確認し、出力を伴うコマンド失敗のテストを追加してください。返されたツールエラーにコマンドの出力が含まれ、エラー生成元がそのメッセージから失敗を分類できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug · Severity: Medium · every tool that runs a CLI · no workaround on the agent side
Affects: kagent-tools v0.1.x to v0.3.0 (bundled with kagent v0.10.3) and main · Component: internal/commands (CommandBuilder.Execute)
What breaks
When a CLI command fails, the tool result tells the agent only the exit status. The command's own message, the part that says why it failed, is written to the tool server's log and dropped.
Asking kagent's k8s-agent to "Show me the YAML of the deployment does-not-exist in the default namespace" gives the agent this tool result:
[Kubernetes] get deployment does-not-exist -o yaml -n default failed: exit status 1
The tool server logs what kubectl actually said:
level=ERROR msg="command execution failed" command=kubectl args="[get deployment does-not-exist -o yaml -n default]" error="exit status 1" output="Error from server (NotFound): deployments.apps \"does-not-exist\" not found\n"
For NotFound the agent can guess. For most failures it can't. In my case an admission webhook refused a k8s_patch_resource call and said exactly what to do next:
Error from server (Forbidden): admission webhook "agents.kubeamber.dev" denied the request: kubeamber: HOLD (risk 40/100, replicas 3 → 6): risk 40/100 is at or above the hold threshold (30). Factors: +10 modifies a resource, +5 changes a workload, +25 namespace "prod" is protected. Held for human approval as change request cr-671cf823-tqrcc (expires in 1h0m0s). Ask an operator to run `kubeamber approve cr-671cf823-tqrcc`, then retry this exact change.
The agent received exit status 1. It then tried the same change three different ways (a merge patch, an annotation, and kubectl apply of an edited manifest) and asked the user whether they had RBAC permissions or "an admission controller, policy, or automation tool … restricting changes". The same happens with RBAC denials, conflicts, validation errors, and failed helm, istioctl and cilium commands.
There is a second effect. NewKubernetesError, NewHelmError and the other error creators choose suggestions and an error code by searching the cause for words such as forbidden, not found and already exists. The cause is always the exit error, so those branches never match: every kubectl failure gets K8S_GENERIC_ERROR. The Helm tools show these suggestions to the agent, so the agent gets the generic fallback for those too.
Reproduce
kagent v0.10.3 on kind with the default install. Ask k8s-agent for any resource that doesn't exist, as above, and expand the tool call's result in the UI. Then compare it with the tool server's log:
kubectl -n kagent logs deploy/kagent-tools | grep "command execution failed"
Expected vs actual
- Expected: the tool result includes the command's output, for example
... failed: exit status 1: Error from server (NotFound): deployments.apps "does-not-exist" not found. - Actual: it ends at
failed: exit status 1.
Ask
Keep the command's output in the error that CommandBuilder.Execute returns. I have a small PR ready that does this and adds a test.
Root cause
internal/cmd.DefaultShellExecutor.Exec runs cmd.CombinedOutput() and returns both the output and the error. CommandBuilder.executeCommand (internal/commands/builder.go; this handling dates from #7) wraps only the error:
output, err := executor.Exec(ctx, command, args...)
if err != nil {
var toolError *errors.ToolError
switch command {
case "kubectl":
toolError = errors.NewKubernetesError(strings.Join(args, " "), err)
...
return string(output), toolError
}
and Execute then discards the returned output (return "", err). runKubectlCommand in pkg/k8s turns the error into the tool result with mcp.NewToolResultError(err.Error()), so only exit status 1 survives.
- 主要言語
- Go
- スター
- 39
- フォーク
- 31
- 平均マージ
- 2日 8時間
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
kagent-dev/tools のほかの issue
-
LOG_LEVEL is documented but not implemented対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
kagent-dev/tools#94 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
kagent-dev/tools#93 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
kagent-dev/tools#92 ·
-
[BUG] MCP clients get no tools from v0.3.0: kubescape_get_vulnerability_details outputSchema is not an object再び着手できるかも @nishanthchandr4 が 30 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
kagent-dev/tools#87 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
kagent-dev/tools#54 ·
kagent-dev/tools の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
open-telemetry/opentelemetry-go-compile-instrumentation#1713 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
JakeChampion/lang#14392 ·
メンテナーはふだん 1 日以内に返信
-
agent-butler-finding bug
難易度 1/5 1〜3時間 初心者へのやさしさ 84/100
jordansmall/spindrift#6557 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] Custom tool truncation leaves unused stream copies open対応中かも @OUAO-FRANK が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信