Repository navigation
Fix max_retries=0, wait timeouts, run_many retries and partial failures, input encoding #89
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
jadenfix
wants to merge
8
commits into
roe-ai:main
Choose a base branch
from
jadenfix:fix/correctness
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−20
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dd9cdeb
Respect max_retries=0 in RoeConfig.from_env
jadenfix 69d1084
Stop Job.wait and JobBatch.wait from sleeping past the timeout
jadenfix 44918ae
Close files opened for FileUpload(path=...) agent inputs
jadenfix cef3ed5
Send the package version in the User-Agent header
jadenfix efc1fa5
Fail JobBatch.wait when the status response omits a job
jadenfix 338a429
Don't retry run_many batch submissions
jadenfix 76cb07d
Keep earlier job IDs when a run_many chunk fails
jadenfix e5e5e43
Send dict and list agent inputs as JSON in multipart runs
jadenfix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import roe | ||
| from roe.auth import RoeAuth | ||
| from roe.config import RoeConfig | ||
|
|
||
|
|
||
| def test_user_agent_uses_package_version(): | ||
| auth = RoeAuth(RoeConfig(api_key="key", organization_id="org")) | ||
|
|
||
| assert auth.get_headers()["User-Agent"] == f"roe-python/{roe.__version__}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from roe.config import RoeConfig | ||
|
|
||
|
|
||
| def test_max_retries_zero_is_respected(monkeypatch): | ||
| monkeypatch.setenv("ROE_MAX_RETRIES", "5") | ||
| config = RoeConfig.from_env(api_key="key", organization_id="org", max_retries=0) | ||
| assert config.max_retries == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import pytest | ||
|
|
||
| from roe.models.file import FileUpload | ||
| from roe.utils.inputs import build_execution_multipart | ||
|
|
||
|
|
||
| def test_file_upload_path_is_read_not_left_open(tmp_path): | ||
| path = tmp_path / "invoice.pdf" | ||
| path.write_bytes(b"%PDF-1.4") | ||
|
|
||
| _, files = build_execution_multipart({"document": FileUpload(path=str(path))}) | ||
|
|
||
| assert files["document"] == ("invoice.pdf", b"%PDF-1.4", "application/pdf") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("value", "expected"), | ||
| [({"a": "b"}, '{"a": "b"}'), (["x", 1], '["x", 1]'), (3, "3"), (True, "True")], | ||
| ) | ||
| def test_non_string_inputs_are_sent_as_form_values(value, expected): | ||
| form_data, _ = build_execution_multipart({"field": value}) | ||
|
|
||
| assert form_data == {"field": expected} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from types import SimpleNamespace | ||
| from uuid import UUID | ||
|
|
||
| import pytest | ||
|
|
||
| from roe.exceptions import NotFoundError | ||
| from roe.models import job as job_module | ||
| from roe.models.job import Job, JobBatch, JobStatus | ||
|
|
||
|
|
||
| class FakeClock: | ||
| def __init__(self): | ||
| self.now = 0.0 | ||
|
|
||
| def monotonic(self): | ||
| return self.now | ||
|
|
||
| def sleep(self, seconds): | ||
| self.now += seconds | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def clock(monkeypatch): | ||
| fake = FakeClock() | ||
| monkeypatch.setattr(job_module, "time", fake) | ||
| return fake | ||
|
|
||
|
|
||
| def test_job_wait_does_not_sleep_past_timeout(clock): | ||
| jobs = SimpleNamespace( | ||
| retrieve_status=lambda job_id: SimpleNamespace( | ||
| status=JobStatus.STARTED, error_message=None | ||
| ) | ||
| ) | ||
| job = Job(SimpleNamespace(jobs=jobs), "job-1") | ||
|
|
||
| with pytest.raises(TimeoutError): | ||
| job.wait(interval=60, timeout=1) | ||
|
|
||
| assert clock.now == 1 | ||
|
|
||
|
|
||
| def test_job_batch_wait_does_not_sleep_past_timeout(clock): | ||
| jobs = SimpleNamespace( | ||
| retrieve_status_many=lambda job_ids: [ | ||
| SimpleNamespace(id=UUID(job_id), status=JobStatus.STARTED) | ||
| for job_id in job_ids | ||
| ] | ||
| ) | ||
| batch = JobBatch( | ||
| SimpleNamespace(jobs=jobs), ["00000000-0000-0000-0000-000000000001"] | ||
| ) | ||
|
|
||
| with pytest.raises(TimeoutError): | ||
| batch.wait(interval=60, timeout=1) | ||
|
|
||
| assert clock.now == 1 | ||
|
|
||
|
|
||
| def test_job_batch_wait_raises_when_status_response_omits_a_job(clock): | ||
| present = "00000000-0000-0000-0000-000000000001" | ||
| missing = "00000000-0000-0000-0000-000000000002" | ||
| jobs = SimpleNamespace( | ||
| retrieve_status_many=lambda job_ids: [ | ||
| SimpleNamespace(id=UUID(present), status=JobStatus.STARTED) | ||
| ] | ||
| ) | ||
| batch = JobBatch(SimpleNamespace(jobs=jobs), [present, missing]) | ||
|
|
||
| with pytest.raises(NotFoundError, match=missing): | ||
| batch.wait(interval=5, timeout=60) | ||
|
|
||
| assert clock.now == 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.