From a5cbd30bb6dbe92ea22c925d87182bd2b084482e Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 24 Mar 2026 20:56:41 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20stale=20phase=20file=20poisons=20recover?= =?UTF-8?q?y=20=E2=80=94=20clear=20before=20respawn=20(#628)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Clear phase file after reading it in recovery mode so new sessions start clean instead of inheriting stale state - When last phase was escalate, tell Claude "previous session escalated — starting fresh" instead of "resume from escalate" to prevent re-escalation - Add explicit "PR already exists — do NOT create a new PR" instructions to recovery prompt to prevent Claude from calling forge API directly Co-Authored-By: Claude Opus 4.6 (1M context) --- dev/dev-agent.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dev/dev-agent.sh b/dev/dev-agent.sh index 70fdbc7..aa3e666 100755 --- a/dev/dev-agent.sh +++ b/dev/dev-agent.sh @@ -606,6 +606,7 @@ if [ "$RECOVERY_MODE" = true ]; then # Build recovery context GIT_DIFF_STAT=$(git -C "$WORKTREE" diff "origin/${PRIMARY_BRANCH}..HEAD" --stat 2>/dev/null | head -20 || echo "(no diff)") LAST_PHASE=$(read_phase) + rm -f "$PHASE_FILE" # Clear stale phase — new session starts clean CI_RESULT=$(cat "/tmp/ci-result-${PROJECT_NAME}-${ISSUE}.txt" 2>/dev/null || echo "") REVIEW_COMMENTS=$(curl -sf -H "Authorization: token ${FORGE_TOKEN}" \ "${API}/issues/${PR_NUMBER}/comments?limit=10" | \ @@ -628,9 +629,14 @@ Git is the checkpoint — your code changes survived. ${GIT_DIFF_STAT} \`\`\` -### Last known phase: ${LAST_PHASE:-unknown} +$(if [ "$LAST_PHASE" = "PHASE:escalate" ]; then + printf '### Previous session escalated — starting fresh\nThe previous session hit an issue and escalated. Do NOT re-escalate for the same reason.\nRead the issue and review comments carefully, then address the problem.' +else + printf '### Last known phase: %s' "${LAST_PHASE:-unknown}" +fi) ### PR: #${PR_NUMBER} (${BRANCH}) +**IMPORTANT: PR #${PR_NUMBER} already exists — do NOT create a new PR.** Do NOT call the Codeberg/Gitea/Forgejo API to create PRs. The orchestrator manages PR creation. ### Recent PR comments: ${REVIEW_COMMENTS} @@ -638,8 +644,9 @@ $(if [ -n "$CI_RESULT" ]; then printf '\n### Last CI result:\n%s\n' "$CI_RESULT" ### Next steps 1. Run \`git log --oneline -5\` and \`git status\` to understand current state. -2. Resume from the last known phase. -3. Follow the phase protocol below. +2. **PR #${PR_NUMBER} already exists.** Address any review comments, commit, push to \`${BRANCH}\`, then write \`PHASE:awaiting_ci\`. +3. Do NOT attempt to create PRs via API calls — the orchestrator handles that. +4. Follow the phase protocol below. ${SCRATCH_INSTRUCTION}