Skip to content

The agent that grows with you

fix(checkpoints): classify the backend on every /rollback instead of remembering it

Sora-bluesky3220b9ed2fab
diff --git a/agent/tool_executor.py b/agent/tool_executor.py
index 515629469e0..5c12edcc7d8 100644
--- a/agent/tool_executor.py
+++ b/agent/tool_executor.py
@@ -87,10 +87,8 @@ def _ensure_file_checkpoint(agent, function_name: str, function_args: dict, effe
file_path = function_args.get("path", "")
if not file_path:
return
- backend = _checkpoint_container_backend(effective_task_id)
- if backend is not None:
- agent._checkpoint_mgr.note_unsupported_backend(backend)
- return
+ if _checkpoint_container_backend(effective_task_id) is not None:
+ return # container paths: nothing to checkpoint on the host
from agent.file_safety import is_nt_namespace_path
from tools.file_tools_paths import _resolve_path_for_task
@@ -991,10 +989,7 @@ def _begin_tool_execution(agent, ref: _ToolCallRef, display_index: int | None) -
elif function_name == "terminal":
command = function_args.get("command", "")
if _is_destructive_command(command):
- backend = _checkpoint_container_backend(effective_task_id)
- if backend is not None:
- agent._checkpoint_mgr.note_unsupported_backend(backend)
- else:
+ if _checkpoint_container_backend(effective_task_id) is None:
from agent.runtime_cwd import scope_terminal_cwd
cwd = function_args.get("workdir") or scope_terminal_cwd() or os.getcwd()
agent._checkpoint_mgr.ensure_checkpoint(cwd, f"before terminal: {command[:60]}")
diff --git a/agent/turn_explainers.py b/agent/turn_explainers.py
index 44021620559..b517690fb22 100644
--- a/agent/turn_explainers.py
+++ b/agent/turn_explainers.py
@@ -257,10 +257,7 @@ class TurnExplainersMixin:
with suppress(Exception):
from agent.tool_executor import _checkpoint_container_backend
backend = _checkpoint_container_backend(task_id or "default")
- if backend is not None:
- with suppress(Exception):
- mgr.note_unsupported_backend(backend)
- else:
+ if backend is None: # container paths carry no host ledger entry
for _p in landed_paths:
with suppress(Exception):
mgr.record_agent_write(_p)
diff --git a/tests/agent/test_tool_executor_checkpoint_paths.py b/tests/agent/test_tool_executor_checkpoint_paths.py
index 343e2e787dc..8fd91c9df66 100644
--- a/tests/agent/test_tool_executor_checkpoint_paths.py
+++ b/tests/agent/test_tool_executor_checkpoint_paths.py
@@ -67,10 +67,9 @@ def test_relative_file_checkpoint_uses_task_workspace(tmp_path, monkeypatch):
assert manager.list_checkpoints(str(process_cwd)) == []
-def _assert_container_skipped(manager):
+def _assert_container_skipped(manager, task_id):
assert manager.list_all_checkpoints() == []
- assert manager.unsupported_backend == "docker"
- assert "docker" in manager.unsupported_backend_reason()
+ assert "docker" in manager.unsupported_backend_reason(task_id)
def test_container_backend_file_checkpoint_is_not_taken_on_missing_host_path(
@@ -80,7 +79,7 @@ def test_container_backend_file_checkpoint_is_not_taken_on_missing_host_path(
_ensure_file_checkpoint(
agent, "write_file", {"path": "/workspace/project/a.txt"}, container_task_id
)
- _assert_container_skipped(manager)
+ _assert_container_skipped(manager, container_task_id)
@pytest.mark.skipif(os.name == "nt", reason="POSIX absolute container path")
@@ -98,7 +97,7 @@ def test_container_backend_file_checkpoint_does_not_snapshot_a_colliding_host_tr
container_task_id,
)
assert manager.list_checkpoints(str(host_dir)) == []
- _assert_container_skipped(manager)
+ _assert_container_skipped(manager, container_task_id)
def test_container_backend_destructive_terminal_checkpoint_is_not_taken(
@@ -124,7 +123,7 @@ def test_container_backend_destructive_terminal_checkpoint_is_not_taken(
[],
)
_begin_tool_execution(agent, ref, None)
- _assert_container_skipped(manager)
+ _assert_container_skipped(manager, container_task_id)
def test_container_backend_post_write_ledger_is_not_recorded(
@@ -150,7 +149,21 @@ def test_container_backend_post_write_ledger_is_not_recorded(
task_id=container_task_id,
)
assert not (tmp_path / "checkpoints" / "store" / "ledgers").exists()
- _assert_container_skipped(manager)
+ _assert_container_skipped(manager, container_task_id)
+
+
+def test_backend_reason_follows_the_session_backend(monkeypatch, manager):
+ """Nothing is remembered: the same manager answers for the backend configured right now,
+ even after a container-backed mutation went through the checkpoint hook."""
+ monkeypatch.setenv("TERMINAL_ENV", "docker")
+ _ensure_file_checkpoint(
+ SimpleNamespace(_checkpoint_mgr=manager), "write_file", {"path": "/workspace/project/a.txt"}, "default"
+ )
+ assert "docker" in manager.unsupported_backend_reason()
+ monkeypatch.setenv("TERMINAL_ENV", "local")
+ assert manager.unsupported_backend_reason() is None
+ monkeypatch.setenv("TERMINAL_ENV", "docker")
+ assert "docker" in manager.unsupported_backend_reason()
def test_local_backend_behaviour_unchanged(tmp_path, monkeypatch, manager):
diff --git a/tools/checkpoint_manager.py b/tools/checkpoint_manager.py
index f6a4a8a157c..06640f0ab5d 100644
--- a/tools/checkpoint_manager.py
+++ b/tools/checkpoint_manager.py
@@ -603,33 +603,21 @@ class CheckpointManager:
max(1, int(max_snapshots)), max(0, int(max_total_size_mb)), max(0, int(max_file_size_mb)))
self._checkpointed_dirs: Set[str] = set()
self._git_available: Optional[bool] = None # lazy probe
- self.unsupported_backend: Optional[str] = None
def new_turn(self) -> None:
"""Reset per-turn dedup. Call at the start of each agent iteration."""
self._checkpointed_dirs.clear()
- def note_unsupported_backend(self, backend: str) -> None:
- """Remember the first backend whose paths cannot be checkpointed. Never raises."""
- try:
- if self.unsupported_backend is None:
- self.unsupported_backend = backend
- logger.debug("Checkpoints skipped for container backend: %s", backend)
- except Exception:
- pass
-
def unsupported_backend_reason(self, task_id: str = "default") -> Optional[str]:
"""Explain why host checkpoints are off limits for a container-backed session.
- Classifies the task's backend directly so /rollback is refused before the first
- mutation is observed; the recorded backend, when set, is the same answer."""
- backend = self.unsupported_backend
- if backend is None:
- try:
- from tools.file_tools_paths import container_backend_for_task
- backend = container_backend_for_task(task_id)
- except Exception:
- backend = None
+ Classifies the task's backend at call time (nothing is remembered), so /rollback is
+ refused before the first mutation and follows a backend change within the session."""
+ try:
+ from tools.file_tools_paths import container_backend_for_task
+ backend = container_backend_for_task(task_id)
+ except Exception:
+ backend = None
if backend is None:
return None
return (
diff --git a/website/docs/user-guide/checkpoints-and-rollback.md b/website/docs/user-guide/checkpoints-and-rollback.md
index 512157bd1e1..299f3246235 100644
--- a/website/docs/user-guide/checkpoints-and-rollback.md
+++ b/website/docs/user-guide/checkpoints-and-rollback.md
@@ -236,7 +236,7 @@ Restore just one file from a checkpoint without affecting the rest of the direct
### Container Backends
-With a container terminal backend (`docker`, `singularity`, `modal`, `daytona`, `vercel_sandbox`, or a container plugin), file paths belong to the sandbox rather than the host. Hermes therefore does not take checkpoints or record the agent-write ledger for those paths, and `/rollback` explains the limitation; local and SSH backends are unaffected.
+With a container terminal backend (`docker`, `singularity`, `modal`, `daytona`, `vercel_sandbox`, or a container plugin), file paths belong to the sandbox rather than the host. Hermes therefore does not take checkpoints or record the agent-write ledger for those paths, and `/rollback` explains the limitation: it still lists existing host checkpoints but refuses diff and restore. Over the gateway RPC, `rollback.list` and `rollback.diff` remain available for inspecting host checkpoints while `rollback.restore` is refused. Local and SSH backends are unaffected.
- **Git availability** — if `git` is not found on `PATH`, checkpoints are transparently disabled.
- **Directory scope** — Hermes skips overly broad directories (root `/`, home `$HOME`).