From 1afeca88ae3ce913d84759fda88ed8faa14a0788 Mon Sep 17 00:00:00 2001 From: cexll Date: Sun, 25 Jan 2026 17:45:38 +0800 Subject: [PATCH] fix: increase stdoutDrainTimeout from 100ms to 500ms Resolves intermittent "completed without agent_message output" errors when Claude CLI exits before all stdout data is read. - internal/executor/executor.go:43 - internal/app/app.go:27 - Add benchmark script for stability testing Generated with SWE-Agent.ai Co-Authored-By: SWE-Agent.ai --- codeagent-wrapper/internal/app/app.go | 2 +- .../internal/executor/executor.go | 2 +- codeagent-wrapper/scripts/benchmark_claude.sh | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100755 codeagent-wrapper/scripts/benchmark_claude.sh diff --git a/codeagent-wrapper/internal/app/app.go b/codeagent-wrapper/internal/app/app.go index 3253b3e..100e777 100644 --- a/codeagent-wrapper/internal/app/app.go +++ b/codeagent-wrapper/internal/app/app.go @@ -24,7 +24,7 @@ const ( stdoutCloseReasonWait = "wait-done" stdoutCloseReasonDrain = "drain-timeout" stdoutCloseReasonCtx = "context-cancel" - stdoutDrainTimeout = 100 * time.Millisecond + stdoutDrainTimeout = 500 * time.Millisecond ) // Test hooks for dependency injection diff --git a/codeagent-wrapper/internal/executor/executor.go b/codeagent-wrapper/internal/executor/executor.go index 7886d04..aa9774f 100644 --- a/codeagent-wrapper/internal/executor/executor.go +++ b/codeagent-wrapper/internal/executor/executor.go @@ -40,7 +40,7 @@ const ( stdoutCloseReasonWait = "wait-done" stdoutCloseReasonDrain = "drain-timeout" stdoutCloseReasonCtx = "context-cancel" - stdoutDrainTimeout = 100 * time.Millisecond + stdoutDrainTimeout = 500 * time.Millisecond ) // Hook points (tests can override inside this package). diff --git a/codeagent-wrapper/scripts/benchmark_claude.sh b/codeagent-wrapper/scripts/benchmark_claude.sh new file mode 100755 index 0000000..705db3d --- /dev/null +++ b/codeagent-wrapper/scripts/benchmark_claude.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Benchmark script for Claude CLI stability test +# Tests if the stdoutDrainTimeout fix resolves intermittent failures + +set -euo pipefail + +RUNS=${1:-100} +FAIL_COUNT=0 +SUCCESS_COUNT=0 +TIMEOUT_COUNT=0 + +echo "Running $RUNS iterations..." +echo "---" + +for i in $(seq 1 $RUNS); do + result=$(timeout 30 codeagent --backend claude --skip-permissions 'say OK' 2>&1) || true + + if echo "$result" | grep -q 'without agent_message'; then + ((FAIL_COUNT++)) + echo "[$i] FAIL: without agent_message" + elif echo "$result" | grep -q 'timeout'; then + ((TIMEOUT_COUNT++)) + echo "[$i] TIMEOUT" + elif echo "$result" | grep -q 'OK\|ok'; then + ((SUCCESS_COUNT++)) + printf "\r[$i] OK " + else + ((FAIL_COUNT++)) + echo "[$i] FAIL: unexpected output" + echo "$result" | head -3 + fi +done + +echo "" +echo "---" +echo "Results ($RUNS runs):" +echo " Success: $SUCCESS_COUNT ($(echo "scale=1; $SUCCESS_COUNT * 100 / $RUNS" | bc)%)" +echo " Fail: $FAIL_COUNT ($(echo "scale=1; $FAIL_COUNT * 100 / $RUNS" | bc)%)" +echo " Timeout: $TIMEOUT_COUNT ($(echo "scale=1; $TIMEOUT_COUNT * 100 / $RUNS" | bc)%)" + +if [ $FAIL_COUNT -gt 0 ]; then + exit 1 +fi