From 810b083d53376245542e7c6d96245453f8d3f983 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 11 Apr 2026 21:31:40 +0000 Subject: [PATCH] fix: vision: remove external flock from lib/agent-sdk.sh once CLAUDE_CONFIG_DIR rollout is verified (#647) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gate both flock call sites (agent_run main invocation and nudge) behind CLAUDE_EXTERNAL_LOCK env var. Default off — the native Claude Code proper-lockfile-based OAuth refresh lock handles concurrency. Set CLAUDE_EXTERNAL_LOCK=1 to re-enable the external flock for rollback. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/agent-sdk.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/agent-sdk.sh b/lib/agent-sdk.sh index ca38dca..e2bd4e2 100644 --- a/lib/agent-sdk.sh +++ b/lib/agent-sdk.sh @@ -141,7 +141,13 @@ 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 9 || exit 1; claude_run_with_watchdog claude "${args[@]}" ) 9>"$lock_file" 2>>"$LOGFILE") && rc=0 || rc=$? + # External flock is redundant once CLAUDE_CONFIG_DIR rollout is verified (#647). + # Gate behind CLAUDE_EXTERNAL_LOCK for rollback safety; default off. + if [ -n "${CLAUDE_EXTERNAL_LOCK:-}" ]; then + output=$(cd "$run_dir" && ( flock -w 600 9 || exit 1; claude_run_with_watchdog claude "${args[@]}" ) 9>"$lock_file" 2>>"$LOGFILE") && rc=0 || rc=$? + else + output=$(cd "$run_dir" && claude_run_with_watchdog claude "${args[@]}" 2>>"$LOGFILE") && rc=0 || rc=$? + fi if [ "$rc" -eq 124 ]; then log "agent_run: timeout after ${CLAUDE_TIMEOUT:-7200}s (exit code $rc)" elif [ "$rc" -ne 0 ]; then @@ -182,7 +188,11 @@ 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 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 [ -n "${CLAUDE_EXTERNAL_LOCK:-}" ]; then + 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=$? + else + output=$(cd "$run_dir" && 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=$? + fi 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