Skip to content

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

TypeScript

fix(desktop): carry retryAfterSeconds across IPC for every GFS read

Alfredo Lopezc9f0a4941f49
diff --git a/desktop-app/src/__tests__/appService.gfs.test.ts b/desktop-app/src/__tests__/appService.gfs.test.ts
index d04063c1c..8e87383c7 100644
--- a/desktop-app/src/__tests__/appService.gfs.test.ts
+++ b/desktop-app/src/__tests__/appService.gfs.test.ts
@@ -992,3 +992,63 @@ describe('legacy GFS descriptor safety', () => {
}
})
})
+
+describe('AppService GFS proxy read transport', () => {
+ it('carries retryAfterSeconds out of a rate-limited proxy download body', async () => {
+ // The uriHandler suite injects a fake fetchBytes, so the real transport
+ // literal on AppService is only reachable from here. Drive both legs of
+ // download(): resolve must succeed so the proxy leg is the one that 429s.
+ const service = new AppService() as unknown as {
+ sessionToken: string | null
+ downloadGfsUri: (uri: string) => Promise<{ bytes: ArrayBuffer }>
+ }
+ service.sessionToken = 'session-token'
+
+ const resolved = {
+ drive: 'main',
+ resourceId: RESOURCE_ID,
+ parentResourceId: null,
+ gfsUri: `gfs://main/${RESOURCE_ID}`,
+ name: 'report.md',
+ kind: 'file',
+ version: 3,
+ }
+ const originalFetch = globalThis.fetch
+ const fetchMock = vi.fn(async (input: unknown) => {
+ const url = String(input)
+ if (url.includes('/gfs/resolve')) {
+ return new Response(JSON.stringify({ ok: true, data: resolved }), {
+ status: 200,
+ headers: { 'content-type': 'application/json' },
+ })
+ }
+ if (url.includes(`/gfs/proxy/${RESOURCE_ID}`)) {
+ return new Response(JSON.stringify({ error: 'Too Many Requests', retryAfterSeconds: 7 }), {
+ status: 429,
+ statusText: 'Too Many Requests',
+ headers: { 'content-type': 'application/json', 'retry-after': '7' },
+ })
+ }
+ throw new Error(`unexpected request to ${url}`)
+ })
+ globalThis.fetch = fetchMock as unknown as typeof fetch
+
+ try {
+ const error = await service.downloadGfsUri(`gfs://main/${RESOURCE_ID}`).then(
+ () => {
+ throw new Error('expected the rate-limited proxy download to reject')
+ },
+ (rejected: unknown) => rejected
+ )
+ const message = error instanceof Error ? error.message : String(error)
+ expect(message).toContain('gfs download failed: 429')
+ expect(message).toContain('retryAfterSeconds=7')
+ // Liveness witness: both legs ran, so the 429 came from the proxy read
+ // and not from a resolve that never happened.
+ expect(fetchMock).toHaveBeenCalledTimes(2)
+ expect(String(fetchMock.mock.calls[1]?.[0])).toContain(`/gfs/proxy/${RESOURCE_ID}`)
+ } finally {
+ globalThis.fetch = originalFetch
+ }
+ })
+})
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index 585ca3c8a..252883810 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -856,7 +856,15 @@ export class AppService {
fetchBytes: async (url, token) => {
const res = await fetch(url, { headers: { authorization: `Bearer ${token}` } })
if (!res.ok) {
- throw new ApiError(`gfs download failed: ${res.status}`, res.status, '')
+ // Keep the body and Retry-After: a 429 on the proxy read carries
+ // retryAfterSeconds, and surfaceGfsGrantError can only lift it out of
+ // bodyText. Discarding them left the renderer with no retry hint.
+ throw new ApiError(
+ `gfs download failed: ${res.status}`,
+ res.status,
+ await res.text(),
+ res.headers.get('retry-after')
+ )
}
return res.arrayBuffer()
},
diff --git a/desktop-app/src/gfs/uriHandler.ts b/desktop-app/src/gfs/uriHandler.ts
index 2f0e988c3..a0e8f834b 100644
--- a/desktop-app/src/gfs/uriHandler.ts
+++ b/desktop-app/src/gfs/uriHandler.ts
@@ -417,12 +417,16 @@ export class GfsClient {
/** Resolve a gfs:// URI to its current resource (validates the URI locally first). */
async resolveUri(uri: string, token: string): Promise<ResolvedGfsResource> {
parseGfsUri(uri) // fail fast on a malformed URI before a round-trip
- const payload = await this.transport.requestJson<GfsEnvelope<ResolvedGfsResource>>(
- 'GET',
- joinUrl(this.transport.baseUrl, `/api/v1/me/gfs/resolve?uri=${encodeURIComponent(uri)}`),
- { token }
- )
- return unwrap(payload)
+ try {
+ const payload = await this.transport.requestJson<GfsEnvelope<ResolvedGfsResource>>(
+ 'GET',
+ joinUrl(this.transport.baseUrl, `/api/v1/me/gfs/resolve?uri=${encodeURIComponent(uri)}`),
+ { token }
+ )
+ return unwrap(payload)
+ } catch (error) {
+ throw surfaceGfsGrantError(error)
+ }
}
/** Resolve then download the resource bytes through the brokered proxy. */
@@ -430,15 +434,21 @@ export class GfsClient {
uri: string,
token: string
): Promise<{ resource: ResolvedGfsResource; bytes: ArrayBuffer }> {
+ // resolveUri runs first and already surfaces its own verdict, so a 429 on the
+ // resolve leg reaches the renderer with the resolve message, not this one.
const resource = await this.resolveUri(uri, token)
- const bytes = await this.transport.fetchBytes(
- joinUrl(
- this.transport.baseUrl,
- `/api/v1/me/gfs/proxy/${resource.resourceId}?drive=${encodeURIComponent(resource.drive)}`
- ),
- token
- )
- return { resource, bytes }
+ try {
+ const bytes = await this.transport.fetchBytes(
+ joinUrl(
+ this.transport.baseUrl,
+ `/api/v1/me/gfs/proxy/${resource.resourceId}?drive=${encodeURIComponent(resource.drive)}`
+ ),
+ token
+ )
+ return { resource, bytes }
+ } catch (error) {
+ throw surfaceGfsGrantError(error)
+ }
}
/**
@@ -454,15 +464,19 @@ export class GfsClient {
const q = new URLSearchParams()
q.set('drive', opts?.drive ?? DEFAULT_DRIVE)
if (opts?.cursor) q.set('cursor', opts.cursor)
- const payload = await this.transport.requestJson<GfsEnvelope<GfsChildrenPage>>(
- 'GET',
- joinUrl(
- this.transport.baseUrl,
- `/api/v1/me/gfs/resources/${encodeURIComponent(resourceId)}/children?${q.toString()}`
- ),
- { token }
- )
- return unwrap(payload)
+ try {
+ const payload = await this.transport.requestJson<GfsEnvelope<GfsChildrenPage>>(
+ 'GET',
+ joinUrl(
+ this.transport.baseUrl,
+ `/api/v1/me/gfs/resources/${encodeURIComponent(resourceId)}/children?${q.toString()}`
+ ),
+ { token }
+ )
+ return unwrap(payload)
+ } catch (error) {
+ throw surfaceGfsGrantError(error)
+ }
}
async listAccessible(
@@ -472,12 +486,16 @@ export class GfsClient {
const q = new URLSearchParams()
q.set('drive', opts?.drive ?? DEFAULT_DRIVE)
if (opts?.cursor) q.set('cursor', opts.cursor)
- const payload = await this.transport.requestJson<GfsEnvelope<GfsAccessibleResourcesPage>>(
- 'GET',
- joinUrl(this.transport.baseUrl, '/api/v1/me/gfs/resources?' + q.toString()),
- { ['token']: session }
- )
- return unwrap(payload)
+ try {
+ const payload = await this.transport.requestJson<GfsEnvelope<GfsAccessibleResourcesPage>>(
+ 'GET',
+ joinUrl(this.transport.baseUrl, '/api/v1/me/gfs/resources?' + q.toString()),
+ { ['token']: session }
+ )
+ return unwrap(payload)
+ } catch (error) {
+ throw surfaceGfsGrantError(error)
+ }
}
/**
@@ -490,14 +508,18 @@ export class GfsClient {
token: string,
drive: string = DEFAULT_DRIVE
): Promise<GfsHeldAffordances> {
- return this.transport.requestJson<GfsHeldAffordances>(
- 'GET',
- joinUrl(
- this.transport.baseUrl,
- `/api/v1/me/gfs/resources/${encodeURIComponent(resourceId)}/affordances?drive=${encodeURIComponent(drive)}`
- ),
- { token }
- )
+ try {
+ return await this.transport.requestJson<GfsHeldAffordances>(
+ 'GET',
+ joinUrl(
+ this.transport.baseUrl,
+ `/api/v1/me/gfs/resources/${encodeURIComponent(resourceId)}/affordances?drive=${encodeURIComponent(drive)}`
+ ),
+ { token }
+ )
+ } catch (error) {
+ throw surfaceGfsGrantError(error)
+ }
}
/**
@@ -744,8 +766,8 @@ function parseGfsGrantErrorFields(bodyText: string): GfsGrantErrorFields {
}
/**
- * Re-throw a grant/share/list failure with the server's structured verdict
- * fields embedded in the message.
+ * Re-throw any GFS failure — grant, share, or read — with the server's
+ * structured verdict fields embedded in the message.
*
* The transport (httpClient) throws an `ApiError` that stashes the raw response
* body on `.bodyText`, but ONLY the `Error.message` survives the Electron IPC
@@ -756,6 +778,12 @@ function parseGfsGrantErrorFields(bodyText: string): GfsGrantErrorFields {
* `retryAfterSeconds=…`), keeping the original message — and therefore the server
* error CODE (`subjects_invalid`, `foreign_agent_forbidden`, `429`, …) — intact.
*
+ * The READ methods (`resolveUri`, `download`, `listChildren`, `listAccessible`,
+ * `affordances`) route through this too. They share the per-actor `resource`
+ * rate-limit budget in control-api, so a 429 here is the common case, not an
+ * edge one: without the hint the renderer can tell the user it was rate limited
+ * but not when to retry.
+ *
* When there is nothing structured to surface, the ORIGINAL error propagates
* unchanged (fail loud; never swallow the server's verdict).
*/
diff --git a/desktop-app/test/gfsUriHandler.test.ts b/desktop-app/test/gfsUriHandler.test.ts
index 58c38ba1b..52087f215 100644
--- a/desktop-app/test/gfsUriHandler.test.ts
+++ b/desktop-app/test/gfsUriHandler.test.ts
@@ -639,3 +639,60 @@ describe('parseSubjectKey', () => {
expect(() => parseSubjectKey('context:engineering')).toThrow(GfsUriError)
})
})
+
+/**
+ * A 429 on a GFS READ must carry the server's retryAfterSeconds hint across the
+ * Electron IPC boundary, which only preserves `Error.message` — `.bodyText` is
+ * dropped. Without this the renderer can detect the 429 but cannot tell the user
+ * when to retry, which is what left the Files page with no countdown during the
+ * 2026-09-18 rate-limit incident.
+ */
+const RATE_LIMIT_BODY = JSON.stringify({ error: 'Too Many Requests', retryAfterSeconds: 7 })
+
+function rateLimitedTransport(): GfsTransport {
+ return transport({
+ requestJson: vi.fn(async () => {
+ throw new ApiError('429 Too Many Requests: Too Many Requests', 429, RATE_LIMIT_BODY, '7')
+ }) as GfsTransport['requestJson'],
+ })
+}
+
+describe('GfsClient read paths surface retryAfterSeconds across IPC', () => {
+ it('appends retryAfterSeconds to a rate-limited listAccessible rejection', async () => {
+ const client = new GfsClient(rateLimitedTransport())
+ await expect(client.listAccessible('sess')).rejects.toThrow(/^429 Too Many Requests/)
+ await expect(client.listAccessible('sess')).rejects.toThrow(/retryAfterSeconds=7/)
+ })
+
+ it('appends retryAfterSeconds to a rate-limited resolveUri rejection', async () => {
+ const client = new GfsClient(rateLimitedTransport())
+ await expect(client.resolveUri(`gfs://main/${RID}`, 'tok')).rejects.toThrow(
+ /^429 Too Many Requests/
+ )
+ await expect(client.resolveUri(`gfs://main/${RID}`, 'tok')).rejects.toThrow(
+ /retryAfterSeconds=7/
+ )
+ })
+
+ it('appends retryAfterSeconds to a rate-limited listChildren rejection', async () => {
+ const client = new GfsClient(rateLimitedTransport())
+ await expect(client.listChildren(RID, 'tok')).rejects.toThrow(/retryAfterSeconds=7/)
+ })
+
+ it('appends retryAfterSeconds to a rate-limited affordances rejection', async () => {
+ const client = new GfsClient(rateLimitedTransport())
+ await expect(client.affordances(RID, 'tok')).rejects.toThrow(/retryAfterSeconds=7/)
+ })
+
+ it('leaves a non-rate-limited read rejection untouched', async () => {
+ const t = transport({
+ requestJson: vi.fn(async () => {
+ throw new ApiError('403 Forbidden: denied', 403, '{"error":"forbidden"}')
+ }) as GfsTransport['requestJson'],
+ })
+ // Fail loud: an error with nothing structured to surface propagates verbatim,
+ // it is never rewritten or swallowed.
+ await expect(new GfsClient(t).listAccessible('sess')).rejects.toThrow('403 Forbidden: denied')
+ expect(t.requestJson).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/desktop-app/ui/src/lib/gfsGrantErrors.ts b/desktop-app/ui/src/lib/gfsGrantErrors.ts
index 49eef6503..89ce09383 100644
--- a/desktop-app/ui/src/lib/gfsGrantErrors.ts
+++ b/desktop-app/ui/src/lib/gfsGrantErrors.ts
@@ -41,7 +41,7 @@ function parseInvalidIndexes(message: string): number[] {
.filter(index => Number.isInteger(index) && index >= 0)
}
-function parseRetryAfterSeconds(message: string): number | null {
+export function parseRetryAfterSeconds(message: string): number | null {
const match = message.match(/retryAfterSeconds[^\d]*(\d+)/)
if (!match?.[1]) return null
const seconds = Number.parseInt(match[1], 10)