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(security): keep socket errors out of the filesystem_error token (#7645)

Mayuri07bebcf1bc50
diff --git a/changelog.d/7524.bugfix.md b/changelog.d/7524.bugfix.md
new file mode 100644
index 0000000000..e5e7fa9a9c
--- /dev/null
+++ b/changelog.d/7524.bugfix.md
@@ -0,0 +1 @@
+Downloads that fail with a socket error (connection reset, broken pipe, connection refused or aborted) are now reported as network errors with the short network retry cooldown, instead of as filesystem errors with a one-hour cooldown.
diff --git a/src/local_deep_research/security/client_safe_errors.py b/src/local_deep_research/security/client_safe_errors.py
index 0e80ef8021..262edf598f 100644
--- a/src/local_deep_research/security/client_safe_errors.py
+++ b/src/local_deep_research/security/client_safe_errors.py
@@ -30,6 +30,9 @@ CLIENT_SAFE_DOWNLOAD_MESSAGES: dict[str, str] = {
# Network surface — never echo the URL / host the caller already knows.
"ConnectionError": "network_unavailable",
"ConnectionResetError": "network_reset",
+ "ConnectionAbortedError": "network_reset",
+ "BrokenPipeError": "network_reset",
+ "ConnectionRefusedError": "network_unavailable",
"Timeout": "network_timeout",
"HTTPError": "http_error",
"ChunkedEncodingError": "network_unavailable",
@@ -71,8 +74,20 @@ def client_safe_download_message(exc: BaseException) -> str:
URL, or path content. Custom constructions like
``OSError(28, "leak: secret file contents")`` deliberately don't match the
canonical message and fall through to the class-name default.
+
+ The ``ConnectionError`` family (``ConnectionResetError``,
+ ``ConnectionAbortedError``, ``BrokenPipeError``, ``ConnectionRefusedError``)
+ are ``OSError`` subclasses that carry an errno too, so they skip the errno
+ branch and keep their network token. Other socket-level ``OSError``
+ subclasses (for example ``TimeoutError(ETIMEDOUT)`` or ``ENETUNREACH``)
+ are not covered by that guard and still take the ``filesystem_error:``
+ branch.
"""
- if isinstance(exc, OSError) and exc.errno is not None:
+ if (
+ isinstance(exc, OSError)
+ and not isinstance(exc, ConnectionError)
+ and exc.errno is not None
+ ):
canonical = os.strerror(exc.errno)
if exc.strerror and exc.strerror == canonical:
return f"filesystem_error:{exc.strerror}"
diff --git a/tests/security/test_client_safe_errors_shared_6564.py b/tests/security/test_client_safe_errors_shared_6564.py
index 9e303fd254..b2de8000ef 100644
--- a/tests/security/test_client_safe_errors_shared_6564.py
+++ b/tests/security/test_client_safe_errors_shared_6564.py
@@ -1,7 +1,10 @@
"""PR #6564 optional #1: single source of truth for safe download tokens."""
+import errno
import os
+import pytest
+
from local_deep_research.security.client_safe_errors import (
CLIENT_SAFE_DOWNLOAD_MESSAGES,
client_safe_download_message,
@@ -61,6 +64,57 @@ class TestSharedTable:
leaked = OSError(28, "leak /etc/passwd")
assert client_safe_download_message(leaked) == "download_error:OSError"
+ @pytest.mark.parametrize(
+ ("exc_class", "err_no", "expected"),
+ [
+ (ConnectionResetError, errno.ECONNRESET, "network_reset"),
+ (ConnectionAbortedError, errno.ECONNABORTED, "network_reset"),
+ (BrokenPipeError, errno.EPIPE, "network_reset"),
+ (ConnectionRefusedError, errno.ECONNREFUSED, "network_unavailable"),
+ ],
+ )
+ def test_socket_errors_with_errno_keep_network_token(
+ self, exc_class, err_no, expected
+ ):
+ # Real socket errors carry an errno and the canonical strerror, the
+ # same shape the filesystem branch matches on.
+ exc = exc_class(err_no, os.strerror(err_no))
+ assert client_safe_download_message(exc) == expected
+
+ def test_errno_less_socket_error_keeps_network_token(self):
+ assert (
+ client_safe_download_message(ConnectionAbortedError())
+ == "network_reset"
+ )
+
+ def test_plain_connection_error_with_errno_keeps_network_token(self):
+ exc = ConnectionError(errno.ECONNRESET, os.strerror(errno.ECONNRESET))
+ assert client_safe_download_message(exc) == "network_unavailable"
+
+ def test_socket_error_with_custom_strerror_does_not_leak(self):
+ exc = BrokenPipeError(errno.EPIPE, "leak secret")
+ msg = client_safe_download_message(exc)
+ assert msg == "network_reset"
+ assert "secret" not in msg
+
+ def test_socket_error_token_gets_network_cooldown(self):
+ from datetime import timedelta
+
+ from local_deep_research.library.download_management.failure_classifier import (
+ FailureClassifier,
+ )
+
+ token = client_safe_download_message(
+ ConnectionResetError(
+ errno.ECONNRESET, os.strerror(errno.ECONNRESET)
+ )
+ )
+ failure = FailureClassifier().classify_failure(
+ error_type=token, details=token
+ )
+ assert failure.error_type == "network_error"
+ assert failure.retry_after == timedelta(minutes=5)
+
def test_never_echoes_exception_text(self):
exc = RuntimeError("INSERT INTO document_collections VALUES (1)")
msg = client_safe_download_message(exc)