From 2d17904153f59c3d6ff6474ffd1ec13b9f6e02b0 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Fri, 25 Jul 2025 15:44:03 -0700 Subject: [PATCH] fix: Pull branch if push errors (#534) --- apps/open-swe/src/utils/github/git.ts | 30 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/open-swe/src/utils/github/git.ts b/apps/open-swe/src/utils/github/git.ts index 40c98dfa..13c40fc4 100644 --- a/apps/open-swe/src/utils/github/git.ts +++ b/apps/open-swe/src/utils/github/git.ts @@ -128,16 +128,34 @@ export async function checkoutBranchAndCommit( ); if (pushRes instanceof Error) { + logger.info("Failed to push changes, attempting to pull and push again"); + // attempt to git pull, then push again + await sandbox.git.pull( + absoluteRepoDir, + "git", + options.githubInstallationToken, + ); + logger.info("Successfully pulled changes. Pushing again."); + const pushRes2 = await withRetry( + async () => { + return await sandbox.git.push( + absoluteRepoDir, + "git", + options.githubInstallationToken, + ); + }, + { retries: 3, delay: 0 }, + ); const gitStatus = await sandbox.git.status(absoluteRepoDir); const errorFields = { - ...(pushRes instanceof Error + ...(pushRes2 instanceof Error ? { - name: pushRes.name, - message: pushRes.message, - stack: pushRes.stack, - cause: pushRes.cause, + name: pushRes2.name, + message: pushRes2.message, + stack: pushRes2.stack, + cause: pushRes2.cause, } - : pushRes), + : pushRes2), }; logger.error("Failed to push changes", { ...errorFields,