Skip to content

agent_ui: Fix panic in message editor#51918

Merged
bennetbo merged 2 commits intomainfrom
famos-k2r5mmw0
Mar 19, 2026
Merged

agent_ui: Fix panic in message editor#51918
bennetbo merged 2 commits intomainfrom
famos-k2r5mmw0

Conversation

@bennetbo
Copy link
Copy Markdown
Member

@bennetbo bennetbo commented Mar 19, 2026

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 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

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

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

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 19, 2026
@github-actions
Copy link
Copy Markdown

📏 PR Size: 523 lines changed (size/L)

Please note: this PR exceeds the 400 LOC soft limit.

  • Consider splitting into separate PRs if the changes are separable
  • Ensure the PR description includes a guided tour in the "How to Review" section so reviewers know where to start

@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, benbrandt and mikayla-maki and removed request for a team March 19, 2026 10:43
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Mar 19, 2026
@github-actions github-actions bot added size/L and removed size/L labels Mar 19, 2026
@github-actions github-actions bot added size/L and removed size/L labels Mar 19, 2026
@bennetbo bennetbo merged commit 9a2ed29 into main Mar 19, 2026
30 checks passed
@bennetbo bennetbo deleted the famos-k2r5mmw0 branch March 19, 2026 11:11
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
## 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
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
## 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
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement large-pr staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants