From c29d49cd5c9becd06ffc5c598076dfdb361225c8 Mon Sep 17 00:00:00 2001 From: Agent Date: Tue, 7 Apr 2026 08:41:11 +0000 Subject: [PATCH] fix: fix: triage agent must clean up throwaway debug branch on exit/crash (#341) Add an EXIT trap in entrypoint-reproduce.sh that: - Switches back to the primary branch - Deletes the triage-debug-${ISSUE_NUMBER} branch This ensures the throwaway branch used for debug instrumentation (console.log, verbose logging) is cleaned up if the agent crashes or times out, preventing repository pollution. The trap is combined with existing cleanup (heartbeat kill, stack lock release) into a single EXIT handler. --- docker/reproduce/entrypoint-reproduce.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docker/reproduce/entrypoint-reproduce.sh b/docker/reproduce/entrypoint-reproduce.sh index da25aa6..2cbb3f9 100644 --- a/docker/reproduce/entrypoint-reproduce.sh +++ b/docker/reproduce/entrypoint-reproduce.sh @@ -140,7 +140,6 @@ log "Issue: ${ISSUE_TITLE}" # --------------------------------------------------------------------------- log "Acquiring stack lock for project ${PROJECT_NAME}..." stack_lock_acquire "$LOCK_HOLDER" "$PROJECT_NAME" 900 -trap 'stack_lock_release "$PROJECT_NAME" "$LOCK_HOLDER"; log "Stack lock released (trap)"' EXIT log "Stack lock acquired." # --------------------------------------------------------------------------- @@ -154,7 +153,18 @@ heartbeat_loop() { } heartbeat_loop & HEARTBEAT_PID=$! -trap 'kill "$HEARTBEAT_PID" 2>/dev/null; stack_lock_release "$PROJECT_NAME" "$LOCK_HOLDER"; log "Stack lock released (trap)"' EXIT + +# --------------------------------------------------------------------------- +# Debug branch cleanup trap (for triage-agent throwaway branches) +# --------------------------------------------------------------------------- +DEBUG_BRANCH="triage-debug-${ISSUE_NUMBER}" + +# Combined EXIT trap: heartbeat kill + stack lock release + debug branch cleanup +trap 'kill "$HEARTBEAT_PID" 2>/dev/null || true + stack_lock_release "$PROJECT_NAME" "$LOCK_HOLDER" || true + git -C "$PROJECT_REPO_ROOT" checkout "$PRIMARY_BRANCH" 2>/dev/null || true + git -C "$PROJECT_REPO_ROOT" branch -D "$DEBUG_BRANCH" 2>/dev/null || true + log "Cleanup completed (trap)"' EXIT # --------------------------------------------------------------------------- # Boot the project stack if formula declares stack_script -- 2.49.1