Skip to content

Commit d41cb2a

Browse files
committed
fix: add 10ms delay for readline to process buffered data
After process exits, readline interfaces may still have buffered data to process. Add a small 10ms delay before destroying streams to allow readline to finish processing. This prevents empty output in tests.
1 parent 2b65be4 commit d41cb2a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/services/tools/bash.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
237237
}
238238
});
239239

240-
// SIMPLE: Wait for process to exit (streams are destroyed by DisposableProcess)
240+
// Wait for process to exit
241241
let exitCode: number;
242242
try {
243243
exitCode = await execStream.exitCode;
244244
} catch (err: unknown) {
245-
// Cleanup immediately - don't wait for streams
245+
// Cleanup immediately
246246
stdoutReader.close();
247247
stderrReader.close();
248248
stdoutNodeStream.destroy();
@@ -256,7 +256,11 @@ export const createBashTool: ToolFactory = (config: ToolConfiguration) => {
256256
};
257257
}
258258

259-
// Cleanup immediately after exit - streams are already cancelled by DisposableProcess
259+
// Give readline interfaces a moment to process final buffered data
260+
// Process has exited but readline may still be processing buffered chunks
261+
await new Promise((resolve) => setTimeout(resolve, 10));
262+
263+
// Now cleanup
260264
stdoutReader.close();
261265
stderrReader.close();
262266
stdoutNodeStream.destroy();

0 commit comments

Comments
 (0)