Skip to content

Autoloop: fast-forward long-running branch to main when ahead=0#179

Merged
mrjf merged 2 commits intomainfrom
copilot/fix-autoloop-perf-comparison
Apr 22, 2026
Merged

Autoloop: fast-forward long-running branch to main when ahead=0#179
mrjf merged 2 commits intomainfrom
copilot/fix-autoloop-perf-comparison

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

A stale autoloop/{program-name} branch that is ahead=0, behind>0 versus main was being brought up to date with an unconditional git merge origin/main. The resulting merge commit's patch re-exposes every historical file, producing 1400+ file diffs that trip gh-aw's hard-coded MAX_FILES=100 and fail new PR creation with E003.

Changes

  • .github/workflows/autoloop.md (Step 3 prompt): Replace the unconditional merge with git rev-list --count based ahead/behind detection. When ahead=0, behind>0, do a lossless fast-forward (git checkout -B ... origin/main + git push --force-with-lease) instead of a merge. Only merge when truly diverged (ahead>0, behind>0).
  • .github/workflows/sync-branches.md: Same ahead/behind logic in the per-branch sync loop. Added explicit returncode checks on git rev-list so a failed call is never silently coerced to ahead=0 (which would otherwise risk an incorrect destructive force-push).
  • .github/workflows/sync-branches.lock.yml: Regenerated the verbatim-embedded python run: value to match sync-branches.md.

Sketch of the new branch-update logic

ahead=$(git rev-list --count origin/main..origin/autoloop/{program-name})
behind=$(git rev-list --count origin/autoloop/{program-name}..origin/main)

if [ "$ahead" = "0" ] && [ "$behind" != "0" ]; then
  # Lossless: every commit on the branch is already in main.
  git checkout -B autoloop/{program-name} origin/main
  git push --force-with-lease origin autoloop/{program-name}
elif [ "$ahead" != "0" ] && [ "$behind" != "0" ]; then
  # True divergence: merge as before.
  git checkout -B autoloop/{program-name} origin/autoloop/{program-name}
  git merge origin/main --no-edit -m "Merge main into autoloop/{program-name}"
else
  git checkout -B autoloop/{program-name} origin/autoloop/{program-name}
fi

Notes

  • --force-with-lease is safe here precisely because ahead=0 proves no commits are lost.
  • Once sync-branches runs against the new default-branch HEAD, currently-stale canonical branches (e.g. autoloop/perf-comparison) will be fast-forwarded back to ahead=0, behind=0, eliminating the per-iteration noise that was causing E003.
  • Independent of the upstream gh-aw MAX_FILES discussion — small, focused PRs are desirable on their own merits.

Copilot AI changed the title [WIP] Fix autoloop fast-forward for long-running branch Autoloop: fast-forward long-running branch to main when ahead=0 Apr 22, 2026
Copilot AI requested a review from mrjf April 22, 2026 05:10
Copilot finished work on behalf of mrjf April 22, 2026 05:10
@mrjf mrjf marked this pull request as ready for review April 22, 2026 15:08
@mrjf mrjf merged commit c117efc into main Apr 22, 2026
17 checks passed
@mrjf mrjf deleted the copilot/fix-autoloop-perf-comparison branch April 22, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autoloop: fast-forward long-running branch to main when ahead=0 (prevents E003 on new PR creation)

2 participants