Repository navigation
Description
Symptom
Standard CI (code-checks / quality) fails intermittently with:
test/telemetry/test_tracing_backend.py::<test_name> - httpx.ReadTimeout
The failure appears on one Python matrix leg (usually 3.11 or 3.13), cancelling the others. It is not deterministic — the same test passes on other runs without any code change.
Why it happens
All five tests in test/telemetry/test_tracing_backend.py call a real Ollama instance:
| Test | What it checks |
|---|---|
test_span_duration_captures_async_operation |
span duration ≥ 0.1 s |
test_context_propagation_parent_child |
parent/child span IDs match |
test_token_usage_recorded_after_completion |
Gen-AI OTel attributes present |
test_span_not_closed_prematurely |
span not closed before avalue() returns |
test_multiple_generations_separate_spans |
two generations → two distinct span IDs |
CI runners are CPU-only (no GPU). Ollama evicts models after 5 minutes of inactivity (OLLAMA_KEEP_ALIVE=5m). These tests run near the end of the ~22-minute suite, by which point the model has been evicted and must reload. On a loaded CPU runner, that reload exceeds the 300 s httpx read timeout on OllamaModelBackend, so the request raises httpx.ReadTimeout and the test fails.
Background
PR #1302 fixed an earlier, worse version of this problem: test_streaming_span_duration was hanging for the full 900 s pytest-timeout budget. The fix:
- Added a 300 s default timeout to
OllamaModelBackend - Split the streaming test — fast mocked version runs on every push; real-Ollama version marked
@pytest.mark.slow
The commit message for #1302 explicitly noted that test_span_not_closed_prematurely and test_multiple_generations_separate_spans were already hitting ReadTimeout during development, and 300 s was chosen hoping it would be enough. It wasn't — test_multiple_generations_separate_spans hit httpx.ReadTimeout in standard CI on PR #1292 (run 28017020057).
Proposed fix
Apply the same split-and-mock treatment to the remaining five tests:
- New
integration-marked tests (noollamamarker) that patchollama.AsyncClient.chatto return a synthetic response and assert the same structural/OTel invariants. These run on every push, take < 1 s each. - Existing real-Ollama tests marked
@pytest.mark.slowso they are excluded from the defaultaddopts = "-m not slow"and run only on nightly/GPU-backed runners.
test_span_duration_captures_async_operation is the one test that checks actual wall-clock timing. A mock with an artificial asyncio.sleep delay — as used in test_streaming_tracing_integration.py — is sufficient to verify the timing invariant without a live model.
Reference
test/telemetry/test_streaming_tracing_integration.py— the mock pattern to follow- PR fix(tracing+ollama): split streaming span test into fast mock + slow e2e; add 300s default timeout #1302 — partial fix (streaming test only)
- Issue test: test_streaming_span_duration hangs >900s on slow CPU-only Ollama runner #1272 — original hang report
Activity
[-]test: complete PR #1302 fix — replace remaining e2e+ollama backend tracing tests with mocked equivalents[/-][+]test: backend tracing tests flake with httpx.ReadTimeout on loaded CI runners[/+]planetf1 commentedon Jun 25, 2026
Seen again on PR #1323 (2026-06-25):
test_ollama_generate_from_raw_metrics_integrationhithttpx.ReadTimeouton all three Python versions (3.11/3.12/3.13) in the quality CI workflow. Caused the quality checks to go red; re-run cleared it. No code changes on that test path in this PR.dk3yyyy commentedon Jul 29, 2026
Hi, I'd like to work on this. I verified that current main still runs the five affected telemetry tests against real Ollama under the standard e2e/ollama markers. My plan is to add mocked integration coverage for the same OpenTelemetry invariants, including a delayed async response for span duration, and mark the real-Ollama variants as slow. Could you confirm that approach and assign the issue to me?
planetf1 commentedon Jul 30, 2026
Thanks for offering to take this on, and your read of
mainis correct — those five tests are stille2e+ollama, noslowmarker.Two things have moved since I opened this, worth folding in before you start:
The flake itself is already handled. #1369 (merged 6 July, closing #1367 — the same symptom in
test_metrics_backend.py) added a retry to everyollama-marked test intest/conftest.py:I checked two of yesterday's PR runs directly (job logs, not just the config) — Ollama genuinely serves and all five tests pass against it on every PR, every Python version. No recurrence since #1369 went in. So this is no longer CI-blocking; it's a coverage/speed improvement now — I'd suggest dropping the
bug/p2labels, happy to do that if useful.Please don't mark the real-Ollama tests
slow. That part of my original proposal was wrong —addoptsexcludesslowunconditionally, including in the nightly script, soslowcurrently means "runs nowhere", not "runs on nightly only".test_stream_with_chunking_e2efrom #1302 is already stuck there. Moving these five into that category would delete coverage, not relocate it.Given that, mocked versions wouldn't close a CI gap either — the real tests already run there. Where they'd help: local
pytestruns without Ollama up (currently these five just get skipped), and a fast, deterministic failure instead of the retry-then-300s-timeout path on a stalled runner.One correction to my own root-cause writeup: it's not just the 5-minute keep-alive.
conftest.pyevicts all loaded models at every module boundary, so this file pays a cold load on its firstollamatest regardless of timing — worth knowing since it affects how much wall-clock the mocks actually buy back.So: yes to adding the mocked tests (the
asyncio.sleeppattern fromtest_streaming_tracing_integration.pyworks for the duration assertion), as additions alongside the real ones, not replacements. Assigning to you on that basis — let me know if that doesn't match what you had in mind.