The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): disable Take over until display.observe has minted this window's viewer id
teknium1008898042267
diff --git a/apps/desktop/src/plugins/hermes-bots/screen-pane.tsx b/apps/desktop/src/plugins/hermes-bots/screen-pane.tsxindex 6b33930aff6..4d1f9df48a5 100644--- a/apps/desktop/src/plugins/hermes-bots/screen-pane.tsx+++ b/apps/desktop/src/plugins/hermes-bots/screen-pane.tsx@@ -251,10 +251,16 @@ export function BotScreenPane({ bot }: { bot: RosterRow }) {}, [bot])const takeOver = useCallback(async () => {+ // The button is disabled without a viewer; the guard keeps a keyboard-activated+ // stale closure from sending an empty viewer_id the server rejects.+ if (!viewer) {+ return+ }+setBusy(true)try {- const result = await displayRequest<{ lease: DisplayLease }>(bot, 'display.lease.acquire', { viewer_id: viewer?.id })+ const result = await displayRequest<{ lease: DisplayLease }>(bot, 'display.lease.acquire', { viewer_id: viewer.id })setScreenLease(bot, result.lease)if (conn !== 'live') {@@ -265,7 +271,7 @@ export function BotScreenPane({ bot }: { bot: RosterRow }) {} finally {setBusy(false)}- }, [attach, bot, conn, viewer?.id])+ }, [attach, bot, conn, viewer])// `force` is the escape hatch for a lease this window no longer owns (a reload// minted a fresh viewer id; the old one still holds): the server refuses a@@ -352,7 +358,10 @@ export function BotScreenPane({ bot }: { bot: RosterRow }) {<Codicon name="debug-continue" /> {t.screen.handBackForce}</Button>) : null}- <Button disabled={busy || conn === 'attaching'} onClick={() => void takeOver()} size="sm">+ {/* The lease is granted to a server-minted viewer id; until `display.observe` has+ minted one for this attach a Take over could only send an empty id and dead-end+ on "viewer_id required". Reconnect is the way to mint one. */}+ <Button disabled={busy || conn === 'attaching' || !viewer} onClick={() => void takeOver()} size="sm"><Codicon name="record-keys" /> {t.screen.takeOver}</Button></>diff --git a/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsx b/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsxindex 04a782af7eb..5e4243435a6 100644--- a/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsx+++ b/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsx@@ -151,3 +151,23 @@ it('offers a forced hand-back for a human lease this window does not hold, sendiexpect(vi.mocked(displayRequest)).toHaveBeenCalledWith(bot, 'display.lease.release', { force: true })view.unmount()})++it('does not offer Take over while no server-minted viewer id exists, even once the attach has settled', async () => {+ vi.mocked(displayRequest).mockImplementation((_bot, method) =>+ method === 'display.observe' ? Promise.reject(new Error('ticket refused')) : Promise.resolve(status)+ )+ const view = render(<BotScreenPane bot={bot} />)+ await waitFor(() => expect(view.getByText('ticket refused')).toBeTruthy())+ // The attach failed before observe minted an id: a Take over now would send an empty+ // viewer_id and the server would answer "viewer_id required" — a dead end.+ expect(view.getByText('Take over').closest('button')?.disabled).toBe(true)++ vi.mocked(displayRequest).mockImplementation(async (_bot, method) =>+ method === 'display.observe' ? { ...status, ticket: 'test-ticket', viewer_id: MINTED } : status+ )+ await act(async () => {+ view.getByTitle('Reconnect').click()+ })+ await waitFor(() => expect(view.getByText('Take over').closest('button')?.disabled).toBe(false))+ view.unmount()+})