# agent_ui: Reuse visible sessions when reopening threads \(\#53905\) · gitcafe/zed

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

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

Visibility: public

Requested revision: a33a1eb90413e9ae6de57a5f1d4b6ac6e043b337

Requested commit: a33a1eb90413e9ae6de57a5f1d4b6ac6e043b337

Commit: a33a1eb90413e9ae6de57a5f1d4b6ac6e043b337

Tree: 1fac4ce2dcd68b526206e83a030d1a8525233dcb

Author: Nathan Sobo

Committer: GitHub

## Message

```
agent_ui: Reuse visible sessions when reopening threads (#53905)

When reopening a thread that is already visible in the agent panel,
`open_thread` could recreate the session instead of reusing the existing
visible thread. That left the UI holding a thread whose backend session
could be closed out from under it.

This change routes `AgentPanel::open_thread` through
`load_agent_thread`, which already handles the right behavior for
existing sessions:
- reuse the active thread when it already matches
- promote a retained thread when it matches
- only load when the session is not already present

The regression coverage is now a focused behavioral test at the
`AgentPanel::open_thread` boundary that verifies reopening an
already-visible session keeps the thread usable.

cc @bennetbo

Release Notes:

- Fixed reopening an already-visible agent thread so it reuses the
existing session instead of creating a broken duplicate.
```

## Parents

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

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