From 162d66016e2ef389e01a3de5df9e38f4764f9328 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Mon, 4 Aug 2025 17:57:08 -0700 Subject: [PATCH] chore: Better git debug logging (#673) --- apps/open-swe/src/utils/github/git.ts | 44 +++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/apps/open-swe/src/utils/github/git.ts b/apps/open-swe/src/utils/github/git.ts index e961f89f..3ddc11f4 100644 --- a/apps/open-swe/src/utils/github/git.ts +++ b/apps/open-swe/src/utils/github/git.ts @@ -284,14 +284,45 @@ export async function checkoutBranchAndCommit( ); if (pushRes instanceof Error) { - logger.info("Failed to push changes, attempting to pull and push again"); + const errorFields = + pushRes instanceof Error + ? { + message: pushRes.message, + name: pushRes.name, + } + : pushRes; + + logger.error("Failed to push changes, attempting to pull and push again", { + ...errorFields, + }); + // attempt to git pull, then push again - await sandbox.git.pull( - absoluteRepoDir, - "git", - options.githubInstallationToken, + const pullRes = await withRetry( + async () => { + return await sandbox.git.pull( + absoluteRepoDir, + "git", + options.githubInstallationToken, + ); + }, + { retries: 1, delay: 0 }, ); - logger.info("Successfully pulled changes. Pushing again."); + + if (pullRes instanceof Error) { + const errorFields = + pullRes instanceof Error + ? { + message: pullRes.message, + name: pullRes.name, + } + : pullRes; + logger.error("Failed to pull changes after a push failed.", { + ...errorFields, + }); + } else { + logger.info("Successfully pulled changes. Pushing again."); + } + const pushRes2 = await withRetry( async () => { return await sandbox.git.push( @@ -302,6 +333,7 @@ export async function checkoutBranchAndCommit( }, { retries: 3, delay: 0 }, ); + if (pushRes2 instanceof Error) { const gitStatus = await sandbox.git.status(absoluteRepoDir); const errorFields = {