ollama - ✅(Solved) Fix server: stabilize TestSchedExpireRunner timeout [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#16011Fetched 2026-05-07 03:31:44
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
cross-referenced ×1labeled ×1

Error Message

The TestSchedExpireRunner test is frequently flaky in CI environments, especially on Windows and macOS runners. The test fails with the error message expected model to be unloaded, which indicates that a model remains in the scheduler's memory instead of being correctly expired and unloaded.

Root Cause

Technical Analysis

The issue is caused by a very aggressive context timeout of 20ms used in the test setup. In virtualized CI environments, the time needed to initialize the scheduler and process the asynchronous model unloading often exceeds this narrow window.

Fix Action

Fixed

PR fix notes

PR #16012: server: stabilize flaky TestSchedExpireRunner

Description (problem / solution / changelog)

Stabilizes the TestSchedExpireRunner test, which is currently flaky in CI environments (Windows/macOS).

Problem

The test uses a hardcoded 20ms context timeout. On slow CI runners, this window often expires before the scheduler can process the model unload signal, causing the test to fail with expected model to be unloaded.

Solution

Updated the test to run the scheduler's completion loop in the background and implemented a polling mechanism with a 1s timeout. This ensures the test is:

  1. Fast: Completes as soon as the model is unloaded (typically ~10ms locally).
  2. Stable: Provides a sufficient buffer for slower virtualized environments.

Fixes #16011

Changed files

  • server/sched_test.go (modified, +17/-8)

Code Example

time=2026-05-06T12:51:27.651Z level=DEBUG msg="shutting down scheduler completed loop"
time=2026-05-06T12:51:27.651Z level=DEBUG msg="context for request finished"
--- FAIL: TestSchedExpireRunner (0.04s)
    sched_test.go:597: expected model to be unloaded
RAW_BUFFERClick to expand / collapse

What is the issue?

The TestSchedExpireRunner test is frequently flaky in CI environments, especially on Windows and macOS runners. The test fails with the error message expected model to be unloaded, which indicates that a model remains in the scheduler's memory instead of being correctly expired and unloaded.

Technical Analysis

The issue is caused by a very aggressive context timeout of 20ms used in the test setup. In virtualized CI environments, the time needed to initialize the scheduler and process the asynchronous model unloading often exceeds this narrow window.

Logs from failed CI runs show the following debug message: level=DEBUG msg="shutting down scheduler completed loop"

This confirms that the scheduler's background loop is exiting prematurely because the context has timed out. When the loop shuts down too early, it misses the signal to process the finished request and unload the model. As a result, the model stays in the internal "loaded" map, causing the test's final assertion to fail.

Example of failure: https://github.com/ollama/ollama/actions/runs/25435750600/job/74613160524?pr=16001

Relevant log output

time=2026-05-06T12:51:27.651Z level=DEBUG msg="shutting down scheduler completed loop"
time=2026-05-06T12:51:27.651Z level=DEBUG msg="context for request finished"
--- FAIL: TestSchedExpireRunner (0.04s)
    sched_test.go:597: expected model to be unloaded

OS

No response

GPU

No response

CPU

No response

Ollama version

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

ollama - ✅(Solved) Fix server: stabilize TestSchedExpireRunner timeout [1 pull requests, 1 participants]