fix: fix: triage agent must clean up throwaway debug branch on exit/crash (#341)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

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.
This commit is contained in:
Agent 2026-04-07 08:41:11 +00:00
parent 064366678b
commit c29d49cd5c

View file

@ -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