Skip to content

fix(ai): Jev helpers reuse an HTTP client on a new event loop #4318

Closed as not planned

Description

@dan-petty

Problem or Motivation

_run_decide in src/devops_cli/ai/jev.py runs asyncio.run(model.decide(request, settings)). Each call starts a new event loop. A SystemOneModel that owns its HTTP client (the model that create_jev_model builds) keeps pooled connections that belong to the loop of the first call. The second call with the same model fails with RuntimeError: Event loop is closed.

I found it in a live run of a new caller (#4298): the first Jev request worked and the next request on the same model raised the error. The model that the gateway settings build gets a client of the HTTP entry point, which the provider does not own, so async with model does not replace it. The caller must build a model for each request and close its client on the loop that used it. select_skill_with_jev makes two requests with one model, so it hits the same fault. The tests of jev.py do not see it, because they build the model with a mock transport and so the provider owns no client.

I reproduced it with a model over a loopback socket (a keep-alive HTTP server in the test process): without the fix the second request raises Event loop is closed.

Proposed Solution & Architectural Design

Build a model for each request and close its client on the loop that used it, as #4298 does in src/devops_cli/roadmap/intake/intake_jev.py. When #4309 gives jev.py a public decide_with_jev, put the context there once and let both callers use it. Add a test that makes two requests with one model that owns its client.

Target Subsystem

AI & Agentic Review Pipeline.

Existing Tool Considered

The pydantic_ai provider refreshes a client that it owns (providers/__init__.py, _refresh_http_client), but not one that the caller gives it. No new tool is needed: httpx2.AsyncClient.aclose() closes the client.

Activity

  1. added
    source/agent
    type/bug
    scope/ai
    status/new
    value/medium
    effort/low
    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. A runtime error breaks the second request on the same model, but a workaround exists (build a model per request).
    • Value: Medium. Fixes a real failure when a caller makes two Jev requests with one model.
    • Effort: Low. The fix is to build a model per request and close its client, a small change already shown in #4298.
    • Related: refactor(ai): jev.py exposes a public one-request decide function #4309, which asks for a different change. Both items modify jev.py, but #4309 adds a public decide function while the candidate fixes the RuntimeError from reusing an HTTP client across event loops.
  3. added
    priority/p2-medium
    on Nov 10, 2026
  4. dan-petty commented on Nov 10, 2026

    @dan-petty
    OwnerAuthor

    This is a duplicate of #4319, which an agent works on. I added my evidence there.

  5. removed
    status/new
    on Nov 10, 2026
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/lowpriority/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