Skip to content

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

TypeScript

fix(desktop): delimit the 404 verdict and drop the seam field nobody read

Alfredo Lopez3f12b520a921
diff --git a/desktop-app/ui/src/components/agents/ComposerGlobalFilesModal/index.tsx b/desktop-app/ui/src/components/agents/ComposerGlobalFilesModal/index.tsx
index c4ba7379b..0496156bc 100644
--- a/desktop-app/ui/src/components/agents/ComposerGlobalFilesModal/index.tsx
+++ b/desktop-app/ui/src/components/agents/ComposerGlobalFilesModal/index.tsx
@@ -79,7 +79,6 @@ export function ComposerGlobalFilesModal({ onAdd, onClose }: ComposerGlobalFiles
failure: {
kind,
message: ctrl.error,
- retryAfterSeconds,
retryAvailableAt:
kind === 'rate-limited' && retryAfterSeconds !== null
? ctrl.errorUpdatedAt + retryAfterSeconds * 1000
diff --git a/desktop-app/ui/src/components/agents/__tests__/ComposerGlobalFilesModal.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ComposerGlobalFilesModal.test.tsx
index cf5ff32e4..4b52540b3 100644
--- a/desktop-app/ui/src/components/agents/__tests__/ComposerGlobalFilesModal.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerGlobalFilesModal.test.tsx
@@ -103,7 +103,6 @@ describe('ComposerGlobalFilesModal', () => {
discoveryFailure: {
kind: 'rate-limited',
message: RATE_LIMITED_DISCOVERY,
- retryAfterSeconds: 7,
retryAvailableAt: Date.now() + 7_000,
},
retryDiscovery,
@@ -193,7 +192,6 @@ describe('ComposerGlobalFilesModal', () => {
discoveryFailure: {
kind: 'rate-limited',
message: RATE_LIMITED_DISCOVERY,
- retryAfterSeconds: 7,
retryAvailableAt: Date.now() + 7_000,
},
})
@@ -215,7 +213,6 @@ describe('ComposerGlobalFilesModal', () => {
discoveryFailure: {
kind: 'unsupported',
message: '404 Not Found: Not Found',
- retryAfterSeconds: null,
retryAvailableAt: null,
},
})
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 793518f22..0ce218599 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -90,9 +90,6 @@ function Probe() {
<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="discovery-failure-retry-at">
{ctrl.discoveryFailure?.retryAvailableAt ?? 'none'}
</div>
@@ -1170,6 +1167,48 @@ describe('useGfsBrowserController', () => {
expect(screen.getByTestId('discovery-failure-kind').textContent).toBe('unsupported')
})
+ it('does not call a server unsupported because its error body quoted a 404', async () => {
+ // `httpClient` copies the RAW response body into the message whenever the
+ // JSON carries no top-level `error`/`message`, so a path, a filename or a
+ // log line from the failing server reaches the classifier verbatim. Under
+ // `\b` the phrase below was a word-boundary match — `/` and `-` are
+ // boundaries — and a 500 was reported as a server with no discovery
+ // endpoint. That verdict has no way back: `unsupported` offers no retry,
+ // so the user was told their files cannot be listed by a server that
+ // would have answered the next request.
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ listAccessible: vi.fn(async () => {
+ throw new Error(
+ '500 Internal Server Error: render failed for /docs/404 Not Found.md - upstream'
+ )
+ }),
+ 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(() =>
+ expect(screen.getByTestId('discovery-failure-kind').textContent).toBe('failed')
+ )
+ // Liveness witness: the failure really reached the classifier — the notice
+ // that `unsupported` produces is absent because this branch was NOT taken,
+ // not because discovery never ran.
+ expect(screen.getByTestId('accessible-notice').textContent).toBe('none')
+ expect(screen.getByTestId('accessible-error').textContent).toContain('404 Not Found.md')
+ })
+
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
@@ -1205,7 +1244,17 @@ describe('useGfsBrowserController', () => {
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 parsed window, asserted through the field the UI actually counts
+ // down from. The seam used to publish the duration alongside the deadline
+ // and this assertion read that copy — so the number was verified in a
+ // spelling no screen consumed, and the one the card reads went unchecked.
+ // `retryAvailableAt` is `errorUpdatedAt + 7s` and the query settled just
+ // now, so the remaining wait is 7s less the test's own elapsed time; the
+ // lower bound absorbs that without admitting 0, null or the 120s fixture.
+ const remainingMs =
+ Number(screen.getByTestId('discovery-failure-retry-at').textContent) - Date.now()
+ expect(remainingMs).toBeLessThanOrEqual(7_000)
+ expect(remainingMs).toBeGreaterThan(6_000)
// 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
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 878c72c54..193a281ee 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -162,7 +162,6 @@ export type GfsDiscoveryFailureKind = 'unsupported' | 'rate-limited' | 'failed'
export interface GfsDiscoveryFailure {
kind: GfsDiscoveryFailureKind
message: string
- retryAfterSeconds: number | null
/**
* Absolute epoch (ms) at which the server's own window closes, or null when
* this failure named no window.
@@ -178,6 +177,12 @@ export interface GfsDiscoveryFailure {
*
* A deadline also survives a remount and cannot drift: a consumer counting
* down derives the remainder from the clock instead of decrementing state.
+ *
+ * The parsed duration itself is deliberately NOT carried alongside. It was,
+ * and no consumer ever read it — every surface counts down from this
+ * deadline — so the seam published a second, redundant spelling of the same
+ * fact that nothing validated against the first. A future consumer reaching
+ * for it would have trusted a number no test covered.
*/
retryAvailableAt: number | null
}
@@ -192,9 +197,22 @@ export interface GfsDiscoveryFailure {
* `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.
+ *
+ * Delimited on both sides for the same reason `isRateLimited` is, and with the
+ * same delimiter set: `\b` counts `-` and `/` as boundaries, so a failure whose
+ * body merely QUOTED the phrase — a path like `/docs/404 Not Found.md`, which
+ * `httpClient` copies verbatim into the message when the JSON carries no
+ * top-level `error`/`message` — was classified as a server that has no
+ * discovery endpoint. That verdict is the one with no way back: `unsupported`
+ * offers no retry, so the user is told their files cannot be listed by a
+ * server that would have answered.
+ *
+ * Every shape the wire produces delimits the status the same way
+ * (`404 Not Found: <body>`, and through IPC `…: Error: 404 Not Found: …`), so
+ * requiring the delimiter loses no real detection.
*/
function classifyDiscoveryFailure(message: string): GfsDiscoveryFailureKind {
- if (/\b404 Not Found\b/.test(message)) return 'unsupported'
+ if (/(?:^|[\s:])404 Not Found(?=[\s:]|$)/.test(message)) return 'unsupported'
// Share the predicate with the presentation layer rather than restating it.
// A third copy of "what counts as rate limited" is a copy that will rot, and
// the two must agree: the card renders copy chosen by `describeGfsReadError`
@@ -720,7 +738,6 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
return {
kind,
message: accessibleErrorMessage,
- retryAfterSeconds,
retryAvailableAt:
kind === 'rate-limited' && retryAfterSeconds !== null
? accessibleErrorUpdatedAt + retryAfterSeconds * 1000
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index 4b4d4a694..7b82b9ef4 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -1140,7 +1140,6 @@ export function FilesPage({
return {
kind,
message: error,
- retryAfterSeconds,
retryAvailableAt:
kind === 'rate-limited' && retryAfterSeconds !== null
? ctrl.errorUpdatedAt + retryAfterSeconds * 1000
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.discoverySeam.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.discoverySeam.test.tsx
index de2569ab3..87d3b9807 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.discoverySeam.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.discoverySeam.test.tsx
@@ -2,7 +2,7 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { AuthContext, type AuthContextValue } from '@contexts/AuthContext'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import { cleanup, render, screen, waitFor } from '@testing-library/react'
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { FilesPage } from '../FilesPage'
/**
@@ -100,4 +100,51 @@ describe('FilesPage against the real GFS browser controller', () => {
// page that never got started.
expect(listAccessible).toHaveBeenCalledTimes(1)
})
+
+ it('spends a second request only when the user presses the card’s own retry', async () => {
+ // The test above asserts the button EXISTS. That leaves the other half of
+ // the seam uncovered: rename `retryDiscovery` and both this file and the
+ // module-mocked suite stay green while the button does nothing at all —
+ // the same leak the file was written to close for `discoveryFailure`.
+ //
+ // The fixture names no window on purpose. A 429 that carries
+ // `retryAfterSeconds` disables the button for exactly that long, and the
+ // point here is the wiring, not the countdown the sibling test pins.
+ const listAccessible = vi.fn(async () => {
+ throw new Error(
+ "Error invoking remote method 'gfs:listAccessible': Error: 429 Too Many Requests: " +
+ 'Too Many Requests'
+ )
+ })
+ 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,
+ })),
+ },
+ },
+ })
+
+ renderFilesPage()
+
+ const retry = await screen.findByRole('button', { name: /retry file listing/i })
+ // Witness that this is the settled-failure card and not some other button:
+ // an unparseable window leaves no countdown to show, so the control is
+ // live immediately.
+ expect((retry as HTMLButtonElement).disabled).toBe(false)
+ expect(listAccessible).toHaveBeenCalledTimes(1)
+
+ fireEvent.click(retry)
+
+ // The route assertion: the click reached the real controller's refetch.
+ await waitFor(() => expect(listAccessible).toHaveBeenCalledTimes(2))
+ })
})
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index a66006065..8981c9566 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -2209,9 +2209,15 @@ describe('FilesPage', () => {
it('toasts a rate-limited download in read words, not permission words', async () => {
const download = vi.fn(async () => {
+ // The producer's exact shape. `appService.fetchBytes` throws
+ // `gfs download failed: ${res.status}` and `surfaceGfsGrantError`
+ // appends the window it vetted — so there is no inner colon and no
+ // "Too Many Requests" on this leg. The old fixture classified the same,
+ // which is why it went unnoticed, but a presentation test written to a
+ // string the wire never carries proves nothing about the wire.
throw new Error(
- "Error invoking remote method 'gfs:download': Error: gfs download failed: 429: " +
- 'Too Many Requests retryAfterSeconds=7'
+ "Error invoking remote method 'gfs:download': Error: " +
+ 'gfs download failed: 429 retryAfterSeconds=7'
)
})
const pushToast = vi.fn()
@@ -3552,7 +3558,6 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'rate-limited',
message: rawMessage,
- retryAfterSeconds: 7,
retryAvailableAt: Date.now() + 7_000,
},
retryDiscovery,
@@ -3620,7 +3625,6 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'rate-limited',
message: rawMessage,
- retryAfterSeconds: 120,
retryAvailableAt: Date.now() + 120_000,
},
})
@@ -3644,7 +3648,7 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'unsupported',
message: '404 Not Found: Not Found',
- retryAfterSeconds: null,
+ retryAvailableAt: null,
},
})
@@ -3670,7 +3674,6 @@ describe('FilesPage', () => {
kind: 'failed',
message:
"Error invoking remote method 'gfs:listAccessible': Error: 503 Service Unavailable: upstream_unreachable",
- retryAfterSeconds: null,
retryAvailableAt: null,
},
})
@@ -3703,7 +3706,6 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'rate-limited',
message: rawMessage,
- retryAfterSeconds: 7,
retryAvailableAt: Date.now() + 7_000,
},
})
@@ -3755,7 +3757,6 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'rate-limited',
message: rawMessage,
- retryAfterSeconds: 7,
retryAvailableAt: Date.now() + 7_000,
},
})
@@ -3784,7 +3785,6 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'rate-limited',
message: rawMessage,
- retryAfterSeconds: 120,
retryAvailableAt: Date.now() + 120_000,
},
})
@@ -3809,7 +3809,6 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'unsupported',
message: '404 Not Found: Not Found',
- retryAfterSeconds: null,
retryAvailableAt: null,
},
})
@@ -3857,7 +3856,6 @@ describe('FilesPage', () => {
discoveryFailure: {
kind: 'rate-limited',
message: rawMessage,
- retryAfterSeconds: 7,
retryAvailableAt: Date.now() + 7_000,
},
})