Skip to content

bash tool: unbounded stdout/stderr buffering can OOM the agent #469

Description

@euxaristia

Problem

The bash tool (and to a lesser extent exec_command) allocates full command output into bytes.Buffer with no size limit:

// internal/tools/bash.go:127
var stdout bytes.Buffer
var stderr bytes.Buffer
command.Stdout = &stdout
command.Stderr = &stderr
...
output := formatBashOutput(stdout.String(), ...)

Other tools (grep, read_file, web_fetch) use applyOutputBudget + io.LimitReader. Bash does not.

Impact

  • Easy OOM or unresponsiveness on large output (cat huge file, gh pr with thousands of comments, find /, verbose tests, etc.).
  • Directly caused the "Not enough memory resources..." errors reported during PR review work.
  • No backpressure; the process can be killed before the command even finishes.

Suggested fix

  • Add a reasonable byte limit (e.g. 10-50 MiB) + io.LimitReader for stdout/stderr in bash.go (and review exec_command).
  • Reuse or extend applyOutputBudget / max_output_tokens logic.
  • Truncate early and surface a clear message + suggestion to narrow the command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions