Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): make the marker strip linear and close the last leaking surface
Alfredo Lopezff6ac4405ab7
diff --git a/desktop-app/src/gfs/uriHandler.ts b/desktop-app/src/gfs/uriHandler.tsindex 3d299de2e..84d1d606b 100644--- a/desktop-app/src/gfs/uriHandler.ts+++ b/desktop-app/src/gfs/uriHandler.ts@@ -754,6 +754,17 @@ interface GfsGrantErrorFields {* untouched. This never swallows a failure — `surfaceGfsGrantError` always* re-throws.*/+/**+ * Widest retry window this process will republish, in seconds.+ *+ * It is the `\d{1,7}` the `Retry-After` header parser already accepts, stated+ * as a number so the body path and the header path cannot drift apart. The+ * renderer clamps what it reads to 300 seconds; this bound is about the shape+ * of the token rather than the length of the wait, and it exists so every+ * value this process emits is one the renderer's `\d+` anchors can read back.+ */+const MAX_EMITTED_RETRY_AFTER_SECONDS = 9_999_999+function parseGfsGrantErrorFields(bodyText: string): GfsGrantErrorFields {let parsed: unknowntry {@@ -770,7 +781,19 @@ function parseGfsGrantErrorFields(bodyText: string): GfsGrantErrorFields {)if (indexes.length > 0) fields.invalidIndexes = indexes}- if (Number.isInteger(record.retryAfterSeconds) && (record.retryAfterSeconds as number) >= 0) {+ // Same bound as `parseRetryAfterHeader`'s `\d{1,7}`, because the two feed the+ // same suffix and the renderer reads that suffix with `\d+$`. An integer is+ // not enough: `Number.isInteger(1e21)` is true and `${1e21}` is `1e+21`, so+ // an out-of-range body value would compose a marker that neither+ // `parseRetryAfterSeconds` nor `stripVettedMarkers` matches — the window+ // would be unreadable AND the token would render in the banner. Refusing it+ // yields no window, which the renderer already states as "try again+ // shortly"; that is the same answer it gives for an unparseable header.+ if (+ Number.isInteger(record.retryAfterSeconds) &&+ (record.retryAfterSeconds as number) >= 0 &&+ (record.retryAfterSeconds as number) <= MAX_EMITTED_RETRY_AFTER_SECONDS+ ) {fields.retryAfterSeconds = record.retryAfterSeconds as number}return fieldsdiff --git a/desktop-app/test/gfsUriHandler.test.ts b/desktop-app/test/gfsUriHandler.test.tsindex bb656b9f5..0591f0233 100644--- a/desktop-app/test/gfsUriHandler.test.ts+++ b/desktop-app/test/gfsUriHandler.test.ts@@ -407,6 +407,33 @@ describe('GfsClient.listGrants', () => {new GfsClient(transport({ requestJson })).listGrants({ resourceId: RID }, 'tok')).rejects.toThrow(/429 .*retryAfterSeconds=45/)})++ it('emits no window for a body value too large to spell in digits', async () => {+ // `Number.isInteger(1e21)` is true and `${1e21}` is `1e+21`, so an+ // unbounded body value composed a marker the renderer can neither read+ // (`retryAfterSeconds=\d+$`) nor strip — an unreadable window AND the+ // token rendered in the banner. The header parser already bounds its input+ // to `\d{1,7}`; the body now answers to the same bound.+ const requestJson = vi.fn(async () => {+ throw new ApiError(+ '429 Too Many Requests: Too Many Requests',+ 429,+ JSON.stringify({ error: 'Too Many Requests', retryAfterSeconds: 1e21 })+ )+ }) as GfsTransport['requestJson']++ const rejection = await new GfsClient(transport({ requestJson }))+ .listGrants({ resourceId: RID }, 'tok')+ .catch((error: unknown) => error)++ const message = (rejection as Error).message+ // Witness that the refusal is about the window and not about the whole+ // surfacing step: the status marker the same builder appends is present,+ // so this message did go through `surfaceGfsGrantError`.+ expect(message).toContain('httpStatus=429')+ expect(message).not.toContain('retryAfterSeconds')+ expect(message).not.toContain('1e+21')+ })})describe('GfsClient.revokeGrant', () => {diff --git a/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts b/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.tsindex bd71a4819..55c9e2f84 100644--- a/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts+++ b/desktop-app/ui/src/lib/__tests__/gfsGrantErrors.test.ts@@ -298,6 +298,23 @@ describe('describeGfsReadError', () => {)})+ it('removes one separator, not a whitespace run', () => {+ // The builder joins with a single space, so one is all this may take. The+ // pattern that took `\s+` backtracked over every starting position in a+ // whitespace run that did not end in the literal — quadratic on the UI+ // thread, over a message `httpClient` fills from an unbounded server error+ // body (10k spaces measured at 102 ms, 100k at 8.9 s).+ //+ // Asserted as behavior rather than as elapsed time: a timing threshold is+ // a flake on a loaded machine, and the narrower pattern is observable+ // without one. Whitespace the SERVER put at the end of its own message is+ // not the builder's separator and survives.+ const raw = '500 Internal Server Error: padded httpStatus=500'++ expect(parseHttpStatus(raw)).toBe(500)+ expect(describeGfsReadError(new Error(raw)).message).toBe('500 Internal Server Error: padded ')+ })+it("leaves a lookalike the server's own body carried", () => {// Only the suffix position is ours. A token ahead of it is the server's// text, and `surfaceGfsGrantError` already stripped the ones that coulddiff --git a/desktop-app/ui/src/lib/gfsGrantErrors.ts b/desktop-app/ui/src/lib/gfsGrantErrors.tsindex ca5b5be7d..9b5d88bad 100644--- a/desktop-app/ui/src/lib/gfsGrantErrors.ts+++ b/desktop-app/ui/src/lib/gfsGrantErrors.ts@@ -63,9 +63,23 @@ export function stripIpcWrapper(message: string): string {* `parseRetryAfterSeconds` all read these markers; a message cleaned first is a* message that can no longer be classified, which is the incident this module* exists to prevent.+ *+ * ONE whitespace character, never `\s+`. The builder joins its parts with a+ * single space (`uriHandler` surfaceGfsGrantError), so one is exactly what it+ * wrote — and `\s+` before a literal that is usually absent backtracks over+ * every starting position in a whitespace run, which is quadratic. This runs+ * on the renderer's UI thread over `ApiError.message`, and `httpClient` fills+ * that from the server's error body with no size bound, so a body of a few+ * hundred KB of whitespace from a hostile or broken upstream would freeze the+ * window for tens of seconds. Measured on the `\s+` form: 10k spaces 102 ms,+ * 100k spaces 8.9 s. The single-character form is flat at ~0.01 ms.+ *+ * Narrower is also more correct: a server message that legitimately ends in+ * whitespace keeps it, because only the separator the builder added is ours to+ * remove.*/export function stripVettedMarkers(message: string): string {- return message.replace(/\s+retryAfterSeconds=\d+$/, '').replace(/\s+httpStatus=\d{3}$/, '')+ return message.replace(/\sretryAfterSeconds=\d+$/, '').replace(/\shttpStatus=\d{3}$/, '')}function rawMessage(error: unknown): string {diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsxindex 25c1b5914..d33d66002 100644--- a/desktop-app/ui/src/pages/FilesPage.tsx+++ b/desktop-app/ui/src/pages/FilesPage.tsx@@ -803,10 +803,14 @@ export function FilesPage({try {const access = await resolveFolderDropAccess(destination)if (!access.allowed) {+ // Through the read-plane presenter, like `handleDownload`. The+ // affordances check is one of the methods `surfaceGfsGrantError`+ // wraps, so its rejection carries the IPC wrapper and the vetted+ // markers; raw, this toast read "… httpStatus=403". A 403 or 429 here+ // is a policy verdict, not an authority failure, so it does not fail+ // closed and this really is the path the user sees.const message = access.error- ? access.error instanceof Error- ? access.error.message- : String(access.error)+ ? describeGfsReadError(access.error).message: `You can’t move files to ${destination.name} because you don’t have write permission for this folder.`pushToast?.(message, 'error')returndiff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsxindex fc73ddbff..005832755 100644--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx@@ -2670,6 +2670,92 @@ describe('FilesPage', () => {})})+ it('presents a rate-limited drop check in the shared read-plane words', async () => {+ // The affordances check is one of the nine methods `surfaceGfsGrantError`+ // wraps, so its rejection reaches the renderer as the IPC wrapper plus the+ // vetted markers. This toast rendered that raw. A 429 is a policy verdict,+ // not an authority failure, so it does not fail closed and the user really+ // does see this string.+ const pushToast = vi.fn()+ const moveResource = vi.fn(async () => ({}))+ const affordances = vi.fn(async () => {+ throw new Error(+ "Error invoking remote method 'gfs:affordances': Error: 429 Too Many Requests: " ++ 'Too Many Requests httpStatus=429 retryAfterSeconds=7'+ )+ })+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: { gfs: { affordances } },+ })+ hookMock.useGfsBrowserController.mockReturnValue({+ ...baseController(),+ current: {+ resourceId: 'folder-1',+ gfsUri: 'gfs://main/folder-1',+ name: 'Product',+ kind: 'directory',+ version: 1,+ },+ items: [+ {+ resourceId: 'file-1',+ rid: 'file-1',+ gfsUri: 'gfs://main/file-1',+ drive: 'main',+ parentResourceId: 'folder-1',+ name: 'notes.txt',+ kind: 'file',+ path: '/Product/notes.txt',+ version: 3,+ bytes: 12,+ },+ {+ resourceId: 'private-1',+ rid: 'private-1',+ gfsUri: 'gfs://main/private-1',+ drive: 'main',+ parentResourceId: 'folder-1',+ name: 'Private',+ kind: 'directory',+ path: '/Product/Private',+ version: 2,+ bytes: 0,+ },+ ],+ moveResource,+ })+ renderFilesPage(pushToast)++ const sourceRow = screen.getByRole('button', { name: 'Open notes.txt' })+ const destinationRow = screen.getByRole('button', { name: 'Open Private' })+ const dataTransfer = {+ types: ['application/x-evenfire-gfs-resource'],+ files: [],+ effectAllowed: 'none',+ dropEffect: 'none',+ setData: vi.fn(),+ }++ fireEvent.dragStart(sourceRow, { dataTransfer })+ fireEvent.dragEnter(destinationRow, { dataTransfer })+ // Liveness witness: the check really ran and really rejected, so the+ // absence assertions below describe a presented verdict rather than a drop+ // that never asked.+ await waitFor(() => expect(affordances).toHaveBeenCalledWith('private-1', 'main'))++ fireEvent.drop(destinationRow, { dataTransfer })++ await waitFor(() => {+ expect(moveResource).not.toHaveBeenCalled()+ expect(pushToast).toHaveBeenCalledWith('Too many file requests — try again in 7s.', 'error')+ })+ const toasted = pushToast.mock.calls.map(([text]) => String(text)).join('\n')+ expect(toasted).not.toContain('httpStatus=')+ expect(toasted).not.toContain('retryAfterSeconds=')+ expect(toasted).not.toContain('Error invoking remote method')+ })+it('renames a folder child from its row menu once write affordances resolve', async () => {const pushToast = vi.fn()const renameResource = vi.fn(async () => ({}))