Skip to content

Long-running bash commands with large outputs cause truncation and agent retry loops #11313

@nabilfreeman

Description

@nabilfreeman

Description

Long-running bash commands with verbose output are being truncated and/or timed out, causing agents to re-attempt commands instead of polling the saved tool output. This creates serious idempotency issues in workflows where commands should run to completion.

Current behavior:

  1. Bash commands have a hardcoded 2-minute default timeout (src/tool/bash.ts:21)
  2. Output is truncated at 2,000 lines or 50KB (src/tool/truncation.ts:10-11)
  3. When output is truncated, full output is saved to ~/.opencode/data/tool-output/, but agents frequently re-run the command instead of reading the saved output
  4. Commands are killed after timeout, even if they would have completed successfully

The problem:

  • Commands that produce large build logs, test outputs, or verbose diagnostics get truncated
  • Agents see truncated output and often retry the command instead of using Read with offset/limit on the saved output file
  • This creates duplicate work, wasted API calls, and potential side effects from non-idempotent commands
  • For CI/CD workflows, this behavior is unacceptable - commands should never exit until a proper exit code is received

Current configuration options:

  • OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS - env var for timeout (exists)
  • No configuration for MAX_LINES or MAX_BYTES truncation limits (hardcoded)

Proposed solution:
Add opencode.json configuration for these limits:

{
  "experimental": {
    "bash": {
      "timeout_ms": 600000,      // 10 minutes
      "max_lines": 10000,        // or null to disable
      "max_bytes": 512000        // or null to disable
    }
  }
}

This would allow users to configure behavior appropriate for their workflows without needing environment variables.

Plugins

None

OpenCode version

Current (main branch)

Steps to reproduce

  1. Run a command that produces more than 2,000 lines of output (e.g., npm install with verbose logging, large test suite)
  2. Observe output is truncated with message about saved file
  3. Watch agent retry the command instead of reading the saved output
  4. For timeout: run any command that takes longer than 2 minutes

Screenshot and/or share link

No response

Operating System

macOS

Terminal

No response

Metadata

Metadata

Assignees

Labels

perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions