Skip to content

The agent that grows with you

fix(file-sync): sync-back cap is a config.yaml key, not an env var

teknium1775aedabce88
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.py
index 1927ee07a17..68956bc370d 100644
--- a/hermes_cli/config_defaults.py
+++ b/hermes_cli/config_defaults.py
@@ -288,6 +288,9 @@ DEFAULT_CONFIG = {
# Env vars passed into sandboxed terminal/execute_code (skill-declared
# required_environment_variables pass through automatically).
"env_passthrough": [],
+ # Remote-backend sync-back refuses to extract a downloaded state archive larger than this
+ # (bytes); raise it for a ~/.hermes tree that legitimately exceeds 2 GiB.
+ "sync_back_max_bytes": 2 * 1024 * 1024 * 1024,
# HOME for host tool subprocesses: "auto" = host keeps the real OS-user HOME, containers use
# HERMES_HOME/home; "real" = force real HOME; "profile" = force HERMES_HOME/home when it
# exists (strict per-profile isolation).
diff --git a/tests/tools/test_file_sync_back.py b/tests/tools/test_file_sync_back.py
index e913e0905f0..f014dad2cf4 100644
--- a/tests/tools/test_file_sync_back.py
+++ b/tests/tools/test_file_sync_back.py
@@ -500,8 +500,8 @@ class TestSyncBackSizeCap:
"""The size cap refuses to extract tars above the configured limit."""
def test_sync_back_refuses_oversized_tar(self, tmp_path, caplog):
- """A tar larger than _SYNC_BACK_MAX_BYTES should be skipped with a warning."""
- # Build a download_fn that writes a small tar, but patch the cap
+ """A tar larger than terminal.sync_back_max_bytes should be skipped with a warning."""
+ # Build a download_fn that writes a small tar, but lower the configured cap
# so the test doesn't need to produce a 2 GiB file.
skill_host = _write_file(tmp_path / "host_skill.md", b"original")
files = {"root/.hermes/skill.md": b"remote_version"}
@@ -515,7 +515,7 @@ class TestSyncBackSizeCap:
# Cap at 1 byte so any non-empty tar exceeds it
with caplog.at_level(logging.WARNING, logger="tools.environments.file_sync"):
- with patch("tools.environments.file_sync._SYNC_BACK_MAX_BYTES", 1):
+ with patch("hermes_cli.config.load_config", return_value={"terminal": {"sync_back_max_bytes": 1}}):
mgr.sync_back(hermes_home=tmp_path / ".hermes")
# Host file should be untouched because extraction was skipped
@@ -539,23 +539,30 @@ class TestSyncBackSizeCap:
mgr.sync_back(hermes_home=tmp_path / ".hermes")
assert Path(host_file).read_bytes() == b"remote_version"
- def test_cap_override_env_raises_the_cap(self, tmp_path, monkeypatch, caplog):
- """HERMES_SYNC_BACK_MAX_BYTES overrides the 2 GiB default; a non-integer value is
- ignored with a warning and the default applies."""
+ def test_cap_override_config_key_raises_the_cap(self, tmp_path, monkeypatch, caplog):
+ """config.yaml ``terminal.sync_back_max_bytes`` overrides the 2 GiB default; a
+ non-integer value is ignored with a warning and the default applies. The env var
+ the first cut used is gone — non-secret settings live in config.yaml."""
+ from hermes_cli.config_defaults import DEFAULT_CONFIG
+ assert DEFAULT_CONFIG["terminal"]["sync_back_max_bytes"] == 2 * 1024 * 1024 * 1024
+
host_file = _write_file(tmp_path / "host_skill.md", b"original")
files = {"root/.hermes/skill.md": b"remote_version"}
mgr = _make_manager(tmp_path, file_mapping=[(host_file, "/root/.hermes/skill.md")],
bulk_download_fn=_make_download_fn(files))
- monkeypatch.setenv("HERMES_SYNC_BACK_MAX_BYTES", "1")
+ monkeypatch.setenv("HERMES_SYNC_BACK_MAX_BYTES", "1") # the first cut's env var: must be ignored
+ monkeypatch.setattr("hermes_cli.config.load_config",
+ lambda: {"terminal": {"sync_back_max_bytes": 1}})
mgr.sync_back(hermes_home=tmp_path / ".hermes")
assert Path(host_file).read_bytes() == b"original" # 1-byte cap: skipped
- monkeypatch.setenv("HERMES_SYNC_BACK_MAX_BYTES", "lots")
+ monkeypatch.setattr("hermes_cli.config.load_config",
+ lambda: {"terminal": {"sync_back_max_bytes": "lots"}})
with caplog.at_level(logging.WARNING, logger="tools.environments.file_sync"):
mgr.sync_back(hermes_home=tmp_path / ".hermes")
assert Path(host_file).read_bytes() == b"remote_version" # default cap applies
- assert any("HERMES_SYNC_BACK_MAX_BYTES" in r.message for r in caplog.records)
+ assert any("sync_back_max_bytes" in r.message for r in caplog.records)
class TestSyncBackWindowsHost:
diff --git a/tools/environments/file_sync.py b/tools/environments/file_sync.py
index 5fe54171578..05aee926b7f 100644
--- a/tools/environments/file_sync.py
+++ b/tools/environments/file_sync.py
@@ -24,6 +24,8 @@ except ImportError:
from pathlib import Path
from typing import Callable
+import psutil
+
from hermes_constants import get_hermes_home
from tools.environments.base import _file_mtime_key
@@ -48,7 +50,7 @@ GetFilesFn = Callable[[], list[tuple[str, str]]] # () -> [(host_path, remote_pa
_SYNC_BACK_MAX_RETRIES = 3
_SYNC_BACK_BACKOFF = (2, 4, 8) # seconds between retries
_SYNC_BACK_MAX_BYTES = 2 * 1024 * 1024 * 1024 # 2 GiB — refuse to extract larger tars
-_SYNC_BACK_MAX_BYTES_ENV = "HERMES_SYNC_BACK_MAX_BYTES"
+_SYNC_BACK_MAX_BYTES_KEY = "sync_back_max_bytes" # config.yaml terminal.<key>
_SYNC_BACK_TEMP_PREFIX = "hermes-sync-back-"
# A sync-back temp entry (the downloaded tar or the extraction staging dir) is only leaked by
# a hard kill (SIGKILL/OOM/power loss — the ``finally`` never runs). Entry names embed the
@@ -60,14 +62,16 @@ _SYNC_BACK_STALE_SECONDS = 30 * 60
def _sync_back_max_bytes() -> int:
- """Extraction cap; ``HERMES_SYNC_BACK_MAX_BYTES`` overrides it for trees that legitimately
- exceed 2 GiB (a skipped extraction silently discards the whole download)."""
- raw = os.environ.get(_SYNC_BACK_MAX_BYTES_ENV, "").strip()
- if raw:
+ """Extraction cap; config.yaml ``terminal.sync_back_max_bytes`` overrides it for trees that
+ legitimately exceed 2 GiB (a skipped extraction silently discards the whole download)."""
+ from hermes_cli.config import load_config
+
+ raw = ((load_config() or {}).get("terminal") or {}).get(_SYNC_BACK_MAX_BYTES_KEY)
+ if raw is not None:
try:
return int(raw)
- except ValueError:
- logger.warning("sync_back: ignoring non-integer %s=%r", _SYNC_BACK_MAX_BYTES_ENV, raw)
+ except (TypeError, ValueError):
+ logger.warning("sync_back: ignoring non-integer terminal.%s=%r", _SYNC_BACK_MAX_BYTES_KEY, raw)
return _SYNC_BACK_MAX_BYTES
@@ -80,14 +84,10 @@ def _sync_back_temp_prefix() -> str:
def _temp_entry_owner_alive(name: str) -> bool:
"""Whether the process that created a sync-back temp entry may still be running.
- Names without a PID (and hosts without psutil) count as alive: the age cutoff applies."""
+ Names without a PID count as alive: the age cutoff applies."""
pid_part = name[len(_SYNC_BACK_TEMP_PREFIX):].split("-", 1)[0]
if not pid_part.isdigit():
return True
- try:
- import psutil
- except ImportError:
- return True
return psutil.pid_exists(int(pid_part))
@@ -404,8 +404,8 @@ class FileSyncManager:
max_bytes = _sync_back_max_bytes()
if tar_size > max_bytes:
logger.warning(
- "sync_back: remote tar is %d bytes (cap %d, override with %s) — skipping extraction",
- tar_size, max_bytes, _SYNC_BACK_MAX_BYTES_ENV)
+ "sync_back: remote tar is %d bytes (cap %d, override with terminal.%s) — skipping extraction",
+ tar_size, max_bytes, _SYNC_BACK_MAX_BYTES_KEY)
return
with tempfile.TemporaryDirectory(prefix=_sync_back_temp_prefix()) as staging:
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index 3ddd941face..3b79fac99c1 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -224,6 +224,7 @@ terminal:
timeout: 180 # Per-command timeout in seconds
home_mode: auto # auto | real | profile — subprocess HOME policy
env_passthrough: [] # Env var names to forward to sandboxed execution (terminal + execute_code)
+ sync_back_max_bytes: 2147483648 # Remote backends: refuse to extract a state archive larger than this (bytes)
singularity_image: "docker://nikolaik/python-nodejs:python3.11-nodejs20" # Container image for Singularity backend
modal_image: "nikolaik/python-nodejs:python3.11-nodejs20" # Container image for Modal backend
daytona_image: "nikolaik/python-nodejs:python3.11-nodejs20" # Container image for Daytona backend
@@ -591,7 +592,7 @@ When in doubt, set `terminal.backend` back to `local` and verify that commands r
For the **SSH**, **Modal**, and **Daytona** backends, Hermes pushes your `~/.hermes/` state (credential files, skills, cache) into the remote sandbox during the session, and on teardown **syncs changed state files back** to their original host locations. Files that differ from what was originally pushed (compared by content hash) are applied back in place; new remote files under a synced directory (e.g. a skill the agent created remotely) are mapped back to the corresponding host path. Upload-only credential files are never overwritten on the host.
-- The sync-back retries up to 3 times with backoff and refuses to extract remote archives larger than 2 GiB; set `HERMES_SYNC_BACK_MAX_BYTES` (bytes) to raise the cap for a larger state tree. Live sockets under the remote `~/.hermes/` (e.g. `gateway.sock`) are skipped rather than failing the transfer.
+- The sync-back retries up to 3 times with backoff and refuses to extract remote archives larger than 2 GiB; set `terminal.sync_back_max_bytes` (bytes) in `config.yaml` to raise the cap for a larger state tree. Live sockets under the remote `~/.hermes/` (e.g. `gateway.sock`) are skipped rather than failing the transfer.
- The downloaded archive is staged under the system temp directory (`hermes-sync-back-<pid>-*`); leftovers from a hard-killed process are reclaimed on the next sync-back.
- Docker and Singularity use bind mounts (live host filesystem view) and don't need this.
- This covers Hermes state (`~/.hermes/`), **not** arbitrary working-tree files inside the sandbox — have the agent copy important artifacts out explicitly (e.g. `scp`, `modal volume put`) before the sandbox is destroyed.