Skip to content

Commit 3faf701

Browse files
Copilotmrjf
andauthored
Fix stale branch causing create_pull_request patch failures
Replace simple merge-from-main with reset-if-merged approach in Step 3 of the autoloop workflow. When a program branch's changes have already been merged into main (git diff produces no output), the branch is reset to origin/main instead of merging. This prevents format-patch from generating patches with already-merged commits that cause git am failures. Fixes #69 Agent-Logs-Url: https://github.com/githubnext/autoloop/sessions/1aea5829-61b7-4958-bf7e-56e7bd4f6d9d Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
1 parent 5d58edb commit 3faf701

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.github/workflows/autoloop.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,11 @@ Examples:
644644
### How It Works
645645

646646
1. On the **first accepted iteration**, the branch is created from the default branch.
647-
2. On **subsequent iterations**, the agent checks out the existing branch and ensures it is up to date with the default branch (by merging the default branch into it).
647+
2. On **subsequent iterations**, the agent checks out the existing branch and ensures it is up to date with the default branch. If the branch's changes have already been merged into the default branch (i.e., `git diff origin/main..autoloop/{program-name}` is empty), the branch is **reset to `origin/main`** to avoid stale commits. Otherwise, the default branch is merged into it.
648648
3. **Accepted iterations** are committed and pushed to the branch. Each commit message references the GitHub Actions run URL.
649649
4. **Rejected or errored iterations** do not commit — changes are discarded.
650650
5. A **single draft PR** is created for the branch on the first accepted iteration. Future accepted iterations push additional commits to the same PR.
651-
6. The branch may be **merged into the default branch** at any time (by a maintainer or CI). After merging, the branch continues to be used for future iterations — it is never deleted while the program is active.
651+
6. The branch may be **merged into the default branch** at any time (by a maintainer or CI). After merging, the branch continues to be used for future iterations — it is never deleted while the program is active. On the next iteration, the branch is automatically reset to the default branch (see step 2) so that already-merged commits do not cause patch conflicts.
652652
7. A **sync workflow** automatically merges the default branch into all active `autoloop/*` branches whenever the default branch changes, keeping them up to date.
653653

654654
### Cross-Linking
@@ -691,7 +691,10 @@ Each run executes **one iteration for the single selected program**:
691691

692692
### Step 3: Implement
693693

694-
1. Check out the program's long-running branch `autoloop/{program-name}`. If the branch does not yet exist, create it from the default branch. If it does exist, ensure it is up to date with the default branch (merge the default branch into it).
694+
1. Check out the program's long-running branch `autoloop/{program-name}`. If the branch does not yet exist, create it from the default branch. If it does exist:
695+
- Fetch the default branch: `git fetch origin main`.
696+
- Check whether the branch's changes have already been merged into main. If `git diff origin/main..autoloop/{program-name}` produces no output (i.e., every change on the branch is already on main), the branch is stale — **reset it to `origin/main`**: `git reset --hard origin/main`.
697+
- Otherwise, merge the default branch into the long-running branch to pick up any upstream changes.
695698
2. Make the proposed changes to the target files only.
696699
3. **Respect the program constraints**: do not modify files outside the target list.
697700

workflows/autoloop.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,11 @@ Examples:
719719
### How It Works
720720

721721
1. On the **first accepted iteration**, the branch is created from the default branch.
722-
2. On **subsequent iterations**, the agent checks out the existing branch and ensures it is up to date with the default branch (by merging the default branch into it).
722+
2. On **subsequent iterations**, the agent checks out the existing branch and ensures it is up to date with the default branch. If the branch's changes have already been merged into the default branch (i.e., `git diff origin/main..autoloop/{program-name}` is empty), the branch is **reset to `origin/main`** to avoid stale commits. Otherwise, the default branch is merged into it.
723723
3. **Accepted iterations** are committed and pushed to the branch. Each commit message references the GitHub Actions run URL.
724724
4. **Rejected or errored iterations** do not commit — changes are discarded.
725725
5. A **single draft PR** is created for the branch on the first accepted iteration. Future accepted iterations push additional commits to the same PR.
726-
6. The branch may be **merged into the default branch** at any time (by a maintainer or CI). After merging, the branch continues to be used for future iterations — it is never deleted while the program is active.
726+
6. The branch may be **merged into the default branch** at any time (by a maintainer or CI). After merging, the branch continues to be used for future iterations — it is never deleted while the program is active. On the next iteration, the branch is automatically reset to the default branch (see step 2) so that already-merged commits do not cause patch conflicts.
727727
7. A **sync workflow** automatically merges the default branch into all active `autoloop/*` branches whenever the default branch changes, keeping them up to date.
728728

729729
### Cross-Linking
@@ -766,7 +766,10 @@ Each run executes **one iteration for the single selected program**:
766766

767767
### Step 3: Implement
768768

769-
1. Check out the program's long-running branch `autoloop/{program-name}`. If the branch does not yet exist, create it from the default branch. If it does exist, ensure it is up to date with the default branch (merge the default branch into it).
769+
1. Check out the program's long-running branch `autoloop/{program-name}`. If the branch does not yet exist, create it from the default branch. If it does exist:
770+
- Fetch the default branch: `git fetch origin main`.
771+
- Check whether the branch's changes have already been merged into main. If `git diff origin/main..autoloop/{program-name}` produces no output (i.e., every change on the branch is already on main), the branch is stale — **reset it to `origin/main`**: `git reset --hard origin/main`.
772+
- Otherwise, merge the default branch into the long-running branch to pick up any upstream changes.
770773
2. Make the proposed changes to the target files only.
771774
3. **Respect the program constraints**: do not modify files outside the target list.
772775

0 commit comments

Comments
 (0)