Skip to content

fix: fold Ollama's timeout-kwarg handling into the provider confi - #220

Open
Mr-Neutr0n wants to merge 3 commits into
Finntegrate:mainfrom
Mr-Neutr0n:agent/issue-164-fold-ollamas-timeout-kw
Open

Mr-Neutr0n wants to merge 3 commits into
Finntegrate:mainfrom
Mr-Neutr0n:agent/issue-164-fold-ollamas-timeout-kw

Conversation

@Mr-Neutr0n

@Mr-Neutr0n Mr-Neutr0n commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #164

Folded Ollama's timeout-kwarg quirk into the ProviderConfig table via a new timeout_kwarg field and an apply_timeout helper in backend/app/services/llm_providers.py, and made build_chat_model in backend/app/services/chat_model.py read the wiring from the table instead of comparing against the removed _OLLAMA_PROVIDER constant. Behaviour is unchanged, including the fallback to the plain top-level timeout kwarg for a provider with no table entry. New tests in backend/tests/services/test_llm_providers.py.

Verification: uv run --directory backend pytest (as CONTRIBUTING.md documents) — 300 passed. The earlier "No local test suite detected" note was wrong: backend/, crawler/, ingest/ and register/ each have a suite and there are mise run test:* tasks.


This change was prepared with AI assistance under human direction and review.

Summary by CodeRabbit

  • Bug Fixes
    • Timeout settings are now applied using the format expected by each AI provider, including providers that require timeout settings to be nested. This helps ensure configured time limits are respected across supported providers.
    • A default timeout format is used when no provider-specific configuration is available.

…ovider confi

Signed-off-by: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1be557f7-834d-41e2-b925-58620b5b452c
Commits

Reviewing files that changed from the base of the PR and between 9c19734 and da3a5a9.

Files selected for processing: 3
  • backend/app/services/chat_model.py
  • backend/app/services/llm_providers.py
  • backend/tests/services/test_llm_providers.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Provider timeout handling now uses a shared helper and provider configuration. Chat model construction delegates timeout argument setup to that helper, which supports top-level and nested client_kwargs timeout arguments.

Changes: Provider timeout handling

Layer / File(s) Summary
Configure provider timeout arguments
backend/app/services/llm_providers.py, backend/tests/services/test_llm_providers.py
ProviderConfig now specifies the timeout argument location. apply_timeout uses that setting, defaults to the top-level timeout argument when no provider is configured, and has tests for both argument shapes.
Apply provider timeout configuration
backend/app/services/chat_model.py
build_chat_model now calls apply_timeout instead of handling Ollama timeouts in a provider-specific branch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: brylie

Merge Risk: Minimal · up to da3a5

Ollama timeout handling is preserved; no merge-blocking issue was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately identifies the main change: moving Ollama timeout-kwarg handling into provider configuration. The final word is truncated, but the intended change remains clear.
Linked Issues check Passed [#164] The three checklist items are implemented.

1. Field added: ProviderConfig.timeout_kwarg: str | None = DEFAULT_TIMEOUT_KWARG ("timeout") in backend/app/services/llm_providers.py. The `oll…
Out of Scope Changes check Passed All changed source hunks map to #164.

- llm_providers.py: DEFAULT_TIMEOUT_KWARG, the timeout_kwarg field and its comments, the ollama table entry, and apply_timeout implement the requested …
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

[#164] The three checklist items are implemented.

  1. Field added: ProviderConfig.timeout_kwarg: str | None = DEFAULT_TIMEOUT_KWARG ("timeout") in backend/app/services/llm_providers.py. The ollama entry sets timeout_kwarg=None, which means nested under client_kwargs. Openai and anthropic use the default top-level timeout.
  2. build_chat_model in backend/app/services/chat_model.py now calls apply_timeout(provider, kwargs, timeout) where provider = PROVIDERS.get(provider_name). The _OLLAMA_PROVIDER constant and the provider_name == _OLLAMA_PROVIDER comparison are removed from that file.
  3. Behavior is preserved, checked by code reading of the diff:
    • ollama: provider.timeout_kwarg is None, so kwargs["client_kwargs"] = {"timeout": timeout}. Same as before.
    • openai and anthropic: timeout_kwarg == "timeout", so kwargs["timeout"] = timeout. Same as before.
    • Provider with no table entry: provider is None, so the default "timeout" applies. Same as before.

The new tests in backend/tests/services/test_llm_providers.py cover apply_timeout. I did not read that test file directly. Its existence and the 300-pass result come from the PR description, not from my own run. This does not change the verdict, because the requirement is structural and the code paths above are established from source.

Full details: Out of Scope Changes check

Explanation

All changed source hunks map to #164.

  • llm_providers.py: DEFAULT_TIMEOUT_KWARG, the timeout_kwarg field and its comments, the ollama table entry, and apply_timeout implement the requested table-driven timeout wiring. The module docstring addition references the same issue.
  • chat_model.py: the import of apply_timeout, the removal of _OLLAMA_PROVIDER, and the replacement branch in build_chat_model implement the requested refactor.
  • test_llm_providers.py: tests for the new helper support the objective.

No unrelated behavior change appears in the reviewed hunks. The PR description's notes about test suites and mise tasks document the author's verification. They do not add code changes.

Unresolved: I did not search the wider repository for other imports of the removed _OLLAMA_PROVIDER constant. The removal is in scope, and the PR reports a passing suite, so I found no evidence of a problem.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

CI Results

Service Check Result
crawler ruff (lint) ✅ Passed
crawler mypy ✅ Passed
crawler pyrefly ✅ Passed
crawler pytest + coverage ✅ Passed
ingest ruff (lint) ✅ Passed
ingest mypy ✅ Passed
ingest pyrefly ✅ Passed
ingest pytest + coverage ✅ Passed
register ruff (lint) ✅ Passed
register mypy ✅ Passed
register pyrefly ✅ Passed
register pytest + coverage ✅ Passed
backend ruff (lint) ✅ Passed
backend mypy ✅ Passed
backend pyrefly ✅ Passed
backend pytest + coverage ✅ Passed
app lint (eslint + prettier) ✅ Passed

All checks passed. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fold Ollama's timeout-kwarg handling into the provider config table

2 participants