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
This commit is contained in:
@@ -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<unknown>) {
|
||||
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<string, unknown>) => (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()
|
||||
})
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user