Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-ui): r8-l5 isolate create-recovery guards

Josué4c563a7d9801
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.tsx
index 58ba5a276..cdbf5d8ec 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,6 +1,10 @@
// @vitest-environment jsdom
import { 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'
@@ -17,6 +21,34 @@ 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.ts
index afcc8c853..62388ee01 100644
--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts
+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts
@@ -94,6 +94,31 @@ 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
@@ -1054,12 +1079,18 @@ 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 (
- selectedAgentRef.current === agentRef &&
- requestGenerationRef.current === requestGeneration &&
- authorityScopeGenerationRef.current === authorityScopeGeneration &&
- currentAuthorityScopeRef.current === authorityScopeAtCreate &&
- selectionIntentRevision !== undefined &&
- host.current?.getSelectionIntentRevision() === selectionIntentRevision
+ 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(),
+ })
) {
const restoreChatId =
pendingSelection?.mode === 'specific'