Skip to content

The agent that grows with you

fix(terminal): align worker limit with local guard

Dominic Bejarb0346ba42ab4
diff --git a/tests/tools/test_process_registry.py b/tests/tools/test_process_registry.py
index 7d2238f24dd..fce8fe50053 100644
--- a/tests/tools/test_process_registry.py
+++ b/tests/tools/test_process_registry.py
@@ -1793,10 +1793,10 @@ class TestSystemdCgroupIsolation:
assert argv[-3:] == ["/bin/bash", "-lic", "set +m; codex"]
assert session.systemd_unit == f"hermes-worker-{session.id}.scope"
- def test_worker_memory_limit_accepts_valid_byte_override(self, monkeypatch):
+ def test_worker_memory_limit_honors_local_guard_mb_override(self, monkeypatch):
import tools.process_registry as pr
- monkeypatch.setenv("HERMES_WORKER_MEMORY_MAX_BYTES", "123456789")
+ monkeypatch.setenv("TERMINAL_LOCAL_MEMORY_MAX_MB", "123")
monkeypatch.setattr("shutil.which", lambda name: "/usr/bin/systemd-run")
argv = pr._build_systemd_scope_argv(
@@ -1804,7 +1804,7 @@ class TestSystemdCgroupIsolation:
unit_suffix="test",
)
- assert "MemoryMax=123456789" in argv
+ assert f"MemoryMax={123 * 1024 * 1024}" in argv
def test_kill_recovered_detached_already_exited_stops_persisted_scope(
self, registry, monkeypatch
diff --git a/tools/process_registry.py b/tools/process_registry.py
index 8a22956c2e3..aec51dd15b8 100644
--- a/tools/process_registry.py
+++ b/tools/process_registry.py
@@ -108,25 +108,26 @@ _WORKER_MEMORY_MAX_CAP_BYTES = 4 * 1024 * 1024 * 1024
def _worker_memory_max_bytes() -> int:
"""Return a finite per-worker cgroup limit without widening host risk.
- An explicit byte override is useful for operators with known workload
- requirements. Otherwise retain the tighter of the gateway's current
- cgroup-v2 ``memory.max`` and half of physical RAM, capped at 4 GiB. This
- keeps the sibling worker outside the gateway cgroup while ensuring the
- worker cannot consume memory up to the enclosing user slice or host limit.
+ The proposed local-memory-guard environment override is honored so this
+ isolation composes with PR #57121 instead of inventing a second knob.
+ Otherwise retain the tighter of the gateway's current cgroup-v2
+ ``memory.max`` and half of physical RAM, capped at 4 GiB. This keeps the
+ sibling worker outside the gateway cgroup while ensuring the worker cannot
+ consume memory up to the enclosing user slice or host limit.
"""
- override = os.getenv("HERMES_WORKER_MEMORY_MAX_BYTES", "").strip()
+ override = os.getenv("TERMINAL_LOCAL_MEMORY_MAX_MB", "").strip()
if override:
try:
- parsed = int(override)
+ parsed = int(override) * 1024 * 1024
if parsed >= _MIN_WORKER_MEMORY_MAX_BYTES:
return parsed
except ValueError:
pass
logger.warning(
- "Ignoring invalid HERMES_WORKER_MEMORY_MAX_BYTES=%r; "
- "expected an integer of at least %d bytes",
+ "Ignoring invalid TERMINAL_LOCAL_MEMORY_MAX_MB=%r; "
+ "expected an integer representing at least %d MiB",
override,
- _MIN_WORKER_MEMORY_MAX_BYTES,
+ _MIN_WORKER_MEMORY_MAX_BYTES // (1024 * 1024),
)
candidates: List[int] = []