From 8b293331b6c0ff8093f88d8180487e6219d7f084 Mon Sep 17 00:00:00 2001 From: openhands Date: Sat, 21 Mar 2026 15:00:01 +0000 Subject: [PATCH] fix: phase-handler.sh FAILURE_REASON fallback does not handle missing phase file (#410) The sed pipeline `sed -n 2p "$PHASE_FILE" 2>/dev/null | sed "s/^Reason: //"` exits 0 even when $PHASE_FILE does not exist because the second sed reads empty stdin and succeeds, leaving FAILURE_REASON as "" instead of "unspecified". Replace with an explicit file-existence check and use ${FAILURE_REASON:-unspecified} as the default assignment. Co-Authored-By: Claude Opus 4.6 (1M context) --- dev/phase-handler.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/phase-handler.sh b/dev/phase-handler.sh index 53b74e6..9e4aa7c 100644 --- a/dev/phase-handler.sh +++ b/dev/phase-handler.sh @@ -657,7 +657,10 @@ Instructions: # ── PHASE: failed ─────────────────────────────────────────────────────────── elif [ "$phase" = "PHASE:failed" ]; then - FAILURE_REASON=$(sed -n '2p' "$PHASE_FILE" 2>/dev/null | sed 's/^Reason: //' || echo "unspecified") + if [[ -f "$PHASE_FILE" ]]; then + FAILURE_REASON=$(sed -n '2p' "$PHASE_FILE" | sed 's/^Reason: //') + fi + FAILURE_REASON="${FAILURE_REASON:-unspecified}" log "phase: failed — reason: ${FAILURE_REASON}" # Gitea labels API requires []int64 — look up the "backlog" label ID once BACKLOG_LABEL_ID=$(codeberg_api GET "/labels" 2>/dev/null \