fix(scheduler): catch OverflowError on non-finite research settings

Catch OverflowError in addition to TypeError and ValueError when converting
research_max_tokens, research_extraction_timeout_seconds, and
research_extraction_concurrency to int. Non-finite numbers parsed from JSON
(such as 1e309 or -1e309 representing float infinity) raise OverflowError on
int() conversion, which previously escaped the handler and crashed scheduled
research execution. Also add unit tests covering exponent overflow values.
This commit is contained in:
Alexandre Teixeira
2026-10-19 14:40:27 +01:00
committed by PR #6029 Reviewer
parent 8946100695
commit c1d90beeff
2 changed files with 26 additions and 3 deletions
+3 -3
View File
@@ -368,19 +368,19 @@ def _resolve_research_settings(get_setting_fn):
"""
try:
max_tokens = int(get_setting_fn("research_max_tokens", 8192))
except (TypeError, ValueError):
except (TypeError, ValueError, OverflowError):
max_tokens = 8192
try:
extraction_timeout = int(
get_setting_fn("research_extraction_timeout_seconds", 90) or 90
)
except (TypeError, ValueError):
except (TypeError, ValueError, OverflowError):
extraction_timeout = 90
try:
extraction_concurrency = int(
get_setting_fn("research_extraction_concurrency", 3) or 3
)
except (TypeError, ValueError):
except (TypeError, ValueError, OverflowError):
extraction_concurrency = 3
return max_tokens, extraction_timeout, extraction_concurrency
@@ -15,6 +15,8 @@ same reads defensively; this is the scheduler's equivalent.
from __future__ import annotations
import json
from src.task_scheduler import _resolve_research_settings
@@ -77,3 +79,24 @@ def test_valid_ints_pass_through():
)
assert _resolve_research_settings(get) == (2048, 120, 6)
def test_non_finite_json_numbers_fall_back_individually():
"""JSON exponent overflow produces infinity, which int() cannot convert."""
keys = (
"research_max_tokens",
"research_extraction_timeout_seconds",
"research_extraction_concurrency",
)
valid = (4096, 45, 2)
defaults = (8192, 90, 3)
for non_finite in (json.loads("1e309"), json.loads("-1e309")):
for index, key in enumerate(keys):
values = dict(zip(keys, valid))
values[key] = non_finite
expected = list(valid)
expected[index] = defaults[index]
assert _resolve_research_settings(
_fake_get_setting(values)
) == tuple(expected)