Skip to content

The agent that grows with you

fix(state): tolerate Windows resource stubs

KoNit-K576e7c9cfc68
diff --git a/hermes_state_readpool.py b/hermes_state_readpool.py
index 5b86cff7cc3..50c55daee79 100644
--- a/hermes_state_readpool.py
+++ b/hermes_state_readpool.py
@@ -101,7 +101,7 @@ def _fd_soft_limit() -> Optional[int]:
return None
try:
soft, _hard = resource.getrlimit(resource.RLIMIT_NOFILE)
- except (OSError, ValueError):
+ except (AttributeError, OSError, ValueError):
return None
if soft in (resource.RLIM_INFINITY, -1):
return None
diff --git a/tests/hermes_cli/test_resource_limits.py b/tests/hermes_cli/test_resource_limits.py
index 22018f30a74..a4dd998cf4d 100644
--- a/tests/hermes_cli/test_resource_limits.py
+++ b/tests/hermes_cli/test_resource_limits.py
@@ -100,6 +100,13 @@ def test_unsupported_platform_is_a_safe_noop(monkeypatch):
assert resource_limits.apply_nofile_soft_limit({}) is False
+def test_windows_resource_stub_without_rlimit_attributes_is_a_safe_noop(monkeypatch):
+ """Windows can import ``resource`` even when its POSIX API is absent."""
+ monkeypatch.setattr(resource_limits, "_resource", object())
+
+ assert resource_limits.apply_nofile_soft_limit({}) is False
+
+
def test_fresh_process_import_without_posix_resource_is_a_safe_noop():
code = textwrap.dedent(
"""
diff --git a/tests/hermes_state/test_session_db_read_conn_pool.py b/tests/hermes_state/test_session_db_read_conn_pool.py
index 696d00caae7..3d8f0352b43 100644
--- a/tests/hermes_state/test_session_db_read_conn_pool.py
+++ b/tests/hermes_state/test_session_db_read_conn_pool.py
@@ -627,6 +627,16 @@ def test_fd_headroom_guard_fails_open_where_it_cannot_measure(monkeypatch):
assert readpool._fd_headroom_ok() is False
+def test_fd_soft_limit_ignores_windows_resource_stub(monkeypatch):
+ """A Windows resource stub has no POSIX RLIMIT attributes."""
+ import sys
+ from types import SimpleNamespace
+
+ monkeypatch.setitem(sys.modules, "resource", SimpleNamespace())
+
+ assert hermes_state_readpool._fd_soft_limit() is None
+
+
@pytest.mark.requires_wal
def test_duplicate_handles_on_one_path_are_reported(db, caplog):
"""Writer connections cannot be capped, so duplicates must be visible."""