Skip to content

Conversation

@cgwalters
Copy link

What does this PR do?

Both bash.ts (BashTool) and prompt.ts (shell command execution) had duplicated logic for accumulating command output that caused O(n²) memory usage from repeated string concatenation.

Extract a shared Output utility that:

  • Accumulates output in memory up to a threshold (50KB)
  • Streams to a temp file when threshold is exceeded
  • Provides preview for UI display while streaming
  • Handles cleanup on abort

This prep commit deduplicates the streaming logic so both code paths benefit from the fix and future improvements only need to be made once.

Assisted-by: OpenCode (Claude claude-sonnet-4-20250514)

How did you verify your code works?

Ran unit tests (though some fail locally here on git main too), and some light interactive testing.

Both bash.ts (BashTool) and prompt.ts (shell command execution) had
duplicated logic for accumulating command output that caused O(n²)
memory usage from repeated string concatenation.

Extract a shared Output utility that:
- Accumulates output in memory up to a threshold (50KB)
- Streams to a temp file when threshold is exceeded
- Provides preview for UI display while streaming
- Handles cleanup on abort

This prep commit deduplicates the streaming logic so both code paths
benefit from the fix and future improvements only need to be made once.

Assisted-by: OpenCode (Claude claude-sonnet-4-20250514)
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found Potential Related PR:

PR #9693: "fix: Prevent O(n²) memory usage in command output"
#9693

This PR appears to be closely related - it addresses the same O(n²) memory usage issue from string concatenation in command output handling that PR #10076 is refactoring into a shared utility.

@cgwalters
Copy link
Author

Sorry this change incorrectly rolled in the O(N^2) work too, I didn't review closely enough before filing.

@cgwalters cgwalters closed this Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant