Skip to content

Conversation

@MichaelAnders
Copy link
Contributor

Summary

  • Add ECONNREFUSED to retryable errors so connection-refused gets retried with backoff
  • Wrap invokeModel in try/catch returning structured 503 instead of raw TypeError bubbling to Express

Problem

When the Ollama provider was offline, the raw TypeError from the failed fetch crashed through to Express error middleware, producing an unhelpful 500 error. The retry client also didn't recognize ECONNREFUSED, so it failed immediately without retrying.

Changes

  • src/clients/retry.js: Added ECONNREFUSED to retryable errors list; added check for nested .cause.code since Node's undici wraps connection errors as TypeError
  • src/orchestrator/index.js: Wrapped invokeModel call in try/catch that detects connection errors and returns a structured 503 with provider_unreachable error type

Testing

  • Stopped Ollama, sent request → returns clean 503 with provider_unreachable
  • Previously: raw TypeError crash in Express middleware
  • Started Ollama back up → requests resume normally
  • ECONNREFUSED triggers backoff retries before returning 503
  • npm run test:unit passes with no regressions

Problem: When the Ollama provider was offline or unreachable, the raw TypeError
from the failed fetch bubbled up to the Express error middleware, producing an
unhelpful 500 error. The retry client also did not recognize ECONNREFUSED as a
retryable error, so connection-refused failures failed immediately without any
backoff attempt.

Changes implemented:

1. Add ECONNREFUSED to retryable errors (src/clients/retry.js)
   - Added ECONNREFUSED to the retryableErrors list alongside ECONNRESET, etc.
   - Added check for nested .cause.code on errors, since Node's undici wraps
     connection errors as TypeError with the actual code on .cause
   - Connection-refused errors now get retried with exponential backoff

2. Wrap invokeModel in try/catch (src/orchestrator/index.js)
   - Catches connection errors (ECONNREFUSED, fetch failed) from invokeModel
   - Returns a structured 503 response with provider_unreachable error type
   - Prevents raw TypeError from bubbling to Express error middleware
   - Non-connection errors are re-thrown unchanged

Testing:
- Stopped Ollama, sent a request: returns clean 503 with provider_unreachable
- Previously: raw TypeError crash in Express middleware
- Started Ollama back up: requests resume normally
- Retry behavior verified: ECONNREFUSED triggers backoff retries before 503
- npm run test:unit passes with no regressions
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