From 55b5a674c2381741c9bbea5469e1e5e74e6006bb Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 20 Mar 2026 00:50:52 +0000 Subject: [PATCH] fix: Idle Stop hook marker unused by action-agent monitor loop (#327) Co-Authored-By: Claude Opus 4.6 (1M context) --- action/action-agent.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/action/action-agent.sh b/action/action-agent.sh index f6e529b..3c75f27 100644 --- a/action/action-agent.sh +++ b/action/action-agent.sh @@ -176,14 +176,23 @@ matrix_send "action" "⚡ #${ISSUE}: session started — ${ISSUE_TITLE}" \ # --- Monitor session until Claude exits or idle timeout --- log "monitoring session: ${SESSION_NAME} (idle_timeout=${IDLE_TIMEOUT}s)" -ELAPSED=0 +IDLE_ELAPSED=0 POLL_INTERVAL=30 +IDLE_MARKER="/tmp/claude-idle-${SESSION_NAME}.ts" while tmux has-session -t "${SESSION_NAME}" 2>/dev/null; do sleep "$POLL_INTERVAL" - ELAPSED=$((ELAPSED + POLL_INTERVAL)) - if [ "$ELAPSED" -ge "$IDLE_TIMEOUT" ]; then + # Use the Stop hook idle marker to distinguish active vs idle: + # marker exists → Claude finished responding and is at the prompt (idle) + # marker absent → Claude is mid-turn or hasn't started yet (active) + if [ -f "$IDLE_MARKER" ]; then + IDLE_ELAPSED=$((IDLE_ELAPSED + POLL_INTERVAL)) + else + IDLE_ELAPSED=0 + fi + + if [ "$IDLE_ELAPSED" -ge "$IDLE_TIMEOUT" ]; then log "idle timeout (${IDLE_TIMEOUT}s) — killing session for issue #${ISSUE}" matrix_send "action" "⚠️ #${ISSUE}: session idle for $((IDLE_TIMEOUT / 3600))h — killed" \ "${THREAD_ID}" 2>/dev/null || true