Skip to content

The agent that grows with you

fix(bot-relay): tolerate invalid envelope TTL config

Xipong09e3f4b87a70
diff --git a/tests/tools/test_bot_relay.py b/tests/tools/test_bot_relay.py
index 79192cb5d60..81ef17651e5 100644
--- a/tests/tools/test_bot_relay.py
+++ b/tests/tools/test_bot_relay.py
@@ -652,6 +652,12 @@ def test_drain_ttl_zero_disables_expiry(root, monkeypatch):
assert [e["id"] for e in claimed] == [env["id"]]
+def test_invalid_ttl_config_falls_back_instead_of_breaking_drain(monkeypatch):
+ monkeypatch.setattr(bot_relay, "_bot_mode_cfg", lambda *args, **kwargs: "not-a-number")
+
+ assert bot_relay._envelope_ttl_seconds() == bot_relay.DEFAULT_ENVELOPE_TTL_SECONDS
+
+
def test_ttl_config_read_is_lazy_and_defensive(monkeypatch):
import builtins
diff --git a/tools/bot_relay.py b/tools/bot_relay.py
index 6794f4beeb9..badc8c07144 100644
--- a/tools/bot_relay.py
+++ b/tools/bot_relay.py
@@ -250,7 +250,13 @@ def _envelope_ttl_seconds() -> int:
"""Configured drain TTL (``bot_mode.envelope_ttl_seconds``), read per-drain.
``0`` (or negative) disables expiry."""
val = _bot_mode_cfg("envelope_ttl_seconds", loader="load_config_readonly")
- return DEFAULT_ENVELOPE_TTL_SECONDS if val is None else int(val)
+ if val is None:
+ return DEFAULT_ENVELOPE_TTL_SECONDS
+ try:
+ return int(val)
+ except (TypeError, ValueError, OverflowError):
+ logger.debug("Invalid bot_mode.envelope_ttl_seconds %r; using fallback", val)
+ return DEFAULT_ENVELOPE_TTL_SECONDS
def _target_liveness(root: Path | str, target: dict) -> Optional[bool]: