Repository navigation
Conversation
When kubectl, helm, istioctl or cilium exits non-zero, executeCommand wraps only the exit error, so the agent is told "exit status 1" and never sees the command's own message, such as kubectl's "Error from server (Forbidden): ...". The output is logged by the shell executor but not returned. Include the trimmed output in the error's cause. The original error stays wrapped, and the error creators now see the real message, so the suggestions they pick from it (permission, not found, already exists, connection refused) apply instead of the generic fallback. Signed-off-by: Sathpal-Singh <sathpal.gnec@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #89
What this changes
When a command fails,
CommandBuilder.executeCommandnow puts the command's trimmed output into the error's cause:so a failed
kubectl getreaches the agent asinstead of ending at
exit status 1.executeCommand, cached or not.%w), so nothing that inspects it changes.forbidden,not found,already exists,connection refused) pick the matching suggestions and error code instead of the generic fallback.Tests
internal/commands/builder_errors_test.goadds a table-driven test with the mock shell executor: an admission webhook denial, an RBAC denial (nowK8S_PERMISSION_ERROR) and a failure with no output. The first two fail onmain.internal/commandscoverage goes from 69.2% to 79.8%.go test -tags=test -cover ./pkg/... ./internal/... ./cmd/...: all packages passgolangci-lint run --build-tags=test(v2.13.2, the Makefile's version): 0 issuesgo fmt ./...: no changesChecked on a cluster
kagent
v0.10.3on kind, with this build of the tool server mounted over/tool-serverand an admission webhook that holds risky changes. Asked to scale a deployment in a protected namespace, kagent's unchangedk8s-agentnow receives the webhook's full message. It explained the hold, quoted the approval command and stopped after one tool call. Without the fix it gotexit status 1and tried the change three different ways.Prepared with an AI coding assistant; I reviewed the change and ran the tests and the cluster check above.