From 7156f21e121629e3426da1a56b5eb216168c5d09 Mon Sep 17 00:00:00 2001 From: openhands Date: Sat, 21 Mar 2026 02:14:47 +0000 Subject: [PATCH] fix: extract restore_to_backlog() to eliminate duplicate label reset pattern The cleanup_labels + curl POST + CLAIMED=false pattern was duplicated across dev-agent.sh (idle_timeout and crashed cases) and phase-handler.sh (PHASE:crashed handler), triggering duplicate-detection CI failure. Extract restore_to_backlog() shared helper; call it from all three sites. Co-Authored-By: Claude Sonnet 4.6 --- dev/dev-agent.sh | 26 ++++++++++++-------------- dev/phase-handler.sh | 9 +-------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/dev/dev-agent.sh b/dev/dev-agent.sh index c01511b..031460f 100755 --- a/dev/dev-agent.sh +++ b/dev/dev-agent.sh @@ -131,6 +131,16 @@ cleanup_labels() { "${API}/issues/${ISSUE}/labels/${IN_PROGRESS_LABEL_ID}" >/dev/null 2>&1 || true } +restore_to_backlog() { + cleanup_labels + curl -sf -X POST \ + -H "Authorization: token ${CODEBERG_TOKEN}" \ + -H "Content-Type: application/json" \ + "${API}/issues/${ISSUE}/labels" \ + -d "{\"labels\":[${BACKLOG_LABEL_ID}]}" >/dev/null 2>&1 || true + CLAIMED=false # Don't unclaim again in cleanup() +} + CLAIMED=false cleanup() { rm -f "$LOCKFILE" "$STATUSFILE" @@ -750,13 +760,7 @@ case "${_MONITOR_LOOP_EXIT:-}" in echo "{\"issue\":${ISSUE},\"pr\":${PR_NUMBER:-0},\"reason\":\"${_MONITOR_LOOP_EXIT:-idle_timeout}\",\"ts\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" \ >> "${FACTORY_ROOT}/supervisor/escalations-${PROJECT_NAME}.jsonl" # Restore labels: remove in-progress, add backlog - cleanup_labels - curl -sf -X POST \ - -H "Authorization: token ${CODEBERG_TOKEN}" \ - -H "Content-Type: application/json" \ - "${API}/issues/${ISSUE}/labels" \ - -d "{\"labels\":[${BACKLOG_LABEL_ID}]}" >/dev/null 2>&1 || true - CLAIMED=false # Don't unclaim again in cleanup() + restore_to_backlog if [ -n "${PR_NUMBER:-}" ]; then log "keeping worktree (PR #${PR_NUMBER} still open)" else @@ -771,13 +775,7 @@ case "${_MONITOR_LOOP_EXIT:-}" in # Belt-and-suspenders: _on_phase_change(PHASE:crashed) handles primary # cleanup, but ensure labels and files are cleaned up if callback was # interrupted (e.g. set -e propagation). - cleanup_labels - curl -sf -X POST \ - -H "Authorization: token ${CODEBERG_TOKEN}" \ - -H "Content-Type: application/json" \ - "${API}/issues/${ISSUE}/labels" \ - -d "{\"labels\":[${BACKLOG_LABEL_ID}]}" >/dev/null 2>&1 || true - CLAIMED=false + restore_to_backlog if [ -z "${PR_NUMBER:-}" ]; then cleanup_worktree fi diff --git a/dev/phase-handler.sh b/dev/phase-handler.sh index 86b2e90..f67a36d 100644 --- a/dev/phase-handler.sh +++ b/dev/phase-handler.sh @@ -726,14 +726,7 @@ $(printf '%s' "$REFUSAL_JSON" | head -c 2000) >> "${FACTORY_ROOT}/supervisor/escalations-${PROJECT_NAME}.jsonl" # Restore backlog label so issue can be retried - cleanup_labels - curl -sf -X POST \ - -H "Authorization: token ${CODEBERG_TOKEN}" \ - -H "Content-Type: application/json" \ - "${API}/issues/${ISSUE}/labels" \ - -d "{\"labels\":[${BACKLOG_LABEL_ID}]}" >/dev/null 2>&1 || true - - CLAIMED=false # Don't unclaim again in cleanup() + restore_to_backlog if [ -n "${PR_NUMBER:-}" ]; then log "keeping worktree (PR #${PR_NUMBER} still open)" else