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>
c821538b57Hazi committed on 9/28/2026, 4:16:26 PM· committed by GitHubparent408c713
8 files changedLine totals unavailable