Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-ui): r9-l1 simplify create recovery guards
Josué0c917386d760
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/createChatFailureRevisionGuard.characterization.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/createChatFailureRevisionGuard.characterization.test.tsxindex cdbf5d8ec..58ba5a276 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/createChatFailureRevisionGuard.characterization.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/createChatFailureRevisionGuard.characterization.test.tsx@@ -1,10 +1,6 @@// @vitest-environment jsdomimport { afterEach, beforeEach, describe, expect, it } from 'vitest'import { act, waitFor } from '@testing-library/react'-import {- type CreateFailureRecoveryOwner,- isCreateFailureRecoveryOwned,-} from '../useChatListController'import { deferred } from './__fixtures__/catalogFixtures'import { renderController } from './__fixtures__/controllerHarness'import { type MockClerum, installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'@@ -21,34 +17,6 @@ afterEach(() => {})describe('failed New chat selection ownership', () => {- it('checks each failed-create recovery guard independently', () => {- const owner: CreateFailureRecoveryOwner = {- agentRef: 'agent-x',- selectedAgent: 'agent-x',- requestGenerationAtCreate: 7,- requestGeneration: 7,- authorityScopeGenerationAtCreate: 3,- authorityScopeGeneration: 3,- authorityScopeIdentityAtCreate: 'true:user-1:team-1',- currentAuthorityScopeIdentity: 'true:user-1:team-1',- selectionIntentRevisionAtCreate: 12,- currentSelectionIntentRevision: 12,- }- const changedGuards: Array<[string, Partial<CreateFailureRecoveryOwner>]> = [- ['selected agent', { selectedAgent: 'agent-y' }],- ['list request generation', { requestGeneration: 8 }],- ['authority scope generation', { authorityScopeGeneration: 4 }],- ['authority scope identity', { currentAuthorityScopeIdentity: 'true:user-1:team-2' }],- ['selection intent revision', { currentSelectionIntentRevision: 13 }],- ['missing selection revision', { selectionIntentRevisionAtCreate: undefined }],- ]-- expect(isCreateFailureRecoveryOwned(owner)).toBe(true)- for (const [guard, change] of changedGuards) {- expect(isCreateFailureRecoveryOwned({ ...owner, ...change }), guard).toBe(false)- }- })-it('does not restore an older target after the user selects a newer chat', async () => {await clerum.chat.create('agent-x', 'target')await clerum.chat.upsertMessages('agent-x', 'target', [diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.tsindex a5814a6e3..249bddeac 100644--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts@@ -94,31 +94,6 @@ export type PendingChatSelection =| { mode: 'none'; chatId: null }| { mode: 'specific'; chatId: string; title?: string; isRemote?: boolean }-export interface CreateFailureRecoveryOwner {- agentRef: string- selectedAgent: string | null- requestGenerationAtCreate: number- requestGeneration: number- authorityScopeGenerationAtCreate: number- authorityScopeGeneration: number- authorityScopeIdentityAtCreate: string- currentAuthorityScopeIdentity: string- selectionIntentRevisionAtCreate: number | undefined- currentSelectionIntentRevision: number | undefined-}--/** Each recovery boundary independently proves the failed create still owns the view. */-export function isCreateFailureRecoveryOwned(owner: CreateFailureRecoveryOwner): boolean {- return (- owner.selectedAgent === owner.agentRef &&- owner.requestGeneration === owner.requestGenerationAtCreate &&- owner.authorityScopeGeneration === owner.authorityScopeGenerationAtCreate &&- owner.currentAuthorityScopeIdentity === owner.authorityScopeIdentityAtCreate &&- owner.selectionIntentRevisionAtCreate !== undefined &&- owner.currentSelectionIntentRevision === owner.selectionIntentRevisionAtCreate- )-}-/*** Parent-owned collaborators the CRUD flows need. The parent fills this ref each* render (after switchToChat & friends are defined) so the controller's stable@@ -1073,7 +1048,6 @@ export function useChatListController({const selectionIntentRevision = host.current?.beginSelectionIntent()host.current?.clearPendingSelection(agentRef)const requestGeneration = requestGenerationRef.current- const authorityScopeGeneration = authorityScopeGenerationRef.currentconst authorityScopeAtCreate = currentAuthorityScopeRef.currentconst chatId = crypto.randomUUID()let meta: ChatMetadata@@ -1084,18 +1058,10 @@ export function useChatListController({// its visible conversation only while this create still owns the same scope// and selection revision; a newer navigation must remain authoritative.if (- isCreateFailureRecoveryOwned({- agentRef,- selectedAgent: selectedAgentRef.current,- requestGenerationAtCreate: requestGeneration,- requestGeneration: requestGenerationRef.current,- authorityScopeGenerationAtCreate: authorityScopeGeneration,- authorityScopeGeneration: authorityScopeGenerationRef.current,- authorityScopeIdentityAtCreate: authorityScopeAtCreate,- currentAuthorityScopeIdentity: currentAuthorityScopeRef.current,- selectionIntentRevisionAtCreate: selectionIntentRevision,- currentSelectionIntentRevision: host.current?.getSelectionIntentRevision(),- })+ selectionIntentRevision !== undefined &&+ requestGenerationRef.current === requestGeneration &&+ currentAuthorityScopeRef.current === authorityScopeAtCreate &&+ host.current?.getSelectionIntentRevision() === selectionIntentRevision) {const restoreChatId =pendingSelection?.mode === 'specific'