Skip to content

fix(python-sdk): classify evaluation type connection timeouts - #2013

Open
gtdd123 wants to merge 1 commit into
openlit:mainfrom
gtdd123:fix/eval-types-connect-timeout
Open

gtdd123 wants to merge 1 commit into
openlit:mainfrom
gtdd123:fix/eval-types-connect-timeout

Conversation

@gtdd123

@gtdd123 gtdd123 commented Nov 25, 2026 •

Copy link
Copy Markdown

Issue number: Fixes #2012

Change description:

requests.exceptions.ConnectTimeout is both a timeout and a connection error. Try the timeout handler first so openlit.get_eval_types() raises TimeoutError for either a connection timeout or a read timeout. Ordinary connection errors still raise ConnectionError.

The public-API regression reproduced the connection timeout misclassification before the fix. All 87 offline evaluation, score logging, and environment configuration tests passed after it. Pylint passed on all changed Python files. poetry check and poetry build passed, with existing metadata deprecation warnings.

Codex assisted with the investigation, implementation, tests, and drafting. Validation used mocked requests and local test data.

Checklist

  • PR title follows Conventional Commit format.
  • I have reviewed the contributing guidelines.
  • I checked for other open pull requests for this change.
  • I performed a self-review of the diff.
  • Changes have been tested.
  • Changes are documented in the public SDK docstring.

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

Summary by Sourcery

Correct evaluation type timeout classification in the Python SDK.

Bug Fixes:

  • Classify connection and read timeouts consistently as TimeoutError when fetching evaluation types, while preserving ConnectionError for other connection failures.

Enhancements:

  • Document the timeout behavior of the public get_eval_types API.

Tests:

  • Add coverage verifying that both connection and read timeouts raise TimeoutError and preserve the underlying exception.

@gtdd123
gtdd123 requested review from a team and ishanjainn as code owners November 25, 2026 05:59
@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

API

Document the public timeout behavior of get_eval_types alongside its public docstring.

  • sdk/python/src/openlit/__init__.py L749-750

Implementation

Handle requests timeouts before connection errors so connection timeouts are classified as TimeoutError while ordinary connection errors retain ConnectionError.

  • sdk/python/src/openlit/evals/offline.py L357 (removed lines), L361-364

Tests

Add public-API regression coverage confirming connect and read timeouts raise TimeoutError and preserve the original exception as the cause.

  • sdk/python/tests/test_offline_eval.py L564-582

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix evaluation-type connection timeout classification

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 Less than 10 minutes

Grey Divider

AI Description

• Classify connection and read timeouts as TimeoutError while preserving ConnectionError for
 other connection failures.
• Document the public timeout behavior and test both timeout types through
 openlit.get_eval_types().
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed behavior is the SDK's end-to-end operation for fetching available evaluation types from the OpenLIT server.
  • The public wrapper delegates directly to fetch_eval_types, so the wrapper and HTTP implementation are one bounded capability rather than separate capabilities.
  • No independent downstream production behavior is evidenced in this repository.
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before, the ConnectionError handler appeared before the Timeout handler, so timeout subclasses with ConnectionError ancestry could be classified differently from other timeout subclasses.
  • After, the Timeout handler precedes ConnectionError, making both connection and read timeout cases satisfy the public TimeoutError contract.
  • The new correctness condition is that exception-subclass precedence must preserve the intended public mapping for each supported requests timeout type.
  • This is a small compatibility-case change, not a new algorithm, concurrency protocol, persistent invariant, or multi-capability interaction.
Potential damage 🟢 Low 🩹 Reversible

  • When activated by a request timeout, callers now receive TimeoutError for both connection and read timeout cases.
  • A caller that specifically relied on the former ConnectTimeout-to-ConnectionError classification could require updated exception handling, but the operation has no indicated persistent write, state mutation, or external side effect.
  • Recovery is available by handling TimeoutError and retrying or reissuing the metadata request; reverting the code restores the prior exception contract, while already-running caller code may still need compatible handling.
  • Recoverable through caller exception handling and retry/re-request.
  • No persistent state repair or external compensation is required.
Assessed commit 61c5a41
Diagram

graph TD
  A["SDK caller"] --> B["get_eval_types"] --> C["fetch_eval_types"] --> D["requests.get"] --> E{"Timeout?"} -->|yes| F["TimeoutError"]
  E -->|other connection error| G["ConnectionError"]
Loading
High-Level Assessment

Keep the existing exception translation and check the more specific timeout category first. This corrects the overlapping ConnectTimeout classification without changing the public API or unrelated request handling.

Files changed (3) +25 / -4

Bug fix (1) +4 / -4
offline.pyHandle timeouts before connection errors +4/-4

Handle timeouts before connection errors

• Moves the timeout handler ahead of the connection-error handler so 'ConnectTimeout' raises 'TimeoutError'. Other connection errors continue to raise 'ConnectionError'.

sdk/python/src/openlit/evals/offline.py

Tests (1) +19 / -0
test_offline_eval.pyCover both timeout types through the public API +19/-0

Cover both timeout types through the public API

• Adds a parameterized test for 'ConnectTimeout' and 'ReadTimeout' through 'get_eval_types()', checking the public exception type and preserved cause.

sdk/python/tests/test_offline_eval.py

Documentation (1) +2 / -0
__init__.pyDocument timeout behavior on the public API +2/-0

Document timeout behavior on the public API

• The 'get_eval_types()' docstring now states that connection and response-read timeouts raise 'TimeoutError'.

sdk/python/src/openlit/init.py

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit 61c5a41

#2012 Bug: get_eval_types raises ConnectionError on a connection timeout · 2 of 2 met

# Requirement Status Notes
1 Both connection and read timeouts raise TimeoutError. ✅ Met The timeout handler now precedes the connection-error handler, and the public-API test covers ConnectTimeout and ReadTimeout.
2 A non-timeout connection failure still raises ConnectionError. ✅ Met ConnectionError is still handled separately after the timeout handler, and the existing test checks a connection refusal.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch was previously deployed

1 inactive deployment
release-notes — 61c5a414 Deployed Nov 25, 2026 by gtdd123 via Normalize / Conventional title #904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: get_eval_types raises ConnectionError on a connection timeout

1 participant