From 3a967d4f9abee1272c1b3f142310120367c38fb3 Mon Sep 17 00:00:00 2001 From: Nefelibata <124799179+MeiSiristhebest@users.noreply.github.com> Date: Sat, 15 Aug 2026 15:40:43 +0800 Subject: [PATCH] fix(memory): reject non-finite mem0 timeout_seconds (#4823) --- .../harness/deerflow/agents/memory/backends/mem0/config.py | 5 +++-- backend/tests/test_mem0_memory_backend.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/packages/harness/deerflow/agents/memory/backends/mem0/config.py b/backend/packages/harness/deerflow/agents/memory/backends/mem0/config.py index 074113504..d4f2be8b2 100644 --- a/backend/packages/harness/deerflow/agents/memory/backends/mem0/config.py +++ b/backend/packages/harness/deerflow/agents/memory/backends/mem0/config.py @@ -11,6 +11,7 @@ from __future__ import annotations import os from dataclasses import dataclass +from math import isfinite from typing import Any from urllib.parse import urlsplit @@ -105,8 +106,8 @@ class Mem0Config: raise ValueError("mem0 score_threshold must be in [0, 1]") if config.max_injection_chars <= 0: raise ValueError("mem0 max_injection_chars must be positive") - if config.timeout_seconds <= 0: - raise ValueError("mem0 timeout_seconds must be positive") + if not isfinite(config.timeout_seconds) or config.timeout_seconds <= 0: + raise ValueError("mem0 timeout_seconds must be a finite value > 0") if not config.api_key_env.strip(): raise ValueError("mem0 api_key_env must be a non-empty env var name") parsed_base_url = urlsplit(config.base_url) diff --git a/backend/tests/test_mem0_memory_backend.py b/backend/tests/test_mem0_memory_backend.py index eda6b1e4d..95e5d93d6 100644 --- a/backend/tests/test_mem0_memory_backend.py +++ b/backend/tests/test_mem0_memory_backend.py @@ -77,6 +77,9 @@ class TestMem0Config: ("score_threshold", 1.5), ("max_injection_chars", 0), ("timeout_seconds", 0), + ("timeout_seconds", float("nan")), + ("timeout_seconds", float("inf")), + ("timeout_seconds", float("-inf")), ], ) def test_invalid_values_rejected(self, key: str, value: object) -> None: