Repository navigation
fix(swe-fast): clone repo before git_init so PR creation works #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,10 @@ | |
| import asyncio | ||
| import os | ||
| import re | ||
| import subprocess | ||
|
|
||
| from agentfield import Agent | ||
| from agentfield.types import AgentStatus | ||
| from swe_af.execution.envelope import unwrap_call_result as _unwrap | ||
| from swe_af.fast import fast_router | ||
| from swe_af.fast.schemas import FastBuildConfig, FastBuildResult, fast_resolve_models | ||
|
|
@@ -29,6 +31,14 @@ | |
|
|
||
| app.include_router(fast_router) | ||
|
|
||
|
|
||
| @app.on_event("startup") | ||
| async def _mark_ready(): | ||
| """Promote lifecycle_status to READY after the SDK's own startup completes.""" | ||
| await asyncio.sleep(3) | ||
| app._current_status = AgentStatus.READY | ||
|
|
||
|
|
||
| # Include the planner's execution router so that router.note() calls inside | ||
| # the original execution_agents functions (run_coder, run_verifier, etc.) | ||
| # work when delegated to via the thin wrappers. | ||
|
|
@@ -73,7 +83,43 @@ async def build( | |
| if not repo_path: | ||
| raise ValueError("Either repo_path or repo_url must be provided") | ||
|
|
||
| os.makedirs(repo_path, exist_ok=True) | ||
| git_dir = os.path.join(repo_path, ".git") | ||
| if effective_repo_url and not os.path.exists(git_dir): | ||
| app.note(f"Cloning {effective_repo_url} → {repo_path}", tags=["fast_build", "clone"]) | ||
| os.makedirs(repo_path, exist_ok=True) | ||
| clone_result = subprocess.run( | ||
| ["git", "clone", effective_repo_url, repo_path], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: |
||
| if clone_result.returncode != 0: | ||
| err = clone_result.stderr.strip() | ||
| app.note(f"Clone failed: {err}", tags=["fast_build", "clone", "error"]) | ||
| raise RuntimeError(f"git clone failed: {err}") | ||
| elif effective_repo_url and os.path.exists(git_dir): | ||
| default_branch = cfg.github_pr_base or "main" | ||
| app.note( | ||
| f"Repo exists at {repo_path} — resetting to origin/{default_branch}", | ||
| tags=["fast_build", "clone", "reset"], | ||
| ) | ||
| subprocess.run(["git", "fetch", "origin"], cwd=repo_path, capture_output=True, text=True) | ||
| subprocess.run(["git", "checkout", "-f", default_branch], cwd=repo_path, capture_output=True, text=True) | ||
| reset = subprocess.run( | ||
| ["git", "reset", "--hard", f"origin/{default_branch}"], | ||
| cwd=repo_path, capture_output=True, text=True, | ||
| ) | ||
| if reset.returncode != 0: | ||
| import shutil | ||
| shutil.rmtree(repo_path, ignore_errors=True) | ||
| os.makedirs(repo_path, exist_ok=True) | ||
| clone_result = subprocess.run( | ||
| ["git", "clone", effective_repo_url, repo_path], | ||
| capture_output=True, text=True, | ||
| ) | ||
| if clone_result.returncode != 0: | ||
| raise RuntimeError(f"git re-clone failed: {clone_result.stderr.strip()}") | ||
| else: | ||
| os.makedirs(repo_path, exist_ok=True) | ||
|
|
||
| resolved = fast_resolve_models(cfg) | ||
| ai_provider = _runtime_to_provider(cfg.runtime) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI failure is from this PR —
test_repo_url_without_repo_path_auto_derives_repo_pathpatchesos.makedirsbut notsubprocess.run, so this hits realgit cloneagainst/workspaces/my-project(permission denied on CI, remote-not-found locally). Either patchswe_af.fast.app.subprocess.runin that test or short-circuit the clone branch by pre-creating the.gitdir intmp_pathand pointingrepo_paththere.