Skip to content

fix(swe-fast): clone repo before git_init so PR creation works#53

Open
williamhdean wants to merge 1 commit intoAgent-Field:mainfrom
williamhdean:fix/swe-fast-no-clone-no-pr
Open

fix(swe-fast): clone repo before git_init so PR creation works#53
williamhdean wants to merge 1 commit intoAgent-Field:mainfrom
williamhdean:fix/swe-fast-no-clone-no-pr

Conversation

@williamhdean
Copy link
Copy Markdown

Fixes #52

Summary

  • swe_af/fast/app.py: Add clone logic before run_git_init. When repo_url is provided and .git does not exist, git clone the repo. On subsequent runs, fetch + reset --hard to the default branch (re-clone on failure). This ensures remote_url is populated so the enable_github_pr gate passes.
  • docker-compose.yml: Add env_file: .env to the swe-fast service so GH_TOKEN and other API keys are sourced from .env rather than requiring them to be exported in the host shell.

Test plan

  • Call swe-fast build endpoint with a repo_url pointing to a real GitHub repo
  • Verify the workspace contains the cloned repo (not an empty dir)
  • Verify a draft PR is created on success
  • Run with a pre-existing workspace to verify fetch+reset path works
  • Confirm GH_TOKEN is available inside the container without manual shell export

🤖 Generated with Claude Code

swe-fast was calling git_init on an empty directory (os.makedirs only,
no clone) when repo_url was provided. git_init would do `git init` on
the empty folder, leaving no remote. The subsequent PR step checks
`if remote_url and cfg.enable_github_pr`, which was always False, so
the PR was silently skipped and the agent worked on invented code
instead of the actual repo.

Fix: mirror the clone logic from swe_af/app.py — git clone on first
run, fetch + reset to default branch on subsequent runs, re-clone as
fallback on reset failure.

Also add env_file: .env to the swe-fast Docker service so GH_TOKEN
and other API keys are sourced from .env rather than requiring them
to be exported in the host shell at docker compose up time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@williamhdean williamhdean requested a review from AbirAbbas as a code owner April 21, 2026 18:20
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Billy seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@AbirAbbas
Copy link
Copy Markdown
Collaborator

reviewing, in the meantime if you could sign the CLA as well!

Comment thread swe_af/fast/app.py
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(
Copy link
Copy Markdown
Collaborator

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_path patches os.makedirs but not subprocess.run, so this hits real git clone against /workspaces/my-project (permission denied on CI, remote-not-found locally). Either patch swe_af.fast.app.subprocess.run in that test or short-circuit the clone branch by pre-creating the .git dir in tmp_path and pointing repo_path there.

Comment thread swe_af/fast/app.py
["git", "clone", effective_repo_url, repo_path],
capture_output=True,
text=True,
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: subprocess.run is synchronous and blocks the event loop for the full clone duration (can be tens of seconds on large repos). Parent swe_af/app.py has the same pattern, so matching it is fine — just flagging for a follow-up (asyncio.create_subprocess_exec or asyncio.to_thread).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(swe-fast): repo never cloned — git_init works on empty dir, PR creation always skipped

3 participants