Skip to content

Commit 518be83

Browse files
authored
🤖 Remove line limit for IPC bash execution (#345)
Removes the 10K line limit for executeBash over IPC to enable more robust code review operations. The 1MB byte limit remains in place to prevent unbounded memory usage. _Generated with `cmux`_
1 parent 2b73afa commit 518be83

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

src/constants/toolLimits.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export const BASH_MAX_TOTAL_BYTES = 16 * 1024; // 16KB total output to show agen
77
export const BASH_MAX_FILE_BYTES = 100 * 1024; // 100KB max to save to temp file
88

99
// truncate policy limits (IPC - generous for UI features like code review)
10-
export const BASH_TRUNCATE_HARD_MAX_LINES = 10_000; // 10K lines
10+
// No line limit for IPC - only byte limit applies
1111
export const BASH_TRUNCATE_MAX_TOTAL_BYTES = 1024 * 1024; // 1MB total output
12+
export const BASH_TRUNCATE_MAX_FILE_BYTES = 1024 * 1024; // 1MB file limit (same as total for IPC)
1213

1314
// Shared limits
1415
export const BASH_MAX_LINE_BYTES = 1024; // 1KB per line (shared across both policies)

src/services/tools/bash.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ describe("bash tool", () => {
166166
});
167167

168168
const args: BashToolArgs = {
169-
script: "for i in {1..11000}; do echo line$i; done", // Exceeds 10K line hard cap for truncate policy
169+
// Generate ~1.5MB of output (1700 lines * 900 bytes) to exceed 1MB byte limit
170+
script: 'perl -e \'for (1..1700) { print "A" x 900 . "\\n" }\'',
170171
timeout_secs: 5,
171172
};
172173

@@ -177,15 +178,14 @@ describe("bash tool", () => {
177178
expect(result.truncated).toBeDefined();
178179
if (result.truncated) {
179180
expect(result.truncated.reason).toContain("exceeded");
180-
// Should collect all lines up to when truncation was triggered
181-
expect(result.truncated.totalLines).toBeGreaterThan(10000);
181+
// Should collect lines up to ~1MB (around 1150-1170 lines with 900 bytes each)
182+
expect(result.truncated.totalLines).toBeGreaterThan(1000);
183+
expect(result.truncated.totalLines).toBeLessThan(1300);
182184
}
183185

184-
// Should contain collected lines
185-
expect(result.output).toContain("line1");
186-
expect(result.output).toContain("line10000");
187-
// Might or might not contain line 11000 depending on when truncation triggers
188-
expect(result.output).toContain("line11000");
186+
// Should contain output that's around 1MB
187+
expect(result.output?.length).toBeGreaterThan(1000000);
188+
expect(result.output?.length).toBeLessThan(1100000);
189189

190190
// Should NOT create temp file with truncate policy
191191
const files = fs.readdirSync(tempDir.path);

src/services/tools/bash.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
BASH_MAX_LINE_BYTES,
1111
BASH_MAX_TOTAL_BYTES,
1212
BASH_MAX_FILE_BYTES,
13-
BASH_TRUNCATE_HARD_MAX_LINES,
1413
BASH_TRUNCATE_MAX_TOTAL_BYTES,
14+
BASH_TRUNCATE_MAX_FILE_BYTES,
1515
} from "@/constants/toolLimits";
1616

1717
import type { BashToolResult } from "@/types/tools";
@@ -62,13 +62,14 @@ class DisposableProcess implements Disposable {
6262
*/
6363
export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
6464
// Select limits based on overflow policy
65-
// truncate = IPC calls (generous limits for UI features)
65+
// truncate = IPC calls (generous limits for UI features, no line limit)
6666
// tmpfile = AI agent calls (conservative limits for LLM context)
6767
const overflowPolicy = config.overflow_policy ?? "tmpfile";
6868
const maxTotalBytes =
6969
overflowPolicy === "truncate" ? BASH_TRUNCATE_MAX_TOTAL_BYTES : BASH_MAX_TOTAL_BYTES;
70-
const maxLines =
71-
overflowPolicy === "truncate" ? BASH_TRUNCATE_HARD_MAX_LINES : BASH_HARD_MAX_LINES;
70+
const maxFileBytes =
71+
overflowPolicy === "truncate" ? BASH_TRUNCATE_MAX_FILE_BYTES : BASH_MAX_FILE_BYTES;
72+
const maxLines = overflowPolicy === "truncate" ? Infinity : BASH_HARD_MAX_LINES;
7273

7374
return tool({
7475
description: TOOL_DEFINITIONS.bash.description + "\nRuns in " + config.cwd + " - no cd needed",
@@ -248,9 +249,9 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
248249
totalBytesAccumulated += lineBytes + 1; // +1 for newline
249250

250251
// Check file limit first (hard stop)
251-
if (totalBytesAccumulated > BASH_MAX_FILE_BYTES) {
252+
if (totalBytesAccumulated > maxFileBytes) {
252253
triggerFileTruncation(
253-
`Total output exceeded file preservation limit: ${totalBytesAccumulated} bytes > ${BASH_MAX_FILE_BYTES} bytes (at line ${lines.length})`
254+
`Total output exceeded file preservation limit: ${totalBytesAccumulated} bytes > ${maxFileBytes} bytes (at line ${lines.length})`
254255
);
255256
return;
256257
}
@@ -290,9 +291,9 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
290291
totalBytesAccumulated += lineBytes + 1; // +1 for newline
291292

292293
// Check file limit first (hard stop)
293-
if (totalBytesAccumulated > BASH_MAX_FILE_BYTES) {
294+
if (totalBytesAccumulated > maxFileBytes) {
294295
triggerFileTruncation(
295-
`Total output exceeded file preservation limit: ${totalBytesAccumulated} bytes > ${BASH_MAX_FILE_BYTES} bytes (at line ${lines.length})`
296+
`Total output exceeded file preservation limit: ${totalBytesAccumulated} bytes > ${maxFileBytes} bytes (at line ${lines.length})`
296297
);
297298
return;
298299
}

0 commit comments

Comments
 (0)