Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(settings): add LDR_DISABLE_RATE_LIMITING alias for legacy bare flag (#3905) (#3936)

LearningCircuit79393b782465
diff --git a/changelog.d/+3905-ldr-disable-rate-limiting-alias.misc.md b/changelog.d/+3905-ldr-disable-rate-limiting-alias.misc.md
new file mode 100644
index 0000000000..5de7fc2a9b
--- /dev/null
+++ b/changelog.d/+3905-ldr-disable-rate-limiting-alias.misc.md
@@ -0,0 +1 @@
+Added `LDR_DISABLE_RATE_LIMITING` as the canonical name for disabling HTTP rate limiting, matching the `LDR_` env-var convention. The legacy `DISABLE_RATE_LIMITING` still works but emits a deprecation warning. Note: this is distinct from `LDR_RATE_LIMITING_ENABLED`, which controls the adaptive search-engine rate limiter — a different subsystem (#3905).
diff --git a/docs/CI_CD_INFRASTRUCTURE.md b/docs/CI_CD_INFRASTRUCTURE.md
index 28b95b0055..9eb6cb4e8f 100644
--- a/docs/CI_CD_INFRASTRUCTURE.md
+++ b/docs/CI_CD_INFRASTRUCTURE.md
@@ -262,7 +262,7 @@ docker run --rm -v "$PWD":/app -w /app ldr-test \
|----------|---------|
| `CI=true` | Indicates CI environment |
| `LDR_TESTING_WITH_MOCKS=true` | Enable test mocks |
-| `DISABLE_RATE_LIMITING=true` | Disable rate limits in tests |
+| `LDR_DISABLE_RATE_LIMITING=true` | Disable HTTP rate limits in tests (canonical name). The legacy `DISABLE_RATE_LIMITING=true` is still honored but emits a deprecation warning. Distinct from `LDR_RATE_LIMITING_ENABLED`, which controls the adaptive search-engine rate limiter — different subsystem. |
---
diff --git a/src/local_deep_research/settings/env_registry.py b/src/local_deep_research/settings/env_registry.py
index 4a7b870f8e..8895e649db 100644
--- a/src/local_deep_research/settings/env_registry.py
+++ b/src/local_deep_research/settings/env_registry.py
@@ -66,27 +66,76 @@ def is_github_actions() -> bool:
)
+# Module-level flag so the deprecation warning fires at most once per process.
+_legacy_disable_warned = False
+
+
+def _reset_legacy_warning_flag_for_tests() -> None:
+ """Test seam: reset the module-level deprecation-warning flag.
+
+ Tests that exercise the legacy `DISABLE_RATE_LIMITING` form
+ multiple times need to verify the warning fires once per process,
+ not once per call. Reload-based tests should also call this.
+ """
+ global _legacy_disable_warned
+ _legacy_disable_warned = False
+
+
def is_rate_limiting_enabled() -> bool:
"""
- Check if rate limiting should be enabled.
+ Check if HTTP rate limiting (Flask-Limiter) should be enabled.
Returns:
True if rate limiting should be enabled, False otherwise
Logic:
- - If DISABLE_RATE_LIMITING=true, disable rate limiting
- - Otherwise, enable rate limiting (default)
+ - Canonical: ``LDR_DISABLE_RATE_LIMITING=true`` disables rate limiting
+ - Legacy: ``DISABLE_RATE_LIMITING=true`` (no LDR_ prefix) is still
+ honored for backward compatibility, but emits a one-shot deprecation
+ warning. Operators should migrate to the canonical name.
+ - Otherwise, rate limiting is enabled (default).
+
+ Name-collision warning:
+ ``LDR_RATE_LIMITING_ENABLED`` (without DISABLE_) is a DIFFERENT
+ env var that controls the *adaptive search-engine* rate limiter
+ (see ``rate_limiting.enabled`` setting and
+ ``web_search_engines/rate_limiting/tracker.py``). It does NOT affect
+ the Flask HTTP rate limiter governed by this function. Operators
+ routinely confuse the two — see issue #3905.
Note:
- This function intentionally does NOT check CI environment.
- Rate limiting control should be explicit via the dedicated flag.
+ This function intentionally does NOT check the CI environment.
+ Rate-limiting control should be explicit via the dedicated flag.
"""
import os
from loguru import logger
- disable_flag = os.environ.get("DISABLE_RATE_LIMITING", "").lower()
-
- if disable_flag in ("true", "1", "yes"):
+ # Canonical form takes absolute precedence when set to any value.
+ # An explicit `LDR_DISABLE_RATE_LIMITING=false` should override a stale
+ # legacy `DISABLE_RATE_LIMITING=true` from another tool's environment.
+ canonical_raw = os.environ.get("LDR_DISABLE_RATE_LIMITING")
+ if canonical_raw is not None and canonical_raw != "":
+ if canonical_raw.lower() in ("true", "1", "yes"):
+ logger.debug(
+ "Rate limiting DISABLED due to LDR_DISABLE_RATE_LIMITING=true"
+ )
+ return False
+ logger.debug(
+ "Rate limiting ENABLED (LDR_DISABLE_RATE_LIMITING set non-truthy)"
+ )
+ return True
+
+ legacy = os.environ.get("DISABLE_RATE_LIMITING", "").lower()
+ if legacy in ("true", "1", "yes"):
+ global _legacy_disable_warned
+ if not _legacy_disable_warned:
+ logger.warning(
+ "DISABLE_RATE_LIMITING is deprecated; use "
+ "LDR_DISABLE_RATE_LIMITING for consistency with the LDR_ "
+ "env-var convention. The legacy name still works but will "
+ "be removed in a future release."
+ )
+ _legacy_disable_warned = True
logger.debug("Rate limiting DISABLED due to DISABLE_RATE_LIMITING=true")
return False
@@ -102,4 +151,5 @@ __all__ = [
"is_ci_environment",
"is_github_actions",
"is_rate_limiting_enabled",
+ "_reset_legacy_warning_flag_for_tests",
]
diff --git a/tests/settings/test_env_registry_behavior.py b/tests/settings/test_env_registry_behavior.py
index 39a52f0504..d166a84602 100644
--- a/tests/settings/test_env_registry_behavior.py
+++ b/tests/settings/test_env_registry_behavior.py
@@ -232,6 +232,73 @@ class TestIsRateLimitingEnabled:
with patch.dict(os.environ, {"DISABLE_RATE_LIMITING": "TRUE"}):
assert is_rate_limiting_enabled() is False
+ def test_legacy_form_emits_deprecation_warning_once(self, loguru_caplog):
+ """Legacy DISABLE_RATE_LIMITING=true emits warning exactly once per process."""
+ from local_deep_research.settings.env_registry import (
+ is_rate_limiting_enabled,
+ _reset_legacy_warning_flag_for_tests,
+ )
+
+ _reset_legacy_warning_flag_for_tests()
+ try:
+ with patch.dict(os.environ, {"DISABLE_RATE_LIMITING": "true"}):
+ with loguru_caplog.at_level("WARNING"):
+ is_rate_limiting_enabled()
+ first_warnings = [
+ r
+ for r in loguru_caplog.records
+ if "DISABLE_RATE_LIMITING is deprecated" in r.getMessage()
+ ]
+ assert len(first_warnings) == 1, (
+ "Legacy form should emit deprecation warning on first call"
+ )
+
+ loguru_caplog.clear()
+ with loguru_caplog.at_level("WARNING"):
+ is_rate_limiting_enabled()
+ is_rate_limiting_enabled()
+ repeat_warnings = [
+ r
+ for r in loguru_caplog.records
+ if "DISABLE_RATE_LIMITING is deprecated" in r.getMessage()
+ ]
+ assert repeat_warnings == [], (
+ "Deprecation warning should not re-fire after first call"
+ )
+ finally:
+ _reset_legacy_warning_flag_for_tests()
+
+ def test_canonical_form_does_not_emit_deprecation_warning(
+ self, loguru_caplog
+ ):
+ """LDR_DISABLE_RATE_LIMITING does not emit deprecation warning."""
+ from local_deep_research.settings.env_registry import (
+ is_rate_limiting_enabled,
+ _reset_legacy_warning_flag_for_tests,
+ )
+
+ _reset_legacy_warning_flag_for_tests()
+ try:
+ env_clean = {
+ k: v
+ for k, v in os.environ.items()
+ if k != "DISABLE_RATE_LIMITING"
+ }
+ env_clean["LDR_DISABLE_RATE_LIMITING"] = "true"
+ with patch.dict(os.environ, env_clean, clear=True):
+ with loguru_caplog.at_level("WARNING"):
+ assert is_rate_limiting_enabled() is False
+ warnings = [
+ r
+ for r in loguru_caplog.records
+ if "deprecated" in r.getMessage()
+ ]
+ assert warnings == [], (
+ "Canonical form should not emit deprecation warning"
+ )
+ finally:
+ _reset_legacy_warning_flag_for_tests()
+
class TestModuleExports:
"""Tests for module __all__ exports."""
diff --git a/tests/settings/test_env_registry_extended.py b/tests/settings/test_env_registry_extended.py
index a0ce72f937..b375c58dc6 100644
--- a/tests/settings/test_env_registry_extended.py
+++ b/tests/settings/test_env_registry_extended.py
@@ -215,43 +215,83 @@ class TestIsRateLimitingEnabledFunction:
@pytest.fixture(autouse=True)
def clean_env(self):
"""Clean environment before each test."""
- original_env = {
- k: v for k, v in os.environ.items() if k == "DISABLE_RATE_LIMITING"
- }
- os.environ.pop("DISABLE_RATE_LIMITING", None)
+ env_vars = ("DISABLE_RATE_LIMITING", "LDR_DISABLE_RATE_LIMITING")
+ original_env = {k: os.environ[k] for k in env_vars if k in os.environ}
+ for k in env_vars:
+ os.environ.pop(k, None)
+ # Reset the module-level deprecation-warning flag so tests asserting
+ # warning behavior get a fresh state per case.
+ from local_deep_research.settings.env_registry import (
+ _reset_legacy_warning_flag_for_tests,
+ )
+
+ _reset_legacy_warning_flag_for_tests()
yield
- os.environ.pop("DISABLE_RATE_LIMITING", None)
+ for k in env_vars:
+ os.environ.pop(k, None)
for key, value in original_env.items():
os.environ[key] = value
+ _reset_legacy_warning_flag_for_tests()
def test_is_rate_limiting_enabled_default(self):
"""Test is_rate_limiting_enabled returns True by default."""
assert is_rate_limiting_enabled() is True
def test_is_rate_limiting_enabled_disabled_true(self):
- """Test is_rate_limiting_enabled returns False when DISABLE_RATE_LIMITING=true."""
+ """Legacy DISABLE_RATE_LIMITING=true still disables rate limiting."""
os.environ["DISABLE_RATE_LIMITING"] = "true"
-
assert is_rate_limiting_enabled() is False
def test_is_rate_limiting_enabled_disabled_1(self):
- """Test is_rate_limiting_enabled returns False when DISABLE_RATE_LIMITING=1."""
+ """Legacy DISABLE_RATE_LIMITING=1 still disables rate limiting."""
os.environ["DISABLE_RATE_LIMITING"] = "1"
-
assert is_rate_limiting_enabled() is False
def test_is_rate_limiting_enabled_disabled_yes(self):
- """Test is_rate_limiting_enabled returns False when DISABLE_RATE_LIMITING=yes."""
+ """Legacy DISABLE_RATE_LIMITING=yes still disables rate limiting."""
os.environ["DISABLE_RATE_LIMITING"] = "yes"
-
assert is_rate_limiting_enabled() is False
def test_is_rate_limiting_enabled_with_false_flag(self):
- """Test is_rate_limiting_enabled returns True when DISABLE_RATE_LIMITING=false."""
+ """Legacy DISABLE_RATE_LIMITING=false leaves rate limiting enabled."""
os.environ["DISABLE_RATE_LIMITING"] = "false"
+ assert is_rate_limiting_enabled() is True
+
+ def test_canonical_ldr_disable_true(self):
+ """LDR_DISABLE_RATE_LIMITING=true disables rate limiting."""
+ os.environ["LDR_DISABLE_RATE_LIMITING"] = "true"
+ assert is_rate_limiting_enabled() is False
+
+ def test_canonical_ldr_disable_1(self):
+ """LDR_DISABLE_RATE_LIMITING=1 disables rate limiting."""
+ os.environ["LDR_DISABLE_RATE_LIMITING"] = "1"
+ assert is_rate_limiting_enabled() is False
+ def test_canonical_ldr_disable_yes(self):
+ """LDR_DISABLE_RATE_LIMITING=yes disables rate limiting."""
+ os.environ["LDR_DISABLE_RATE_LIMITING"] = "yes"
+ assert is_rate_limiting_enabled() is False
+
+ def test_canonical_ldr_disable_false(self):
+ """LDR_DISABLE_RATE_LIMITING=false leaves rate limiting enabled."""
+ os.environ["LDR_DISABLE_RATE_LIMITING"] = "false"
assert is_rate_limiting_enabled() is True
+ def test_canonical_wins_when_both_set_with_conflicting_values(self):
+ """When both forms are set with conflicting values, canonical wins.
+
+ canonical=false → enabled=True even though legacy=true would disable.
+ """
+ os.environ["LDR_DISABLE_RATE_LIMITING"] = "false"
+ os.environ["DISABLE_RATE_LIMITING"] = "true"
+ assert is_rate_limiting_enabled() is True
+
+ def test_canonical_wins_when_both_disable(self):
+ """Both set to disable: canonical short-circuits, no legacy warning."""
+ os.environ["LDR_DISABLE_RATE_LIMITING"] = "true"
+ os.environ["DISABLE_RATE_LIMITING"] = "true"
+ assert is_rate_limiting_enabled() is False
+
class TestRegistryGlobalInstance:
"""Tests for the global registry instance."""