Skip to content

Add transport worker factory and abstract base class for background worker #4580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: srothh/transport-class-hierarchy
Choose a base branch
from

Conversation

srothh
Copy link
Member

@srothh srothh commented Jul 14, 2025

Add a new abstract base class for the background worker implementations in the transport. This allows for implementation of the upcoming async task-based worker in addition to the current thread based worker used in the sync context. Additionally, add a factory method in the HttpTransportCore shared class, to allow the worker methods to live higher up in the class hierarchy regardless of specific implementation.

GH-4578

Copy link

codecov bot commented Jul 14, 2025

❌ 54 Tests Failed:

Tests completed Failed Passed Skipped
21100 54 21046 1098
View the top 3 failed test(s) by shortest run time
tests.integrations.huggingface_hub.test_huggingface_hub::test_bad_chat_completion
Stack Traces | 0.122s run time
.../integrations/huggingface_hub/test_huggingface_hub.py:149: in test_bad_chat_completion
    client.text_generation(prompt="hello")
sentry_sdk/integrations/huggingface_hub.py:84: in new_text_generation
    raise e from None
sentry_sdk/integrations/huggingface_hub.py:80: in new_text_generation
    res = f(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../huggingface_hub/inference/_client.py:2297: in text_generation
    request_parameters = provider_helper.prepare_request(
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/_common.py:93: in prepare_request
    provider_mapping_info = self._prepare_mapping_info(model)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/hf_inference.py:38: in _prepare_mapping_info
    _check_supported_task(model_id, self.task)
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/hf_inference.py:187: in _check_supported_task
    raise ValueError(
E   ValueError: Model 'mistralai/Mistral-Nemo-Instruct-2407' doesn't support task 'text-generation'. Supported tasks: 'None', got: 'text-generation'
tests.integrations.huggingface_hub.test_huggingface_hub::test_streaming_chat_completion[False-False-True]
Stack Traces | 0.129s run time
.../integrations/huggingface_hub/test_huggingface_hub.py:112: in test_streaming_chat_completion
    client.text_generation(
sentry_sdk/integrations/huggingface_hub.py:84: in new_text_generation
    raise e from None
sentry_sdk/integrations/huggingface_hub.py:80: in new_text_generation
    res = f(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../huggingface_hub/inference/_client.py:2297: in text_generation
    request_parameters = provider_helper.prepare_request(
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/_common.py:93: in prepare_request
    provider_mapping_info = self._prepare_mapping_info(model)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/hf_inference.py:38: in _prepare_mapping_info
    _check_supported_task(model_id, self.task)
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/hf_inference.py:187: in _check_supported_task
    raise ValueError(
E   ValueError: Model 'mistralai/Mistral-Nemo-Instruct-2407' doesn't support task 'text-generation'. Supported tasks: 'None', got: 'text-generation'
tests.integrations.huggingface_hub.test_huggingface_hub::test_streaming_chat_completion[False-True-False]
Stack Traces | 0.129s run time
.../integrations/huggingface_hub/test_huggingface_hub.py:112: in test_streaming_chat_completion
    client.text_generation(
sentry_sdk/integrations/huggingface_hub.py:84: in new_text_generation
    raise e from None
sentry_sdk/integrations/huggingface_hub.py:80: in new_text_generation
    res = f(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../huggingface_hub/inference/_client.py:2297: in text_generation
    request_parameters = provider_helper.prepare_request(
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/_common.py:93: in prepare_request
    provider_mapping_info = self._prepare_mapping_info(model)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/hf_inference.py:38: in _prepare_mapping_info
    _check_supported_task(model_id, self.task)
.tox/py3.12-huggingface_hub-v0.33.4/lib/python3.12.../inference/_providers/hf_inference.py:187: in _check_supported_task
    raise ValueError(
E   ValueError: Model 'mistralai/Mistral-Nemo-Instruct-2407' doesn't support task 'text-generation'. Supported tasks: 'None', got: 'text-generation'

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@srothh
Copy link
Member Author

srothh commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 78.26087% with 5 lines in your changes missing coverage. Please review.

Project coverage is 84.90%. Comparing base (fe27100) to head (a6be4a3).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/worker.py 73.68% 5 Missing ⚠️
Additional details and impacted files

The uncovered lines of code here are just the pass calls from the abstract class definition.

@srothh srothh force-pushed the srothh/transport-class-hierarchy branch from 53b92f2 to 3607d44 Compare July 21, 2025 09:48
@srothh srothh force-pushed the srothh/worker-class-hierarchy branch from 1261319 to 2896602 Compare July 21, 2025 09:58
srothh added 5 commits July 23, 2025 16:01
Add an abstract bass class for implementation of the background worker. This was done to provide a shared interface for the current
implementation of a threaded worker in the sync context as well as the upcoming async task-based worker implementation.

GH-4578
Add a new factory method instead of direct instatiation of the threaded background worker.
This allows for easy extension to other types of workers, such as the upcoming task-based async worker.

GH-4578
Add a new flush_async method to worker ABC. This is necessary because the async transport cannot use a
synchronous blocking flush.

GH-4578
Move the flush_async down to the concrete subclass to not break existing testing. This makes sense,
as this will only really be needed by the async worker anyway and therefore is not shared logic.

GH-4578
Coroutines have a return value, however the current function signature for the worker methods does not
accomodate for this. Therefore, this signature was changed.

GH-4578
@srothh srothh force-pushed the srothh/worker-class-hierarchy branch from 2896602 to 268ea1a Compare July 23, 2025 14:02
@srothh srothh marked this pull request as ready for review July 24, 2025 07:49
@srothh srothh requested a review from a team as a code owner July 24, 2025 07:49
Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

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

If you add some docstrings, this is fine to merg!

@property
@abstractmethod
def is_alive(self) -> bool:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Please add docstrings to all methods in the new abstract worker class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, thanks!

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.

2 participants