# agent_ui: Smarter logic for when we drop background threads \(\#52016\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 53db8891f028ab26dd57191549ce8d4e8d7746a0

Requested commit: 53db8891f028ab26dd57191549ce8d4e8d7746a0

Commit: 53db8891f028ab26dd57191549ce8d4e8d7746a0

Tree: d91483017dff4cf8c64db962e3b07065baafb28d

Author: Ben Brandt

Committer: GitHub

## Message

```
agent_ui: Smarter logic for when we drop background threads (#52016)

## Context

Previously we were very eagerly dropping threads from memory. However,
reloading threads has a cost:
- For our agent, we have to replay events, which is lossy
- It's slower for external agents
- Some agents don't support reloading

So we keep the most recent 5 idle threads (or all threads who can't be
reloaded) and clean up our list after every insertion.


## Self-Review Checklist

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A

---------

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
```

## Parents

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

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