# agent: Release completed terminal PTY resources \(\#62978\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 3b90a9683096f32c2d6ea452355460e9cabea020

Requested commit: 3b90a9683096f32c2d6ea452355460e9cabea020

Commit: 3b90a9683096f32c2d6ea452355460e9cabea020

Tree: 724db815f77542e0574e066bd717353f93b2f118

Author: Grant Hutchins

Committer: GitHub

## Message

```
agent: Release completed terminal PTY resources (#62978)

Closes #62972

Completed Agent terminal cards remain alive so conversation history can
render their output. Each retained terminal also kept its Alacritty PTY
sender alive, which retained a poller and one kqueue descriptor after
the command exited.

Terminal lifecycle state is now more strongly typed to prevent this
class of regression. Task terminals are created through a sealed
`TerminalMode` API that pairs their running state with the correct
completion channel, while PTY resources use explicit active and released
states. This makes invalid lifecycle combinations unrepresentable
instead of relying on callers to coordinate independent `Option` values
correctly.

- Release the live PTY sender after final terminal output is captured.
- Preserve PTY process metadata and working-directory behavior for
historical terminal cards.
- Represent PTY resources as explicit active or released lifecycle
states.
- Construct interactive and task terminals through typed modes so a task
cannot omit its running state or use a mismatched completion channel.
- Keep resource release idempotent for later ACP release and entity
destruction.
- Add a macOS regression test that retains the historical terminal
entity while exercising the complete sandboxed terminal tool path.

Release Notes:

- Fixed Agent terminal tool calls leaking file descriptors on macOS.

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
```

## Parents

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

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