fix: fix flock/binding issues with claude_run_with_watchdog
This commit is contained in:
parent
ec5eb48224
commit
d6f93bb8f5
2 changed files with 12 additions and 3 deletions
|
|
@ -104,6 +104,14 @@ claude_run_with_watchdog() {
|
|||
kill "$grace_pid" 2>/dev/null || true
|
||||
wait "$grace_pid" 2>/dev/null || true
|
||||
|
||||
# When timeout fires (rc=124), explicitly kill the orphaned claude process
|
||||
# tail --pid is a passive waiter, not a supervisor
|
||||
if [ "$rc" -eq 124 ]; then
|
||||
kill "$pid" 2>/dev/null || true
|
||||
sleep 1
|
||||
kill -KILL "$pid" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Output the captured stdout
|
||||
cat "$out_file"
|
||||
return "$rc"
|
||||
|
|
@ -132,7 +140,8 @@ agent_run() {
|
|||
mkdir -p "$(dirname "$lock_file")"
|
||||
local output rc
|
||||
log "agent_run: starting (resume=${resume_id:-(new)}, dir=${run_dir})"
|
||||
output=$(cd "$run_dir" && flock -w 600 "$lock_file" claude_run_with_watchdog claude "${args[@]}" 2>>"$LOGFILE") && rc=0 || rc=$?
|
||||
# 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=$?
|
||||
if [ "$rc" -eq 124 ]; then
|
||||
log "agent_run: timeout after ${CLAUDE_TIMEOUT:-7200}s (exit code $rc)"
|
||||
elif [ "$rc" -ne 0 ]; then
|
||||
|
|
@ -173,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" 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 "$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=$?
|
||||
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
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
# Requires: lib/env.sh, lib/worktree.sh, lib/agent-sdk.sh sourced first for shared helpers.
|
||||
|
||||
# Source agent-sdk for claude_run_with_watchdog watchdog helper
|
||||
source "$(dirname "$0")/agent-sdk.sh"
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/agent-sdk.sh"
|
||||
|
||||
# ── Run guards ───────────────────────────────────────────────────────────
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue