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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions