Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r1-l1 preserve target team during deep-link retries
Josuéb3dd345de8de
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex 5b9c335ee..c1cab0caf 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -177,6 +177,7 @@ export function App() {const processingSandboxUiDeepLinkIdRef = React.useRef<number | null>(null)const launchingSandboxUiDeepLinkRef = React.useRef<PendingSandboxUiDeepLinkLaunch | null>(null)const pendingSandboxUiDeepLinksRef = React.useRef<PendingSandboxUiDeepLink[]>([])+ const sandboxUiDeepLinkRestoreTeamByIdRef = React.useRef(new Map<number, string>())const sandboxUiDeepLinkIdentityRef = React.useRef<string | null | undefined>(undefined)const sandboxUiDeepLinkGenerationRef = React.useRef(0)const sandboxUiShortcutOpenRequestIdRef = React.useRef(0)@@ -275,6 +276,7 @@ export function App() {setPendingSandboxUiDeepLinks([])processingSandboxUiDeepLinkIdRef.current = nulllaunchingSandboxUiDeepLinkRef.current = null+ sandboxUiDeepLinkRestoreTeamByIdRef.current.clear()sandboxUiDeepLinkGenerationRef.current += 1void window.clerum.sandboxUi.clearPendingDeepLinks().catch(error => {console.warn('[Desktop] Could not clear stale app deep links:', error)@@ -406,6 +408,7 @@ export function App() {const next = removePendingSandboxUiDeepLink(pendingSandboxUiDeepLinksRef.current, linkId)setPendingSandboxUiDeepLinkState(next)clearSandboxUiDeepLinkProcessing(linkId)+ sandboxUiDeepLinkRestoreTeamByIdRef.current.delete(linkId)try {await window.clerum.sandboxUi.acknowledgeDeepLink(linkId)} catch (error) {@@ -416,7 +419,11 @@ export function App() {)const deferSandboxUiDeepLink = React.useCallback(- (pending: PendingSandboxUiDeepLink, message: string, tone: 'info' | 'error' = 'error') => {+ (+ pending: PendingSandboxUiDeepLink,+ message: string,+ tone: 'info' | 'error' = 'error'+ ): boolean => {clearSandboxUiDeepLinkProcessing(pending.link.id)if ((pending.retryCount ?? 0) >= MAX_SANDBOX_UI_DEEP_LINK_RETRY_ATTEMPTS) {const next = failPendingSandboxUiDeepLink(@@ -426,7 +433,7 @@ export function App() {)setPendingSandboxUiDeepLinkState(next)vm.pushToast(`Could not open app link: ${message}`, 'error')- return+ return true}const next = deferPendingSandboxUiDeepLink(pendingSandboxUiDeepLinksRef.current,@@ -435,6 +442,7 @@ export function App() {)setPendingSandboxUiDeepLinkState(next)vm.pushToast(message, tone)+ return false},[clearSandboxUiDeepLinkProcessing, setPendingSandboxUiDeepLinkState, vm.pushToast])@@ -530,21 +538,32 @@ export function App() {const processingGeneration = sandboxUiDeepLinkGenerationRef.currentvoid (async () => {- const originalTeamId = vm.getCurrentTeamId()- let switchedTeam = false+ const restoreTeamId = sandboxUiDeepLinkRestoreTeamByIdRef.current.get(pending.link.id)+ const originalTeamId = restoreTeamId ?? vm.getCurrentTeamId()+ let switchedTeam = Boolean(+ restoreTeamId && pending.link.teamId && restoreTeamId !== pending.link.teamId+ )try {if (processingGeneration !== sandboxUiDeepLinkGenerationRef.current) returnif (pending.link.teamId && pending.link.teamId !== vm.getCurrentTeamId()) {await closeActiveSandboxUiEmbedForHandoff()try {- switchedTeam = await vm.handleEnsureTeamContext({+ const didSwitchTeam = await vm.handleEnsureTeamContext({teamId: pending.link.teamId,announce: true,})+ switchedTeam = switchedTeam || didSwitchTeam+ if (switchedTeam && originalTeamId !== pending.link.teamId) {+ sandboxUiDeepLinkRestoreTeamByIdRef.current.set(pending.link.id, originalTeamId)+ }} catch (error) {switchedTeam =- originalTeamId !== pending.link.teamId &&- vm.getCurrentTeamId() === pending.link.teamId+ switchedTeam ||+ (originalTeamId !== pending.link.teamId &&+ vm.getCurrentTeamId() === pending.link.teamId)+ if (switchedTeam && originalTeamId !== pending.link.teamId) {+ sandboxUiDeepLinkRestoreTeamByIdRef.current.set(pending.link.id, originalTeamId)+ }throw error}}@@ -567,12 +586,14 @@ export function App() {switchedTeam,conversationOrigin: pending.conversationOrigin,}- await restoreSandboxUiDeepLinkTeam(launchContext)- deferSandboxUiDeepLink(+ const exhaustedRetryBudget = deferSandboxUiDeepLink(pending,`${resolution.label} is still starting up. This link will retry shortly.`,'info')+ if (exhaustedRetryBudget) {+ await restoreSandboxUiDeepLinkTeam(launchContext)+ }return}const requestId = launchSandboxUiApp(diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsxindex 920cab786..7818e86d9 100644--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx@@ -551,6 +551,71 @@ describe('App deep-link orchestration', () => {await waitFor(() => expect(acknowledgeDeepLink).toHaveBeenCalledWith(1))})+ it('keeps the target team during cross-team starting app retries', async () => {+ vi.useFakeTimers({ shouldAdvanceTime: true })+ let liveTeamId = 'team-a'+ const ensureTeamContext = vi.fn(async ({ teamId }: { teamId?: string }) => {+ if (!teamId || teamId === liveTeamId) return false+ liveTeamId = teamId+ return true+ })+ currentController = makeController({+ initialExperienceLoading: false,+ handleEnsureTeamContext: ensureTeamContext,+ getCurrentTeamId: () => liveTeamId,+ })+ let ready = false+ listApps.mockImplementation(async () => ({+ apps: [+ {+ appRef: 'ns/app',+ title: 'Linked App',+ defaultPath: '/',+ ready,+ phase: ready ? 'active' : 'deploying',+ },+ ],+ }))+ render(<App />)+ await waitFor(() => expect(emitDeepLink).not.toBeNull())++ act(() => {+ emitDeepLink?.({ id: 1, appRef: 'ns/app', teamId: 'team-b' })+ })++ await waitFor(() => {+ expect(currentController.pushToast).toHaveBeenCalledWith(+ 'Linked App is still starting up. This link will retry shortly.',+ 'info'+ )+ })+ expect(liveTeamId).toBe('team-b')+ expect(ensureTeamContext).toHaveBeenCalledTimes(1)+ expect(ensureTeamContext).toHaveBeenCalledWith({+ teamId: 'team-b',+ announce: true,+ })++ await act(async () => {+ vi.advanceTimersByTime(1_000)+ await Promise.resolve()+ })+ await waitFor(() => expect(currentController.pushToast).toHaveBeenCalledTimes(2))+ expect(liveTeamId).toBe('team-b')+ expect(ensureTeamContext).toHaveBeenCalledTimes(1)++ ready = true+ await act(async () => {+ vi.advanceTimersByTime(2_000)+ await Promise.resolve()+ })+ await reportShortcutOpenResult()++ await waitFor(() => expect(acknowledgeDeepLink).toHaveBeenCalledWith(1))+ expect(liveTeamId).toBe('team-b')+ expect(ensureTeamContext).toHaveBeenCalledTimes(1)+ })+it('keeps a failed native mount unacked and continues with later links', async () => {currentController = makeController({ initialExperienceLoading: false })listApps.mockResolvedValue({