Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r1-l2 retry transient team-context failures
Josué4af84814f8b3
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex c1cab0caf..c5c9916c2 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -69,6 +69,58 @@ type PendingSandboxUiDeepLinkLaunch = {conversationOrigin: SandboxUiConversationOrigin | null}+const TRANSIENT_TEAM_CONTEXT_ERROR_CODES = new Set([+ 'ECONNRESET',+ 'ECONNREFUSED',+ 'EPIPE',+ 'ETIMEDOUT',+ 'ENOTFOUND',+ 'EAI_AGAIN',+ 'UND_ERR_CONNECT_TIMEOUT',+ 'UND_ERR_SOCKET',+])++function errorMessage(error: unknown): string {+ return error instanceof Error ? error.message : String(error || 'Unknown error')+}++function errorCode(error: unknown): string {+ if (!error || typeof error !== 'object') return ''+ const record = error as { code?: unknown; cause?: { code?: unknown } }+ return String(record.code || record.cause?.code || '').toUpperCase()+}++function isTransientSandboxUiTeamContextError(error: unknown): boolean {+ const message = errorMessage(error).toLowerCase()+ if (+ /\b(400|401|403|404)\b/.test(message) ||+ message.includes('access denied') ||+ message.includes('authenticat') ||+ message.includes('forbidden') ||+ message.includes('not a member') ||+ message.includes('permission') ||+ message.includes('select a team') ||+ message.includes('teamid is required') ||+ message.includes('validation')+ ) {+ return false+ }++ const code = errorCode(error)+ if (TRANSIENT_TEAM_CONTEXT_ERROR_CODES.has(code)) return true++ return (+ message.includes('connection refused') ||+ message.includes('connection reset') ||+ message.includes('fetch failed') ||+ message.includes('network error') ||+ message.includes('socket hang up') ||+ message.includes('temporarily unavailable') ||+ message.includes('timed out') ||+ message.includes('timeout')+ )+}+function getInitialThemeMode(): ThemeMode {if (typeof window === 'undefined') return 'dark'try {@@ -564,6 +616,28 @@ export function App() {if (switchedTeam && originalTeamId !== pending.link.teamId) {sandboxUiDeepLinkRestoreTeamByIdRef.current.set(pending.link.id, originalTeamId)}+ if (isTransientSandboxUiTeamContextError(error)) {+ const launchContext: PendingSandboxUiDeepLinkLaunch = {+ linkId: pending.link.id,+ requestId: 0,+ generation: processingGeneration,+ originalTeamId,+ linkTeamId: pending.link.teamId,+ switchedTeam,+ conversationOrigin: pending.conversationOrigin,+ }+ const exhaustedRetryBudget = deferSandboxUiDeepLink(+ pending,+ `Could not switch to the linked team yet: ${errorMessage(+ error+ )}. This link will retry shortly.`,+ 'info'+ )+ if (exhaustedRetryBudget) {+ await restoreSandboxUiDeepLinkTeam(launchContext)+ }+ return+ }throw error}}diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsxindex 7818e86d9..519a17a91 100644--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx@@ -616,6 +616,120 @@ describe('App deep-link orchestration', () => {expect(ensureTeamContext).toHaveBeenCalledTimes(1)})+ it('retries a transient team-context failure and opens without duplicate mounts', async () => {+ vi.useFakeTimers({ shouldAdvanceTime: true })+ let liveTeamId = 'team-a'+ const transientError = Object.assign(new Error('fetch failed'), { code: 'ECONNRESET' })+ const ensureTeamContext = vi+ .fn()+ .mockRejectedValueOnce(transientError)+ .mockImplementation(async ({ teamId }: { teamId?: string }) => {+ if (!teamId || teamId === liveTeamId) return false+ liveTeamId = teamId+ return true+ })+ currentController = makeController({+ initialExperienceLoading: false,+ handleEnsureTeamContext: ensureTeamContext,+ getCurrentTeamId: () => liveTeamId,+ })+ listApps.mockResolvedValue({+ apps: [+ {+ appRef: 'ns/app',+ title: 'Linked App',+ defaultPath: '/',+ ready: true,+ phase: 'active',+ },+ ],+ })+ render(<App />)+ await waitFor(() => expect(emitDeepLink).not.toBeNull())++ act(() => {+ emitDeepLink?.({ id: 1, appRef: 'ns/app', teamId: 'team-b' })+ })++ await waitFor(() => {+ expect(currentController.pushToast).toHaveBeenCalledWith(+ 'Could not switch to the linked team yet: fetch failed. This link will retry shortly.',+ 'info'+ )+ })+ expect(acknowledgeDeepLink).not.toHaveBeenCalled()++ await act(async () => {+ vi.advanceTimersByTime(1_000)+ await Promise.resolve()+ })+ await reportShortcutOpenResult()++ await waitFor(() => expect(acknowledgeDeepLink).toHaveBeenCalledWith(1))+ expect(acknowledgeDeepLink).toHaveBeenCalledTimes(1)+ expect(currentController.handleNavSelect).toHaveBeenCalledTimes(1)+ expect(liveTeamId).toBe('team-b')+ })++ it('keeps a transient team-context failure pending when retry budget is exhausted', async () => {+ vi.useFakeTimers({ shouldAdvanceTime: true })+ const ensureTeamContext = vi.fn(async () => {+ throw Object.assign(new Error('fetch failed'), { code: 'ECONNRESET' })+ })+ currentController = makeController({+ initialExperienceLoading: false,+ handleEnsureTeamContext: ensureTeamContext,+ })+ render(<App />)+ await waitFor(() => expect(emitDeepLink).not.toBeNull())++ act(() => {+ emitDeepLink?.({ id: 1, appRef: 'ns/app', teamId: 'team-b' })+ })++ await waitFor(() => expect(ensureTeamContext).toHaveBeenCalledTimes(1))+ await waitFor(() => {+ expect(currentController.pushToast).toHaveBeenCalledWith(+ 'Could not switch to the linked team yet: fetch failed. This link will retry shortly.',+ 'info'+ )+ })++ for (const [index, delay] of [1_000, 2_000, 4_000, 8_000, 15_000].entries()) {+ await act(async () => {+ vi.advanceTimersByTime(delay)+ await Promise.resolve()+ })+ await waitFor(() => expect(ensureTeamContext).toHaveBeenCalledTimes(index + 2))+ }++ await waitFor(() => {+ expect(confirmDialogHarness.props?.title).toBe('App link could not be opened')+ })+ expect(ensureTeamContext).toHaveBeenCalledTimes(6)+ expect(acknowledgeDeepLink).not.toHaveBeenCalled()+ })++ it('does not retry permanent team access failures', async () => {+ const ensureTeamContext = vi.fn(async () => {+ throw new Error('403 forbidden: not a member of team-b')+ })+ currentController = makeController({+ initialExperienceLoading: false,+ handleEnsureTeamContext: ensureTeamContext,+ })+ render(<App />)+ await waitFor(() => expect(emitDeepLink).not.toBeNull())++ act(() => {+ emitDeepLink?.({ id: 1, appRef: 'ns/app', teamId: 'team-b' })+ })++ await waitFor(() => expect(acknowledgeDeepLink).toHaveBeenCalledWith(1))+ expect(ensureTeamContext).toHaveBeenCalledTimes(1)+ expect(confirmDialogHarness.props?.title).not.toBe('App link could not be opened')+ })+it('keeps a failed native mount unacked and continues with later links', async () => {currentController = makeController({ initialExperienceLoading: false })listApps.mockResolvedValue({