Skip to content

Fix: Improve bash tool timeout and output handling #1811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

xhuw
Copy link

@xhuw xhuw commented Aug 11, 2025

My attempt to resolve #1721

2 key changes:

  1. Detects timeouts and report to the LLM
  2. create separate output for the LLM which identifies the stdout, stderr, exitCode and timeout

10 minute max timeout is still too short. I am not sure why its there though so not changing it

@xhuw xhuw force-pushed the bash-timeout-and-output-handling branch 4 times, most recently from b6f08d6 to 191dc02 Compare August 12, 2025 18:11
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGENTS.md Guidelines Review

I've reviewed this PR against the guidelines in AGENTS.md and found several suggestions for improvement. These are suggestions to help maintain code consistency - you can decide whether to address them.

Main Violations Found:

  1. Multiple let statements (lines 133, 134, 136, 137, 147, 157, 193) - The guidelines recommend avoiding let statements where possible. Consider using const with objects to track mutable state.

  2. Use of else if statements (lines 195-202) - The guidelines recommend avoiding else statements unless necessary.

Suggested Improvements:

For the mutable variables:

const terminatedState = { terminated: false, byTimeout: true }
const outputState = { stderr: "", stdout: "" }  
const sizeState = { stdout: 0, stderr: 0 }

For the conditional logic:

const baseOutput = `<stdout>${stdout}</stdout>\n<stderr>${stderr}</stderr>\n<exitCode>${process.exitCode}</exitCode>`

const timeoutMessage = terminated && terminatedByTimeout 
  ? `\n<timeout>Process was terminated by timeout after ${timeout}ms...</timeout>`
  : ''

const truncatedMessage = terminated && (stdoutSize >= MAX_OUTPUT_LENGTH || stderrSize >= MAX_OUTPUT_LENGTH) && !terminatedByTimeout
  ? `\n<outputTruncated>Output was truncated to ${MAX_OUTPUT_LENGTH} characters...</outputTruncated>`
  : ''

const forLLM = baseOutput + timeoutMessage + truncatedMessage

These are suggestions - feel free to keep the current approach if it works better for your use case!

@xhuw xhuw force-pushed the bash-timeout-and-output-handling branch 3 times, most recently from e9efcbe to 0a52eb8 Compare August 13, 2025 07:51
@xhuw
Copy link
Author

xhuw commented Aug 13, 2025

In response to the bot above:

  1. I think let makes sense as they are simple values which I am mutating. not a TS expert though
  2. else is required here as the only way to determine the difference between maxBuffer error and timeout error is if the output size is less than maxBuffer. hence else

@xhuw xhuw force-pushed the bash-timeout-and-output-handling branch 4 times, most recently from b80f207 to eae2424 Compare August 15, 2025 22:34
@xhuw xhuw changed the title Improve bash tool timeout and output handling Fix: Improve bash tool timeout and output handling Aug 15, 2025
@xhuw xhuw force-pushed the bash-timeout-and-output-handling branch from eae2424 to 4ffd9ed Compare August 15, 2025 23:04
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.

bash tool often times out
1 participant