The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: sockets keep a short temp root; lint skips git-ignored artifacts; test runner scratch leaves /tmp
teknium107df62d604a1
diff --git a/hermes_constants.py b/hermes_constants.pyindex 37aac235802..94f65b86843 100644--- a/hermes_constants.py+++ b/hermes_constants.py@@ -978,6 +978,25 @@ _SCRATCH_PRUNE_STAMP = ".last_prune"_SCRATCH_PRUNE_INTERVAL_SECONDS = 3600_scratch_pruned_once = False+# AF_UNIX socket paths cap at 104 bytes (macOS) / 108 (Linux). Chrome appends+# ``com.google.Chrome.XXXXXX/SingletonSocket`` (~45) and the code kernel+# ``hermes_rpc_<32 hex>.sock`` (~49) to the temp root, so a root longer than this budget+# makes the bind fail (Chrome: "Socket path too long" at startup).+SOCKET_TMPDIR_MAX_LEN = 50+++def socket_safe_tmpdir() -> str:+ """Temp root short enough for AF_UNIX sockets. The scratch dir usually fits; macOS+ ``TMPDIR`` never does and a deep profile home may not, so those fall back to the OS+ default root for sockets only (everything else stays in the scratch dir)."""+ import tempfile+ if sys.platform == "darwin":+ return "/tmp" # no-tmp: ok — AF_UNIX 104-byte socket path limit on darwin+ candidate = tempfile.gettempdir()+ if len(candidate) <= SOCKET_TMPDIR_MAX_LEN or not os.path.isdir("/tmp"): # no-tmp: ok — probe, not a write target+ return candidate+ return "/tmp" # no-tmp: ok — AF_UNIX 108-byte socket path limit on Linux+def get_scratch_dir(home: str | Path | None = None, *, prune: bool = True) -> Path:"""``<home>/cache/scratch`` (created, owner-only); *home* defaults to the active Hermes home.diff --git a/scripts/check_no_tmp_literals.py b/scripts/check_no_tmp_literals.pyindex 1f1bb1a10ba..892c94acf09 100644--- a/scripts/check_no_tmp_literals.py+++ b/scripts/check_no_tmp_literals.py@@ -46,6 +46,7 @@ from __future__ import annotationsimport argparseimport os+import subprocessimport reimport sysimport warnings@@ -163,8 +164,23 @@ def _skip_file(path: Path) -> bool:return any(p.search(path.name) for p in SKIP_FILE_PATTERNS)+def _git_ignored(root: Path) -> set[Path]:+ """Ignored/untracked-by-.gitignore paths (runner artifacts such as ``test_durations.json``)+ are build products, not sources; a scan that reads them fails on whatever the last test+ run wrote. Empty when *root* is not a git checkout."""+ try:+ out = subprocess.run(+ ["git", "-C", str(root), "ls-files", "--others", "--ignored", "--exclude-standard", "-z"],+ capture_output=True, text=True, check=True, stdin=subprocess.DEVNULL,+ ).stdout+ except (OSError, subprocess.CalledProcessError):+ return set()+ return {root / rel for rel in out.split("\0") if rel}++def iter_files(root: Path | None = None):root = (root or ROOT).resolve()+ ignored = _git_ignored(root)for dirpath, dirnames, filenames in os.walk(root):here = Path(dirpath)rel_here = here.relative_to(root) if here != root else Path()@@ -174,7 +190,7 @@ def iter_files(root: Path | None = None):)for filename in sorted(filenames):path = here / filename- if not _skip_file(path):+ if path not in ignored and not _skip_file(path):yield pathdiff --git a/scripts/run_tests_parallel.py b/scripts/run_tests_parallel.pyindex 81424bb7640..f1727b46192 100755--- a/scripts/run_tests_parallel.py+++ b/scripts/run_tests_parallel.py@@ -58,6 +58,16 @@ from concurrent.futures import ThreadPoolExecutor, Futurefrom pathlib import Pathfrom typing import Dict, List, Optional, Tuple+def _runner_scratch_root() -> str:+ """Per-run temp roots live under the developer's Hermes scratch dir, never the system+ temp dir: a full-suite run writes gigabytes of tmp_path fixtures, and /tmp is RAM-backed+ tmpfs on many Linux hosts. Resolved without importing the tree under test."""+ home = os.environ.get("HERMES_HOME") or os.path.join(os.path.expanduser("~"), ".hermes")+ root = os.path.join(home, "cache", "scratch", "pytest")+ os.makedirs(root, exist_ok=True)+ return root++# Default test discovery roots._DEFAULT_ROOTS = ["tests"]@@ -452,8 +462,11 @@ def _run_one_file_once(# One root for each subprocess removes the shared directory that the race# needs. The parent deletes the root after the attempt.env = os.environ.copy()- temproot = tempfile.mkdtemp(prefix="hermes-pytest-tmproot-")+ temproot = tempfile.mkdtemp(prefix="hermes-pytest-tmproot-", dir=_runner_scratch_root())env["PYTEST_DEBUG_TEMPROOT"] = temproot+ # Every tempfile.* call inside the test process lands in the same per-run root, so the+ # parent's cleanup of ``temproot`` removes them too instead of leaving them in /tmp.+ env["TMPDIR"] = temprootsubproc_start = time.monotonic()# launch the pytest processdiff --git a/tools/browser_tool.py b/tools/browser_tool.pyindex 0dc127717bf..f8b2ea2bbb1 100644--- a/tools/browser_tool.py+++ b/tools/browser_tool.py@@ -57,7 +57,11 @@ def _build_browser_env() -> dict:env[key] = value# The Browser Use harness dials the resolved local CDP URL over ``websockets``; without a# loopback NO_PROXY a macOS system proxy captures that dial (#110565).- return add_loopback_no_proxy(env)+ env = add_loopback_no_proxy(env)+ # Chrome puts its SingletonSocket under $TMPDIR; a deep scratch dir overflows the AF_UNIX+ # path cap and Chrome dies at startup ("Socket path too long"), so browsers get the short root.+ env["TMPDIR"] = _socket_safe_tmpdir()+ return envtry:@@ -352,9 +356,10 @@ def _last_session_key(task_id: str) -> str:def _socket_safe_tmpdir() -> str:- """Short temp dir for Unix sockets: macOS ``TMPDIR`` + ``agent-browser-hermes_…``- exceeds the 104-byte AF_UNIX limit (silent screenshot failures), so use /tmp there."""- return "/tmp" if sys.platform == "darwin" else tempfile.gettempdir() # no-tmp: ok — AF_UNIX 104-byte socket path limit on darwin+ """Temp root short enough for the agent-browser socket dir and Chrome's SingletonSocket+ (``hermes_constants.socket_safe_tmpdir``)."""+ from hermes_constants import socket_safe_tmpdir+ return socket_safe_tmpdir()# Active sessions keyed by "session key": the bare task_id, or f"{task_id}::local"diff --git a/tools/code_kernel.py b/tools/code_kernel.pyindex 5e5008a7bea..ee6698df0f3 100644--- a/tools/code_kernel.py+++ b/tools/code_kernel.py@@ -565,7 +565,8 @@ def _bind_rpc_socket(kernel: SessionKernel) -> str:host, port = server_sock.getsockname()[:2]rpc_endpoint = f"tcp://{host}:{port}"else:- sock_tmpdir = "/tmp" if sys.platform == "darwin" else tempfile.gettempdir() # no-tmp: ok — AF_UNIX 104-byte socket path limit on darwin+ from hermes_constants import socket_safe_tmpdir+ sock_tmpdir = socket_safe_tmpdir()rpc_endpoint = kernel.sock_path = os.path.join(sock_tmpdir, f"hermes_rpc_{uuid.uuid4().hex}.sock")server_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)server_sock.bind(kernel.sock_path)