From 5711f1f32bddb2653547aa6dbbd30e9012e21d89 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Tue, 27 Jan 2026 14:14:14 -0700 Subject: [PATCH] fix: ensure onCompleted callback finishes before using persistedResult - Update RooTerminalCallbacks.onCompleted type to allow async callbacks (void | Promise) - Track onCompleted completion with a promise and await it before using persistedResult - This fixes a race condition where exitDetails could be set before the async finalize() completes - Fix test callback to not return assignment value --- src/core/tools/ExecuteCommandTool.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/tools/ExecuteCommandTool.ts b/src/core/tools/ExecuteCommandTool.ts index bc16886ded..f94f70ebeb 100644 --- a/src/core/tools/ExecuteCommandTool.ts +++ b/src/core/tools/ExecuteCommandTool.ts @@ -210,6 +210,7 @@ export async function executeCommandInTerminal( // Bound accumulated output buffer size to prevent unbounded memory growth for long-running commands. // The interceptor preserves full output; this buffer is only for UI display (100KB limit). const maxAccumulatedOutputSize = 100_000 + // Track when onCompleted callback finishes to avoid race condition. // The callback is async but Terminal/ExecaTerminal don't await it, so we track completion // explicitly to ensure persistedResult is set before we use it.