From d803ee7cf5610444e69059384899c2957e2e4f8a Mon Sep 17 00:00:00 2001 From: Felix Faerber Date: Sat, 4 Jul 2026 13:21:04 +0300 Subject: [PATCH] fix(route): resume an existing ai/issue-N branch instead of losing re-triggered work When an agent was re-triggered on an issue that already had a branch/open PR, route.sh created a fresh branch from main (git checkout -b), so the push back was rejected non-fast-forward and the new commits were silently dropped (|| true) -- the run reported success and re-announced the stale PR, but the work was gone (observed on issue #17 run #88). Resume the existing branch when it exists, so new commits fast-forward onto it and update its PR; only branch from main when none exists. Co-Authored-By: Claude Opus 4.8 (1M context) --- .gitea/workflows/scripts/route.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/scripts/route.sh b/.gitea/workflows/scripts/route.sh index 727af61..f4452f9 100755 --- a/.gitea/workflows/scripts/route.sh +++ b/.gitea/workflows/scripts/route.sh @@ -55,7 +55,13 @@ if [ -n "$IS_PR" ]; then # comment on a PR -> resume its bra ref=$(curl -s -H "Authorization: token $GT" "$API/pulls/$NUM" | jq -r .head.ref) git fetch origin "$ref" && git checkout "$ref" { echo "branch=$ref"; echo "new=false"; } >> "$GITHUB_OUTPUT" -else # comment on an issue -> new branch +elif git ls-remote --exit-code --heads origin "ai/issue-$NUM" >/dev/null 2>&1; then + # comment on an issue whose branch ALREADY exists (a prior run / open PR) -> RESUME it, so new + # commits fast-forward onto the same branch and update its PR. Branching fresh from main here would + # be rejected on push as non-fast-forward and the new work would be silently lost (see issue #17). + git fetch origin "ai/issue-$NUM" && git checkout "ai/issue-$NUM" + { echo "branch=ai/issue-$NUM"; echo "new=false"; } >> "$GITHUB_OUTPUT" +else # comment on an issue, no branch yet -> new branch git checkout -b "ai/issue-$NUM" { echo "branch=ai/issue-$NUM"; echo "new=true"; } >> "$GITHUB_OUTPUT" # For dev agents, publish the branch immediately and tell the maintainer where to watch. -- 2.54.0