Fix selection loss while an agent thread is loading (#64252)
## Objective
Fix the bug where selected context is lost if “Add Selection to Thread”
runs before a new agent thread finishes loading. This can leave the
message empty, particularly with slower-starting external agents such as
Claude ACP.
This addresses the [loading bug
mentioned](https://github.com/zed-industries/zed/pull/62957#issuecomment-5408347793)
in #62957.
## Solution
Preserve selected context until the destination thread’s message editor
is ready, then add it without sending the message or taking focus from
the source. This fixes the existing “Add Selection to Thread” behavior
without introducing another action.
## Testing
GPUI regression tests pass on macOS for context delivery during delayed
startup, with additional authentication, draft lifecycle, and retry
coverage.
Recommended manual check: on macOS with the default keymap, temporarily
add [this
entry](https://github.com/porada/domfiles/blob/ad86e7d0a38cd477070dec7f12a1ade4a6dce504/home/.config/zed/keymap.json#L27-L33)
to your keymap:
```json
{
"context": "!AcpThread > (Editor && mode == full)",
"bindings": {
"ctrl-enter": [
"workspace::SendKeystrokes",
"cmd-? cmd-n cmd-? cmd->"
]
}
}
```
Make sure Claude ACP is set as the default for new threads. Select code
in the editor and press `ctrl-enter`. After the thread loads, confirm
that the selected context appears in the new message and the message
remains unsent.
## Self-Review Checklist:
- [x] I’ve reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed’s UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable
---
Release Notes:
- Fixed the bug where selected context can get lost when added before an
agent thread finishes loading.
---------
Co-authored-by: Christopher Biscardi <chris@christopherbiscardi.com>
f8c2cc8440Dom Porada committed on 10/1/2026, 1:49:50 AM· committed by GitHubparent40180d9