# Add timeout support to terminal tool \(\#44895\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/7d7ca129db29190fb6a99876d94c753e1db77560)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 7d7ca129db29190fb6a99876d94c753e1db77560

Requested commit: 7d7ca129db29190fb6a99876d94c753e1db77560

Commit: 7d7ca129db29190fb6a99876d94c753e1db77560

Tree: b2c2d9509ddfff38cf6a53e65dae3de6d104b673

Author: Nathan Sobo

Committer: GitHub

## Message

```
Add timeout support to terminal tool (#44895)

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
```

## Parents

- [7cd483321b4f070d5433d31ed3101f97b8d7f866](https://git.cafe/gitcafe/zed/commit/7cd483321b4f070d5433d31ed3101f97b8d7f866?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/7d7ca129db29190fb6a99876d94c753e1db77560?format=markdown)
