Skip to content

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

TypeScript

fix(desktop): classify GFS discovery failures by signal, not by IPC wording

Alfredo Lopez8621fa99041c
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index e53dcaa8c..fa30abe30 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -89,6 +89,12 @@ function Probe() {
<div data-testid="items-count">{ctrl.items.length}</div>
<div data-testid="accessible-error">{ctrl.accessibleError ?? 'none'}</div>
<div data-testid="accessible-notice">{ctrl.accessibleNotice ?? 'none'}</div>
+ <div data-testid="discovery-failure-kind">{ctrl.discoveryFailure?.kind ?? 'none'}</div>
+ <div data-testid="discovery-failure-retry">
+ {ctrl.discoveryFailure?.retryAfterSeconds ?? 'none'}
+ </div>
+ <div data-testid="loading-accessible">{ctrl.loadingAccessible ? 'loading' : 'idle'}</div>
+ <div data-testid="row-affordances">{ctrl.rowAffordances?.held.join(',') ?? 'none'}</div>
<div data-testid="held-permissions">{ctrl.affordances?.held.join(',') ?? 'none'}</div>
{ctrl.items.map(item => (
<div key={item.resourceId} data-testid={`row-affordances-${item.resourceId}`}>
@@ -944,6 +950,56 @@ describe('useGfsBrowserController', () => {
expect(screen.getByTestId('accessible-count').textContent).toBe('0')
})
+ it('classifies a rate-limited discovery failure instead of calling the server unsupported', async () => {
+ // Electron's ipcRenderer.invoke always prefixes a rejection with
+ // "Error invoking remote method '<channel>'", so classifying on that
+ // substring matched every failure of this call, a 429 included.
+ const listAccessible = vi.fn(async () => {
+ throw new Error(
+ "Error invoking remote method 'gfs:listAccessible': Error: 429 Too Many Requests: " +
+ 'Too Many Requests retryAfterSeconds=7'
+ )
+ })
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ listAccessible,
+ resolve: vi.fn(),
+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
+ affordances: vi.fn(async () => ({
+ held: [],
+ canDelegate: false,
+ grantableBits: [],
+ canCreateShare: false,
+ })),
+ },
+ },
+ })
+
+ render(<Probe />, { wrapper: Harness })
+
+ await waitFor(() => {
+ // The notice assertion is the one that fails against the substring
+ // classifier, which reports this 429 as "discovery is not available".
+ expect(screen.getByTestId('accessible-notice').textContent).toBe('none')
+ expect(screen.getByTestId('discovery-failure-kind').textContent).toBe('rate-limited')
+ })
+ expect(screen.getByTestId('discovery-failure-retry').textContent).toBe('7')
+
+ // The authority revalidation gate must not open on a 429: a rate-limit
+ // verdict does not re-prove the session. Written as a positive assertion
+ // so it cannot pass by the field disappearing.
+ expect(screen.getByTestId('authority-pending').textContent).toBe('pending')
+ expect(screen.getByTestId('access-state').textContent).toBe('active')
+ expect(screen.getByTestId('items-count').textContent).toBe('0')
+ expect(screen.getByTestId('row-affordances').textContent).toBe('none')
+ expect(screen.getByTestId('loading-accessible').textContent).toBe('idle')
+
+ // Liveness witness: discovery really ran, and exactly once.
+ expect(listAccessible).toHaveBeenCalledTimes(1)
+ })
+
it('reconciles the open folder after a move and feeds the returned version into follow-up actions', async () => {
const docsId = '11111111-1111-1111-1111-111111111111'
const rootId = '00000000-0000-0000-0000-00000000000a'
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index aea7d5be0..006191a64 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -8,6 +8,7 @@ import {
useQueryClient,
} from '@tanstack/react-query'
import { GFS_BREADCRUMB_MAX_DEPTH } from '@constants/gfsBrowser'
+import { parseRetryAfterSeconds } from '@lib/gfsGrantErrors'
import type { GfsGrantListItem, GfsShareListItem } from '@/gfs/delegation.types'
import { desktopQueryKeys } from './queryKeys'
@@ -138,12 +139,29 @@ function toMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}
-function isResourceDiscoveryUnavailable(message: string): boolean {
- return (
- message.includes('listAccessible is not a function') ||
- message.includes('gfs:listAccessible') ||
- message.includes('404 Not Found')
- )
+export type GfsDiscoveryFailureKind = 'unsupported' | 'rate-limited' | 'failed'
+
+export interface GfsDiscoveryFailure {
+ kind: GfsDiscoveryFailureKind
+ message: string
+ retryAfterSeconds: number | null
+}
+
+/**
+ * Classify a discovery rejection by a signal we actually produce, never by the
+ * IPC wording. Electron's `ipcRenderer.invoke` always prefixes a rejection with
+ * `Error invoking remote method 'gfs:listAccessible'`, so matching that
+ * substring classified EVERY failure of the call — a 429 included — as "this
+ * server does not support discovery".
+ *
+ * `404 Not Found` is our own httpClient format, so it still identifies a server
+ * that predates the endpoint. The preload-absent case is not handled here: it
+ * has no error to classify and stays on the `canListAccessibleResources` branch.
+ */
+function classifyDiscoveryFailure(message: string): GfsDiscoveryFailureKind {
+ if (/\b404 Not Found\b/.test(message)) return 'unsupported'
+ if (/\b429\b/.test(message)) return 'rate-limited'
+ return 'failed'
}
const SESSION_AUTHORITY_ERROR_CODES = [
@@ -604,10 +622,21 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
[authorityPending, sharesQuery.data]
)
const accessibleErrorMessage = accessibleQuery.error ? toMessage(accessibleQuery.error) : null
+ const discoveryFailure = useMemo<GfsDiscoveryFailure | null>(
+ () =>
+ accessibleErrorMessage
+ ? {
+ kind: classifyDiscoveryFailure(accessibleErrorMessage),
+ message: accessibleErrorMessage,
+ retryAfterSeconds: parseRetryAfterSeconds(accessibleErrorMessage),
+ }
+ : null,
+ [accessibleErrorMessage]
+ )
const accessibleNotice =
sessionScope && !canListAccessibleResources
? 'Automatic GFS discovery is not available in this desktop runtime. You can still open any GFS link you have.'
- : accessibleErrorMessage && isResourceDiscoveryUnavailable(accessibleErrorMessage)
+ : discoveryFailure?.kind === 'unsupported'
? 'Automatic GFS discovery is not available from this server yet. You can still open any GFS link you have.'
: null
@@ -828,15 +857,24 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
? null
: ((rowAffordancesQuery.data as GfsBrowserAffordances | undefined) ?? null),
rowAffordancesError: rowAffordancesQuery.error ? toMessage(rowAffordancesQuery.error) : null,
- loading: (authorityPending || childrenQuery.isFetching) && items.length === 0,
+ // A settled discovery error is not a pending load. Without this the
+ // spinner outlived the failure for every consumer that derives its
+ // loading state from here alone (ComposerGlobalFilesModal); FilesPage
+ // reads authorityPending directly and is fixed separately.
+ loading:
+ (authorityPending || childrenQuery.isFetching) &&
+ items.length === 0 &&
+ !accessibleQuery.isError,
loadingAccessible:
- (authorityPending && canListAccessibleResources) ||
- (canListAccessibleResources &&
- accessibleQuery.isFetching &&
- accessibleResources.length === 0),
+ !accessibleQuery.isError &&
+ ((authorityPending && canListAccessibleResources) ||
+ (canListAccessibleResources &&
+ accessibleQuery.isFetching &&
+ accessibleResources.length === 0)),
error: childrenQuery.error ? toMessage(childrenQuery.error) : null,
accessibleError: accessibleNotice ? null : accessibleErrorMessage,
accessibleNotice,
+ discoveryFailure,
openError,
resolving,
hasMore: Boolean(childrenQuery.hasNextPage),