Skip to content

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

TypeScript

fix(mcp-host): log an output quota setting that is not a whole number

marcoteb095eaef2e520
diff --git a/deploy/base/sandbox-recipes/workflow-output-pvc.yaml b/deploy/base/sandbox-recipes/workflow-output-pvc.yaml
index 69396e269..1ff86b73d 100644
--- a/deploy/base/sandbox-recipes/workflow-output-pvc.yaml
+++ b/deploy/base/sandbox-recipes/workflow-output-pvc.yaml
@@ -9,7 +9,7 @@
# multi-recipe external claim; see docs/deploy/workflow-output-pvc-upgrade.md.
#
# Size: 1Gi MVP — holds ~20 concurrent recipes × 50 MB quota per recipe
-# (see CLERUM_WORKFLOW_OUTPUT_QUOTA_MB in mcp-host/internalTools.ts).
+# (see CLERUM_WORKFLOW_OUTPUT_QUOTA_MB in mcp-host/src/workflow/artifactOutput.ts).
#
# Expandable: the chosen StorageClass MUST have allowVolumeExpansion: true
# (default for GCE-PD, Filestore, most RWX provisioners). Expand with:
diff --git a/mcp-host/src/workflow/__tests__/artifactOutput.test.ts b/mcp-host/src/workflow/__tests__/artifactOutput.test.ts
index 7e7515047..e67d20ae7 100644
--- a/mcp-host/src/workflow/__tests__/artifactOutput.test.ts
+++ b/mcp-host/src/workflow/__tests__/artifactOutput.test.ts
@@ -1,7 +1,8 @@
-import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
+import { logger } from '../../logger'
import {
PARTIAL_PREFIX,
artifactResult,
@@ -225,6 +226,29 @@ describe('enforceQuota', () => {
else process.env.CLERUM_WORKFLOW_OUTPUT_QUOTA_MB = prev
}
})
+
+ it.each(['2GB', '1.5', '0', 'fifty'])(
+ 'reads %j as no quota of its own: the default applies, and that is logged once',
+ value => {
+ const prev = process.env.CLERUM_WORKFLOW_OUTPUT_QUOTA_MB
+ process.env.CLERUM_WORKFLOW_OUTPUT_QUOTA_MB = value
+ const warn = vi.spyOn(logger, 'warn')
+ try {
+ // Three megabytes: over the 2 or 1 a lenient read would take, under the 50 default.
+ fs.writeFileSync(path.join(outputDir, 'some.bin'), Buffer.alloc(3 * 1024 * 1024))
+ expect(() => enforceQuota(outputDir, 1024)).not.toThrow()
+ expect(() => enforceQuota(outputDir, 1024)).not.toThrow()
+ const reports = warn.mock.calls.filter(([, message]) =>
+ String(message).includes('CLERUM_WORKFLOW_OUTPUT_QUOTA_MB')
+ )
+ expect(reports).toHaveLength(1)
+ } finally {
+ warn.mockRestore()
+ if (prev === undefined) delete process.env.CLERUM_WORKFLOW_OUTPUT_QUOTA_MB
+ else process.env.CLERUM_WORKFLOW_OUTPUT_QUOTA_MB = prev
+ }
+ }
+ )
})
describe('generators through the shared output path', () => {
diff --git a/mcp-host/src/workflow/artifactOutput.ts b/mcp-host/src/workflow/artifactOutput.ts
index 93d1fc582..adf59ac2b 100644
--- a/mcp-host/src/workflow/artifactOutput.ts
+++ b/mcp-host/src/workflow/artifactOutput.ts
@@ -278,6 +278,30 @@ export function getDirectorySize(dir: string): number {
return total
}
+/** The last invalid quota setting logged, so each is logged once. */
+let reportedQuotaSetting: string | undefined
+
+/**
+ * CLERUM_WORKFLOW_OUTPUT_QUOTA_MB as a whole number of megabytes. Anything
+ * else ("2GB", "1.5", "0") leaves the default, and is logged once: read
+ * leniently, "2GB" became a quota of 2 MB.
+ */
+function outputQuotaMB(raw: string | undefined): number {
+ const text = raw?.trim() ?? ''
+ if (text === '') return DEFAULT_QUOTA_MB
+ if (/^\d+$/.test(text) && Number(text) > 0 && Number.isSafeInteger(Number(text))) {
+ return Number(text)
+ }
+ if (reportedQuotaSetting !== raw) {
+ reportedQuotaSetting = raw
+ logger.warn(
+ { component: 'ArtifactOutput', value: text.slice(0, 32), defaultMB: DEFAULT_QUOTA_MB },
+ 'CLERUM_WORKFLOW_OUTPUT_QUOTA_MB is not a whole number of megabytes; the default applies'
+ )
+ }
+ return DEFAULT_QUOTA_MB
+}
+
/**
* Enforce the output quota of one folder before a file is written: a workflow
* run's output, or one chat caller's folder, so in chat each user has their
@@ -296,9 +320,7 @@ export function getDirectorySize(dir: string): number {
* quota; the 1Gi PVC hard cap enforced by kubelet is the primary defense.
*/
export function enforceQuota(outputDir: string, incomingBytes: number, replacingBytes = 0): void {
- const raw = process.env.CLERUM_WORKFLOW_OUTPUT_QUOTA_MB
- const parsed = raw ? parseInt(raw, 10) : NaN
- const quotaMB = Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_QUOTA_MB
+ const quotaMB = outputQuotaMB(process.env.CLERUM_WORKFLOW_OUTPUT_QUOTA_MB)
const quotaBytes = quotaMB * 1024 * 1024
const current = getDirectorySize(outputDir) - replacingBytes