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 <noreply@anthropic.com>
This commit is contained in:
parent
7f9cefa847
commit
7156f21e12
2 changed files with 13 additions and 22 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue