Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
Merge origin/dev (#1005) into fix/issue-1022-processing-lease-lifecycle
Alfredo Lopez98030ef74475
diff --cc mcp-host/package-lock.jsonindex 173cbea9d,0ad0982c9..c06fc7ee3--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@@ -1,12 -1,12 +1,12 @@@{"name": "clerum-mcp-host",- "version": "0.1.507",- "version": "0.1.506",++ "version": "0.1.508","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.507",- "version": "0.1.506",++ "version": "0.1.508","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --cc mcp-host/package.jsonindex b6b73c3b7,3cb8a689f..bbaf43977--- a/mcp-host/package.json+++ b/mcp-host/package.json@@@ -1,6 -1,6 +1,6 @@@{"name": "clerum-mcp-host",- "version": "0.1.507",- "version": "0.1.506",++ "version": "0.1.508","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --cc mcp-host/src/agent/taskExecutor.tsindex 8585a7a17,08d32ccb3..53e5de74e--- a/mcp-host/src/agent/taskExecutor.ts+++ b/mcp-host/src/agent/taskExecutor.ts@@@ -2127,7 -2150,15 +2147,10 @@@ export class TaskExecutorappConfig,this.deps.failover?.policy.fallbacks)+ // #1003 — native-tool presentation is host-wide and provider-independent:+ // it never depends on the MCP presentation resolved above.+ const nativeAuto = appConfig.nativeToolPresentation === 'auto'const gfsCallerIdentity = this.task.sourceMessage?.sender ?? GFS_SYSTEM_CALLER_IDENTITY- const gfsProcessingLeaseProvider =- this.deps.gfsProcessingLeaseProvider ??- (this.deps.gfsDownloadStore && gfsCallerIdentity- ? this.deps.gfsDownloadStore.processingLeaseProvider(gfsCallerIdentity)- : undefined)const gfsWorkspace = gfsManagedWorkspaceExecution({approvalEnabled: appConfig.enableApproval,source: this.task.source,diff --cc mcp-host/src/config.tsindex a58c799ed,d49f85a8a..18b876f91--- a/mcp-host/src/config.ts+++ b/mcp-host/src/config.ts@@@ -7,10 -7,12 +7,13 @@@ import type { GuardrailsConfig } from 'import { NativeToolConfig } from './core/interfaces'import {type CodexToolPresentation,+ type NativeToolPresentation,parseCodexToolDiscoveryBytes,parseCodexToolPresentation,+ parseNativeToolDiscoveryBytes,+ parseNativeToolPresentation,} from './core/orchestration/toolPresentationPolicy'+import { SHELL_TIMEOUT_CLEANUP_MS } from './core/tools/shellTimeouts'import { ALL_PROVIDERS, type LlmProvider, descriptorFor, isLlmProvider } from './llm/registryCore'import type { McpCatalogBootstrapConfig } from './mcp/grantProbe'import { HostSpec, McpServerInfo, MemoryConfig, ModelConfig, PersonalizationConfig } from './types'diff --cc mcp-host/src/internalTools/gfsDownloadStore.tsindex 483a88057,1a2dd9dad..66fb6a0e7--- a/mcp-host/src/internalTools/gfsDownloadStore.ts+++ b/mcp-host/src/internalTools/gfsDownloadStore.ts@@@ -15,7 -9,16 +15,11 @@@ importGFS_HOST_ACTIVE_DOWNLOADS,GFS_HOST_RETAINED_FILES,} from './gfsFilePolicy'- import { openPrivateStoreObject, verifyPrivateStoreDirectory } from './gfsStorePrivateFiles'-import type {- GfsProcessingLease,- GfsProcessingLeaseAcquisition,- GfsProcessingLeaseProvider,-} from './gfsProcessingLease'+ import {+ PrivateStoreNameMovedError,+ openPrivateStoreObject,+ verifyPrivateStoreDirectory,+ } from './gfsStorePrivateFiles'import { GfsStoreWriterLease, GfsStoreWriterOwnershipError } from './gfsStoreWriterLease'export type GfsDownloadStoreErrorCode =diff --cc mcp-host/src/internalTools/gfsDownloadStoreAdversarialQuota.test.tsindex b7d17039c,fced13bf9..91d8b7962--- a/mcp-host/src/internalTools/gfsDownloadStoreAdversarialQuota.test.ts+++ b/mcp-host/src/internalTools/gfsDownloadStoreAdversarialQuota.test.ts@@@ -671,240 -644,3 +671,241 @@@ describe('GFS download store adversaria})})})++const MARGIN = 16 * 1024 * 1024+const capacitySource = sourceFor(200, 7)++/** Physical-capacity admission, ported from the deleted lease-capacity suite (#1019). */+describe('GFS download store physical capacity and reclaim', () => {+ const capacityStores: GfsDownloadStore[] = []+ const capacityRoots: string[] = []++ afterEach(async () => {+ vi.restoreAllMocks()+ statfsBoundary.mockImplementation(nativeFs.statfs)+ for (const target of capacityStores.splice(0))+ await target.close(0).catch(async () => {+ await (+ target as unknown as { writerLease?: { release(): Promise<void> } }+ ).writerLease?.release()+ })+ for (const root of capacityRoots.splice(0))+ await nativeFs.rm(root, { recursive: true, force: true })+ })++ async function setup(extra: Record<string, string> = {}) {+ const { Store } = await loadLimitedStore({+ MCP_HOST_GFS_MAX_FILE_BYTES: '20',+ MCP_HOST_GFS_DOWNLOAD_STORAGE_BYTES: '100',+ MCP_HOST_GFS_CALLER_DOWNLOAD_STORAGE_BYTES: '50',+ ...extra,+ })+ const root = await nativeFs.mkdtemp(path.join(tmpdir(), 'gfs-capacity-'))+ capacityRoots.push(root)+ const target = new Store(root)+ capacityStores.push(target)+ await target.initialize()+ return { root, store: target }+ }++ async function copy(+ target: GfsDownloadStore,+ root: string,+ identity: string,+ bytes = 7,+ owner?: string+ ) {+ const transfer = await target.createTransfer({+ callerIdentity: identity,+ callerWorkspacePath: root,+ source: capacitySource,+ sizeBytes: bytes,+ expiresAt: future(),+ retentionOwnerId: owner,+ })+ const body = Buffer.alloc(bytes, 65)+ await nativeFs.writeFile(path.join(root, transfer.partialPath), body)+ return target.publish(transfer.id, identity, createHash('sha256').update(body).digest('hex'))+ }++ async function capacity(root: string, bytes: number) {+ const observed = await nativeFs.statfs(root, { bigint: true })+ statfsBoundary.mockResolvedValue({+ ...observed,+ bsize: 4096n,+ bavail: BigInt(Math.floor(bytes / 4096)),+ })+ }++ it('rejects impossible physical margin before evicting another caller at a logical quota boundary', async () => {+ const { root, store: target } = await setup()+ const otherRoot = await callerDirectory(root, 'caller-b')+ const receipts = []+ for (let index = 0; index < 5; index++)+ receipts.push(await copy(target, otherRoot, 'caller-b', 10))+ const requestRoot = await callerDirectory(root, 'caller-a')+ // Add durable, protected charges to make aggregate 100 while requester has room.+ for (const identity of ['caller-c', 'caller-d', 'caller-e', 'caller-f', 'caller-g'])+ await copy(target, await callerDirectory(root, identity), identity, 10, `${identity}-owner`)+ await capacity(root, 0)+ await expect(+ target.createTransfer({+ callerIdentity: 'caller-a',+ callerWorkspacePath: requestRoot,+ source: capacitySource,+ sizeBytes: 20,+ expiresAt: future(),+ })+ ).rejects.toMatchObject({ code: 'host_quota_exceeded' })+ expect(target.debugUsage()).toMatchObject({ bytes: 100, files: 10 })+ for (const receipt of receipts) expect(target.debugRecord(receipt.id)).toBeDefined()+ for (const identity of ['caller-c', 'caller-d', 'caller-e', 'caller-f', 'caller-g'])+ await target.releaseReceiptOwner(`${identity}-owner`, identity)- })++ // 10 durable publications measured 3.3 s on a loaded host, inside Vitest's 5 s default.++ }, 30_000)++ it(+ 'keeps all default-cap small copies when current physical capacity is zero',+ async () => {+ const { root, store: target } = await setup({+ MCP_HOST_GFS_MAX_FILE_BYTES: '1024',+ MCP_HOST_GFS_DOWNLOAD_STORAGE_BYTES: String(1024 * 1024),+ MCP_HOST_GFS_CALLER_DOWNLOAD_STORAGE_BYTES: String(128 * 1024),+ })+ const receipts = []+ for (let index = 0; index < 8; index++) {+ const identity = `caller-${index}`+ const directory = await callerDirectory(root, identity)+ for (let file = 0; file < 8; file++)+ receipts.push(await copy(target, directory, identity, 1))+ }+ await capacity(root, 0)+ await expect(+ target.createTransfer({+ callerIdentity: 'caller-new',+ callerWorkspacePath: await callerDirectory(root, 'caller-new'),+ source: capacitySource,+ sizeBytes: 1,+ expiresAt: future(),+ })+ ).rejects.toMatchObject({ code: 'host_quota_exceeded' })+ expect(target.debugUsage().files).toBe(64)+ for (const receipt of receipts) expect(target.debugRecord(receipt.id)).toBeDefined()+ },+ DEFAULT_CAP_PUBLICATION_TIMEOUT_MS+ )++ it('respects pending active reservations before any cache-pressure effect', async () => {+ const { root, store: target } = await setup({ MCP_HOST_GFS_CALLER_DOWNLOAD_MAX_FILES: '1' })+ const cachedRoot = await callerDirectory(root, 'caller-a')+ const receipt = await copy(target, cachedRoot, 'caller-a', 7)+ const active = await target.createTransfer({+ callerIdentity: 'caller-b',+ callerWorkspacePath: await callerDirectory(root, 'caller-b'),+ source: capacitySource,+ sizeBytes: 7,+ expiresAt: future(),+ })+ await capacity(root, MARGIN + 4096)+ await expect(+ target.createTransfer({+ callerIdentity: 'caller-a',+ callerWorkspacePath: cachedRoot,+ source: capacitySource,+ sizeBytes: 7,+ expiresAt: future(),+ })+ ).rejects.toMatchObject({ code: 'host_quota_exceeded' })+ expect(target.debugRecord(receipt.id)).toBeDefined()+ await target.fail(active.id, 'caller-b')+ })++ it('never credits sparse apparent bytes as available physical capacity', async () => {+ const bytes = 16 * 1024 * 1024+ const { root, store: target } = await setup({+ MCP_HOST_GFS_MAX_FILE_BYTES: String(bytes),+ MCP_HOST_GFS_DOWNLOAD_STORAGE_BYTES: String(bytes * 4),+ MCP_HOST_GFS_CALLER_DOWNLOAD_STORAGE_BYTES: String(bytes * 2),+ MCP_HOST_GFS_CALLER_DOWNLOAD_MAX_FILES: '1',+ })+ const sparseRoot = await callerDirectory(root, 'caller-a')+ const transfer = await target.createTransfer({+ callerIdentity: 'caller-a',+ callerWorkspacePath: sparseRoot,+ source: capacitySource,+ sizeBytes: bytes,+ expiresAt: future(),+ })+ const handle = await nativeFs.open(path.join(sparseRoot, transfer.partialPath), 'r+')+ await handle.truncate(bytes)+ await handle.close()+ const sparse = await nativeFs.stat(path.join(sparseRoot, transfer.partialPath))+ expect(sparse.blocks * 512).toBeLessThan(sparse.size)+ const receipt = await target.publish(+ transfer.id,+ 'caller-a',+ createHash('sha256').update(Buffer.alloc(bytes)).digest('hex')+ )+ await capacity(root, 0)+ await expect(+ target.createTransfer({+ callerIdentity: 'caller-a',+ callerWorkspacePath: sparseRoot,+ source: capacitySource,+ sizeBytes: 7,+ expiresAt: future(),+ })+ ).rejects.toMatchObject({ code: 'host_quota_exceeded' })+ expect(target.debugRecord(receipt.id)).toBeDefined()+ expect((await nativeFs.stat(path.join(sparseRoot, receipt.path))).size).toBe(bytes)+ })++ it('refuses admission if real capacity changes after a positively settled victim', async () => {+ const { root, store: target } = await setup({ MCP_HOST_GFS_CALLER_DOWNLOAD_MAX_FILES: '1' })+ const victimRoot = await callerDirectory(root, 'caller-a')+ const receipt = await copy(target, victimRoot, 'caller-a', 7)+ const directory = path.join(victimRoot, path.dirname(receipt.path))+ const observed = await nativeFs.statfs(root, { bigint: true })+ statfsBoundary.mockImplementation(async () => {+ try {+ await nativeFs.lstat(directory)+ return observed+ } catch (error) {+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error+ return { ...observed, bavail: 0n }+ }+ })+ await expect(+ target.createTransfer({+ callerIdentity: 'caller-a',+ callerWorkspacePath: victimRoot,+ source: capacitySource,+ sizeBytes: 7,+ expiresAt: future(),+ })+ ).rejects.toMatchObject({ code: 'host_quota_exceeded' })+ expect(target.debugUsage().files).toBe(0)+ await expect(nativeFs.lstat(directory)).rejects.toMatchObject({ code: 'ENOENT' })+ })++ it('reclaims logical quota and admits when real physical capacity is already sufficient', async () => {+ const { root, store: target } = await setup({ MCP_HOST_GFS_CALLER_DOWNLOAD_MAX_FILES: '1' })+ const reclaimRoot = await callerDirectory(root, 'caller-a')+ const receipt = await copy(target, reclaimRoot, 'caller-a', 7)+ const before = await nativeFs.statfs(root, { bigint: true })+ expect(before.bavail * before.bsize).toBeGreaterThan(BigInt(MARGIN + 4096))+ const next = await target.createTransfer({+ callerIdentity: 'caller-a',+ callerWorkspacePath: reclaimRoot,+ source: capacitySource,+ sizeBytes: 7,+ expiresAt: future(),+ })+ expect(target.debugRecord(receipt.id)).toBeUndefined()+ await expect(+ nativeFs.lstat(path.join(reclaimRoot, path.dirname(receipt.path)))+ ).rejects.toMatchObject({ code: 'ENOENT' })+ expect(target.debugRecord(next.id)).toBeDefined()+ await target.fail(next.id, 'caller-a')+ })+})