ollama generators retry a 400 Bad Request forever, so a scan never finishes
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start with OllamaGenerator._call_model and OllamaGeneratorChat._call_model in the Ollama generator code, then read the existing 404 tests in tests/generators/test_ollama.py. Add mocked response coverage for the described 400, 401, 429 and 503 behavior. Done means rejected requests follow the proposed handling while transient errors still back off.
Written by the indexing model from the issue text.
Description
Steps to reproduce
Point the Ollama generator at a model that can't chat. An embedding model is enough, and needs nothing except a local Ollama:
ollama pull nomic-embed-text
python -m garak --target_type ollama --target_name nomic-embed-text \
--probes test.Blank --detectors always.Pass
Ollama answers every request with 400 "nomic-embed-text" does not support chat. The run never finishes and the terminal shows no error. garak.log keeps adding:
INFO HTTP Request: POST http://127.0.0.1:11434/api/chat "HTTP/1.1 400 Bad Request"
INFO Backing off _call_model(...) for 57.9s (garak.exception.GeneratorBackoffTrigger)
I stopped it after 150 s. By then it had retried 12 times, with the wait growing towards the 70 s cap.
I first hit this scanning a RAG server through its Ollama-compatible endpoint (LightRAG). That server returns 400 only for prompts it won't accept, such as ones that are too short. test.Test sends "" and "\\", so the scan stalled on its first prompt and never got to the rest.
Expected behavior
A 400 means the server rejected the request, and sending it again gets the same answer. The other generators already treat it that way:
openai:BadRequestErroris logged and the prompt gets[None]; 401/403 raiseGarakException; onlytransient_retry_codesback off.anthropic: only rate limit, connection, timeout and 5xx errors back off. The comment there says the other 4xx "would loop indefinitely if retried".rest: a 4xx raisesConnectionError, which is outside its backoff.litellmraisesBadGeneratorExceptiononBadRequestError.
Current behavior
OllamaGenerator._call_model and OllamaGeneratorChat._call_model turn every ollama.ResponseError except 404 into GeneratorBackoffTrigger. The backoff.on_exception around them has no max_tries or max_time, so a 400, 401 or 403 is retried forever.
I read #2141 and the "garak is tenacious" reasoning. I'm not asking for a retry limit, and transient errors should keep retrying. This is only about the server saying the request itself is wrong.
Proposed fix
Keep backing off on timeouts, 408, 429 and 5xx. For the rest, follow openai.py:
- 400: log it and return
[None]for that prompt, so one rejected prompt doesn't block the scan. - 401 / 403: raise
GarakExceptionwith a hint to checkOLLAMA_API_KEY. - 404 and other 4xx: raise, as 404 does today.
Tests would be respx mocks next to the existing 404 tests in tests/generators/test_ollama.py: a 400 returns [None] after a single request, a 401 raises, and 429 and 503 still back off. I'm happy to send the PR if this direction works for you.
garak version
main @ 67124f8d (v0.17.2.pre1)
Additional Information
- macOS
- Python 3.12
- Repository checkout,
uv pip install -e . - ollama Python client 0.6.3, local Ollama with
nomic-embed-textpulled - Command line flags only, as above
- Dominant language
- Python
- Stars
- 10.2k
- Forks
- 1.5k
- Avg merge
- 9d 20h
- Merged PRs (30d)
- 15
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/garak
-
tap: prune() drops the only on-topic branch when fewer than two survivePossibly taken @Rajratna-D claimed this 1 day ago. Openbug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NVIDIA/garak#2570 · 2 comments ·
Maintainers usually reply within 2 days
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 2 days
-
load_advbench() re-raises HTTPError as the bare class, so a failed download ends in a TypeErrorPossibly taken @sudonishant claimed this 4 days ago. Openneeds-triage
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Maintainers usually reply within 2 days
-
LangChain generator passes list-form message content into Message.text, so detectors never score the reply textPossibly taken @Varshith-Kali claimed this 9 days ago. Openneeds-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
NVIDIA/garak#2513 · 1 comment ·
Maintainers usually reply within 2 days
-
mistral: list-form message content (reasoning / tool-call replies) is passed to Message as a list, so reply text never reaches detectorsPossibly taken @Varshith-Kali claimed this 9 days ago. Openneeds-triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
NVIDIA/garak#2511 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TigreGotico/orthography2ipa#2950 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Unstructured-IO/unstructured#4876 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
openfoodfacts/openfoodfacts-python#579 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
fairagro/m4.2_sql_to_arc#388 ·
Maintainers usually reply within 1 day