Skip to content

fix(providers): report provider timeouts as REQUEST_TIMEOUT in every adapter - #317

Merged
nathanschmid08 merged 1 commit into
Open-Glassbeetle:mainfrom
nova-loop:fix/316-timeout-504
Nov 12, 2026
Merged

nathanschmid08 merged 1 commit into
Open-Glassbeetle:mainfrom
nova-loop:fix/316-timeout-504

Conversation

@nova-loop

Copy link
Copy Markdown
Contributor

What changed

A provider timeout is now RequestTimeoutError (REQUEST_TIMEOUT, 504) in all four adapters, not just Anthropic. This follows the issue's suggested fix:

  • openai: the timedOut branch in executeFetch throws RequestTimeoutError instead of ProviderUnavailableError. It's the one-word swap plus the import.
  • google: executeFetch has a timedOut flag now. The timer sets it, and the catch checks it before the cancellation branch, so the abort reason's shape no longer decides how the error is classified. The timer still aborts with its descriptive Error reason. The new message is Request to Google Gemini timed out after <n>ms.
  • ollama: there's a generationTimedOut flag next to connectTimedOut. A generation timeout throws RequestTimeoutError (Ollama generation timed out after <n>ms). The connect timeout is unchanged: it is still ProviderUnavailableError with the "Ollama is not running at … ollama serve" message. Caller cancellation is checked first, as before.
  • I also added the small guard the issue mentions in ollama.adapter.ts handleErrorResponse. body.error is only used when it is a string, so an object-shaped error no longer makes mapError throw a TypeError. The status-based mapping applies instead (e.g. 404 → MODEL_NOT_FOUND).

Why

Closes #316

503 tells the user the provider is not there. 504 tells them it is there but didn't finish in time. Before this change, which one you got for the same timeout depended on the provider you had picked.

How it was tested

  • I wrote the new and updated tests first and ran them against the old adapters. All 4 failed, then passed after the change:
    • openai: the existing "fails fast within timeout when an unreachable local server hangs" test asserted ProviderUnavailableError, which is the behaviour the issue describes as wrong. It now asserts RequestTimeoutError with code REQUEST_TIMEOUT and statusCode 504.
    • google: a new Timeouts block. A hanging fetch with timeoutMs: 30 gives RequestTimeoutError/504. A second test checks that a caller abort is still RequestAbortedError.
    • ollama: a generation timeout (generationTimeoutMs: 25) gives RequestTimeoutError/504. The existing connect-timeout test now also asserts PROVIDER_UNAVAILABLE/503. There's also a non-Ollama-shaped 404 body ({"error":{"message":…}}) → ModelNotFoundError test.
    • The hanging-fetch mocks reject with init.signal.reason, as real fetch does when aborted with a reason. That is the path Google's classification used to depend on.
  • npm run lint -w @glassbeetle/api (oxlint): clean.
  • npx vitest run in apps/api: 119 files, 1897 tests pass. The e2e config (vitest.config.e2e.ts): 25 files, 822 tests pass.
  • tsc -p tsconfig.build.json --noEmit for the API: clean. I did not run the root npm run build for the web/desktop workspaces, since nothing there changed.
  • Prettier: the four touched Google/Ollama files already fail prettier --check on main (The format check has never run in CI, and 92 committed files no longer pass it #246). I kept the new lines formatted and did not reformat the rest of those files, to keep the diff focused.

Anything left out, or worth a second opinion

  • In the Ollama adapter, isConnected only becomes true when fetch resolves, i.e. when response headers arrive, and both timers are cleared at that point. With the defaults (connect 5 s, generation 300 s), a request still waiting for headers hits the connect timer first. So the generation timer only wins when it is set shorter than the connect timer, which is what the new test does. I didn't change the timer semantics, since that is outside this issue. It might be worth checking whether a non-streaming complete() against a slow local model (Ollama sends headers only when generation finishes) gets cut off at 5 s.
  • I did not change the issue's "checked, not a problem" items: the time-to-headers timeout for streams, and the Ollama status ladder.

Checklist

  • npm run lint -w @glassbeetle/api passes (API changes)
  • npm test passes (API unit + e2e suites; see above)
  • npm run build passes (only the API tsc build was run)
  • Tests cover the change — failing-first tests for each adapter
  • Docs updated if behaviour or a convention changed (no docs describe per-adapter timeout codes; http-mapping.ts already documents 503 vs 504)
  • The linked issue's acceptance criteria are met, or the gaps are named above

AI assistance

This change was prepared with AI assistance. An AI coding assistant wrote the code and tests from the issue. I reviewed the diff and ran the checks listed above before opening the PR.

…adapter

OpenAI, Google and Ollama (generation timer) now throw RequestTimeoutError
(504) when their own timer fires, like Anthropic already does. The Ollama
connect timeout stays ProviderUnavailableError (503).

Also guard Ollama's error-body parsing against a non-string `error`.

Closes Open-Glassbeetle#316
@nathanschmid08

Copy link
Copy Markdown
Contributor

Hi @nova-loop , Thanks for the PR. I really appreciate it.

I just finished reviewing everything and it looks really good, therefore I will merge it now.

Thanks again and have a great day!

@nathanschmid08
nathanschmid08 merged commit a937251 into Open-Glassbeetle:main Nov 12, 2026
4 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.

A provider timeout is a 504 from one adapter and a 503 from the other three

2 participants