Skip to content

The agent that grows with you

fix(desktop): a group Send that converges on another window's intent keeps this draft

Teknium18b400ba132b
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
index 220dcadfcef..d4dc5b69048 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
@@ -140,3 +140,21 @@ it('reads back retry on the same authority and sends only through the group driv
expect(screen.getByText('Owner reply')).toBeTruthy()
expect(request.mock.calls.every(c => c[1].startsWith('groups.'))).toBe(true)
})
+
+// Review 5475590057 P3: another window won the room's one intent slot after this one restored.
+// Send converges on that durable winner (4149282e49) but this window's typed text is kept, not lost.
+it('a Send that converges on another window\'s pending intent keeps this window\'s draft', async () => {
+ const binding = { connectionId: 'remote', profile: 'team', roomId: 'two-windows' }
+ request.mockImplementation(async (_route, method) => method === 'groups.state'
+ ? { room: { name: 'Room' }, driver_status: {} } : method === 'groups.log' ? { events: [] } : {})
+ render(<CanonicalGroupWorkspace binding={binding} />)
+ await screen.findByText('Room')
+ await waitFor(() => expect((screen.getByRole('textbox') as HTMLTextAreaElement).disabled).toBe(false))
+ const other = await prepareCanonicalGroupSend(binding, { text: 'from the other window', attachments: [] })
+ fireEvent.change(screen.getByRole('textbox'), { target: { value: 'typed here' } })
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }))
+ await waitFor(async () => expect(await readCanonicalGroupSend(binding)).toBeUndefined())
+ expect(request.mock.calls.filter(c => c[1] === 'groups.send').map(c => c[2])).toEqual([{ ...other.params, profile: 'team' }])
+ await waitFor(() => expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe('typed here'))
+ expect((screen.getByRole('textbox') as HTMLTextAreaElement).disabled).toBe(false)
+})
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
index f84c8c4061c..6eea0972504 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
@@ -13,6 +13,9 @@ type RoomEvent = CanonicalGroupEvent
interface Attachment { attachment_id?: string; event_id?: string; kind: string; name: string; mime: string; size?: number }
interface RoomState { room: { name: string }; driver_status?: { pending_actions?: CanonicalPendingAction[] } }
+const sameGroupPayload = (payload: Record<string, unknown>, text: string, attachments: Attachment[]) =>
+ payload.text === text && JSON.stringify(payload.attachments ?? []) === JSON.stringify(attachments)
+
export function CanonicalGroupWorkspace({ binding, visible = true, onBack }: {
binding: CanonicalGroupBinding; visible?: boolean; onBack?: () => void
}) {
@@ -38,6 +41,8 @@ function CanonicalRoomView({ binding: initialBinding, visible, onBack }: {
const alive = useRef(true)
const [discard, setDiscard] = useState<CanonicalPendingAction | null>(null)
const revision = useRef(0)
+ // This window's typed draft while it sends the room's one pending intent another window prepared.
+ const heldDraft = useRef<{ text: string; attachments: Attachment[] } | null>(null)
// eslint-disable-next-line no-restricted-syntax -- journal hydration and mounted lifetime, not a reactive store mirror
useEffect(() => {
@@ -123,13 +128,25 @@ function CanonicalRoomView({ binding: initialBinding, visible, onBack }: {
const exact = pending ?? await prepareCanonicalGroupSend(binding, { text: draft, attachments })
if (!alive.current) {return}
+
+ // Another window won the room's slot: send its intent first, keep this window's words.
+ if (!pending && !sameGroupPayload(exact.params.payload, draft, attachments)) {
+ heldDraft.current = { text: draft, attachments }
+ }
+
setPending(exact)
setDraft(String(exact.params.payload.text ?? ''))
setAttachments((exact.params.payload.attachments as Attachment[] | undefined) ?? [])
await canonicalGroupRequest(exact.binding, 'groups.send', exact.params)
await retireCanonicalGroupSend(exact.binding, exact.params.event_id)
- if (alive.current) {setPending(null); setDraft(''); setAttachments([])}
+ if (alive.current) {
+ const held = heldDraft.current
+ heldDraft.current = null
+ setPending(null)
+ setDraft(held?.text ?? '')
+ setAttachments(held?.attachments ?? [])
+ }
})
}