From cab80a1bb650a4f4e55f138ce155d2b4e4856e87 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 11 Oct 2026 23:25:53 -0700 Subject: [PATCH] fix(desktop): a canonical prompt declined locally is shown again while still pending Mechanism: deliverCanonicalPrompt latches deliveredPrompts[id] before handing the prompt to the renderer. The renderer's fail() (the stopped-session decline) only marked the wrapper settled and sent nothing to the authority, so the latch stayed: if the authority still listed the prompt, every later authoritative snapshot suppressed it as already delivered until reconnect, and the turn stayed blocked. Fix: fail() retires the prompt's delivery key (fenced to the connection generation), so only answered or settled prompts stay deduplicated and the next snapshot that still lists it shows it again. No authority call is added. Test: apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts 'a prompt declined locally is shown again while the authority still lists it' (red on r14-base: the second snapshot delivers nothing). Review: andrexibiza 4243963769 --- ...anonical-ambiguous-owner-reconcile.test.ts | 42 +++++++++++++++++++ apps/desktop/src/api/client.ts | 9 +++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts diff --git a/apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts b/apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts new file mode 100644 index 0000000000..4fe3a819a9 --- /dev/null +++ b/apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts @@ -0,0 +1,42 @@ +import { JsonRpcGatewayClient } from '@hermes/shared' +import { afterEach, expect, test, vi } from 'vitest' + +import { HermesGateway } from './client' + +afterEach(() => vi.restoreAllMocks()) + +// Equal stored session IDs under two profiles: a frame with an epoch neither snapshot named +// cannot be routed until an authoritative owner probe answers. +async function equalIdClient(resume: (profile: string) => Promise) { + vi.spyOn(JsonRpcGatewayClient.prototype, 'connect').mockResolvedValue() + const calls: string[] = [] + + vi.spyOn(JsonRpcGatewayClient.prototype, 'request').mockImplementation(async (method, params) => { + calls.push(`${method}:${params?.profile}`) + + return (method === 'session.resume' ? resume(String(params?.profile)) : { status: 'resolved' }) as never + }) + const client = new HermesGateway() + await client.connect('ws://localhost/api/ws?native_dial=fixture&ticket=first') + + return { calls, client, emit: (event: Record) => (client as any).handleEvent(event) } +} + +const snapshot = (profile: string, epoch: string) => ({ session_id: 'same', revision: 1, execution_generation: 2, replay_epoch: epoch, prompts: [], info: { profile_name: profile } }) + +test('a prompt declined locally is shown again while the authority still lists it', async () => { + const prompt = { kind: 'approval', prompt_id: 'pending', execution_generation: 2, command: 'build', choices: ['once'] } + const { calls, client } = await equalIdClient(async () => ({ session_id: 's', revision: 1, execution_generation: 2, prompts: [prompt] })) + const shown: any[] = [] + + client.onRequest(request => { + shown.push(request) + + if (shown.length === 1) { request.fail(-32603, 'session interrupted') } + }) + await client.request('session.resume', { session_id: 's' }) + await client.request('session.resume', { session_id: 's' }) + expect(shown).toHaveLength(2) + expect(calls.filter(call => call.startsWith('approval.respond'))).toHaveLength(0) + client.close() +}) diff --git a/apps/desktop/src/api/client.ts b/apps/desktop/src/api/client.ts index b2c9790a19..92e0642263 100644 --- a/apps/desktop/src/api/client.ts +++ b/apps/desktop/src/api/client.ts @@ -144,7 +144,14 @@ export class HermesGateway extends JsonRpcGatewayClient { void this.request(`${kind}.respond`, { session_id: sid, profile, request_id: id, ...answer }) .catch(() => this.recoverCanonicalPrompt(id, sid, profile, generation)) }, - fail: () => { settled = true } + // A card this window declined (a stopped session) is not delivered: the next authoritative + // snapshot that still lists the prompt shows it again. Only answered prompts stay deduplicated. + fail: () => { + if (settled) { return } + settled = true + + if (generation === this.connectionGeneration) { this.deliveredPrompts.delete(id) } + } } recordCanonicalOwner(request, this.displayProfiles.get(canonicalSessionKey(sid, profile)) ?? profile)