From f4753b0ba1397b8281fe011577db647808f831df Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 10 Apr 2026 17:48:33 +0000 Subject: [PATCH] fix: correct flock idiom to hold lock during claude invocation --- lib/agent-sdk.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/agent-sdk.sh b/lib/agent-sdk.sh index 580bfe4..ca38dca 100644 --- a/lib/agent-sdk.sh +++ b/lib/agent-sdk.sh @@ -141,7 +141,7 @@ agent_run() { local output rc log "agent_run: starting (resume=${resume_id:-(new)}, dir=${run_dir})" # Acquire lock separately (flock cannot exec bash functions) - output=$(cd "$run_dir" && ( flock -w 600 "$lock_file" || exit 1; claude_run_with_watchdog claude "${args[@]}" ) 2>>"$LOGFILE") && rc=0 || rc=$? + output=$(cd "$run_dir" && ( flock -w 600 9 || exit 1; claude_run_with_watchdog claude "${args[@]}" ) 9>"$lock_file" 2>>"$LOGFILE") && rc=0 || rc=$? if [ "$rc" -eq 124 ]; then log "agent_run: timeout after ${CLAUDE_TIMEOUT:-7200}s (exit code $rc)" elif [ "$rc" -ne 0 ]; then @@ -182,7 +182,7 @@ agent_run() { local nudge="You stopped but did not push any code. You have uncommitted changes. Commit them and push." log "agent_run: nudging (uncommitted changes)" local nudge_rc - output=$(cd "$run_dir" && ( flock -w 600 "$lock_file" || exit 1; claude_run_with_watchdog claude -p "$nudge" --resume "$_AGENT_SESSION_ID" --output-format json --dangerously-skip-permissions --max-turns 50 ${CLAUDE_MODEL:+--model "$CLAUDE_MODEL"} ) 2>>"$LOGFILE") && nudge_rc=0 || nudge_rc=$? + output=$(cd "$run_dir" && ( flock -w 600 9 || exit 1; claude_run_with_watchdog claude -p "$nudge" --resume "$_AGENT_SESSION_ID" --output-format json --dangerously-skip-permissions --max-turns 50 ${CLAUDE_MODEL:+--model "$CLAUDE_MODEL"} ) 9>"$lock_file" 2>>"$LOGFILE") && nudge_rc=0 || nudge_rc=$? if [ "$nudge_rc" -eq 124 ]; then log "agent_run: nudge timeout after ${CLAUDE_TIMEOUT:-7200}s (exit code $nudge_rc)" elif [ "$nudge_rc" -ne 0 ]; then