Repository navigation
fix: run git_sync subprocesses via executor to avoid asyncio hang on clone/fetch - #493
DanCRichards wants to merge 3 commits into
Conversation
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
…clone/fetch asyncio.create_subprocess_exec reliably stalls at 0 bytes transferred for git clone/fetch over an SSH remote (reproduced in isolation, independent of this app, with both PIPE and real file-handle stdout/stderr; --quiet made no difference). Small commands like ls-remote are unaffected via the same mechanism, so this is specific to the long-lived duplex data stream a git child process keeps open through its own ssh child. Swap _run_git() to a classic blocking subprocess.run(...) executed via loop.run_in_executor(None, ...), preserving the same timeout/error semantics. Verified end-to-end against a real CodeCommit SSH remote: git_sync now completes successfully where it failed 100% of the time before. Fixes OpenHands#491
63e4e75 to
b8f5301
Compare
enyst
left a comment
There was a problem hiding this comment.
I'm an AI agent (Claude, based on Opus 5.5) helping Engel Nyst (@enyst) with project work.
Requesting changes: this head breaks two existing tests and conflicts with main's auth-failure handling.
- Two tests fail.
tests/test_git_sync_client.pyspies onasyncio.create_subprocess_execintest_run_git_passes_the_non_interactive_env_to_the_subprocessandtest_leaves_no_checkout_behind. With_run_gitonsubprocess.run, both fail (assert None == '0'andassert 0 == 1). Running that file in a detached worktree: 17 passed and 2 failed on this head, 19 passed with the baseclient.py. Main still has both spies (lines 358 and 428), so they need to spy onsubprocess.runinstead. - Conflict with #536, merged 2026-09-30. Main's
_run_gitnow raisesGitAuthErrorwhen_looks_like_auth_failure(details)matches, and the sync loop backs off on that error. The rebase has to keep that classification in the newresult.returncode != 0branch. Taking this side as-is would quietly disable the backoff.
On CI: Validate PR description fails because the linked issue #491 lacks the ready-for-dev label. That's a triage gate, not a code failure. ci, Run tests, and Docker are action_required and haven't run, which is why the test failures above don't show yet.
Main hasn't fixed or otherwise changed the hang: _run_git still uses asyncio.create_subprocess_exec and proc.communicate(), and #536 only added error classification. I couldn't reproduce the SSH stall here (no SSH remote), so the root cause is unverified. #491 reports it on macOS; a Linux reproduction would show whether production deployments are affected. The approach looks low-risk. subprocess.run kills the child on TimeoutExpired, so timeout behavior is preserved. The one new behavior is at shutdown: a git command running in the default executor keeps its thread busy until git exits or times out (60s by default), and asyncio's executor shutdown waits for it.
Keep main's GitAuthError classification (OpenHands#536) on the subprocess.run path, use capture_output, and move the test spies from asyncio.create_subprocess_exec to subprocess.run. Add regression tests that clone/fetch never use asyncio subprocesses and that a slow git command does not block the event loop. Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
|
📁 PR Artifacts Notice This PR adds or changes temporary PR-specific documents under |
|
@enyst Both points from your review are addressed in 66be6a2 (merge of main, no force-push). (1) The three This comment was created by an AI agent (OpenHands) on behalf of Graham Neubig. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope gate: git_sync/ is explicitly owned by this repository (AGENTS.md: the Automation Service owns git sync; the SDK, Canvas, and extensions repos do not). No maintainer decision needed; proceeding with the technical review.
Review of the change (git_sync/client.py::_run_git_once):
- The swap from
asyncio.create_subprocess_execto blockingsubprocess.runin the default executor preserves every observable semantic I traced againstmain: same argv/env/cwd and no shell,FileNotFoundErrorstill maps toGitSyncError("git executable not found")(worker-thread exceptions propagate throughrun_in_executorto the awaiter),subprocess.TimeoutExpiredstill maps toGitSyncErrorwith the same message, andsubprocess.runkills and reaps the child on timeout (POSIXkill()+wait()), matching the oldproc.kill(); await proc.wait()path. - The
GitAuthErrorclassification from #536 is preserved on the new path (_looks_like_auth_failureon redacted stderr inside_run_git_once), the basic→bearer retry in_run_gitstill wraps it, andgit_sync/loop.py's backoff (isinstance(e, GitAuthError)→consecutive_auth_failures, log suppression past threshold) is unchanged and still functions. - The executor trade-off is bounded and documented: git sync runs one org at a time, the default timeout is 60 s, and
subprocess.runkills the child at timeout, so a mid-flight command delays shutdown by at most ~one git timeout. That is strictly better than the old cancel path, which left the git child orphaned while the task unwound. - Tests were updated coherently: the three spies now patch
subprocess.runwith a signature matching the production call, and the newTestSubprocessRunnercovers both acceptance criteria with real behavior — asserting clone/fetch never touch asyncio subprocess machinery, and that the event loop keeps ticking while a hung git command runs out its 1 s timeout.
Test evidence: uv run python -m pytest tests/test_git_sync_client.py tests/test_git_sync_backoff.py → 65 passed; tests/test_git_sync.py → 80 passed (this sandbox has no Docker daemon, so the router-test fixtures cannot start here; the repo's required unit-tests and ci/backend checks are green on this exact head, and the router suites are covered there). No tracked files were modified.
State checks: head still 720d331f4f57a33825eb6dde8415491e36de8c5b; PR title/body match the described change; all 9 checks pass; review feedback from @enyst (auth classification + test spies) is addressed in 66be6a2 as claimed; linked issue #491 is open with bug/ready-for-dev. The .pr/ evidence files follow the documented PR-artifacts convention and are cleaned up by the release flow.
No material issues found.
✅ APPROVED
Summary
git_sync/client.py's_run_git()spawned every git subprocess viaasyncio.create_subprocess_exec, which reliably stalls at 0 bytes transferred forgit clone/git fetchover an SSH remote (small commands likels-remoteare unaffected). See git_sync: asyncio.create_subprocess_exec hangs indefinitely on git clone/fetch over SSH #491 for the full investigation, ruled-out causes, and isolated repro._run_git()to a blockingsubprocess.run(...)executed vialoop.run_in_executor(None, ...), preserving the same timeout/error semantics (subprocess.TimeoutExpired→GitSyncError, non-zero exit →GitSyncErrorwith redacted stderr).Test plan
git_syncnow completes successfully (last_synced_commitpopulated,last_error: null), where it failed 100% of the time before with the same repo/credentials/timeout.python3 -m py_compileon the changed file.HUMAN: I ran the full agent-canvas + automation stack locally and drove the git-sync test myself against our real AWS CodeCommit repo. Before this change I hit the same
git command timed outfailure on every retry (including with the timeout raised well past what a normal clone should need); after applying the fix and restarting the stack, I triggered a fresh sync and watched it complete successfully end-to-end via the live/git-sync/statusAPI, with a real commit SHA populated and no error. I reviewed the diff inclient.pyand the reasoning for the executor-based approach before asking for this PR to be opened.Fixes #491
Update (13 November): merged with main, review feedback addressed
Pushed on top of the original commit (no force-push):
main. The conflict with feat(git-sync): back off and quiet down on persistent auth failures #536 is resolved: thesubprocess.runpath keeps theGitAuthErrorclassification (_looks_like_auth_failure), so the auth-failure backoff still works, and the basic→bearer auth retry in_run_gitstill wraps it.tests/test_git_sync_client.py(non-interactive env,ls-remote-only check, auth-scheme fallback) now patchsubprocess.runinstead ofasyncio.create_subprocess_exec. NewTestSubprocessRunner:asyncio.create_subprocess_execis replaced with a function that fails (acceptance criterion 2);capture_output=True(ruffUP022).uv run python -m pytest tests/test_git_sync_client.py tests/test_git_sync.py tests/test_git_sync_backoff.py tests/test_git_sync_router.py -n 4: 203 passed.pre-commitpasses on the changed files.Live check on Linux (real SSH remote)
I could not reproduce the stall on Linux. I used a local
sshdserving a ~9 MB repo,BatchMode=yes, and Python 3.12/3.13. The issue's standalone script and a Git Sync cycle through the running service both clone in a few seconds onmaintoo. The original report is macOS + CodeCommit, which I can't run here. So this evidence shows the change works and does not regress Linux. It does not prove the macOS root cause. That comes from the author's end-to-end CodeCommit verification above. Scripts:.pr/repro491.sh.Trade-off from the review: a git command running in the default executor keeps a worker thread busy until it exits or hits its timeout. On shutdown, asyncio waits for that thread.
subprocess.runkills the child on timeout, so that wait is bounded by the git timeout. Git Sync runs one org at a time, so it uses at most one executor thread.This update was made by an AI agent (OpenHands) on behalf of Graham Neubig.
Jev-Fast-Audit
⚡ Jev fast audit · estimates · 0.31s · commit 720d331⚠️ reduced context — partial coverage; 11/11 hunks, 6/6 files (missing patch: 2).
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage:
All estimates and evidence