Skip to content

Commit c2269f7

Browse files
authored
fix(exec): preserve node stderr in results (#123602)
1 parent 7aac8ee commit c2269f7

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎src/agents/bash-tools.exec-host-node-phases.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function createDirectNodeRun(signal?: AbortSignal): DirectNodeRun {
151151
};
152152
}
153153

154-
describe("direct node run cancellation", () => {
154+
describe("direct node run", () => {
155155
beforeEach(() => {
156156
callGatewayToolMock.mockReset();
157157
callGatewayToolMock.mockResolvedValue({
@@ -180,6 +180,33 @@ describe("direct node run cancellation", () => {
180180
}
181181
});
182182

183+
it("surfaces capped stderr and the node error when stdout is also present", async () => {
184+
const stdout = "small stdout";
185+
const stderr = `${"x".repeat(200_000)}\n... (truncated)`;
186+
const errorText = "node command failed";
187+
callGatewayToolMock.mockResolvedValueOnce({
188+
payload: {
189+
success: false,
190+
stdout,
191+
stderr,
192+
error: errorText,
193+
exitCode: 1,
194+
},
195+
});
196+
197+
const result = await invokeNodeSystemRunDirect(createDirectNodeRun());
198+
const visibleText = result.content[0]?.type === "text" ? result.content[0].text : "";
199+
200+
expect(visibleText).toContain("... (truncated)");
201+
expect(visibleText).toContain(errorText);
202+
expect(visibleText).toBe(`${stdout}\n${stderr}\n${errorText}`);
203+
expect(result.details).toMatchObject({
204+
status: "failed",
205+
exitCode: 1,
206+
aggregated: visibleText,
207+
});
208+
});
209+
183210
it("never dispatches a direct node run after cancellation", async () => {
184211
const controller = new AbortController();
185212
const reason = new Error("cancelled before direct node dispatch");

‎src/agents/bash-tools.exec-host-node-phases.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,13 @@ export function formatNodeRunToolResult(params: {
253253
const errorText = typeof payloadObj.error === "string" ? payloadObj.error : "";
254254
const success = typeof payloadObj.success === "boolean" ? payloadObj.success : false;
255255
const exitCode = typeof payloadObj.exitCode === "number" ? payloadObj.exitCode : null;
256+
const output = [stdout, stderr, errorText].filter(Boolean).join("\n");
256257
return {
257258
content: [
258259
{
259260
type: "text",
260261
text: renderExecUpdateText({
261-
tailText: stdout || stderr || errorText,
262+
tailText: output,
262263
warnings: params.warnings ?? [],
263264
}),
264265
},
@@ -267,7 +268,7 @@ export function formatNodeRunToolResult(params: {
267268
status: success ? "completed" : "failed",
268269
exitCode,
269270
durationMs: Date.now() - params.startedAt,
270-
aggregated: [stdout, stderr, errorText].filter(Boolean).join("\n"),
271+
aggregated: output,
271272
cwd: params.cwd,
272273
} satisfies ExecToolDetails,
273274
};

0 commit comments

Comments
 (0)