feat(config): align LLM timeout/retry SLA with FastGPT client (60s/3)
Replaces the unequal SLA (LLM 30s/2 retries vs FastGPT client 60s/3) that made the LangGraph backend look less stable under gray release. - core/fastgpt_client: FASTGPT_TIMEOUT_SECONDS / FASTGPT_MAX_RETRIES module constants (were inline literals in lifespan) - agent/llm: OpenAILLMService defaults 60.0s / 3 retries - core/config: named-profile fallback defaults 60/3 (prefixed and JSON-dict forms) - contract test test/backends/test_sla_alignment.py pins both sides to the same constants so the SLA cannot drift apart again - retry backoff intentionally differs (FastGPT fixed 1s vs LLM exponential) and is documented; aligned parameters are per-call timeout and max retry count Verified: 215 unit tests (3 new SLA contract tests)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""后端超时/重试 SLA 对齐契约测试。
|
||||
|
||||
背景(可替代性清单):FastGPT 客户端为 60s/3 次,LangGraph LLM 侧
|
||||
曾是 30s/2 次,客户端感知到的超时行为不等价。本测试把两端常量
|
||||
钉在一起,防止再次漂移。
|
||||
|
||||
注:退避策略有意不同——FastGPT 固定 1s,LLM 指数退避(限流场景
|
||||
更友好);对齐的是"单次调用总超时"与"最大重试次数"两个 SLA 参数。
|
||||
"""
|
||||
|
||||
import inspect
|
||||
|
||||
from src.agent.llm import OpenAILLMService
|
||||
from src.core.fastgpt_client import FASTGPT_MAX_RETRIES, FASTGPT_TIMEOUT_SECONDS
|
||||
|
||||
|
||||
def test_llm_default_timeout_matches_fastgpt_client():
|
||||
signature = inspect.signature(OpenAILLMService.__init__)
|
||||
default_timeout = signature.parameters["timeout_seconds"].default
|
||||
assert default_timeout == FASTGPT_TIMEOUT_SECONDS == 60.0
|
||||
|
||||
|
||||
def test_llm_default_max_retries_matches_fastgpt_client():
|
||||
signature = inspect.signature(OpenAILLMService.__init__)
|
||||
default_retries = signature.parameters["max_retries"].default
|
||||
assert default_retries == FASTGPT_MAX_RETRIES == 3
|
||||
|
||||
|
||||
def test_named_profile_defaults_match_fastgpt_client(monkeypatch):
|
||||
"""未显式配置 _TIMEOUT_SECONDS/_MAX_RETRIES 的 profile 取 SLA 默认值。"""
|
||||
monkeypatch.setenv("LLM_PROVIDERS", "probe")
|
||||
monkeypatch.setenv("LLM_PROBE_BASE_URL", "http://127.0.0.1:1/v1")
|
||||
monkeypatch.setenv("LLM_PROBE_API_KEY", "probe-key")
|
||||
monkeypatch.setenv("LLM_PROBE_MODEL", "probe-model")
|
||||
|
||||
from src.core.config import Config
|
||||
|
||||
# LLM_PROVIDERS 是 import 时固化的类属性,需直接替换
|
||||
monkeypatch.setattr(Config, "LLM_PROVIDERS", "probe")
|
||||
profile = Config.llm_profile("probe")
|
||||
assert profile["timeout_seconds"] == FASTGPT_TIMEOUT_SECONDS
|
||||
assert profile["max_retries"] == FASTGPT_MAX_RETRIES
|
||||
Reference in New Issue
Block a user