# Route open_thread through load_agent_thread to prevent duplicate sessions \(\#53859\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 5d15e010aee869a9e1f3e168d089b5650aa13ba1

Requested commit: 5d15e010aee869a9e1f3e168d089b5650aa13ba1

Commit: 5d15e010aee869a9e1f3e168d089b5650aa13ba1

Tree: c8e5c674bd465775efd90df887823f46d7b6c1ed

Author: Richard Feldman

Committer: GitHub

## Message

```
Route open_thread through load_agent_thread to prevent duplicate sessions (#53859)

`AgentPanel::open_thread` (called when clicking `@thread` mention links,
pasting thread links, or opening threads via the CLI) was calling
`external_thread` directly, bypassing the de-duplication guards in
`load_agent_thread`. This meant clicking a thread link to the
currently-active thread would create a redundant `ConversationView`
sharing the same `NativeAgent` session. When the old CV was later
evicted from `background_threads`, its `on_release` called
`close_all_sessions`, removing the session and breaking the surviving CV
with "Session not found".

Fix this by routing `open_thread` through `load_agent_thread`, which
checks the active view, retained threads, and background threads before
creating a new `ConversationView`. This prevents the duplicate from
being created in the first place.

Release Notes:

- Fixed a "Session not found" error that could occur after clicking a
thread mention link.
```

## Parents

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

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