Skip to content

Conversation

@nathansobo
Copy link
Contributor

Adds an optional timeout_ms parameter to the terminal tool that allows bounding the runtime of shell commands. When the timeout expires, the running terminal task is killed and the tool returns with the partial output captured so far.

Summary

This PR adds the ability for the agent to specify a maximum runtime when invoking the terminal tool. This helps prevent indefinite hangs when running commands that might wait for network, user prompts, or long builds/tests.

Changes

  • Add timeout_ms field to TerminalToolInput schema
  • Extend TerminalHandle trait with kill() method
  • Implement kill() for AcpTerminalHandle and EvalTerminalHandle
  • Race terminal exit against timeout, killing on expiry
  • Update system prompt to recommend using timeouts for long-running commands
  • Add test for timeout behavior
  • Update .rules to document GPUI executor timers for tests

Testing

  • Added test_terminal_tool_timeout_kills_handle which verifies that when a timeout is specified and expires, the terminal handle is killed and the tool returns with partial output.
  • All existing agent tests pass.

Release Notes:

  • agent: Added optional timeout_ms parameter to the terminal tool, allowing the agent to bound command runtime and prevent indefinite hangs
Adds an optional `timeout_ms` parameter to the terminal tool that allows
bounding the runtime of shell commands. When the timeout expires, the
running terminal task is killed and the tool returns with the partial
output captured so far.

Changes:
- Add `timeout_ms` field to TerminalToolInput schema
- Extend TerminalHandle trait with kill() method
- Implement kill() for AcpTerminalHandle and EvalTerminalHandle
- Race terminal exit against timeout, killing on expiry
- Update system prompt to recommend using timeouts for long-running commands
- Add test for timeout behavior
- Update .rules to document GPUI executor timers for tests

Release Notes:

- agent: Added optional `timeout_ms` parameter to the terminal tool, allowing
  the agent to bound command runtime and prevent indefinite hangs
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 15, 2025
Combine rules 6 and 7 in system prompt to allow running potentially
blocking commands (servers, file watchers, long builds) as long as
a timeout_ms is specified. The user can always request a longer
timeout or no timeout if they're willing to wait or cancel manually.
@nathansobo nathansobo merged commit 7d7ca12 into main Dec 15, 2025
23 checks passed
@nathansobo nathansobo deleted the terminal-tool-timeout branch December 15, 2025 18:36
CherryWorm pushed a commit to CherryWorm/zed that referenced this pull request Dec 16, 2025
Adds an optional `timeout_ms` parameter to the terminal tool that allows
bounding the runtime of shell commands. When the timeout expires, the
running terminal task is killed and the tool returns with the partial
output captured so far.

## Summary

This PR adds the ability for the agent to specify a maximum runtime when
invoking the terminal tool. This helps prevent indefinite hangs when
running commands that might wait for network, user prompts, or long
builds/tests.

## Changes

- Add `timeout_ms` field to `TerminalToolInput` schema
- Extend `TerminalHandle` trait with `kill()` method
- Implement `kill()` for `AcpTerminalHandle` and `EvalTerminalHandle`
- Race terminal exit against timeout, killing on expiry
- Update system prompt to recommend using timeouts for long-running
commands
- Add test for timeout behavior
- Update `.rules` to document GPUI executor timers for tests

## Testing

- Added `test_terminal_tool_timeout_kills_handle` which verifies that
when a timeout is specified and expires, the terminal handle is killed
and the tool returns with partial output.
- All existing agent tests pass.

Release Notes:

- agent: Added optional `timeout_ms` parameter to the terminal tool,
allowing the agent to bound command runtime and prevent indefinite hangs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

2 participants