Skip to content

fix(ollama): make retry loop actually retry all transient errors#872

Merged
starpit merged 1 commit into
IBM:mainfrom
starpit:fix/ollama-pull-retry
Feb 18, 2026
Merged

fix(ollama): make retry loop actually retry all transient errors#872
starpit merged 1 commit into
IBM:mainfrom
starpit:fix/ollama-pull-retry

Conversation

@starpit
Copy link
Copy Markdown
Member

@starpit starpit commented Feb 18, 2026

Summary

  • Fixed ollama_pull_if_needed retry loop where most error paths used ? operator to immediately return, bypassing all 5 retry attempts
  • Replaced blocking std::thread::sleep with async tokio::time::sleep to avoid stalling the tokio runtime (especially problematic in CI with single-threaded runtimes)
  • Made all transient errors (network failures, HTTP status errors, stream read errors, JSON parse errors, streaming "error" status) retryable with consistent 2s backoff
  • Fixed hardcoded delete endpoint URL to use api_base() instead

Test plan

  • Verify cargo check and cargo fmt pass (confirmed locally)
  • CI ollama pull tests no longer fail on transient network errors
  • Confirm "file does not exist" errors still fail immediately (not retried)

🤖 Generated with Claude Code

Most error paths in ollama_pull_if_needed used the ? operator which
immediately returned from the function, bypassing the retry loop entirely.
Only one specific PullResponse::Err case was actually retried.

- Replace ? operators with match arms that set last_err and continue
- Replace std::thread::sleep with tokio::time::sleep to avoid blocking
  the async runtime
- Make HTTP status errors retryable instead of returning immediately
- Make stream read errors and JSON parse errors retryable
- Make streaming "error" status retryable
- Move sleep to top of loop so all retry paths get the 2s backoff
- Use api_base() for delete endpoint instead of hardcoded URL

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Nick Mitchell <nickm@us.ibm.com>
@starpit starpit merged commit 28e64ef into IBM:main Feb 18, 2026
36 of 37 checks passed
@starpit starpit deleted the fix/ollama-pull-retry branch February 18, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant