Skip to content

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

TypeScript

fix(mcp-host): keep only the minimum free space on a disk the Host does not own

marcotebee0e720c5e59
diff --git a/mcp-host/src/core/tools/__tests__/generatedOutputsPrivacy.test.ts b/mcp-host/src/core/tools/__tests__/generatedOutputsPrivacy.test.ts
index e2f6475d4..fbc46ed8a 100644
--- a/mcp-host/src/core/tools/__tests__/generatedOutputsPrivacy.test.ts
+++ b/mcp-host/src/core/tools/__tests__/generatedOutputsPrivacy.test.ts
@@ -17,7 +17,9 @@ import { deriveUserKeyFromSource } from '../../../workspace/userKey'
import { FileWriteTool } from '../fileWrite'
import { NativeToolRegistry } from '../nativeToolRegistry'
-const volume = vi.hoisted(() => ({ mode: 'roomy' as 'roomy' | 'full' | 'unmeasurable' }))
+const volume = vi.hoisted(() => ({
+ mode: 'roomy' as 'roomy' | 'full' | 'unmeasurable' | 'busy-shared' | 'busy-own',
+}))
// A roomy volume is sized to its free space, so the disk's occupancy never
// meets the floor; a full one leaves less than the floor; an unmeasurable one
@@ -31,6 +33,18 @@ vi.mock('fs', async original => {
throw Object.assign(new Error('statfs unavailable'), { code: 'ENOSYS' })
}
const reading = actual.statfsSync(target, options)
+ if (volume.mode === 'busy-shared' || volume.mode === 'busy-own') {
+ // 4 GB, 5% (200 MB) free: under the 15% share, over the minimum.
+ const busy = {
+ ...reading,
+ bsize: 4096n,
+ blocks: 1_000_000n,
+ bfree: 50_000n,
+ bavail: 50_000n,
+ }
+ const own = volume.mode === 'busy-own' && target !== '/'
+ return own ? { ...busy, blocks: 2_000_000n } : busy
+ }
return volume.mode === 'full'
? { ...reading, bsize: 4096n, blocks: 1000n, bfree: 100n, bavail: 100n }
: { ...reading, blocks: reading.bavail, bfree: reading.bavail }
@@ -254,6 +268,17 @@ describe('generated documents are private to their caller', () => {
expect(fs.readdirSync(outputsOf(a))).toEqual(['kept.md'])
})
+ it('keeps only the minimum free space on a disk the Host shares with the root', async () => {
+ const a = rootOf('user-a')
+ volume.mode = 'busy-shared'
+ expect((await markdown(a, 'shared.md', '# fine\n')).is_error).toBe(false)
+ // The same reading on a volume of the Host's own keeps its 15%.
+ volume.mode = 'busy-own'
+ const refused = await markdown(a, 'own.md', '# refused\n')
+ expect(refused.is_error).toBe(true)
+ expect(refused.content).toMatch(/Not enough free space/)
+ })
+
it('writes when the volume cannot be measured, and says so once', async () => {
const warn = vi.spyOn(logger, 'warn')
const a = rootOf('user-a')
diff --git a/mcp-host/src/internalTools/gfsDownloadStore.ts b/mcp-host/src/internalTools/gfsDownloadStore.ts
index 86db91240..c606467b3 100644
--- a/mcp-host/src/internalTools/gfsDownloadStore.ts
+++ b/mcp-host/src/internalTools/gfsDownloadStore.ts
@@ -37,7 +37,7 @@ const META_MAX_BYTES = 64 * 1024
*/
const FREE_SPACE_FLOOR_PERCENT = 15n
/** The floor on a volume too small for its percentage to reach this. */
-const FREE_SPACE_FLOOR_MIN_BYTES = 16n * 1024n * 1024n
+export const FREE_SPACE_FLOOR_MIN_BYTES = 16n * 1024n * 1024n
/**
* Share of the volume, above the floor, that a restore frees once the volume
* fell below the floor. Admission still requires only the floor.
diff --git a/mcp-host/src/workflow/artifactOutput.ts b/mcp-host/src/workflow/artifactOutput.ts
index 9157bae24..df94c5542 100644
--- a/mcp-host/src/workflow/artifactOutput.ts
+++ b/mcp-host/src/workflow/artifactOutput.ts
@@ -4,7 +4,7 @@
import { createHash, randomUUID } from 'crypto'
import * as fs from 'fs'
import * as path from 'path'
-import { freeSpaceFloor } from '../internalTools/gfsDownloadStore'
+import { FREE_SPACE_FLOOR_MIN_BYTES, freeSpaceFloor } from '../internalTools/gfsDownloadStore'
import { logger } from '../logger'
import { CALLER_OUTPUTS_DIR } from '../workspace/callerOutputs'
import type { ArtifactMetadata, InternalToolResult } from './types'
@@ -377,13 +377,30 @@ export function enforceQuota(outputDir: string, incomingBytes: number, replacing
enforceFreeSpaceFloor(outputDir, incomingBytes)
}
+/**
+ * Whether `space` is the filesystem the root is on, judged by its size, its
+ * block size and blocks: volumes of one APFS container, or an overlay root
+ * over the node's disk, report the same size but not the same type or inodes.
+ */
+function sharesRootVolume(space: fs.BigIntStatsFs): boolean {
+ try {
+ const root = fs.statfsSync('/', { bigint: true })
+ return root.bsize === space.bsize && root.blocks === space.blocks
+ } catch {
+ return false
+ }
+}
+
let unmeasurableVolumeReported = false
/**
* Every caller's folder shares the Host volume, so their quotas together do
* not bound it: a write must leave the free space GFS keeps (freeSpaceFloor).
- * Nothing is removed to make room. A volume that cannot be measured does not
- * refuse the write; that is logged once.
+ * On a filesystem the Host does not have to itself, the root's, as in
+ * development or on a hostPath volume, that share would be of the whole disk,
+ * so only the minimum is kept there. Nothing is removed to make room. A
+ * volume that cannot be measured does not refuse the write; that is logged
+ * once.
*/
function enforceFreeSpaceFloor(outputDir: string, incomingBytes: number): void {
let space: fs.BigIntStatsFs | undefined
@@ -403,7 +420,7 @@ function enforceFreeSpaceFloor(outputDir: string, incomingBytes: number): void {
return
}
const blocks = (BigInt(incomingBytes) + space.bsize - 1n) / space.bsize
- const floor = freeSpaceFloor(space)
+ const floor = sharesRootVolume(space) ? FREE_SPACE_FLOOR_MIN_BYTES : freeSpaceFloor(space)
if (blocks * space.bsize + floor > space.bavail * space.bsize) {
const mb = (bytes: bigint) => (Number(bytes) / (1024 * 1024)).toFixed(1)
throw new Error(