Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r3-m1 validate appRef before persisting the outgoing tab route
Diego Zacarias8a9c45f5daf5
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex 111dc8629..e12c2d97e 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -1142,11 +1142,23 @@ export function App() {// strictly before `open()` tears it down. i.e. the read is captured before// the incoming open, not merely "usually first".const gen = sandboxUiActivationGenRef.current+ // The app the outgoing tab hosts. Its appRef is immutable for the tab's+ // lifetime, so capturing it now (before the read) is safe.+ const outgoingAppRef = workspaceTabsRef.current.tabs.find(+ tab => tab.id === outgoingTabId && tab.kind === 'app'+ )?.app?.appRefvoid (async () => {let routePath: string | undefinedtry {const location = await window.clerum.sandboxUi.getLocation()- routePath = location?.routePath+ // Persist the route ONLY when the read belongs to the outgoing tab's own+ // app. On an app→app switch the incoming `open()` can reach main before+ // this `getLocation()` resolves, so the read may surface the INCOMING+ // app's location; persisting it would save app B's route onto tab A. When+ // the appRef doesn't match, fall back to undefined (default route) rather+ // than clobber A with a foreign route. The generation gate below covers+ // the racing-reopen case; this covers a mismatched read within one gen.+ routePath = location && location.appRef === outgoingAppRef ? location.routePath : undefined} catch {routePath = undefined}@@ -1312,10 +1324,16 @@ export function App() {sandboxUiActivationGenRef.current += 1const gen = sandboxUiActivationGenRef.currentif (outgoingTabId !== null) {+ // Persist the route ONLY when the read belongs to the outgoing tab's own+ // app (same guard as the deactivation effect): a mismatched read must not+ // save another app's route onto this tab. appRef is immutable for the tab.+ const outgoingAppRef = workspaceTabsRef.current.tabs.find(+ tab => tab.id === outgoingTabId && tab.kind === 'app'+ )?.app?.appReflet routePath: string | undefinedtry {const location = await window.clerum.sandboxUi.getLocation()- routePath = location?.routePath+ routePath = location && location.appRef === outgoingAppRef ? location.routePath : undefined} catch {routePath = undefined}diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsxindex 1fa67dcf4..5b52c2145 100644--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx@@ -2037,4 +2037,38 @@ describe('App deep-link orchestration', () => {expect(appTabs()[0]?.app?.savedRoutePath).not.toBe('/stale/route')expect(appTabs()[1]?.app?.savedRoutePath).toBeUndefined()})++ // R3-M1 (the missing half of R1-H1): the deactivation continuation must validate+ // that the route it read belongs to the OUTGOING tab's app before persisting it.+ // On an app→app switch the incoming `open()` can reach main before this read+ // resolves, so `getLocation` can surface the INCOMING app's location within a+ // single activation generation — the generation gate does not catch that. Without+ // the appRef guard, App B's route lands on App A's tab.+ it('does not persist the incoming app route onto the outgoing tab (R3-M1, T3)', async () => {+ currentController = makeController({ initialExperienceLoading: false })+ // Two genuinely distinct apps so the read can carry the WRONG app's location.+ listApps.mockResolvedValue({ apps: [READY_APP, READY_APP_B] })+ render(<App />)+ await launchAppFromSidebar('ns/app') // tabs: [chat, A]; A live+ const outgoingId = appTabs()[0]?.id++ // The deactivation read returns the INCOMING app's location (B), not A's.+ getSandboxUiLocation.mockResolvedValue({ appRef: 'ns/app-b', routePath: '/b/route' })++ await launchAppFromSidebar('ns/app-b') // deactivates A (reads B's location), activates B+ await waitFor(() => expect(appTabs()).toHaveLength(2))+ // Let A's deactivation continuation run to completion.+ await act(async () => {+ await Promise.resolve()+ await Promise.resolve()+ })++ // Observable result: A keeps its own identity and is NOT saved with B's route.+ // The read's appRef ('ns/app-b') did not match A's ('ns/app'), so the persist+ // fell back to undefined. (At the pre-guard head A.savedRoutePath === '/b/route'.)+ const appA = currentController.workspaceTabs.tabs.find(tab => tab.id === outgoingId)+ expect(appA?.app?.appRef).toBe('ns/app')+ expect(appA?.app?.savedRoutePath).not.toBe('/b/route')+ expect(appA?.app?.savedRoutePath).toBeUndefined()+ })})