Skip to content

feat(config): configurable LLM request timeout#134

Merged
KylinMountain merged 5 commits into
mainfrom
feat/configurable-llm-timeout
Jun 23, 2026
Merged

feat(config): configurable LLM request timeout#134
KylinMountain merged 5 commits into
mainfrom
feat/configurable-llm-timeout

Conversation

@KylinMountain

Copy link
Copy Markdown
Collaborator

Summary

Adds an optional timeout: config key (seconds), forwarded to LiteLLM's timeout on all of OpenKB's own LLM calls. LiteLLM applies a 600s per-request timeout by default, which slow local backends (e.g. Ollama on large inputs) exceed, raising litellm.Timeout — see #132.

# .openkb/config.yaml
timeout: 1200

What changed

  • config: resolve_timeout() validates a finite positive number of seconds (rejects bool / nan / inf / non-numeric); set_timeout() / get_timeout() stash it process-wide, mirroring the existing extra_headers mechanism.
  • compile path: _llm_call / _llm_call_async forward the timeout, without overriding an explicit per-call value.
  • agent paths (query, chat, lint, skill): forwarded via ModelSettings(extra_args={"timeout": ...}), the way extra_headers already reaches them.
  • cli: _setup_llm_key resolves + applies it from .openkb/config.yaml.
  • docs: README documents the key and notes that PageIndex long-document indexing manages its own timeout and is not affected.

Test plan

  • tests/test_config.py — resolver cases incl. nan/inf/bool/non-numeric rejection.
  • tests/test_llm_timeout.py — timeout forwarded / omitted / not-overridden, sync and async.
  • tests/test_cli.py — config → stash wiring + reset-when-absent.
  • tests/test_query.py — agent-path extra_args coverage.
  • Full suite: 824 passed. (The 4 tests/test_url_ingest.py failures are a pre-existing local-env issue — trafilatura not installed — and are unrelated to this change.)

Refs #132. Covers OpenKB's own calls; PageIndex's internal LLM calls hardcode their request and would need an upstream change to honor this.

Add an optional `timeout:` config key, forwarded to LiteLLM's `timeout`
parameter on OpenKB's own LLM calls. LiteLLM defaults to a 600s per-request
timeout, which slow local backends (e.g. Ollama on large inputs) can exceed,
raising `litellm.Timeout`.

- config: resolve_timeout() validates a positive number of seconds;
  set_timeout()/get_timeout() stash it process-wide (mirrors extra_headers)
- compiler: _llm_call / _llm_call_async forward the configured timeout,
  without overriding an explicit per-call value
- cli: _setup_llm_key resolves + applies it from .openkb/config.yaml
- tests + README

Refs #132. The PageIndex long-doc path hardcodes its own litellm calls and
is unaffected by this (covering it would need an upstream pageindex change).
Addresses self-review of the configurable LLM timeout:

- resolve_timeout(): reject non-finite values (nan/inf, including YAML's
  `.nan`/`.inf`) via math.isfinite — they slipped past the `<= 0` guard and
  would reach litellm as a bogus timeout (hang on nan, OverflowError on inf).
- Extend the configured timeout to the openai-agents paths (query, chat,
  lint, skill) via ModelSettings(extra_args={"timeout": ...}), the way
  extra_headers already reaches them. Previously only the compiler calls
  honored it, so `openkb chat`/`query`/`lint`/`skill` still hit LiteLLM's 600s.
- Tests: nan/inf rejection; async omit/override symmetry; cli wiring
  (config -> stash + reset-when-absent); query-agent extra_args coverage.
- README: note the broadened coverage and that PageIndex indexing is exempt.
- README: list `timeout` in the main config.yaml example (marked optional)
  instead of a separate advanced-options paragraph
- config: shorten the resolve_timeout / _runtime_timeout /
  get_timeout_extra_args comments
@KylinMountain KylinMountain merged commit 840f2b7 into main Jun 23, 2026
1 check passed
@KylinMountain KylinMountain deleted the feat/configurable-llm-timeout branch June 25, 2026 23:08
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.

1 participant