Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(gfs): make upload product admission configurable
Josué157b42641978
diff --git a/gfs-controller/src/config.test.ts b/gfs-controller/src/config.test.tsindex d46288c1d..9a62cde2b 100644--- a/gfs-controller/src/config.test.ts+++ b/gfs-controller/src/config.test.ts@@ -121,6 +121,41 @@ describe('GFS_UPLOAD_V2 strict disabled contract', () => {expect(() => loadConfig()).toThrow(/must match/)})+ it('accepts matching canonical and deprecated runtime product limits', () => {+ vi.stubEnv('GFS_DEV_MODE', 'true')+ vi.stubEnv('GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', String(300 * 1024 * 1024))+ vi.stubEnv('GFS_UPLOAD_MAX_FILE_BYTES', String(300 * 1024 * 1024))+ expect(loadConfig().uploadV2.productMaxFileBytes).toBe(300 * 1024 * 1024)+ })++ it.each([+ ['100 MiB', 100 * 1024 * 1024],+ ['200 MiB', 200 * 1024 * 1024],+ ['250 MiB', 250 * 1024 * 1024],+ ['300 MiB', 300 * 1024 * 1024],+ ['the protocol maximum', 1024 * 1024 * 1024],+ ] as const)('accepts a runtime product limit at %s', (_label, bytes) => {+ vi.stubEnv('GFS_DEV_MODE', 'true')+ vi.stubEnv('GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', String(bytes))+ expect(loadConfig().uploadV2.productMaxFileBytes).toBe(bytes)+ })++ it.each(['', '0', '-1', '1.5', 'NaN', 'Infinity', '1e3', '9007199254740992'])(+ 'rejects invalid runtime product limit %s',+ raw => {+ vi.stubEnv('GFS_DEV_MODE', 'true')+ vi.stubEnv('GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', raw)+ expect(() => loadConfig()).toThrow(/GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES/)+ }+ )++ it('rejects a product limit above the configured protocol maximum', () => {+ vi.stubEnv('GFS_DEV_MODE', 'true')+ vi.stubEnv('GFS_UPLOAD_PROTOCOL_MAX_FILE_BYTES', String(300 * 1024 * 1024))+ vi.stubEnv('GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES', String(300 * 1024 * 1024 + 1))+ expect(() => loadConfig()).toThrow(/GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES/)+ })+it('accepts the plan-owned chunk and millisecond TTL names', () => {vi.stubEnv('GFS_DEV_MODE', 'true')vi.stubEnv('GFS_UPLOAD_PREFERRED_CHUNK_BYTES', '8388608')@@ -143,7 +178,7 @@ describe('GFS_UPLOAD_V2 strict disabled contract', () => {expect(() => loadConfig()).toThrow(/must be exactly 'true' or 'false'/)})- it('rejects a protocol ceiling below the product boundary or above 1 GiB', () => {+ it('rejects a protocol ceiling below the default product boundary or above 1 GiB', () => {for (const raw of ['209715199', '1073741825']) {vi.stubEnv('GFS_DEV_MODE', 'true')vi.stubEnv('GFS_UPLOAD_PROTOCOL_MAX_FILE_BYTES', raw)diff --git a/gfs-controller/src/config.ts b/gfs-controller/src/config.tsindex 76da00817..78d8990e3 100644--- a/gfs-controller/src/config.ts+++ b/gfs-controller/src/config.ts@@ -20,7 +20,7 @@ import {GFS_UPLOAD_V2_FINALIZE_TIMEOUT_MS,GFS_UPLOAD_V2_STALE_PART_LEASE_MS,GFS_UPLOAD_V2_PREFERRED_PART_BYTES,- GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,+ GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,GFS_UPLOAD_V2_PROTOCOL_MAX_BYTES,GFS_UPLOAD_V2_SESSION_TTL_SECONDS,} from './upload/protocol'@@ -235,15 +235,15 @@ function uploadConfig(): GfsUploadConfig {const protocolMaxFileBytes = uploadInteger('GFS_UPLOAD_PROTOCOL_MAX_FILE_BYTES',GFS_UPLOAD_V2_PROTOCOL_MAX_BYTES,- GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,+ GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,GFS_UPLOAD_V2_PROTOCOL_MAX_BYTES)const productMaxFileBytes = uploadIntegerWithAlias('GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES','GFS_UPLOAD_MAX_FILE_BYTES',- GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,- GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,- GFS_UPLOAD_V2_PRODUCT_MAX_BYTES+ GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,+ 1,+ protocolMaxFileBytes)const preferredPartBytes = uploadIntegerWithAlias('GFS_UPLOAD_PREFERRED_CHUNK_BYTES',diff --git a/gfs-controller/src/upload/protocol.test.ts b/gfs-controller/src/upload/protocol.test.tsindex 97584d9c4..d3fd2fbce 100644--- a/gfs-controller/src/upload/protocol.test.ts+++ b/gfs-controller/src/upload/protocol.test.ts@@ -5,7 +5,7 @@ import {GFS_UPLOAD_V2_INSTABILITY_FAILURE_THRESHOLD,GFS_UPLOAD_V2_MAX_PART_BYTES,GFS_UPLOAD_V2_PREFERRED_PART_BYTES,- GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,+ GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,GFS_UPLOAD_V2_PROTOCOL_MAX_BYTES,disabledGfsUploadV2Capability,isGfsUploadV2Route,@@ -17,7 +17,7 @@ import {describe('GFS Upload v2 frozen contract', () => {it('uses binary product/request boundaries without advertising v2', () => {- expect(GFS_UPLOAD_V2_PRODUCT_MAX_BYTES).toBe(209_715_200)+ expect(GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES).toBe(209_715_200)expect(GFS_UPLOAD_V2_PROTOCOL_MAX_BYTES).toBe(1_073_741_824)expect(GFS_UPLOAD_V2_PREFERRED_PART_BYTES).toBe(8_388_608)expect(GFS_UPLOAD_V2_MAX_PART_BYTES).toBe(16_777_216)@@ -34,7 +34,7 @@ describe('GFS Upload v2 frozen contract', () => {it('calculates exact 8 MiB geometry at the product boundary', () => {const geometry = {- expectedBytes: GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,+ expectedBytes: GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,partBytes: GFS_UPLOAD_V2_PREFERRED_PART_BYTES,}expect(partCountFor(geometry)).toBe(25)diff --git a/gfs-controller/src/upload/protocol.ts b/gfs-controller/src/upload/protocol.tsindex 4be93c216..d4f4f7898 100644--- a/gfs-controller/src/upload/protocol.ts+++ b/gfs-controller/src/upload/protocol.ts@@ -9,7 +9,8 @@* legacy surface and reject v2 mutations.*/-export const GFS_UPLOAD_V2_PRODUCT_MAX_BYTES = 209_715_200+/** Default product policy; deployments may lower or raise it within the protocol bound. */+export const GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES = 209_715_200export const GFS_UPLOAD_V2_PROTOCOL_MAX_BYTES = 1_073_741_824export const GFS_UPLOAD_V2_PREFERRED_PART_BYTES = 8 * 1024 * 1024export const GFS_UPLOAD_V2_MAX_PART_BYTES = 16 * 1024 * 1024diff --git a/gfs-controller/src/upload/uploadSession.test.ts b/gfs-controller/src/upload/uploadSession.test.tsindex 4ebdfa5e9..d983c8dda 100644--- a/gfs-controller/src/upload/uploadSession.test.ts+++ b/gfs-controller/src/upload/uploadSession.test.ts@@ -11,8 +11,12 @@ import {type Transactor,type TxClient,} from '../db/writeStore'-import { GFS_UPLOAD_V2_PRODUCT_MAX_BYTES, partGeometry } from './protocol'-import { GfsUploadSessionService, type UploadSessionServiceDeps } from './uploadSession'+import { GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES, partGeometry } from './protocol'+import {+ GfsUploadSessionService,+ type UploadSessionServiceDeps,+ uploadCapabilities,+} from './uploadSession'type Row = Record<string, unknown>@@ -571,11 +575,11 @@ describe('GfsUploadSessionService', () => {const exactDb = new MemoryDb()const exact = await service(exactDb, CONFIG).create({...input,- sizeBytes: GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,+ sizeBytes: GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,idempotencyKey: '11111111-1111-4111-8111-111111111112',})expect(exact.created).toBe(true)- expect(exact.session.expectedBytes).toBe(GFS_UPLOAD_V2_PRODUCT_MAX_BYTES)+ expect(exact.session.expectedBytes).toBe(GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES)expect(exact.session.partBytes).toBe(8 * 1024 * 1024)expect(exact.session.partCount).toBe(25)expect(exactDb.sessions).toHaveLength(1)@@ -584,7 +588,7 @@ describe('GfsUploadSessionService', () => {await expect(service(overDb, CONFIG).create({...input,- sizeBytes: GFS_UPLOAD_V2_PRODUCT_MAX_BYTES + 1,+ sizeBytes: GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES + 1,idempotencyKey: '11111111-1111-4111-8111-111111111113',})).rejects.toMatchObject({ code: 'payload_too_large' })@@ -594,13 +598,68 @@ describe('GfsUploadSessionService', () => {await expect(service(partCountDb, { ...CONFIG, maxPartCount: 24 }).create({...input,- sizeBytes: GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,+ sizeBytes: GFS_UPLOAD_V2_DEFAULT_PRODUCT_MAX_BYTES,idempotencyKey: '11111111-1111-4111-8111-111111111114',})).rejects.toMatchObject({ code: 'payload_too_large' })expect(partCountDb.sessions).toHaveLength(0)})+ it.each([+ ['100 MiB', 100 * 1024 * 1024],+ ['250 MiB', 250 * 1024 * 1024],+ ['300 MiB', 300 * 1024 * 1024],+ ['the protocol maximum', 1024 * 1024 * 1024],+ ] as const)(+ 'advertises and enforces the configured %s product limit before allocation',+ async (_label, productMaxFileBytes) => {+ tempRoot = await mkdtemp(join(tmpdir(), 'gfsc-upload-runtime-boundary-'))+ const config = { ...CONFIG, productMaxFileBytes }+ const capability = uploadCapabilities(true, config).resumableV2+ expect(capability).toMatchObject({ enabled: true, maxFileBytes: productMaxFileBytes })++ const input = {+ ...principal,+ operation: 'create' as const,+ parentRid: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',+ name: 'runtime-boundary.bin',+ }+ const exactDb = new MemoryDb()+ const exact = await service(exactDb, config).create({+ ...input,+ sizeBytes: productMaxFileBytes,+ idempotencyKey: '21111111-1111-4111-8111-111111111112',+ })+ expect(exact.session.expectedBytes).toBe(productMaxFileBytes)+ expect(exactDb.sessions).toHaveLength(1)++ const overDb = new MemoryDb()+ await expect(+ service(overDb, config).create({+ ...input,+ sizeBytes: productMaxFileBytes + 1,+ idempotencyKey: '21111111-1111-4111-8111-111111111113',+ })+ ).rejects.toMatchObject({ code: 'payload_too_large' })+ expect(overDb.sessions).toHaveLength(0)+ }+ )++ it('keeps zero-byte uploads valid with a positive configured product limit', async () => {+ tempRoot = await mkdtemp(join(tmpdir(), 'gfsc-upload-empty-file-'))+ const db = new MemoryDb()+ const created = await service(db, { ...CONFIG, productMaxFileBytes: 1 }).create({+ ...principal,+ operation: 'create',+ parentRid: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',+ name: 'empty.bin',+ sizeBytes: 0,+ idempotencyKey: '21111111-1111-4111-8111-111111111114',+ })+ expect(created.session.expectedBytes).toBe(0)+ expect(created.session.partCount).toBe(0)+ })+it('creates idempotent sessions and keeps indexed commits separate from contiguous progress',{ timeout: 15_000 },diff --git a/gfs-controller/src/upload/uploadSession.ts b/gfs-controller/src/upload/uploadSession.tsindex d7b4a802f..d051855a8 100644--- a/gfs-controller/src/upload/uploadSession.ts+++ b/gfs-controller/src/upload/uploadSession.ts@@ -15,7 +15,6 @@ import type { GfsBrokeredAuthority } from '../auth/verify'import {GFS_UPLOAD_V2_COMPLETE_BODY_MAX_BYTES,GFS_UPLOAD_V2_METADATA_BODY_MAX_BYTES,- GFS_UPLOAD_V2_PRODUCT_MAX_BYTES,GfsUploadGeometryError,type GfsUploadPartGeometry,disabledGfsUploadV2Capability,@@ -540,11 +539,11 @@ export class GfsUploadSessionService {if (!Number.isSafeInteger(input.sizeBytes) ||input.sizeBytes < 0 ||- input.sizeBytes > GFS_UPLOAD_V2_PRODUCT_MAX_BYTES+ input.sizeBytes > this.deps.config.productMaxFileBytes) {throw new GfsError('payload_too_large',- `sizeBytes must be between 0 and ${GFS_UPLOAD_V2_PRODUCT_MAX_BYTES}`+ `sizeBytes must be between 0 and ${this.deps.config.productMaxFileBytes}`)}const name = normalizedName(input.name)diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex e9b28c157..6b6a904d8 100644--- a/host-context-controller/package-lock.json+++ b/host-context-controller/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-host-context-controller",- "version": "0.1.170",+ "version": "0.1.171","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.170",+ "version": "0.1.171","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/image-policy": "file:../packages/image-policy",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex 17c98b81a..bf06f1a88 100644--- a/host-context-controller/package.json+++ b/host-context-controller/package.json@@ -1,6 +1,6 @@{"name": "clerum-host-context-controller",- "version": "0.1.170",+ "version": "0.1.171","description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API","main": "dist/main.js","engines": {diff --git a/host-context-controller/src/gfsConfig.test.ts b/host-context-controller/src/gfsConfig.test.tsindex 941322ec6..f0640671d 100644--- a/host-context-controller/src/gfsConfig.test.ts+++ b/host-context-controller/src/gfsConfig.test.ts@@ -55,8 +55,8 @@ describe('gfsDefaultFactoryConfig', () => {Object.assign(process.env, {CONTEXT_MAPPER_GFSC_UPLOAD_V2_ENABLED: 'true',CONTEXT_MAPPER_GFSC_UPLOAD_PROTOCOL_MAX_FILE_BYTES: '1073741824',- CONTEXT_MAPPER_GFSC_UPLOAD_PRODUCT_MAX_FILE_BYTES: '209715200',- CONTEXT_MAPPER_GFSC_UPLOAD_MAX_FILE_BYTES: '209715200',+ CONTEXT_MAPPER_GFSC_UPLOAD_PRODUCT_MAX_FILE_BYTES: '314572800',+ CONTEXT_MAPPER_GFSC_UPLOAD_MAX_FILE_BYTES: '314572800',CONTEXT_MAPPER_GFSC_UPLOAD_PREFERRED_CHUNK_BYTES: '8388608',CONTEXT_MAPPER_GFSC_UPLOAD_MAX_CHUNK_BYTES: '16777216',CONTEXT_MAPPER_GFSC_UPLOAD_MIN_PART_BYTES: '1048576',@@ -78,8 +78,8 @@ describe('gfsDefaultFactoryConfig', () => {expect(c).toMatchObject({uploadV2Enabled: 'true',uploadProtocolMaxFileBytes: '1073741824',- uploadProductMaxFileBytes: '209715200',- uploadMaxFileBytes: '209715200',+ uploadProductMaxFileBytes: '314572800',+ uploadMaxFileBytes: '314572800',uploadPreferredChunkBytes: '8388608',uploadMaxChunkBytes: '16777216',uploadMinPartBytes: '1048576',diff --git a/host-context-controller/src/k8s/gfsFactory.test.ts b/host-context-controller/src/k8s/gfsFactory.test.tsindex e6def1af2..f4376239e 100644--- a/host-context-controller/src/k8s/gfsFactory.test.ts+++ b/host-context-controller/src/k8s/gfsFactory.test.ts@@ -163,8 +163,8 @@ describe('gfsFactory writer Deployment', () => {maxWriteBodyBytes: '25165824',uploadV2Enabled: 'true',uploadProtocolMaxFileBytes: '1073741824',- uploadProductMaxFileBytes: '209715200',- uploadMaxFileBytes: '209715200',+ uploadProductMaxFileBytes: '314572800',+ uploadMaxFileBytes: '314572800',uploadPreferredChunkBytes: '8388608',uploadMaxChunkBytes: '16777216',uploadMinPartBytes: '1048576',@@ -184,8 +184,8 @@ describe('gfsFactory writer Deployment', () => {}const uploadEnv = {GFS_UPLOAD_PROTOCOL_MAX_FILE_BYTES: '1073741824',- GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES: '209715200',- GFS_UPLOAD_MAX_FILE_BYTES: '209715200',+ GFS_UPLOAD_PRODUCT_MAX_FILE_BYTES: '314572800',+ GFS_UPLOAD_MAX_FILE_BYTES: '314572800',GFS_UPLOAD_PREFERRED_CHUNK_BYTES: '8388608',GFS_UPLOAD_MAX_CHUNK_BYTES: '16777216',GFS_UPLOAD_MIN_PART_BYTES: '1048576',