crw icon indicating copy to clipboard operation
crw copied to clipboard

JSON-schema extraction always times out on content-heavy pages: hardcoded, non-configurable 60s LLM_REQUEST_TIMEOUT

Open norci opened this issue 1 month ago • 3 comments

Environment

  • Self-hosted ghcr.io/us/crw:latest (docker, network_mode: host)
  • [extraction.llm] backed by a local llama.cpp server (provider = "openai-compatible", 127.0.0.1:8070)

Symptoms

Extract jobs with a jsonSchema reliably fail on large pages, and the client only sees a stripped error:

Extraction error: OpenAI API request failed: error sending request

The llama-server side shows the provider request being disconnected by the client exactly 60.00s after dispatch (reproduced 3 independent times in the same window; every disconnect was exactly 60.00s):

10:18:50 ... slot launch_slot_: id 3 | task 0 | processing task
10:19:50 ... srv stop: cancel task, id_task = 0      ← exactly 60.00s after launch
10:19:59 ... slot launch_slot_: id 2 | task 3261     ← the same job's other URL
10:20:30 ... task 3261 total time = 30.9s            ← the list page finished in 30.9s, succeeded

Root cause

crates/crw-extract/src/structured.rs:13:

pub(crate) const LLM_REQUEST_TIMEOUT: Duration = Duration::from_secs(60);
  • A compile-time constant for the JSON-schema extraction path; the whole operation (retries included) shares this budget (structured.rs:259-268)
  • Only basis mode gets BASIS_REQUEST_TIMEOUT = 300s (structured.rs:20-24, :248-251)
  • Timeouts are deliberately not retried (llm.rs:119-121 — a reasonable default for the per-call-billed managed offering, but it leaves self-hosters with no escape hatch)
  • config.rs / docs/docs/configuration.md / the env-var table have no timeout option: [search] has a configurable timeout_ms, [extraction.llm] does not

Token math for this failure: prefill of 21,283 tokens ≈ 10.6s (after the 100KB max_html_bytes truncation), generation at ~66 t/s — the 60s budget minus prefill leaves ~49s ≈ 3,200 output tokens. A portal homepage's item count easily exceeds that, so it times out every time; the same job's smaller list page finished in 30.9s, producing the "one URL succeeded, one failed" illusion.

Impact

  • Self-hosted + a small local model (~66 t/s generation): the "big prompt + long output" combination cannot finish within 60s, and the client-side error is stripped down to "error sending request", which is hard to self-diagnose
  • Basis mode's 300s is the only escape path, but it requires the schema to have ≥ 1 top-level scalar leaf (evidence is emitted per top-level scalar property only, basis.rs:133-141); a purely nested schema such as { news: [ { title, ... } ] } is rejected by the preflight outright, so it cannot use it

Suggestions

  1. Add [extraction.llm] timeout_ms (env: CRW_EXTRACTION__LLM__TIMEOUT_MS), mirroring how [search].timeout_ms works;
  2. Or scale the budget per request (larger prompt tokens / max_tokens → longer budget) — there is already a precedent in the code (leg.max_tokens = leg.max_tokens.min(60 + 60 * n), structured.rs:240);
  3. Or at minimum document in the configuration docs that basis mode (300s) is the only long-budget path, along with its top-level-scalar-leaf precondition.

norci avatar Oct 09 '26 05:10 norci

hey @norci thanks for detailed report, will check it soon!

us avatar Oct 09 '26 21:10 us

thanks @norci, the exact 60.00s disconnect in the llama-server log made this easy to pin down.

fixed in #635: a new [extraction.llm] timeout_ms (env CRW_EXTRACTION__LLM__TIMEOUT_MS), default 60000, so nothing changes unless you set it.

[extraction.llm]
timeout_ms = 240000
  • it covers JSON-schema extraction on every transport, the schema-validation retry included; basis mode keeps at least 300000
  • a timeout now reads timed out after 60s (raise [extraction.llm] timeout_ms for slower models) instead of error sending request
  • synchronous /v1/scrape is also capped by [server] request_timeout_secs; if you go past ~300s, raise that too

it ships in v0.38.0, closing this one.

us avatar Oct 20 '26 21:10 us

I use v 0.44 and the issue is still reproducible

CRW_EXTRACTION__LLM__API_KEY: x
CRW_EXTRACTION__LLM__PROVIDER: openai-compatible
CRW_EXTRACTION__LLM__MODEL: task/gemma4-E4B
CRW_EXTRACTION__LLM__BASE_URL: http://models.test-ai.home/v1
CRW_EXTRACTION__LLM__TIMEOUT_MS: 240000

Here is the request log from the LLM backend. 499 statuses are perfromed from crawler. 200 statuses are the manual checks that model is OK

Снимок экрана_20261113_123541

Please, reopen

constgen avatar Nov 13 '26 10:11 constgen