Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(engine): classify a result line truncated by process death as an exit, not a malformed result (#15918)

Chaker Atallah6bb9c33cd719
diff --git a/packages/core/utils/src/lib/deno.ts b/packages/core/utils/src/lib/deno.ts
index a020c90a5a8..abb7bae61f5 100644
--- a/packages/core/utils/src/lib/deno.ts
+++ b/packages/core/utils/src/lib/deno.ts
@@ -50,7 +50,11 @@ export const deno = {
message = JSON.parse(resultJson)
}
catch {
- reject(sandboxError.build({ error: 'Deno process returned a malformed result', stdout: userOutput, stderr: capturedStderr }))
+ const processDied = code !== 0 || signal !== null
+ const error = processDied
+ ? `Deno process exited with code ${code} and signal ${signal} while writing its result`
+ : 'Deno process returned a malformed result'
+ reject(sandboxError.build({ error, stdout: userOutput, stderr: capturedStderr }))
return
}
diff --git a/packages/server/engine/test/core/code/deno-code-sandbox.test.ts b/packages/server/engine/test/core/code/deno-code-sandbox.test.ts
index c9d3e8dd88c..593283869c9 100644
--- a/packages/server/engine/test/core/code/deno-code-sandbox.test.ts
+++ b/packages/server/engine/test/core/code/deno-code-sandbox.test.ts
@@ -169,6 +169,24 @@ describe('denoCodeSandbox permission boundary', () => {
})
})
+ describe('classifies a truncated result line', () => {
+ it('reports the exit code and signal when the process dies while writing its result', async () => {
+ await expectRejection(runModule(`
+ const encoder = new TextEncoder();
+ console.log = (line) => { Deno.stdout.writeSync(encoder.encode(String(line).slice(0, 45))); Deno.exit(7); };
+ export const code = async () => ({ some: 'value' })
+ `), /exited with code 7 and signal null while writing its result/)
+ })
+
+ it('keeps the malformed-result error for an unparseable line after a clean exit', async () => {
+ await expectRejection(runModule(`
+ const encoder = new TextEncoder();
+ console.log = (line) => { Deno.stdout.writeSync(encoder.encode(String(line).slice(0, 45) + '\\n')); };
+ export const code = async () => ({ some: 'value' })
+ `), /returned a malformed result/)
+ })
+ })
+
describe('runs TypeScript natively', () => {
it('type-strips TS syntax without a compile step', async () => {
const result = await runModule(`