Skip to content

fix(ai): the verify eval agent run fails with ModelConnectionError #4345

Closed

Description

@dan-petty

Problem or Motivation

On 2026-11-10, five processes of devops roadmap eval verify --model deepseek-v4.1-flash-1017 ran at the same time against the gateway. 6 of 48 cases ended with AIClientError: The investigation's model call failed (ModelConnectionError), and the other 42 cases ended. A case that fails this way costs a full run again (about 0.18 USD and 5 to 10 minutes), because the run keeps nothing of the agent loop. The failed cases were 2531, 2524, good-3410, 2554, 2526 and 2559; each of them ran again with no error, so the cause is not the case.

Proposed Solution & Architectural Design

Find the cause before any change: read the gateway log and the client log for the times of the failures (the reports in .data/roadmap_eval/verify/ name the files), and decide if the failure is a connection limit of the gateway, a timeout of a long agent loop, or a stale connection of the client (#4319 describes a closed event loop in the Jev client; check if the agent client has the same problem). The fix is at the cause. If the cause is outside the project, add a check that fails when the problem returns, and do not add a retry that hides it.

Target Subsystem

src/devops_cli/ai/client, the LLM gateway, devops roadmap eval verify.

Existing Tool Considered

The client library (pydantic-ai with httpx2) and the gateway log. No new tool. Cost: the time to read two logs; the fix is unknown until then. Related: #4319, #4282.

Standards Compliance

  • I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 5, zero bare exceptions, tests that cover the changed lines).
  • I am willing to submit a pull request implementing this feature with accompanying tests.

Proposed design

Problem statement

In one run of devops roadmap eval verify with five parallel processes, 6 of 48 cases ended with AIClientError: The investigation's model call failed (ModelConnectionError). Each failed case costs a full run again, about 0.18 USD and 5 to 10 minutes, because nothing of the agent loop is kept. The error text names only the class ModelConnectionError, so the cause cannot be read from it. The cause may be a gateway connection limit, a timeout of a long agent loop, or a stale connection of the agent client, as in #4319. The gateway log and the client log are not in the repository, so a person or the job that has them must read them.

Acceptance criteria

Requirement: Connection failure names its cause

model_call_error SHALL include the class name and the text of the underlying connection error, masked and cut, in the message of an AIClientError for a failed model call.

Scenario: Connection reset in the model call

  • WHEN a ModelConnectionError is raised whose __cause__ is an httpx error with a known text, such as a remote protocol error 'Server disconnected without sending a response'
  • THEN the AIClientError message contains the class name of the cause and its text, and contains no text of a model reply

Requirement: Client survives a new event loop

The agent client MUST NOT reuse a pooled connection that belongs to a closed event loop.

Scenario: Two runs in two event loops

  • WHEN a test runs the agent against a local fake gateway in one event loop, closes that loop, and runs it again in a new loop with the same client factory
  • THEN the second run ends with no ModelConnectionError

Requirement: Cause is guarded by a check

The change SHALL add a test that fails when the confirmed cause of the failure returns.

Scenario: Confirmed cause returns

  • WHEN the test reproduces the confirmed cause offline, such as a stale or limited connection to a fake gateway
  • THEN the test fails on the base commit and passes on the fixed code

Requirement: No retry that hides the cause

The fix SHALL NOT add a blind retry of a failed model call that hides a cause outside the project.

Scenario: Cause outside the project

  • WHEN the gateway refuses a connection for a reason that the client cannot fix
  • THEN the run fails with the error of the first criterion and the fake gateway sees exactly one request

Existing Tool Considered

pydantic-ai with httpx2 already covers the client and offers retries (pydantic_ai.retries, httpx transport retries), but a retry would hide the cause, which the issue and AGENTS.md forbid. No new tool is needed. The cost is the time to read the gateway log and the client log, plus a small change to model_call_error (src/devops_cli/roadmap/agent_run.py:51) and one regression test. No check ran for alternatives.

Key questions

  • What is the cause of the six ModelConnectionError failures?: It cannot be settled from the repository. The error text is only The investigation's model call failed (ModelConnectionError). because model_call_error writes the class name of the pydantic-ai error and nothing of its cause (src/devops_cli/roadmap/agent_run.py:57-61). The gateway log and the client log named by the reports in .data/roadmap_eval/verify/ are needed. First step: make the message carry the class and text of __cause__, then rerun the five parallel processes. Then compare three causes: a gateway connection limit, a timeout of a long agent loop (the client read timeout and the pool of 30 s keepalive in src/devops_cli/config/defaults.py:1034 are the knobs), and a stale connection of the client. [sources: src/devops_cli/roadmap/agent_run.py:51, src/devops_cli/roadmap/refine/refine_investigation.py:601, src/devops_cli/config/defaults.py:1034]
  • Does the agent client have the closed event loop problem that fix(ai): a second Jev request on one model fails #4319 describes for the Jev client?: Possibly, and no test rules it out. The agent runs with agent.run_sync (refine_investigation.py:601). The provider's http_client is an unpooled async_http_client(level) built once per provider in create_pydantic_ai_provider (src/devops_cli/ai/providers/__init__.py:118-126), with a keepalive pool in its own transport (src/devops_cli/http/entry.py:178-213). A client that serves two run_sync calls, each in its own event loop, could hold a connection that belongs to a closed loop. Whether one provider serves more than one run in the eval is not shown in the files read, so the test of the second criterion decides it. [sources: src/devops_cli/roadmap/refine/refine_investigation.py:601, src/devops_cli/ai/providers/init.py:118, src/devops_cli/http/entry.py:178]
  • How must the fix handle a cause that lies outside the project?: Fix the cause at its source. If an outside constraint blocks the fix, add a check that fails when the problem returns, and add no retry that hides it. (best practice) [sources: AGENTS.md]
    • Chosen: Fix at the cause, plus a regression check. The issue states it and AGENTS.md requires it.
    • Rejected: Add a retry around the model call. It hides the cause and still costs time and tokens on each failed attempt.
  • Where does the message of a failed model call get its cause?: In model_call_error, which is shared by the investigation and the implement step (implement_step.py:834, refine_investigation.py:606). It adds the class name and the text of exc.__cause__, passed through bounded_text to mask secrets and cut the length. A connection error holds no model reply, so no reply text is shown. (best practice) [sources: src/devops_cli/roadmap/agent_run.py:51, src/devops_cli/roadmap/agent_run.py:64, src/devops_cli/roadmap/implement/implement_step.py:834]
    • Chosen: Add the cause to model_call_error. One change serves both callers and keeps the masking of bounded_text.
    • Rejected: Log the cause at each caller. It repeats code and the eval report would still show no cause.

Fit

Fits in one pull request.

Suspected block

The gateway log and the client log of 2026-11-10 are outside the repository and must be read to name the cause.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/ai
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  2. dan-petty commented on Nov 10, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. Six of forty-eight cases fail, wasting about 0.18 USD and 5 to 10 minutes per case, but the run still completes for most cases.
    • Value: Medium. Each failed case costs a full re-run and delays the verification pass, but the system still delivers results for the majority of cases.
    • Effort: Medium. The fix depends on diagnosing whether the cause is a gateway limit, a timeout, or a stale client connection, and the solution is unknown until the logs are read.
    • Related: feat(roadmap): eval verify stores each case when it ends and resumes #4344, which asks for a different change. Both address the same 2026-11-10 incident where 6 of 48 cases failed with ModelConnectionError, but the candidate fixes the error at its source while #4344 stores results incrementally to reduce the cost of a failure.
  3. added
    priority/p2-medium
    type/bug
    scope/ai
    source/agent
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  4. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 699026e until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • The gateway log and the client log of 2026-11-10 are outside the repository and must be read to name the cause.
  5. added
    owner/agent
    status/in-progress
    and removed
    status/new
    on Nov 11, 2026
  6. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Investigation of the six ModelConnectionError failures of 2026-11-10 (the logs that the refine block names):

    • Gateway. From 02:30Z to 04:40Z, LiteLLM logged only 200 OK lines (Loki, service_name="llm-gateway"): no error, no restart. The agent runs stream each request, and the server writes 200 OK when the response starts, so this line alone does not prove that a stream ended.
    • Tunnel. cloudflared kept 8 HA connections. It logged one error in the window, at 03:38:00Z: stream ... canceled by remote for a /v1/chat/completions request. That is the line that a client which drops an open stream causes. No such line exists at the six failure times (03:30:56Z two times, 03:35:48Z, 03:35:54Z, 03:41:44Z, 04:01:31Z, from the Tempo traces of the five processes).
    • Not a timeout. pydantic-ai raises the subclass ModelTimeoutError for a timeout. All six messages name ModelConnectionError.
    • Not a closed event loop (fix(ai): a second Jev request on one model fails #4319). In each process, all case checkouts ran on one worker thread, so all cases of a process used one event loop.
    • Not the cluster path. The roadmap Service calls the gateway inside the cluster, not through the tunnel. In the 7 days to 2026-11-11 it logged no ModelConnectionError; its failed model calls had an HTTP status (500 or 502).

    Result: the failed requests most likely had no open stream through the tunnel. The transport broke before the request reached the edge (name lookup, TCP or TLS on the client host), or the edge closed the client connection. Two processes failed in the same second, which fits a short loss of network or DNS on the client host. The cause is outside the project, and the logs cannot tell which part broke, because model_call_error wrote only the class name.

    The fix PR #4460 makes the message name the transport phase and the error of the HTTP library (masked), so the stored eval report of the next failure states the cause. It adds no retry. devops roadmap eval verify --resume (#4344, merged) runs again only the failed cases of a stored report.

  7. removed
    status/in-progress
    owner/agent
    on Nov 11, 2026
  8. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-11 05:46 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions