Skip to content

fix(ai): a second Jev request on one model works - #4331

Merged
dan-petty merged 2 commits into
mainfrom
fix/4319-jev-second-request-event-loop
Nov 10, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/4319-jev-second-request-event-loop

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

A second request on one Jev model failed with "Event loop is closed". The HTTP client of a model keeps connections that belong to the event loop of its first request, and asyncio.run closed that loop after each request.

jev.py now has the public function decide_with_jev(request, *, model=None, settings=None, model_settings=None). It runs every request on one event loop that stays open for the process (an anyio blocking portal), so one model serves any number of requests. It replaces the private _run_decide. The helpers of jev.py, devops ai ask-jev and the completeness check call it, and the eval of the check uses one model for all cases.

_run_decide is removed. A branch that imports it calls decide_with_jev(request, model=model).

This also delivers the public function of #4309. The form allows one closing line, so #4309 needs a manual close after the merge.

Closes #4319

Change: openspec/changes/archive/2026-11-10-4319-a-second-jev-request-on-one/

@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/ai AI review pipeline, personas, prompts, LLM client, or RAG labels Nov 10, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Checks run before the push

uv run devops ci fail-to-pass --base origin/main (base = origin/main):

errored on base: tests.ai.test_jev_gateway_route (collection failure)
failed on base: tests.ai.test_jev_one_model_many_requests::test_a_helper_answers_twice_with_one_model (RuntimeError: Event loop is closed)
failed on base: ...::test_the_public_function_answers_twice_with_one_model (ImportError: decide_with_jev)
failed on base: ...::test_the_call_settings_win_over_the_model_settings (ImportError)
failed on base: ...::test_the_public_function_builds_its_own_model_from_settings (ImportError)
failed on base: ...::test_the_public_function_raises_the_error_of_decide_and_runs_again (ImportError)
failed on base: tests.roadmap.test_jev_completeness_eval::test_a_run_asks_jev_once_for_each_case_... (TypeError: run_cases() got an unexpected keyword argument 'model')
6 failed on base ... 1 errored.

The test that shows the defect (test_a_helper_answers_twice_with_one_model) sends two requests on one model to a keep-alive HTTP server on loopback. httpx2.MockTransport has no loop, so the HTTP fake cannot show it.

The ruff check and format, the openspec check, and 37 Jev and completeness tests pass. mypy reports no error in the changed files.

Live check (gateway, Jev live)

Two requests on one model through decide_with_jev:

1 typesafe/jev-1.14-20261014 0.94 279
2 typesafe/jev-1.14-20261014 0.95 279

uv run devops ai ask-jev noul "Is this a docs-only change?" --context "Fix a typo in README.md" --json:

{"kind": "noul", "answer": "yes", "probability": 0.95, "confidence": null, "score": null,
 "probabilities": {"yes": 0.95, "no": 0.05}, "model": "typesafe/jev-1.14-20261014",
 "input_tokens": 279, "output_tokens": 20}

Not run

The full devops ci did not start before the push: the shared CI lock stayed held by other runs for over 45 minutes. The run is still queued. The required checks of GitHub CI decide the merge.

@dan-petty
dan-petty force-pushed the fix/4319-jev-second-request-event-loop branch from 2eedb52 to 18e6b92 Compare November 10, 2026 03:10
decide_with_jev is the public one-request function of jev.py. It runs every
request on one event loop that stays open (anyio blocking portal), so the
HTTP client of a model no longer meets a closed loop. It replaces _run_decide,
and the ask-jev command and the completeness check call it.
@dan-petty
dan-petty force-pushed the fix/4319-jev-second-request-event-loop branch from 18e6b92 to 5a26003 Compare November 10, 2026 03:22
@dan-petty
dan-petty marked this pull request as ready for review November 10, 2026 03:33
@dan-petty

Copy link
Copy Markdown
Owner Author

Full devops ci (queued behind the shared lock, ran after the first push)

22258 tests passed, 4 failed and 4 errored. All 8 are tests/commands/test_scan.py (known, #4288 and #4321). Every other row passed (lint, format, typecheck, security, docs, openspec, test-tree, constructs, startup-imports and the rest).

The first GitHub run failed the test-tree row: ai/jev.py holds a process-wide event loop, and the test floor must reset it. The second commit adds reset_jev_portal and registers it in tests/conftest.py. The row passes now, and all GitHub checks pass on the final head.

@dan-petty
dan-petty merged commit cdefdd6 into main Nov 10, 2026
26 checks passed
@dan-petty
dan-petty deleted the fix/4319-jev-second-request-event-loop branch November 10, 2026 06:06
dan-petty-release Bot added a commit that referenced this pull request Nov 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.106.1](v0.106.0...v0.106.1)
(2026-11-10)


### Bug Fixes

* **ai:** a second Jev request on one model works
([#4331](#4331))
([cdefdd6](cdefdd6))
* **ci:** the release publishes the mcp-server image
([#4334](#4334))
([b4770d2](b4770d2))
* **roadmap:** a MODIFIED block gets the base scenarios it omits
([#4333](#4333))
([8bd434f](8bd434f))
* **security:** renew MCP server Trivy ignores, bump kubectl, helm
([#4337](#4337))
([ec4aabf](ec4aabf))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ai AI review pipeline, personas, prompts, LLM client, or RAG type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ai): a second Jev request on one model fails

1 participant