The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): add retry action to branch-failure notification
jinglun010cb3a465f3f69
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsxindex 98014f02c5f..2e522e344c3 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx@@ -22,6 +22,7 @@ import {setSessionArchived} from '@/hermes'import { createClientSessionState } from '@/lib/chat-runtime'+import { $notifications, dismissNotification } from '@/store/notifications'import { $clarifyRequests, clearClarifyRequest, setClarifyRequest } from '@/store/clarify'import { clearSessionDraft, stashSessionDraft, takeSessionDraft } from '@/store/composer'import {@@ -6932,3 +6933,68 @@ describe('createBackendSessionForSend creatingSessionRef hold (#66057)', () => {expect(navigate).toHaveBeenLastCalledWith('/stored-new', { replace: true })})})++// ── Branch failure recovery ──────────────────────────────────────────────────+// When session.create fails (backend restart / WS drop mid-RPC), forkBranch's+// catch surfaces a persistent error notification with a Retry action so the+// user can re-attempt without re-doing the whole branch flow.+describe('branchStoredSession failure retry', () => {+ afterEach(() => {+ cleanup()+ setSessions([])+ $notifications.get().forEach(n => dismissNotification(n.id))+ $notifications.set([])+ vi.restoreAllMocks()+ })++ it('surfaces a retry action when session.create fails, and retry succeeds', async () => {+ let createCallCount = 0+ const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {+ if (method === 'session.create') {+ createCallCount += 1++ if (createCallCount === 1) {+ throw new Error('backend restarted mid-RPC')+ }++ return { session_id: 'branch-runtime', stored_session_id: 'branch-stored' } as never+ }++ return {} as never+ })++ setSessions([storedSession({ id: 'stored-parent', message_count: 1 })])+ vi.mocked(getSessionMessages).mockResolvedValue({+ messages: [{ content: 'branch me', role: 'user', timestamp: 1 }],+ session_id: 'stored-parent'+ } as never)++ let branchStoredSession: ((storedSessionId: string) => Promise<boolean>) | null = null+ render(<BranchHarness onReady={branch => (branchStoredSession = branch)} requestGateway={requestGateway} />)+ await waitFor(() => expect(branchStoredSession).not.toBeNull())++ // First attempt fails — forkBranch catches and returns false.+ await expect(branchStoredSession!('stored-parent')).resolves.toBe(false)+ expect(createCallCount).toBe(1)++ // A persistent error notification with a Retry action was surfaced.+ await waitFor(() => {+ const errorNotifications = $notifications.get().filter(n => n.kind === 'error')++ expect(errorNotifications).toHaveLength(1)+ expect(errorNotifications[0].action).toBeDefined()+ expect(errorNotifications[0].action?.label).toMatch(/retry/i)+ })++ // Click retry — re-invokes forkBranch with the same args, succeeds this time.+ const retryAction = $notifications.get().find(n => n.kind === 'error')?.action++ expect(retryAction).toBeDefined()+ await act(async () => {+ retryAction!.onClick()+ })++ // The retry issued a second session.create and succeeded.+ await waitFor(() => expect(createCallCount).toBe(2))+ })+})diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.tsindex a7fc80565f0..5a899e439d7 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts@@ -2930,7 +2930,17 @@ export function useSessionActions({// Navigate throw or earlier failure after arming pending — never leave// creatingSessionRef stuck true.releaseCreatingSessionGuard()- notifyError(err, copy.branchFailed)+ // Backend restart / WS drop mid-RPC leaves the branch uncreated with no+ // recovery path. Surface a persistent error with a retry action so the+ // user can re-attempt without re-doing the whole branch flow.+ notifyError(err, copy.branchFailed, {+ action: {+ label: t.common.retry,+ onClick: () => {+ void forkBranch(branchMessages, sourceSessionId, parentStoredId, cwd, profile, branchCount, ownerRoute)+ }+ }+ })return false} finally {@@ -2947,6 +2957,7 @@ export function useSessionActions({requestGateway,resumeSession,selectedStoredSessionIdRef,+ t,updateSessionState])