From 26cb198bad7a4401822d1bcc1fddea463a91e677 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 21 Nov 2025 10:56:05 +0300 Subject: [PATCH] f --- .forgejo/workflows/agent-development.yml | 2 +- .forgejo/workflows/build-agent-image.yaml | 2 +- tools/agent/agent_orchestrator.py | 68 +++++++++++++++++++++-- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/.forgejo/workflows/agent-development.yml b/.forgejo/workflows/agent-development.yml index bcd5ca7..7667590 100644 --- a/.forgejo/workflows/agent-development.yml +++ b/.forgejo/workflows/agent-development.yml @@ -49,7 +49,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v3 with: fetch-depth: 0 submodules: recursive diff --git a/.forgejo/workflows/build-agent-image.yaml b/.forgejo/workflows/build-agent-image.yaml index a36fc1a..061282d 100644 --- a/.forgejo/workflows/build-agent-image.yaml +++ b/.forgejo/workflows/build-agent-image.yaml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v3 - name: Login to Forgejo Registry uses: docker/login-action@v3 diff --git a/tools/agent/agent_orchestrator.py b/tools/agent/agent_orchestrator.py index 811d5bc..c28c873 100644 --- a/tools/agent/agent_orchestrator.py +++ b/tools/agent/agent_orchestrator.py @@ -292,9 +292,16 @@ class AgentOrchestrator: if not self._git_commit(commit_message): print("⚠️ No changes to commit") - # Push changes + # Push changes (with pull before push to avoid conflicts) print("\n📤 Pushing changes...") - self._git_push() + if not self._git_push(): + print("⚠️ Push failed, pulling latest changes and retrying...") + # Pull latest changes before retrying push + if self._git_pull(): + print("✅ Pulled latest changes, retrying push...") + self._git_push() + else: + print("❌ Failed to pull latest changes") return True @@ -482,7 +489,36 @@ Changes: return False def _git_push(self) -> bool: - """Push changes to remote.""" + """Push changes to remote. Pulls first if needed to avoid conflicts.""" + # First, fetch to check if there are remote changes + fetch_result = subprocess.run( + ["git", "fetch"], + cwd=self.config.project_root, + capture_output=True, + text=True + ) + + if fetch_result.returncode != 0: + print(f"⚠️ Failed to fetch: {fetch_result.stderr}") + # Continue anyway, might be network issue + + # Check if local branch is behind remote + check_result = subprocess.run( + ["git", "rev-list", "--count", "HEAD..origin/master"], + cwd=self.config.project_root, + capture_output=True, + text=True + ) + + if check_result.returncode == 0: + behind_count = check_result.stdout.strip() + if behind_count and int(behind_count) > 0: + print(f"⚠️ Local branch is {behind_count} commit(s) behind remote") + print(" Pulling latest changes before push...") + if not self._git_pull(): + print("❌ Failed to pull, push may fail") + + # Now try to push result = subprocess.run( ["git", "push"], cwd=self.config.project_root, @@ -494,8 +530,30 @@ Changes: print("✅ Pushed to remote") return True else: - print(f"⚠️ Push failed: {result.stderr}") - return False + # If push failed due to remote changes, try pull and push again + if "fetch first" in result.stderr or "Updates were rejected" in result.stderr: + print("⚠️ Push rejected due to remote changes") + print(" Pulling and retrying push...") + if self._git_pull(): + # Retry push after pull + retry_result = subprocess.run( + ["git", "push"], + cwd=self.config.project_root, + capture_output=True, + text=True + ) + if retry_result.returncode == 0: + print("✅ Pushed to remote after pull") + return True + else: + print(f"❌ Push failed after pull: {retry_result.stderr}") + return False + else: + print("❌ Failed to pull before retry") + return False + else: + print(f"⚠️ Push failed: {result.stderr}") + return False def _create_issue_for_failed_task(self, task: Task) -> None: """Create GitHub/Forgejo issue for failed task."""