Skip to content

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

TypeScript

feat(control-ui): honor runtime upload product limits

Josué55fb355f7d1b
diff --git a/control-ui/app/constants/gfsFileUpload.ts b/control-ui/app/constants/gfsFileUpload.ts
index 7e795d01e..f61d005e8 100644
--- a/control-ui/app/constants/gfsFileUpload.ts
+++ b/control-ui/app/constants/gfsFileUpload.ts
@@ -1,7 +1,6 @@
-// Product hard ceiling. Upload v2 sends indexed binary parts, so the 200 MiB
-// file limit is independent of the 8 MiB preferred / 16 MiB hard part limit.
-export const GFS_FILE_UPLOAD_MAX_BYTES = 200 * 1024 * 1024
-export const GFS_FILE_UPLOAD_MAX_MEGABYTES = 200
+// The writer owns product policy. These copies only bound protocol and version skew.
+export const GFS_FILE_UPLOAD_DEFAULT_PRODUCT_MAX_BYTES = 200 * 1024 * 1024
+export const GFS_FILE_UPLOAD_PROTOCOL_MAX_BYTES = 1024 * 1024 * 1024
export const GFS_FILE_UPLOAD_PREFERRED_PART_BYTES = 8 * 1024 * 1024
export const GFS_FILE_UPLOAD_MAX_PART_BYTES = 16 * 1024 * 1024
export const GFS_FILE_UPLOAD_DEFAULT_CONCURRENCY = 4
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsx
index c55ff8db8..220abc1c4 100644
--- a/control-ui/components/GfsBrowser.tsx
+++ b/control-ui/components/GfsBrowser.tsx
@@ -1145,7 +1145,7 @@ export function GfsBrowser(): React.JSX.Element {
fileSummary={
uploadCandidate ? `${formatBytes(uploadCandidate.size)} selected` : undefined
}
- guidance="GFS uploads are limited to 200 MiB per file; each request is streamed in 8 MiB parts (16 MiB hard maximum)."
+ guidance="The writer advertises the Upload v2 file limit (up to the 1 GiB protocol maximum); each request is streamed in 8 MiB parts (16 MiB hard maximum)."
progress={
uploadSnapshot
? {
diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsx
index 9718293b2..c2fd50456 100644
--- a/control-ui/components/__tests__/GfsBrowser.test.tsx
+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
-import { GFS_FILE_UPLOAD_MAX_BYTES } from '@constants/gfsFileUpload'
+import { GFS_FILE_UPLOAD_PROTOCOL_MAX_BYTES } from '@constants/gfsFileUpload'
import { GFS_IMAGE_PREVIEW_MAX_BYTES } from '@constants/gfsImagePreview'
import { GFS_MARKDOWN_PREVIEW_MAX_BYTES } from '@constants/gfsMarkdownPreview'
import {
@@ -137,8 +137,8 @@ describe('GfsBrowser', () => {
mockUploadGfsFile.mockReset()
window.localStorage.clear()
mockUploadGfsFile.mockImplementation(async ({ file }: { file: File }) => {
- if (file.size > GFS_FILE_UPLOAD_MAX_BYTES) {
- throw new Error('GFS uploads are limited to 200 MB per file.')
+ if (file.size > GFS_FILE_UPLOAD_PROTOCOL_MAX_BYTES) {
+ throw new Error('GFS uploads cannot exceed the 1 GiB Upload v2 protocol maximum.')
}
return { state: 'completed' }
})
@@ -250,7 +250,9 @@ describe('GfsBrowser', () => {
fireEvent.click(newFile)
const uploadDialog = await screen.findByRole('dialog', { name: 'Upload file' })
- expect(within(uploadDialog).getByText(/limited to 200 MiB per file/i)).toBeTruthy()
+ expect(
+ within(uploadDialog).getByText(/writer advertises the Upload v2 file limit/i)
+ ).toBeTruthy()
expect(within(uploadDialog).getByText(/drag and drop, or click to browse/i)).toBeTruthy()
fireEvent.click(within(uploadDialog).getByRole('button', { name: 'Cancel' }))
@@ -602,7 +604,7 @@ describe('GfsBrowser', () => {
renderBrowser()
await screen.findByText('No resources are visible in this folder.')
const oversized = new File(['small fixture'], 'oversized.md', { type: 'text/markdown' })
- Object.defineProperty(oversized, 'size', { value: GFS_FILE_UPLOAD_MAX_BYTES + 1 })
+ Object.defineProperty(oversized, 'size', { value: GFS_FILE_UPLOAD_PROTOCOL_MAX_BYTES + 1 })
const arrayBuffer = vi.spyOn(oversized, 'arrayBuffer')
const browser = screen.getByRole('region', { name: 'Global File System browser' })
@@ -610,7 +612,9 @@ describe('GfsBrowser', () => {
dataTransfer: { dropEffect: 'none', files: [oversized], types: ['Files'] },
})
- expect(await screen.findByText('GFS uploads are limited to 200 MB per file.')).toBeTruthy()
+ expect(
+ await screen.findByText('GFS uploads cannot exceed the 1 GiB Upload v2 protocol maximum.')
+ ).toBeTruthy()
expect(arrayBuffer).not.toHaveBeenCalled()
expect(mockApiSend).not.toHaveBeenCalled()
})
diff --git a/control-ui/lib/__tests__/gfsFileUpload.test.ts b/control-ui/lib/__tests__/gfsFileUpload.test.ts
index 8f1ac151e..3a04a07dd 100644
--- a/control-ui/lib/__tests__/gfsFileUpload.test.ts
+++ b/control-ui/lib/__tests__/gfsFileUpload.test.ts
@@ -1,5 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { GFS_FILE_UPLOAD_MAX_BYTES, GFS_FILE_UPLOAD_MAX_MEGABYTES } from '@constants/gfsFileUpload'
import {
GfsUploadJob,
type GfsUploadStatus,
@@ -11,13 +10,14 @@ import {
} from '@lib/gfsFileUpload'
describe('assertGfsFileUploadSize', () => {
- it('accepts files at the upload limit', () => {
- expect(() => assertGfsFileUploadSize(GFS_FILE_UPLOAD_MAX_BYTES)).not.toThrow()
+ it('allows product-policy decisions through the 1 GiB protocol maximum', () => {
+ expect(() => assertGfsFileUploadSize(250 * 1024 * 1024)).not.toThrow()
+ expect(() => assertGfsFileUploadSize(1024 * 1024 * 1024)).not.toThrow()
})
- it('rejects files above the upload limit', () => {
- expect(() => assertGfsFileUploadSize(GFS_FILE_UPLOAD_MAX_BYTES + 1)).toThrow(
- `GFS uploads are limited to ${GFS_FILE_UPLOAD_MAX_MEGABYTES} MB per file.`
+ it('rejects files above the absolute protocol maximum', () => {
+ expect(() => assertGfsFileUploadSize(1024 * 1024 * 1024 + 1)).toThrow(
+ 'GFS uploads cannot exceed the 1 GiB Upload v2 protocol maximum.'
)
})
})
@@ -154,6 +154,214 @@ describe('GfsUploadJob', () => {
expect(createCalls).toBe(0)
})
+ it('reaches writer admission for a 250 MiB file under a 300 MiB capability', async () => {
+ const file = new File([new Uint8Array([1])], 'runtime-raise.bin')
+ const fileSize = 250 * 1024 * 1024
+ Object.defineProperty(file, 'size', { value: fileSize })
+ let capabilityCalls = 0
+ let createSize: number | undefined
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ const method = init?.method ?? 'GET'
+ if (method === 'GET' && String(_input).endsWith('/capabilities')) {
+ capabilityCalls += 1
+ return new Response(
+ JSON.stringify({
+ upload: { resumableV2: { enabled: true, maxFileBytes: 300 * 1024 * 1024 } },
+ }),
+ { status: 200 }
+ )
+ }
+ if (method === 'POST' && String(_input).endsWith('/uploads')) {
+ createSize = JSON.parse(String(init?.body)).sizeBytes
+ throw new Error('writer admission reached')
+ }
+ throw new Error(`unexpected ${method} ${String(_input)}`)
+ })
+ )
+
+ await expect(
+ new GfsUploadJob({
+ file,
+ name: file.name,
+ target: { operation: 'create', parentRid: 'parent-runtime-raise' },
+ }).start()
+ ).rejects.toThrow('writer admission reached')
+ expect(capabilityCalls).toBe(1)
+ expect(createSize).toBe(fileSize)
+ })
+
+ it('enforces a lowered 100 MiB writer product limit before session creation', async () => {
+ const file = new File([new Uint8Array([1])], 'runtime-lower.bin')
+ Object.defineProperty(file, 'size', { value: 100 * 1024 * 1024 + 1 })
+ let createCalls = 0
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ const method = init?.method ?? 'GET'
+ if (method === 'GET' && String(_input).endsWith('/capabilities'))
+ return new Response(
+ JSON.stringify({
+ upload: { resumableV2: { enabled: true, maxFileBytes: 100 * 1024 * 1024 } },
+ }),
+ { status: 200 }
+ )
+ if (method === 'POST') createCalls += 1
+ return new Response(null, { status: 204 })
+ })
+ )
+
+ await expect(
+ new GfsUploadJob({
+ file,
+ name: file.name,
+ target: { operation: 'create', parentRid: 'parent-runtime-lower' },
+ }).start()
+ ).rejects.toThrow(`GFS writer limit is ${100 * 1024 * 1024} bytes`)
+ expect(createCalls).toBe(0)
+ })
+
+ it('uses the 200 MiB compatibility limit when an enabled writer omits maxFileBytes', async () => {
+ const file = new File([new Uint8Array([1])], 'missing-limit.bin')
+ Object.defineProperty(file, 'size', { value: 200 * 1024 * 1024 + 1 })
+ let createCalls = 0
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ const method = init?.method ?? 'GET'
+ if (method === 'GET' && String(_input).endsWith('/capabilities'))
+ return new Response(JSON.stringify({ upload: { resumableV2: { enabled: true } } }), {
+ status: 200,
+ })
+ if (method === 'POST') createCalls += 1
+ return new Response(null, { status: 204 })
+ })
+ )
+
+ await expect(
+ new GfsUploadJob({
+ file,
+ name: file.name,
+ target: { operation: 'create', parentRid: 'parent-missing-limit' },
+ }).start()
+ ).rejects.toThrow(/200 MiB compatibility limit/)
+ expect(createCalls).toBe(0)
+ })
+
+ it.each([0, -1, 1.5, 1024 * 1024 * 1024 + 1, Number.MAX_SAFE_INTEGER + 1, '314572800', null])(
+ 'rejects malformed writer maxFileBytes %s as a capability failure',
+ async maxFileBytes => {
+ const file = new File([new Uint8Array([1])], 'invalid-limit.bin')
+ let createCalls = 0
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ const method = init?.method ?? 'GET'
+ if (method === 'GET' && String(_input).endsWith('/capabilities'))
+ return new Response(
+ JSON.stringify({ upload: { resumableV2: { enabled: true, maxFileBytes } } }),
+ { status: 200 }
+ )
+ if (method === 'POST') createCalls += 1
+ return new Response(null, { status: 204 })
+ })
+ )
+
+ await expect(
+ new GfsUploadJob({
+ file,
+ name: file.name,
+ target: { operation: 'create', parentRid: 'parent-invalid-limit' },
+ }).start()
+ ).rejects.toMatchObject({ name: 'GfsUploadCapabilityError' })
+ expect(createCalls).toBe(0)
+ }
+ )
+
+ it.each([
+ null,
+ {},
+ { upload: null },
+ { upload: { resumableV2: null } },
+ { upload: { resumableV2: { enabled: 'true' } } },
+ ])('normalizes malformed capability shape %# to the canonical failure path', async response => {
+ const file = new File([new Uint8Array([1])], 'invalid-capability.bin')
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(async () => new Response(JSON.stringify(response), { status: 200 }))
+ )
+ await expect(
+ new GfsUploadJob({
+ file,
+ name: file.name,
+ target: { operation: 'create', parentRid: 'parent-invalid-capability' },
+ }).start()
+ ).rejects.toMatchObject({ name: 'GfsUploadCapabilityError' })
+ })
+
+ it('rejects above the 1 GiB protocol maximum before requesting capabilities', async () => {
+ const file = new File([new Uint8Array([1])], 'protocol-max.bin')
+ Object.defineProperty(file, 'size', { value: 1024 * 1024 * 1024 + 1 })
+ const fetchMock = vi.fn()
+ vi.stubGlobal('fetch', fetchMock)
+ await expect(
+ new GfsUploadJob({
+ file,
+ name: file.name,
+ target: { operation: 'create', parentRid: 'parent-protocol-max' },
+ }).start()
+ ).rejects.toThrow(/1 GiB Upload v2 protocol maximum/)
+ expect(fetchMock).not.toHaveBeenCalled()
+ })
+
+ it('resumes an admitted session after the writer product limit is lowered', async () => {
+ const file = new File([new Uint8Array([1, 2])], 'resume-lowered-limit.bin')
+ const session = {
+ uploadId: '92929292-9292-4292-8292-929292929292',
+ drive: 'main',
+ expectedBytes: 2,
+ partBytes: 1,
+ partCount: 2,
+ state: 'paused',
+ contiguousBytes: 0,
+ committedBytes: 0,
+ committedPartCount: 0,
+ activePartCount: 0,
+ }
+ let statusCalls = 0
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ const method = init?.method ?? 'GET'
+ const url = String(_input)
+ if (method === 'GET' && url.endsWith('/capabilities'))
+ return new Response(
+ JSON.stringify({ upload: { resumableV2: { enabled: true, maxFileBytes: 1 } } }),
+ { status: 200 }
+ )
+ if (method === 'HEAD')
+ return new Response(null, { status: 204, headers: { 'upload-length': '2' } })
+ if (method === 'GET' && url.includes('/status')) {
+ statusCalls += 1
+ return new Response(JSON.stringify({ ok: true, data: { session, parts: [] } }), {
+ status: 200,
+ })
+ }
+ throw new Error(`unexpected ${method} ${url}`)
+ })
+ )
+
+ const result = await new GfsUploadJob({
+ file,
+ name: file.name,
+ target: { operation: 'create', parentRid: 'parent-resume-lowered-limit' },
+ resumeUploadId: session.uploadId,
+ }).start()
+ expect(result.state).toBe('paused')
+ expect(statusCalls).toBe(1)
+ })
+
it('rejects a create receipt that changes the canonical control-ui drive', async () => {
const file = new File([new Uint8Array([3])], 'drive-drift.bin')
let partCalls = 0
diff --git a/control-ui/lib/gfsFileUpload.ts b/control-ui/lib/gfsFileUpload.ts
index 6ae738de7..9d636dc53 100644
--- a/control-ui/lib/gfsFileUpload.ts
+++ b/control-ui/lib/gfsFileUpload.ts
@@ -1,9 +1,9 @@
import {
GFS_FILE_UPLOAD_DEFAULT_CONCURRENCY,
+ GFS_FILE_UPLOAD_DEFAULT_PRODUCT_MAX_BYTES,
GFS_FILE_UPLOAD_FALLBACK_CONCURRENCY,
- GFS_FILE_UPLOAD_MAX_BYTES,
- GFS_FILE_UPLOAD_MAX_MEGABYTES,
GFS_FILE_UPLOAD_MAX_PART_BYTES,
+ GFS_FILE_UPLOAD_PROTOCOL_MAX_BYTES,
} from '@constants/gfsFileUpload'
import { apiSend } from './api'
@@ -150,6 +150,50 @@ export class GfsUploadCapabilityError extends Error {
}
}
+function plainObject(value: unknown): value is Record<string, unknown> {
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
+}
+
+function parseUploadCapabilities(value: unknown): NonNullable<UploadCapabilities['upload']> {
+ if (!plainObject(value)) {
+ throw new GfsUploadCapabilityError(
+ 'Invalid GFS upload capabilities response: expected a plain JSON object.'
+ )
+ }
+ const upload = value.upload
+ if (!plainObject(upload)) {
+ throw new GfsUploadCapabilityError(
+ 'Invalid GFS upload capabilities response: missing upload object.'
+ )
+ }
+ const resumableV2 = upload.resumableV2
+ if (!plainObject(resumableV2)) {
+ throw new GfsUploadCapabilityError(
+ 'Invalid GFS upload capabilities response: missing resumableV2 object.'
+ )
+ }
+ if (typeof resumableV2.enabled !== 'boolean') {
+ throw new GfsUploadCapabilityError(
+ 'Invalid GFS upload capabilities response: resumableV2.enabled must be Boolean.'
+ )
+ }
+ return upload as NonNullable<UploadCapabilities['upload']>
+}
+
+export function normalizeUploadProductMaxBytes(value: unknown): number {
+ if (value === undefined) return GFS_FILE_UPLOAD_DEFAULT_PRODUCT_MAX_BYTES
+ if (
+ !Number.isSafeInteger(value) ||
+ (value as number) < 1 ||
+ (value as number) > GFS_FILE_UPLOAD_PROTOCOL_MAX_BYTES
+ ) {
+ throw new GfsUploadCapabilityError(
+ 'Resumable GFS upload capabilities advertised an invalid file ceiling.'
+ )
+ }
+ return value as number
+}
+
export function normalizeInstabilityFailureThreshold(value: unknown): number {
if (value === undefined) return GFS_UPLOAD_DEFAULT_INSTABILITY_FAILURE_THRESHOLD
if (
@@ -1090,11 +1134,11 @@ export class GfsUploadJob {
}
private async loadCapabilities(): Promise<UploadCapabilities['upload']> {
- let capabilities: { data: UploadCapabilities }
+ let capabilityData: unknown
try {
- capabilities = await requestWithLifecycleRetries(
+ const capabilities = await requestWithLifecycleRetries(
() =>
- requestJson<UploadCapabilities>(
+ requestJson<unknown>(
'GET',
'/api/v1/gfs/proxy/v1/capabilities',
undefined,
@@ -1102,13 +1146,14 @@ export class GfsUploadJob {
),
{ signal: this.abortController.signal }
)
+ capabilityData = capabilities.data
} catch (error) {
throw new GfsUploadCapabilityError('Resumable GFS upload capabilities are unavailable.', {
cause: error,
})
}
- const upload = capabilities.data.upload
- if (!upload?.resumableV2?.enabled)
+ const upload = parseUploadCapabilities(capabilityData)
+ if (!upload.resumableV2?.enabled)
throw new GfsUploadCapabilityError('Resumable GFS uploads are not enabled on this writer.')
return upload
}
@@ -1120,14 +1165,7 @@ export class GfsUploadJob {
}> {
const upload = await this.loadCapabilities()
const resumable = upload.resumableV2!
- if (resumable.maxFileBytes !== undefined) {
- if (!Number.isSafeInteger(resumable.maxFileBytes) || resumable.maxFileBytes < 0)
- throw new GfsUploadCapabilityError(
- 'Resumable GFS upload capabilities advertised an invalid file ceiling.'
- )
- if (this.input.file.size > resumable.maxFileBytes)
- throw new Error(`GFS writer limit is ${resumable.maxFileBytes} bytes for this upload.`)
- }
+ const productMaxFileBytes = normalizeUploadProductMaxBytes(resumable.maxFileBytes)
const resumeId = this.session?.uploadId ?? this.input.resumeUploadId
if (resumeId) {
const { session, parts } = (
@@ -1142,6 +1180,14 @@ export class GfsUploadJob {
const committed = await this.validateCommittedParts(session, parts)
return { session, committed, resumable }
}
+ if (this.input.file.size > productMaxFileBytes) {
+ if (resumable.maxFileBytes === undefined) {
+ throw new Error(
+ 'GFS uploads use the 200 MiB compatibility limit because the writer omitted maxFileBytes.'
+ )
+ }
+ throw new Error(`GFS writer limit is ${productMaxFileBytes} bytes for this upload.`)
+ }
const createBody = {
operation: this.input.target.operation,
parentRid: this.input.target.parentRid,
@@ -1393,8 +1439,12 @@ export function createGfsUploadJob(input: GfsUploadJobInput): GfsUploadJob {
}
export function assertGfsFileUploadSize(byteLength: number): void {
- if (byteLength > GFS_FILE_UPLOAD_MAX_BYTES) {
- throw new Error(`GFS uploads are limited to ${GFS_FILE_UPLOAD_MAX_MEGABYTES} MB per file.`)
+ if (
+ !Number.isSafeInteger(byteLength) ||
+ byteLength < 0 ||
+ byteLength > GFS_FILE_UPLOAD_PROTOCOL_MAX_BYTES
+ ) {
+ throw new Error('GFS uploads cannot exceed the 1 GiB Upload v2 protocol maximum.')
}
}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 7148e15d0..d3c00d762 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 2ac54986b..e66af8377 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",