From e4ca2bef8efd7f65d1423d76d860fc12fb8695dc Mon Sep 17 00:00:00 2001 From: scoootscooob Date: Wed, 22 Apr 2026 09:41:44 -0700 Subject: [PATCH] fix(client): reject invalid timeout env values --- clawbench/client.py | 12 +++++++++--- tests/test_client.py | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/clawbench/client.py b/clawbench/client.py index 9a07f64..1e68e3c 100644 --- a/clawbench/client.py +++ b/clawbench/client.py @@ -5,6 +5,7 @@ from __future__ import annotations import asyncio import json import logging +import math import os import re import subprocess @@ -154,17 +155,22 @@ process.stdout.write( def _env_float(name: str, default: float) -> float: """Read a float from the environment, falling back on the default. - Bad / unparseable values are ignored (we log a warning below) so a - typo in ``CLAWBENCH_CONNECT_TIMEOUT`` never silently bricks a run. + Bad, non-finite, or non-positive values are ignored (we log a + warning below) so a typo in ``CLAWBENCH_CONNECT_TIMEOUT`` never + silently bricks a run. """ raw = os.environ.get(name) if raw is None or raw == "": return default try: - return float(raw) + value = float(raw) except ValueError: logger.warning("ignoring invalid %s=%r; using default %s", name, raw, default) return default + if not math.isfinite(value) or value <= 0: + logger.warning("ignoring invalid %s=%r; using default %s", name, raw, default) + return default + return value @dataclass diff --git a/tests/test_client.py b/tests/test_client.py index 0e965b4..a6b27ed 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -28,8 +28,9 @@ def test_gateway_config_env_overrides(monkeypatch): assert cfg.request_timeout == 120.0 -def test_gateway_config_invalid_env_falls_back_to_default(monkeypatch, caplog): - monkeypatch.setenv("CLAWBENCH_CONNECT_TIMEOUT", "not-a-number") +@pytest.mark.parametrize("raw", ["not-a-number", "nan", "inf", "0", "-1"]) +def test_gateway_config_invalid_env_falls_back_to_default(monkeypatch, caplog, raw): + monkeypatch.setenv("CLAWBENCH_CONNECT_TIMEOUT", raw) with caplog.at_level("WARNING"): cfg = GatewayConfig() assert cfg.connect_timeout == 30.0