Skip to content

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

TypeScript

fix(desktop): r1-h2 new gesture supersedes a stale lost-dragend source

M1dcb3f3589c0
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
index ce65fce8c..691261ebe 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
@@ -854,6 +854,61 @@ describe('FileExplorerTree — drag-and-drop moves', () => {
await screen.findByRole('dialog', { name: 'Move folder A to B' })
})
+ it('a new gesture after a lost dragend commits the dragged folder, not the stale one', async () => {
+ // R1-H2: the browser can lose dragend (e.g. the source row is replaced by
+ // a listing refresh mid-drag and dragend fires on a detached node). The
+ // stale source must not adjudicate the NEXT gesture's drop: the new
+ // trusted gesture takes ownership of the session instead.
+ const moveResource = vi.fn(async () => ({ resourceId: 'folderb', version: 9 }))
+ const affordances = vi.fn(async (resourceId: string) => {
+ if (resourceId === 'folderc') return { held: ['read', 'write'] }
+ return { held: ['read', 'write', 'delete'] }
+ })
+ const resolve = vi.fn(async (uri: string) => {
+ const id = uri.split('/').pop()
+ const parent = id === 'grand' ? null : 'grand'
+ const name =
+ id === 'foldera' ? 'A' : id === 'folderb' ? 'B' : id === 'folderc' ? 'C' : 'Grand'
+ return {
+ drive: 'main',
+ resourceId: id === 'grand' ? 'grand' : id,
+ parentResourceId: parent,
+ name,
+ kind: 'directory',
+ version: id === 'foldera' ? 4 : 1,
+ }
+ })
+ installDndClerum({
+ listAccessible: vi.fn(async () =>
+ listAccessiblePage([
+ accessibleResource('foldera', 'A', 'directory', { version: 4 }),
+ accessibleResource('folderb', 'B', 'directory'),
+ accessibleResource('folderc', 'C', 'directory'),
+ ])
+ ),
+ affordances,
+ resolve,
+ moveResource,
+ })
+ renderTreeWithSession()
+
+ const rowA = await screen.findByRole('button', { name: 'A' })
+ const rowB = await screen.findByRole('button', { name: 'B' })
+ const rowC = await screen.findByRole('button', { name: 'C' })
+ const dataTransfer = dragTypes()
+ const cRow = rowC.closest('[role="treeitem"]')!.querySelector('.da-file-explorer__row')!
+
+ // Gesture A starts and its dragend is LOST (no dragEnd fired here).
+ fireEvent.dragStart(rowA, { dataTransfer })
+ // Gesture B supersedes the stale A and drops onto C.
+ fireEvent.dragStart(rowB, { dataTransfer })
+ fireEvent.drop(cRow, { dataTransfer })
+
+ // The confirmation must describe B's move — not the stale A.
+ await screen.findByRole('dialog', { name: 'Move folder B to C' })
+ expect(screen.queryByRole('dialog', { name: 'Move folder A to C' })).toBeNull()
+ })
+
it('moves a dragged folder into an unrelated folder through the one confirmation', async () => {
// Two directly-shared folders under one unshared common parent 'grand':
// the drop must walk B's (bounded) ancestry, find the common anchor via
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
index 630524d86..6ce61c40b 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
@@ -525,7 +525,12 @@ export function FileExplorerTree({
generation: dragSessionEpochRef.current,
}
const { generation: _generation, ...sourceForStore } = source
- dragSession?.beginDrag(sourceForStore)
+ if (dragSession && !dragSession.beginDrag(sourceForStore)) {
+ // The session refused the gesture (foreign scope or revoked access):
+ // never publish a local payload the shared session did not accept.
+ event.preventDefault()
+ return
+ }
adjudication.beginDragSession()
event.dataTransfer.effectAllowed = 'move'
event.dataTransfer.setData(GFS_RESOURCE_DRAG_TYPE, node.resourceId)
diff --git a/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsx b/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsx
index 336d37dcd..ad53044ea 100644
--- a/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsx
+++ b/desktop-app/ui/src/gfs/__tests__/dragSession.test.tsx
@@ -47,16 +47,32 @@ afterEach(() => {
})
describe('GfsDragSessionStore — one active source per session', () => {
- it('begins one drag, refuses a second, and clears on endDrag', () => {
+ it('supersedes a stale same-session source with the next trusted gesture', () => {
+ // A lost dragend (detached-node dragend after a listing refresh) leaves
+ // the old source active. The next same-session gesture must OWN the
+ // session — refusing it would leave the stale source adjudicating the
+ // new gesture's drop (wrong-resource move).
const store = new GfsDragSessionStore()
expect(store.beginDrag(source())).toBe(true)
- expect(store.beginDrag(source({ resourceId: 'r-2' }))).toBe(false)
- expect(store.activeSource()?.resourceId).toBe('r-1')
+ const stale = store.activeSource()
+ expect(store.beginDrag(source({ resourceId: 'r-2', name: 'b.txt' }))).toBe(true)
+ const active = store.activeSource()
+ expect(active?.resourceId).toBe('r-2')
+ expect(active?.generation).toBeGreaterThan(stale?.generation ?? 0)
store.endDrag()
expect(store.activeSource()).toBeNull()
// After clearing, a new drag can start with a fresh generation.
+ expect(store.beginDrag(source({ resourceId: 'r-3' }))).toBe(true)
+ expect(store.activeSource()?.generation).toBeGreaterThan(active?.generation ?? 0)
+ })
+
+ it('refuses a foreign-session gesture and keeps the active source', () => {
+ const store = new GfsDragSessionStore()
+ store.beginDrag(source())
+ expect(store.beginDrag(source({ scope: 'other:user-9:team-9' }))).toBe(false)
+ expect(store.activeSource()?.resourceId).toBe('r-1')
+ // The refused gesture did not consume a generation.
expect(store.beginDrag(source({ resourceId: 'r-2' }))).toBe(true)
- expect(store.activeSource()?.generation).toBeGreaterThan(1)
})
it('matches scope only while the same session drag is active', () => {
@@ -118,4 +134,21 @@ describe('GfsDragSessionProvider — lifecycle binding', () => {
expect(api!.beginDrag(source({ scope: 'other:user-9:' }))).toBe(false)
expect(api!.activeSource()).toBeNull()
})
+
+ it('supersedes a stale same-session drag through the provider guards', () => {
+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ let api: ReturnType<typeof useGfsDragSession> | null = null
+ render(
+ <QueryClientProvider client={queryClient}>
+ <GfsDragSessionProvider>
+ <Probe onApi={captured => (api = captured)} />
+ </GfsDragSessionProvider>
+ </QueryClientProvider>
+ )
+ expect(api!.beginDrag(source())).toBe(true)
+ // Lost dragend: the stale source lingers. The next trusted same-session
+ // gesture passes the provider guards and takes ownership of the session.
+ expect(api!.beginDrag(source({ resourceId: 'r-2' }))).toBe(true)
+ expect(api!.activeSource()?.resourceId).toBe('r-2')
+ })
})
diff --git a/desktop-app/ui/src/gfs/dragSession.tsx b/desktop-app/ui/src/gfs/dragSession.tsx
index 63a84d40c..8d400650d 100644
--- a/desktop-app/ui/src/gfs/dragSession.tsx
+++ b/desktop-app/ui/src/gfs/dragSession.tsx
@@ -1,6 +1,6 @@
import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'
-import { useQuery } from '@tanstack/react-query'
import { useAuthContext } from '@contexts/AuthContext'
+import { useQuery } from '@tanstack/react-query'
import { desktopQueryKeys } from '@hooks/domain/queryKeys'
import type { GfsDragSessionApi, GfsDragSource } from './dragSession.types'
@@ -11,8 +11,11 @@ type GfsAccessState = 'active' | 'revoked'
* source, held in refs (dragover never re-renders the tree). The store is
* bound to the live session scope and the SHARED access-state query, so a
* logout, env/user/team switch or a definite lifecycle rejection clears the
- * drag. Payload identity is the in-window descriptor; generations only
- * discard stale async callbacks — they are not credentials or a wire registry.
+ * drag. A lost dragend must not outlive the next trusted gesture: a
+ * same-session beginDrag SUPERSEDES the stale source with a new generation,
+ * while a foreign-session gesture is still refused. Payload identity is the
+ * in-window descriptor; generations only discard stale async callbacks — they
+ * are not credentials or a wire registry.
*/
export class GfsDragSessionStore implements GfsDragSessionApi {
private active: GfsDragSource | null = null
@@ -20,7 +23,7 @@ export class GfsDragSessionStore implements GfsDragSessionApi {
private boundScope: string | null = null
beginDrag(source: Omit<GfsDragSource, 'generation'>): boolean {
- if (this.active) return false
+ if (this.active && this.boundScope !== source.scope) return false
this.generation += 1
this.active = { ...source, generation: this.generation }
this.boundScope = source.scope
@@ -66,9 +69,7 @@ function sessionScopeOf(auth: {
runtimeConfigState: { envKey: string } | null
}): string | null {
const envKey = auth.runtimeConfigState?.envKey ?? ''
- return auth.isAuthenticated && auth.me
- ? `${envKey}:${auth.me.id}:${auth.me.teamId ?? ''}`
- : null
+ return auth.isAuthenticated && auth.me ? `${envKey}:${auth.me.id}:${auth.me.teamId ?? ''}` : null
}
export function GfsDragSessionProvider({ children }: { children: React.ReactNode }) {
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index 881d6aaae..97345b83b 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -1052,7 +1052,12 @@ export function FilesPage({
generation: dragSessionRef.current,
}
const { generation: _generation, ...sourceForStore } = source
- dragSession?.beginDrag(sourceForStore)
+ if (dragSession && !dragSession.beginDrag(sourceForStore)) {
+ // The session refused the gesture (foreign scope or revoked access):
+ // never publish a local payload the shared session did not accept.
+ event.preventDefault()
+ return
+ }
adjudication.beginDragSession()
event.dataTransfer.effectAllowed = 'move'
event.dataTransfer.setData(GFS_RESOURCE_DRAG_TYPE, resource.resourceId)