# agent: Fix race condition when loading threads \(\#51366\) · gitcafe/zed

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

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

Visibility: public

Requested revision: eeb034c31cea9618d445287c906576c1e0aa0898

Requested commit: eeb034c31cea9618d445287c906576c1e0aa0898

Commit: eeb034c31cea9618d445287c906576c1e0aa0898

Tree: 3e0a55528d8958754f220ef3de69fee27815ea4e

Author: Bennet Bo Fenner

Committer: GitHub

## Message

```
agent: Fix race condition when loading threads (#51366)

This fixes a race condition that could occur when using the sidebar:
`Failed to launch: project state not found`

We were accessing/creating the project state before an await point,
meaning that we could remove the state if session/close was called in
the meantime.

- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- N/A
```

## Parents

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

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