alibaba/open-code-review · error
%s produced more than 64KiB of output
Error message
%s produced more than 64KiB of output
What it means
The credential command's captured stdout is capped at 64KiB. When out.overflow is set, the output is oversized and untrustworthy, so resolveKeyCmd refuses it with this error instead of returning a corrupted or truncated key.
Source
Thrown at internal/llm/keycmd.go:92
// pipe closed. exec.CommandContext SIGKILLs only the shell, so a grandchild
// (gpg-agent, pinentry, `op`) that inherited the stdout pipe keeps it open
// and Wait blocks on the read long past the timeout -- reproducible with
// api_key_cmd = "sleep 200 & printf tok". WaitDelay makes Wait give up
// shortly after the context dies.
out := &cappedBuffer{max: keyCmdMaxOutput}
c.Stdout = out
c.WaitDelay = keyCmdWaitDelay
err := c.Run()
// Checked first so a timeout reports as such instead of as the SIGKILL exit
// status it produces. (Run has already joined every stdout copier, so the
// buffer below is safe to read on all paths.)
if ctx.Err() == context.DeadlineExceeded {
// Wrap ctx.Err() so callers can errors.Is(err, context.DeadlineExceeded).
return "", fmt.Errorf("%s timed out after %s: %w", label, keyCmdTimeout, ctx.Err())
}
if out.overflow {
return "", fmt.Errorf("%s produced more than 64KiB of output", label)
}
// ErrWaitDelay only means an orphaned grandchild still holds the pipe; the
// command itself exited fine and its output is already buffered, so use it
// rather than surfacing an exec-internal error.
if err != nil && !errors.Is(err, exec.ErrWaitDelay) {
// Covers non-zero exit and command-not-found (the shell exits non-zero
// and prints its not-found message on the child's stderr). ExitError.Stderr
// stays nil because we assigned c.Stderr, so no output can leak here.
return "", fmt.Errorf("%s failed: %w", label, err)
}
// Trim a trailing line break; multi-line output past that is ambiguous and refused.
// ContainsAny (not Contains "\n") so a lone interior CR is caught too: TrimRight
// leaves it, TrimSpace below only strips the edges, and a CR inside a credential
// makes net/http reject the Authorization header with an opaque error.
trimmed := strings.TrimRight(out.buf.String(), "\r\n")
if strings.ContainsAny(trimmed, "\n\r") {
return "", fmt.Errorf("%s produced multi-line output; expected a single credential (pipe through 'head -n1' if your command prints more)", label)View on GitHub (pinned to 5cf97d0d15)
Solutions
- Make the command print only the credential to stdout (move logs to stderr)
- Extract the exact field in the shell, e.g. jq -r '.token' or --query ... --output text
- Fix accidental infinite output loops in the helper script
- Verify with: <your-cmd> | wc -c — output must be well under 64KiB
Example fix
// before keyCmd: "aws codeartifact get-authorization-token --output json" // after keyCmd: "aws codeartifact get-authorization-token --output text --query authorizationToken"
Defensive patterns
Strategy: validation
Validate before calling
out, _ := exec.Command("sh", "-c", "<your-key-cmd>").Output()
if len(out) > 60000 { /* oversized; fix the command before use */ } Prevention
- Print only the credential on stdout; send logs to stderr
- Extract exact fields with jq / --query rather than dumping JSON
- Avoid helper scripts with loops or verbose stdout output
When it happens
Trigger: The configured key command prints far more than the key — a script that also dumps debug output to stdout, a CLI printing a full JSON document plus banners, or a loop accidentally emitting data continuously.
Common situations: Helper scripts echoing credentials plus verbose logs; a command streaming progress to stdout instead of stderr; fetching a token bundle when a single key is expected.
Related errors
- %s timed out after %s: %w
- %s failed: %w
- %s produced multi-line output; expected a single credential
- %s produced a control byte 0x%02X at offset %d; a credential
- %s produced empty output
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/43fa883d0b1eb779.
Report an issue: GitHub.