# Fix agent terminal in headless eval sandbox \(\#59969\) · gitcafe/zed

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

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

Visibility: public

Requested revision: a923597341c83df525e082bb5ecb3fa66b53c5f4

Requested commit: a923597341c83df525e082bb5ecb3fa66b53c5f4

Commit: a923597341c83df525e082bb5ecb3fa66b53c5f4

Tree: dd26b06af904a13a2bc909ef2a8951ed3ebc1434

Author: Anant Goel

Committer: GitHub

## Message

```
Fix agent terminal in headless eval sandbox (#59969)

# Objective

Fix the agent `terminal` tool in headless eval environments. In the eval
sandbox, terminal commands failed before the shell ran with `IOError:
Not a tty (os error 25)` because PTY setup attempted to acquire a
controlling terminal.

## Solution

- Add a `terminal::HeadlessTerminal` global that is set by `eval_cli`
only.
- When headless mode is enabled, run terminal task commands as plain
subprocesses with piped stdout/stderr instead of opening a PTY.
- Pump subprocess output through the existing terminal emulator/event
channel so output capture, completion, and task killing keep working.
- Build ACP terminal commands non-interactively in headless mode.
- Keep the normal editor terminal path unchanged when the global is
unset.
- Handle non-PTY output edge cases by preserving split CRLF sequences
and avoiding an indefinite wait if subprocess exit-status polling
errors.

## Testing

- `cargo fmt --all`
- `cargo test -p util non_interactive_omits_interactive_flag`
- `cargo test -p terminal test_no_pty_task_terminal_captures_output`
- `cargo test -p terminal test_convert_lf_to_crlf_preserves_split_crlf`
- `cargo test -p terminal test_write_output`
- `cargo check -p eval_cli`
- `git --no-pager diff --check`

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed the agent terminal tool failing with "Not a tty" in
headless/eval environments
```

## Parents

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

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