fix(#1301): delete stale remote branches before pushing - #1307
Merged
Conversation
When a human closes a code agent PR and re-triggers /fs-code, the old remote branch persists. The post-code script's plain git push fails with non-fast-forward because the new local branch diverges from the stale remote. This caused silent failures requiring manual intervention (e.g., PR #1234 needed 3 attempts). Changes to post-code.sh: - Section 7a: before pushing, check if the remote branch exists via git ls-remote. If it does and no open PR references it, delete the stale remote branch so the fresh push succeeds. - Section 7b: capture push exit code and output. On non-fast-forward errors, retry with --force-with-lease as a fallback safety net. - Error reporting: add an ERR trap that posts a comment on the originating issue when the post-code script fails, including the exit code and a link to the workflow run. This ensures humans get feedback without checking workflow logs. - Move GH_TOKEN export earlier (before section 7a) since both the stale branch check and error reporting need it. Changes to post-code-test.sh: - Add stale branch decision tests (no remote, stale with no PR, branch with open PR). - Add push retry decision tests (success, non-fast-forward, rejected, unexpected error). - Add error comment content tests (exit code, workflow link, retry hint, warning emoji). Note: make lint could not run due to a Go toolchain permission error in the sandbox (unrelated to these shell script changes). The post-code-test.sh suite passes all 38 tests. Closes #1301 Signed-off-by: fullsend-code <fullsend-code@users.noreply.github.com>
Site previewPreview: https://cc3b9f44-site.fullsend-ai.workers.dev Commit: |
ReviewFindingsMedium
Info
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a human closes a code agent PR and re-triggers /fs-code, the old remote branch persists. The post-code script's plain git push fails with non-fast-forward because the new local branch diverges from the stale remote. This caused silent failures requiring manual intervention (e.g., PR #1234 needed 3 attempts).
Changes to post-code.sh:
via git ls-remote. If it does and no open PR references it,
delete the stale remote branch so the fresh push succeeds.
non-fast-forward errors, retry with --force-with-lease as a
fallback safety net.
originating issue when the post-code script fails, including
the exit code and a link to the workflow run. This ensures
humans get feedback without checking workflow logs.
the stale branch check and error reporting need it.
Changes to post-code-test.sh:
branch with open PR).
rejected, unexpected error).
retry hint, warning emoji).
Note: make lint could not run due to a Go toolchain permission error in the sandbox (unrelated to these shell script changes). The post-code-test.sh suite passes all 38 tests.
Closes #1301
Post-script verification
agent/1301-stale-branch-cleanup)33244271743c5a6ab9af8038f2bd69e8d1610ab7..HEAD)