Skip to content

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

TypeScript

fix(desktop): match 429 as a status token, not as three digits anywhere

Alfredo Lopez80f4babba4c0
diff --git a/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts b/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts
index d29cffd16..ad21c517f 100644
--- a/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts
@@ -104,6 +104,30 @@ describe('describeGfsGrantError', () => {
})
})
+ it.each([
+ ['hyphen-delimited, as in a name', '500 Internal Server Error: upstream edge-429-pool refused'],
+ ['slash-delimited, as in a path', '404 Not Found: no handler for /docs/429/index.md'],
+ ])('does not treat a 429 embedded in text as a rate limit (%s)', (_label, raw) => {
+ // `httpClient` copies the RAW body into the message when the JSON carries
+ // no top-level `error`/`message`, so arbitrary server text reaches the
+ // classifier. A word-boundary match fired on `-429-` and `/429/`.
+ const presentation = describeGfsReadError(new Error(raw))
+
+ expect(presentation.code).toBeNull()
+ // Witness: the classifier is live and still recognises the status token in
+ // the very same message, so the null above is a rejected embedding and not
+ // a matcher that stopped working.
+ expect(describeGfsReadError(new Error(`${raw} 429`)).code).toBe('rate_limited')
+ })
+
+ it.each([
+ ['leading status', '429 Too Many Requests'],
+ ['colon-wrapped status', 'gfs download failed: 429: Too Many Requests'],
+ ['trailing status', 'gfs download failed: 429'],
+ ])('still recognises the status token the wire produces (%s)', (_label, raw) => {
+ expect(describeGfsReadError(new Error(raw)).code).toBe('rate_limited')
+ })
+
it('passes unknown errors through verbatim — fail loud, never swallow', () => {
expect(describeGfsGrantError(new Error('total surprise'))).toEqual({
code: null,
diff --git a/desktop-app/ui/src/lib/gfsGrantErrors.ts b/desktop-app/ui/src/lib/gfsGrantErrors.ts
index ec3b3e294..b35f971e0 100644
--- a/desktop-app/ui/src/lib/gfsGrantErrors.ts
+++ b/desktop-app/ui/src/lib/gfsGrantErrors.ts
@@ -96,8 +96,23 @@ export function parseRetryAfterSeconds(message: string): number | null {
return Math.min(seconds, MAX_RETRY_AFTER_SECONDS)
}
+/**
+ * A 429 is recognised as a STATUS TOKEN, not as three digits anywhere.
+ *
+ * `\b` treats `-` and `/` as boundaries, so it matched `429` inside a path or
+ * a name — and `httpClient` copies the RAW response body into the message
+ * whenever the JSON carries no top-level `error`/`message` key, so such text
+ * genuinely reaches here. A non-429 failure whose body mentioned, say, an edge
+ * pool called `edge-429-pool` was presented as "Too many file requests" and
+ * armed a focus pause on a listing that was never rate limited.
+ *
+ * Every shape the wire actually produces delimits the status with whitespace
+ * or a colon — `429 Too Many Requests`, `gfs download failed: 429:` — so
+ * requiring that delimiter on both sides loses no real detection. Erring the
+ * other way is the costly one: a missed 429 is the original incident.
+ */
export function isRateLimited(message: string): boolean {
- return /\b429\b/.test(message) || message.includes('rate_limited')
+ return /(?:^|[\s:])429(?=[\s:]|$)/.test(message) || message.includes('rate_limited')
}
function describeRateLimited(raw: string, subject: string): GfsGrantErrorPresentation {