# agent_ui: Fix panic in message editor \(\#51918\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 9a2ed297dd99e24a12333f7c0d582a44d14cb253

Requested commit: 9a2ed297dd99e24a12333f7c0d582a44d14cb253

Commit: 9a2ed297dd99e24a12333f7c0d582a44d14cb253

Tree: a764949da6fdf5bd398075e86cfbf17befb78535

Author: Bennet Bo Fenner

Committer: GitHub

## Message

```
agent_ui: Fix panic in message editor (#51918)

## Context

Fixes ZED-59M

We could end panicking because of a double lease in message editor. This
could happen when pasting text and this line was executed:
`PromptCompletion::try_parse(line, offset_to_line,
&self.source.supported_modes(cx))`

Since self.source is the Entity<MessageEditor> in this case, we will try
to read message editor while it's being updated.

I took this as an opportunity to refactor `prompt_capabilities` and
`available_commands` which were both passed around as Rc<RefCell<...>>.
Now we have a single struct called `SessionCapabilities` which maintains
both and we pass that around wrapped in an `Arc<RwLock<...>>`
(`SharedSessionCapabilities`)

## Self-Review Checklist

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash when pasting text into the prompt editor in the agent
panel
```

## Parents

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

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