Ignore invalid context budget numbers (#1831)

This commit is contained in:
red person
2026-06-29 11:56:17 -07:00
committed by GitHub
parent bbbe145247
commit df9c20e6c2
2 changed files with 14 additions and 2 deletions
+9 -2
View File
@@ -18,6 +18,13 @@ DEFAULT_BUDGET = 6000
DEFAULT_HEADROOM = 0.85
def _int_or_zero(value) -> int:
try:
return int(value or 0)
except (TypeError, ValueError):
return 0
def compute_input_token_budget(
configured: int,
context_length: int,
@@ -48,8 +55,8 @@ def compute_input_token_budget(
- When the window is unknown (context_length <= 0), use the conservative
``default`` budget and do NOT scale off the fallback.
"""
configured = int(configured or 0)
context_length = int(context_length or 0)
configured = _int_or_zero(configured)
context_length = _int_or_zero(context_length)
if explicit and configured > 0:
return min(configured, context_length) if context_length > 0 else configured
+5
View File
@@ -33,6 +33,11 @@ def test_unknown_window_falls_back_to_configured():
assert compute_input_token_budget(0, 0, explicit=False) == 6000 # default
def test_invalid_numeric_inputs_fall_back_cleanly():
assert compute_input_token_budget("bad", "also bad", explicit=False) == 6000
assert compute_input_token_budget("bad", 128000, explicit=True) == int(128000 * 0.85)
def test_is_setting_overridden_reads_raw_saved_file(tmp_path, monkeypatch):
import src.settings as settings