Repository navigation
Retry GitHub fetch connection errors and raise the timeout cap - #946
majamassarini wants to merge 3 commits into
Conversation
PR Summary by QodoRetry transient GitHub connection failures and extend HTTP timeout
AI Description
Merge Risk
|
Code Review by Qodo
Nice, no open findings for this group Nice, no open findings for this group Nice, no open findings for this group Resolved findings 1.
|
838c6b1 to
bfa516d
Compare
|
Code review by qodo was updated up to the latest commit bfa516d |
|
Code review by qodo was updated up to the latest commit 0cad8dd |
0cad8dd to
fc28328
Compare
|
Code review by qodo was updated up to the latest commit fc28328 |
fc28328 to
a815eda
Compare
|
Code review by qodo was updated up to the latest commit a815eda |
Gateway logs show get_github_patch_full failing on URLs that exist: every
failure takes exactly ~30s (AIOHTTP_TIMEOUT total=30) while the same URL
succeeds in under a second minutes later — bursty egress latency to
api.github.com crossing the cap. Because aiohttp_get_with_retries retried
only HTTP 503, a single slow window failed the task with no retry.
- Raise the GitHub fetch cap via a dedicated GITHUB_AIOHTTP_TIMEOUT
(total=120, connect=10) used only by the privileged GitHub tools, so
slow egress windows don't fail valid requests while dead endpoints
still fail fast.
- Retry connection establishment failures (ClientConnectionError,
TimeoutError) in aiohttp_get_with_retries with the same exponential
backoff as retryable statuses.
- Include the exception type in the GitHub tools' ToolError messages:
str(TimeoutError()) is empty, which left agents with a bare "Error:"
and hid the actual cause.
- Catch UnicodeDecodeError from the patch body read: previously it
escaped _run, and beeai's Tool.run wrapper collapses any non-ToolError
exception into a message-less ToolError ("Tool Error"), losing the
cause entirely — as seen for MariaDB commit 3646569 in the gateway
logs. Now it is reported like any other fetch failure, so messages
such as the pull request tool's "might be private" guidance always
reach the agents.
Assisted-by: GLM-5-3 <noreply@z.ai>
The git analog of the HTTP egress flakiness fixed in the previous commit: clone_repository failed for grafana (262.8s) and postgresql (6.1s) with "RPC failed; curl 56 Recv failure: Connection reset by peer" / "fetch-pack: unexpected disconnect" / "early EOF" — transient network resets mid-transfer that a plain retry would have survived. Assisted-by: GLM-5-3 <noreply@z.ai>
a815eda to
96d0558
Compare
|
Code review by qodo was updated up to the latest commit eb260fd |
c3e0278 to
1091e28
Compare
|
Code review by qodo was updated up to the latest commit 1091e28 |
1091e28 to
94b43b5
Compare
- Never retry permanent remote-side failures: git reports HTTP errors as "RPC failed; curl 22 The requested URL returned error: 403", which the transient classifier matched via "rpc failed; curl \d+", retrying denied fetches three times. A permanent-error check (curl 22, HTTP 4xx/5xx responses) now runs before the transient patterns, also covering HTTP errors trailed by an unexpected disconnect. - Clean a partial clone destination before retrying `git clone`: a failed attempt leaves a populated directory that git refuses to clone into again, making the retry fail instantly. _run_git_cmd gains retry_cleanup_path, used by the clone_repository clone branch; fetch retries are unchanged (git tolerates re-fetching into a partial repo). - Keep the 120s cap for patch fetches only: get_github_pull_request and get_github_compare are called by extract_upstream_repository (120s overall deadline) through the MCP gateway, so they get a tight 30s GITHUB_METADATA_AIOHTTP_TIMEOUT; the upstream_tools docstring wrongly claimed they are never called via MCP. Assisted-by: GLM-5-3 <noreply@z.ai>
94b43b5 to
e121da2
Compare
I wonder if we have any metrics on network utilization? How often and for what repos are we doing a full upstream git clone? I think an interesting thing here is that if we represented our source code "natively" instead of via dist-git, we wouldn't have this problem - or at least, we would have had to ensure we had correct and efficient clones and caching to operate at all. |
| # notably "fetch-pack: invalid index-pack output", which also appears as a | ||
| # trailing symptom of non-retryable local filesystem failures. |
There was a problem hiding this comment.
This is a pretty heuristic and ad-hoc list.
How often do these "non retryable" errors actually occur? I would lean towards just retrying on ~all errors in general, accepting the cost of those retries if the error isn't actually transient to start.
In the last few days, several backports failed because Ymir couldn't download an existing patch after several retries. The cause seems to be egress slowness. This PR increases the connection timeout and adds retries at the lowest level.
Evidence
The gateway logs show
get_github_patch_fullfailing on URLs that exist: every failure takes exactly ~30s (the previousAIOHTTP_TIMEOUT total=30), while the same URL succeeds in under a second minutes later — bursty egress latency toapi.github.comcrossing the cap. Becauseaiohttp_get_with_retriesretried only HTTP 503, a single slow window failed the task with no retry, and the task-level retry only succeeded once latency returned to normal. The same flakiness hits git transfers (clone_repositoryfailing withRPC failed; curl 56 Recv failure: Connection reset by peer/early EOF).Changes
HTTP (GitHub tools)
GITHUB_AIOHTTP_TIMEOUT(total=120, connect=10) for the patch-fetch tools only, so slow egress windows don't fail valid patch downloads while dead endpoints still fail fast. The sharedAIOHTTP_TIMEOUTstays at 30s: most clients run under their own overall deadline (e.g.upstream_search: 300s,extract_upstream_repository: 120s) that a 120s-per-request cap with retries would blow through.GITHUB_METADATA_AIOHTTP_TIMEOUT(total=30, connect=10) forget_github_pull_request/get_github_compare: they are called byextract_upstream_repository(120s overall deadline) through the MCP gateway, so one hung 120s request could consume the whole budget. Worst case with retries (~95s) stays under the deadline. Applied via a per-toolrequest_timeoutattribute.ClientConnectionError,TimeoutError) inaiohttp_get_with_retrieswith the same exponential backoff as retryable statuses. Anacquiringflag keeps the naturalasync with session.get(...)structure while distinguishing where a retryable exception came from: connection establishment is retried, errors raised by the caller while reading the yielded response still propagate without retries.ToolErrormessages:str(TimeoutError())is empty, which left agents with a bareError:and hid the actual cause.UnicodeDecodeErrorfrom the patch body read: previously it escaped_run, and beeai'sTool.runwrapper collapses any non-ToolErrorexception into a message-lessToolError("Tool Error"), losing the cause entirely. Now it is reported like any other fetch failure, so messages such as the pull request tool's "might be private" guidance always reach the agents.Git subprocesses (clone/fetch)
_run_git_cmd(connection reset, timed out, could not resolve host, early EOF, unexpected disconnect,RPC failed), mirroring the HTTP policy: 3 attempts, exponential backoff with jitter. Enabled for the network commands (clone_repositoryfetch+clone,fetch_branch,fetch_commit); local commands (init,checkout,push,ls-remote) keep single-attempt semantics.RPC failed; curl 22 The requested URL returned error: 403— a permanent-error check runs before the transient patterns, so denied fetches fail on the first attempt. Local-state failures (missing refs, template collisions, pack rename errors) are also never retried.git clone: a failed attempt leaves a populated directory that git refuses to clone into again, making the retry useless.