Skip to content

fix(ci): serialize ollama requests to prevent llama-server segfault cascade - #1381

Merged
ajbozarth merged 1 commit into
generative-computing:mainfrom
ajbozarth:fix/ollama-num-parallel-segfault
Jul 13, 2026
Merged

ajbozarth merged 1 commit into
generative-computing:mainfrom
ajbozarth:fix/ollama-num-parallel-segfault

Conversation

@ajbozarth

Copy link
Copy Markdown
Member

Issue

Fixes #

Description

CI's quality job intermittently fails with a cascade of ~56 ollama-dependent
test failures, all tracing to:

ollama._types.ResponseError: llama-server process has terminated: signal: segmentation fault (core dumped)

Root cause: the concurrent-request tests (test_async_parallel_requests,
test_multiple_asyncio_runs, etc.) make Ollama allocate multiple llama-server
runner slots at once. On memory-limited GitHub-hosted CPU runners this spikes
memory and segfaults llama.cpp. Because the whole job shares one ollama serve
(started once via nohup ollama serve &) and the only auto-retry is scoped to
ReadTimeout, a single segfault cascades across every remaining ollama test for
the rest of the run.

Fix: set OLLAMA_NUM_PARALLEL=1 so Ollama queues concurrent requests instead
of spawning parallel slots. The client still issues concurrent requests, so
mellea's async assertions are unchanged — Ollama just serializes execution
internally. Near-zero runtime cost; no model-reload churn.

Reviewer notes:

  • Observed on unpinned Ollama 0.31.2 (the installer is unpinned, so CI tracks
    latest — a recent Ollama/llama.cpp build likely explains the ~1–2 week onset).
  • Reserve levers if this doesn't fully resolve it: OLLAMA_MAX_LOADED_MODELS=1
    (adds model-reload cost) or pinning the Ollama version.

Testing

  • Tests added to the respective file if code was changed — N/A, CI config only
  • New code has 100% coverage if code was added — N/A
  • Ensure existing tests and github automation passes

Attribution

  • AI coding assistants used

Adding a new component, requirement, sampling strategy, or tool?

  • Component
  • Requirement
  • Sampling Strategy
  • Tool

…ascade

Concurrent-request tests made Ollama spawn multiple llama-server slots at
once, which segfaults under the memory limits of GitHub-hosted CPU runners.
A single segfault then cascaded across every remaining ollama-dependent test
because the shared `ollama serve` never recovered and the only auto-retry is
scoped to ReadTimeout.

Setting OLLAMA_NUM_PARALLEL=1 makes Ollama queue concurrent requests instead
of allocating parallel slots, removing the memory spike with no change to test
coverage or meaningful CI runtime.

Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <[email protected]>
@ajbozarth
ajbozarth requested a review from a team as a code owner July 13, 2026 17:26
@github-actions github-actions Bot added the bug Something isn't working label Jul 13, 2026
@ajbozarth ajbozarth self-assigned this Jul 13, 2026
@ajbozarth

Copy link
Copy Markdown
Member Author

I noticed CI was running into this flaky-ness on a handful of PRs last week and asked Claude to suggest a fix. Afaik this is a minimal fix and can be further addressed as outlined in the description, but that would increase runtime, unlike this fix

@AngeloDanducci AngeloDanducci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - noticed this happened once but if you've also seen it in parallel definitely worth addressing.

@ajbozarth
ajbozarth added this pull request to the merge queue Jul 13, 2026
Merged via the queue into generative-computing:main with commit 5a764c1 Jul 13, 2026
8 checks passed
@ajbozarth
ajbozarth deleted the fix/ollama-num-parallel-segfault branch July 13, 2026 18:35
ajbozarth added a commit to ajbozarth/mellea that referenced this pull request Jul 14, 2026
…gfault cascade (generative-computing#1381)" (generative-computing#1387)

This reverts commit 5a764c1.

Setting OLLAMA_NUM_PARALLEL=1 did not prevent the segfault cascade it was
meant to fix, and serializing all ollama requests roughly quadrupled CI
runtime by forcing every concurrent-request test to run sequentially.

Assisted-by: Claude Code

Signed-off-by: Alex Bozarth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants