Skip to content

The agent that grows with you

fix(desktop): a failed owner reconciliation is probed again, not cached until reconnect

Teknium2a4f8a3a1ead
diff --git a/apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts b/apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts
index 4fe3a819a91..4c040081243 100644
--- a/apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts
+++ b/apps/desktop/src/api/canonical-ambiguous-owner-reconcile.test.ts
@@ -24,6 +24,28 @@ async function equalIdClient(resume: (profile: string) => Promise<unknown>) {
const snapshot = (profile: string, epoch: string) => ({ session_id: 'same', revision: 1, execution_generation: 2, replay_epoch: epoch, prompts: [], info: { profile_name: profile } })
+test('a failed owner reconciliation is probed again by the next frame', async () => {
+ let down = false
+
+ const { calls, client, emit } = await equalIdClient(async profile => {
+ if (down) { throw new Error('owner unavailable') }
+
+ return snapshot(profile, `epoch-${profile}`)
+ })
+
+ await client.request('session.resume', { session_id: 'same', profile: 'alpha' })
+ await client.request('session.resume', { session_id: 'same', profile: 'beta' })
+ client.onAny(() => undefined)
+ down = true
+ const probes = () => calls.filter(call => call.startsWith('session.resume')).length - 2
+ emit({ type: 'message.delta', session_id: 'same', replay_epoch: 'restarted', payload: { text: 'a' } })
+ await vi.waitFor(() => expect(probes()).toBe(2))
+ await new Promise(resolve => setTimeout(resolve, 0))
+ emit({ type: 'message.delta', session_id: 'same', replay_epoch: 'restarted', payload: { text: 'b' } })
+ await vi.waitFor(() => expect(probes()).toBe(4))
+ client.close()
+})
+
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] }))
diff --git a/apps/desktop/src/api/client.ts b/apps/desktop/src/api/client.ts
index 92e06422633..204094cc22b 100644
--- a/apps/desktop/src/api/client.ts
+++ b/apps/desktop/src/api/client.ts
@@ -265,12 +265,19 @@ export class HermesGateway extends JsonRpcGatewayClient {
if (this.reconciledEpochs.has(key)) { return }
this.reconciledEpochs.add(key)
+ const generation = this.connectionGeneration
// A new/unknown replay epoch cannot choose between equal stored IDs. One
// authoritative snapshot per known owner recovers cards and establishes routes.
- for (const profile of this.sessionProfiles.get(sessionId) ?? []) {
- void this.request('session.resume', { session_id: sessionId, profile }).catch(() => undefined)
- }
+ const probes = [...this.sessionProfiles.get(sessionId) ?? []].map(profile =>
+ this.request('session.resume', { session_id: sessionId, profile }))
+
+ void Promise.allSettled(probes).then(results => {
+ // No owner answered: a later frame probes again instead of being dropped until reconnect.
+ if (generation === this.connectionGeneration && !results.some(result => result.status === 'fulfilled')) {
+ this.reconciledEpochs.delete(key)
+ }
+ })
}
override async connect(wsUrl: string): Promise<void> {