Repository navigation
Description
Split from #4753.
Four of five devops roadmap eval verify --case 2169 runs on 2026-11-13 stopped with ModelConnectionError, phase read, ConnectionResetError: [Errno 104] Connection reset by peer, each losing a 5 to 20 minute case run (reply on #4753). The agent path has no retry for a reset while the reply is read: create_pydantic_ai_provider builds its client with async_http_client(level), and the async entry point has no retries option, so no retry transport is installed, and the body read is outside the transport in any case.
Why deferred: it needs an opt-in retry for the async entry point and a retry around a pydantic-ai model request that stops after the first chunk, a design of its own; the sync client's fix does not reach it, and the GitHub session, which also builds an async client, must not opt in (ADR 0006).
Acceptance criteria:
- An async client built with
retriesSHALL send the request again after a connect error or a reset before the first chunk, with backoff, and MUST NOT replay after output.- WHEN the model request raises a read reset before the first chunk and the second attempt answers a complete reply
- THEN the agent run continues with the second reply and writes no
AIClientError.
create_pydantic_ai_providerSHALL build its client with the retry policy, and the GitHub session MUST keep its own retry rules.- WHEN the provider client is built
- THEN its transport is the async retry transport, and the GitHub session's client has none.
Proposed design
Problem statement
Agent runs on the async pydantic-ai path lose a 5 to 20 minute case when the reply stream gets a connection reset before the first chunk. The async HTTP client installs no retry transport, and the body read is outside the transport. The fix adds a bounded retry before the first chunk and leaves the GitHub session unchanged.
Acceptance criteria
Requirement: Async retry before first chunk
The async agent client SHALL retry a model request after a connect error or a reset that happens before the first response chunk.
Scenario: Reset before first chunk
- WHEN the first model request raises ConnectionResetError before it yields a chunk and the second attempt returns a complete reply
- THEN the agent run returns the second reply and raises no AIClientError.
Requirement: No replay after output
The async agent client MUST NOT send a model request again after the response stream emitted its first chunk.
Scenario: Reset after first chunk
- WHEN the model response yields one chunk and then raises ConnectionResetError
- THEN the run raises AIClientError and sends no second request.
Requirement: Bounded retry attempts
The async retry SHALL stop after three attempts and SHALL use backoff between them.
Scenario: Retry limit reached
- WHEN each of three attempts raises ConnectionResetError before the first chunk
- THEN the client sends exactly three attempts, waits between them, and raises AIClientError.
Requirement: Non-retryable failures
The async retry MUST NOT retry an HTTP 4xx response.
Scenario: Authentication failure
- WHEN the model request returns HTTP 401 before any chunk
- THEN the client sends one request and raises AIClientError.
Requirement: Provider uses retry transport
create_pydantic_ai_provider SHALL build its async client with the retry policy.
Scenario: Provider client transport
- WHEN the provider builds its async client
- THEN the client transport is the async retry transport.
Requirement: GitHub session unchanged
The GitHub session MUST keep its own retry rules and MUST NOT opt in to the new retry policy.
Scenario: GitHub session client
- WHEN the GitHub session builds its async client
- THEN the client has no retry transport from this change.
Existing Tool Considered
No alternatives check has run. PydanticAI's AsyncTenacityTransport covers transport-level connect retries but not a reset after the reply body starts; httpx-retries has the same transport-level limit. The plan adds a small pre-first-chunk wrapper: about 2,000 to 3,000 output tokens and 1 to 2 hours to build, keep and fix.
Key questions
- Does the async provider client currently install a retry transport?: No. create_pydantic_ai_provider calls async_http_client(level), and the async entry point has no retries option, so no retry transport is installed. [sources: src/devops_cli/ai/providers/init.py:77, src/devops_cli/ai/client/network.py]
- Which retry component should the async provider client use?: Use PydanticAI's AsyncTenacityTransport with RetryConfig for connect errors, and add a small wrapper around the model request for a reset before the first chunk. Do not build a new transport. (best practice) [sources: tests/ai/retries/test_pydantic_ai_retries.py, src/devops_cli/ai/client/network.py, src/devops_cli/ai/providers/init.py:77]
- Chosen: PydanticAI AsyncTenacityTransport plus pre-first-chunk wrapper. It reuses the maintained library and the repository's tested retry path.
- Rejected: Custom httpx transport. It duplicates the library and still cannot retry the body read.
- Rejected: Tenacity around the whole agent run. It can replay tool side effects after output.
- Where must the retry start to avoid replaying output?: At the async stream boundary. Retry only while the stream has yielded no chunk. After the first chunk, surface AIClientError. (best practice) [sources: src/devops_cli/ai/pydantic_ai_bridge.py, src/devops_cli/ai/client/models.py:72]
- Chosen: Async stream boundary. It stops the retry before any output exists.
- Rejected: Transport only. The transport returns before the body read, so it cannot see a reset before the first chunk.
- Rejected: Whole agent run. A replay can repeat tools and side effects after output.
- Which failures are retryable?: httpx.ConnectError, httpx.ReadError and ConnectionResetError before the first chunk. HTTP 4xx responses and errors after output are not retryable. (best practice) [sources: ARCHITECTURE.md:216, src/devops_cli/ai/client/network.py]
- Chosen: Connect and read reset before first chunk. It covers the reported reset and keeps the retry safe for a request with no output.
- Rejected: Every network exception. It retries failures that a new attempt cannot fix.
- Rejected: Every 5xx response. The issue reports a read reset, and a status retry needs its own rule.
- What retry budget and backoff should apply?: At most three attempts, with jittered exponential backoff and no attempt after 20 s. This follows the bounded shape of the service-read retry. (best practice) [sources: ARCHITECTURE.md:216]
- Chosen: Three attempts, jitter, 20 s cap. It bounds the wait and uses the repository's backoff shape.
- Rejected: Unlimited retries. It can hold a case run open after the provider is gone.
- Rejected: Fixed one-second delay. It sends a burst to a provider that is already failing.
- How does the GitHub session stay unchanged?: Add an opt-in retries parameter to the async client builder. create_pydantic_ai_provider passes the policy; the GitHub session keeps its own construction and passes no policy. (best practice) [sources: src/devops_cli/ai/providers/init.py:77, tests/github/test_github_session.py]
- Chosen: Opt-in parameter. It gives the provider the retry and leaves every other async client on its current path.
- Rejected: Global default retry. It changes the GitHub session and breaks its own retry rules.
- Rejected: Separate builder. It duplicates the client construction and its security checks.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
devops-cli-service commentedon Nov 15, 2026
The reset makes 4 of 5 eval runs fail and costs 5 to 20 minutes per retry, which increases retries and AI spend.Both report the connection reset in the verify eval; 5527 tracks the case failure and the candidate adds the async client retry.devops-cli-service commentedon Nov 15, 2026
Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.
fix(ai): retry a reset in the answer read of a pydantic-ai agent run (#…
devops-cli-service commentedon Nov 15, 2026
Released in v0.152.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.152.0
devops-cli-service commentedon Nov 15, 2026
Live since 2026-11-15 12:41 UTC