Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(gfs): reap validation child before releasing image budget
Alfredo Lopezefa7867a2705
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex f376de756..c768862a2 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.374",+ "version": "0.1.375","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.374",+ "version": "0.1.375","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 01ea2fa1e..9021b03f0 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.374",+ "version": "0.1.375","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/visualInput/imageValidation.test.ts b/mcp-host/src/visualInput/imageValidation.test.tsindex 86b994ecc..4c4bc4d20 100644--- a/mcp-host/src/visualInput/imageValidation.test.ts+++ b/mcp-host/src/visualInput/imageValidation.test.ts@@ -481,6 +481,57 @@ describe('validateImage', () => {expect(budget.residentBytes).toBe(0)})+ test('reaps a child when the signal aborts during spawn', async () => {+ const actual = await vi.importActual<typeof import('node:child_process')>('node:child_process')+ const budget = newBudget()+ const controller = new AbortController()+ spawnMock.mockClear()+ spawnMock.mockImplementationOnce((command, args, options) => {+ const child = actual.spawn(command, args, options)+ controller.abort()+ return child+ })++ const pending = validateImage(+ canvasPng(32, 24),+ { mimeType: 'image/png', width: 32, height: 24 },+ { budget, signal: controller.signal }+ )+ expect(spawnMock).toHaveBeenCalledTimes(1)+ const child = spawnMock.mock.results[0].value+ await expect(pending).rejects.toMatchObject({ code: 'cancelled' })+ expect(child.signalCode).toBe('SIGKILL')+ expect(budget.residentBytes).toBe(0)+ })++ test('keeps the reservation until close when the child emits an error', async () => {+ const budget = newBudget()+ spawnMock.mockClear()+ const pending = validateImage(+ canvasPng(32, 24),+ { mimeType: 'image/png', width: 32, height: 24 },+ { budget }+ )+ expect(spawnMock).toHaveBeenCalledTimes(1)+ const child = spawnMock.mock.results[0].value+ let settled = false+ void pending.then(+ () => {+ settled = true+ },+ () => {+ settled = true+ }+ )++ child.emit('error', new Error('synthetic child error'))+ await Promise.resolve()+ expect(settled).toBe(false)+ expect(budget.residentBytes).toBeGreaterThan(0)+ await expect(pending).rejects.toMatchObject({ code: 'invalid_response' })+ expect(budget.residentBytes).toBe(0)+ })+test('rejects a pre-aborted signal without reserving memory', async () => {const budget = newBudget()const controller = new AbortController()diff --git a/mcp-host/src/visualInput/imageValidation.ts b/mcp-host/src/visualInput/imageValidation.tsindex 119f9468b..1b624e9af 100644--- a/mcp-host/src/visualInput/imageValidation.ts+++ b/mcp-host/src/visualInput/imageValidation.ts@@ -273,6 +273,7 @@ function inspectPng(bytes: Buffer): PngDetail {} else if (type === IDAT) {if (!sawHeader || dataClosed) throw new VisualInputError('invalid_image')if (colorType === 3 && !sawPalette) throw new VisualInputError('invalid_image')+ // Disjoint framed chunks keep this total within bytes.byteLength.// Only the total is retained; the child re-reads the payloads itself.compressedBytes += lengthsawData = true@@ -518,8 +519,9 @@ function parseChildReply(chunks: Buffer[]): ChildReply | null {* pinned canvas build decodes, rasterises and materialises the pixels so a real* decode is forced before the dimensions are reported.*- * The parent passes only bounded integers as metadata, so nothing in argv can- * widen the work this program does.+ * The child consumes the same bytes passed through the parent's framing and+ * CRC checks. The parent passes only bounded integers as metadata, so nothing+ * in argv can widen the work this program does.*/const CHILD_SOURCE = ['const canvasPath = process.argv[1]',@@ -613,7 +615,7 @@ function runValidationChild()const timer = setTimeout(() => {- failure = new VisualInputError('timeout')+ if (!failure) failure = new VisualInputError('timeout')child.kill('SIGKILL')}, VISUAL_INPUT_LIMITS.validationTimeoutMs)@@ -621,7 +623,6 @@ function runValidationChild(failure = new VisualInputError('cancelled')child.kill('SIGKILL')}- signal?.addEventListener('abort', onAbort, { once: true })const settle = (outcome: VisualInputError | null) => {if (settled) return@@ -651,7 +652,8 @@ function runValidationChild(child.stdin.on('error', () => {})child.on('error', () => {- settle(new VisualInputError('invalid_response'))+ // An error can precede close; keep the reservation until the child is reaped.+ if (!failure) failure = new VisualInputError('invalid_response')})child.on('close', (code, signalName) => {const reply = parseChildReply(stdoutChunks)@@ -674,6 +676,12 @@ function runValidationChild(settle(null)})+ signal?.addEventListener('abort', onAbort, { once: true })+ if (signal?.aborted) {+ onAbort()+ return+ }+// The payload is bounded before this point, so this write is capped too.child.stdin.end(bytes)})