# agent: Add configurable idle thread retention \(\#64547\) · gitcafe/zed

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

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

Visibility: public

Requested revision: c821538b57701b3a42b59e618bee184d6c6c5d97

Requested commit: c821538b57701b3a42b59e618bee184d6c6c5d97

Commit: c821538b57701b3a42b59e618bee184d6c6c5d97

Tree: c85f2f9674315c3ba0290b8a48c43a271babb123

Author: Hazi

Committer: GitHub

## Message

````
agent: Add configurable idle thread retention (#64547)

## Objective

Add a configurable limit for idle, loadable agent threads retained in
memory.

Previously, a thread that was still running when the user switched away
from it was retained correctly, but was not reconsidered for unloading
after it completed. It could remain loaded until a later cleanup
trigger.

## Solution

- Add the `agent.max_idle_retained_threads` setting, defaulting to `5`.
- Re-run retained-thread cleanup when a retained ACP thread transitions
to `Idle`.
- Remove retained-thread status subscriptions when their thread is
unloaded or reactivated.
- Add regression coverage for unloading a retained thread after it
completes when the limit is `0`.

## Testing

- Added a GPUI regression test covering a running thread that is
retained, completes, and is then unloaded with:

  ```json
  {
    "agent": {
      "max_idle_retained_threads": 0
    }
  }
  ```

## 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
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Added a setting to control how many idle agent threads remain loaded.

---------

Co-authored-by: Christopher Biscardi <chris@christopherbiscardi.com>
````

## Parents

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

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