Spaces:
Running
Hand comments to an agent that is actually listening
The comment box pre-mentioned whichever of your agents was registered first, online or not, and the @ menu ranked the same way. Mentioning an offline agent is not wrong — the task waits on the queue until it polls again — but it is rarely what you meant when another agent is sitting there connected.
Both now rank connected first, yours second, so the pre-mention and the row Enter lands on are an agent that can pick the work up now. The green dot beside each row already explains the order.
The part that makes it actually work: presence only arrived with the initial page load, so by the time you selected text it could be minutes stale — long enough for the "connected" agent to be the wrong one. Opening the box now re-checks presence in the background and corrects the mention, but only while the box still holds exactly the text it was given, so it can never overwrite a handle you typed or picked yourself.
Test registers two agents, puts one online through the real /api/mentions/stream long-poll (presence is derived from that, not from /api/mentions, which is only a snapshot), then asserts the box pre-mentions the connected one and that it sorts to the top of the @ menu.
Independent of the other PRs in this set, but it touches client/src/doc.js and test/browser.js, which they also touch — expect textual conflicts depending on merge order.