The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(checkpoints): refuse rollback.diff from container-backed sessions on the TUI/Desktop RPC
teknium11efc02716a19
diff --git a/tests/tui_gateway/test_rollback_container_refusal.py b/tests/tui_gateway/test_rollback_container_refusal.pynew file mode 100644index 00000000000..cf25213eb90--- /dev/null+++ b/tests/tui_gateway/test_rollback_container_refusal.py@@ -0,0 +1,57 @@+"""``rollback.diff`` refuses a container-backed session like every other ``/rollback diff`` surface.++The host tree vs a host checkpoint is not the sandbox session's diff, so the RPC must not run+``mgr.diff`` once the manager classifies the task's backend as a container."""+import threading+import types++from tui_gateway import server+++def test_rollback_diff_refuses_container_backed_session():+ seen = {}++ class _Mgr:+ enabled = True++ def unsupported_backend_reason(self, task_id="default"):+ seen["task_id"] = task_id+ return "Checkpoints are not taken for terminal.backend=docker: file paths belong to the container."++ def list_checkpoints(self, cwd):+ return [{"hash": "abc123"}]++ def diff(self, cwd, target):+ raise AssertionError("mgr.diff must not run for a container-backed session")++ server._sessions["sid"] = _session(+ agent=types.SimpleNamespace(_checkpoint_mgr=_Mgr()), session_key="container-session"+ )+ try:+ resp = server.handle_request(+ {"id": "1", "method": "rollback.diff", "params": {"session_id": "sid", "hash": "abc123"}}+ )+ finally:+ server._sessions.pop("sid", None)++ assert "result" not in resp+ assert "terminal.backend=docker" in resp["error"]["message"]+ assert seen["task_id"] == "container-session"+++def _session(agent, **extra):+ return {+ "agent": agent,+ "session_key": "session-key",+ "history": [],+ "history_lock": threading.Lock(),+ "history_version": 0,+ "running": False,+ "attached_images": [],+ "image_counter": 0,+ "cols": 80,+ "slash_worker": None,+ "show_reasoning": False,+ "tool_progress_mode": "all",+ **extra,+ }diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex 4c1e6480fc0..e65800a7f4e 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -966,19 +966,7 @@ def _(rid, params: dict, session) -> dict:return _err(rid, 4009, busy_message("rollback restore"))def go(mgr, cwd):- # Container-backed session: the host checkpoints listed are not this session's tree. Classify- # with the identity and scopes a turn binds (prompt_turn.py): the session key is the tool-call- # task id, the session context drives the terminal registry lookup, and the profile scope- # supplies the terminal policy; otherwise a cached launch-profile environment or the launch- # config would answer for another profile's session.- task_id = session.get("session_key") or "default"- tokens = _set_session_context(task_id, cwd=cwd)- try:- with _session_profile_runtime_scope(session):- reason = getattr(mgr, "unsupported_backend_reason", lambda *_: None)(task_id)- finally:- _clear_session_context(tokens)- if reason:+ if reason := _container_checkpoint_refusal(session, mgr, cwd):return {"success": False, "error": reason}result = mgr.restore(cwd, _resolve_checkpoint_hash(mgr, cwd, target), file_path=file_path or None)if result.get("success") and not file_path:@@ -999,12 +987,34 @@ def _(rid, params: dict, session) -> dict:def _(rid, params: dict, session) -> dict:if not (target := params.get("hash", "")):return _err(rid, 4014, "hash required")- r = _with_checkpoints(session, lambda mgr, cwd: mgr.diff(cwd, _resolve_checkpoint_hash(mgr, cwd, target)))- raw = r.get("diff", "")[:4000]- payload = {"stat": r.get("stat", ""), "diff": raw}- if rendered := render_diff(raw, session.get("cols", 80)):- payload["rendered"] = rendered- return _ok(rid, payload)++ def go(mgr, cwd):+ # Host tree vs host checkpoint is not this session's diff either (same refusal as /rollback diff).+ if reason := _container_checkpoint_refusal(session, mgr, cwd):+ return _err(rid, 5022, reason)+ r = mgr.diff(cwd, _resolve_checkpoint_hash(mgr, cwd, target))+ raw = r.get("diff", "")[:4000]+ payload = {"stat": r.get("stat", ""), "diff": raw}+ if rendered := render_diff(raw, session.get("cols", 80)):+ payload["rendered"] = rendered+ return _ok(rid, payload)+ return _with_checkpoints(session, go)+++def _container_checkpoint_refusal(session, mgr, cwd) -> str | None:+ """Why host checkpoints are off limits for a container-backed session, else ``None``.++ Classifies with the identity and scopes a turn binds (prompt_turn.py): the session key is the+ tool-call task id, the session context drives the terminal registry lookup, and the profile+ scope supplies the terminal policy; otherwise a cached launch-profile environment or the launch+ config would answer for another profile's session."""+ task_id = session.get("session_key") or "default"+ tokens = _set_session_context(task_id, cwd=cwd)+ try:+ with _session_profile_runtime_scope(session):+ return mgr.unsupported_backend_reason(task_id)+ finally:+ _clear_session_context(tokens)@method("browser.manage")diff --git a/website/docs/user-guide/checkpoints-and-rollback.md b/website/docs/user-guide/checkpoints-and-rollback.mdindex 0809207a869..c8a512381ba 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: it still lists existing host checkpoints but refuses diff and restore, on the CLI and in messaging-gateway chats alike; `/diff session` answers with the same reason. Over the TUI/Desktop RPC, `rollback.list` and `rollback.diff` remain available for inspecting host checkpoints while `rollback.restore` is refused. Local and SSH backends are unaffected. To point `terminal.cwd` at the container-side view of a mounted directory see [`terminal.docker_mount_cwd_to_workspace`](./configuration.md).+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, on the CLI and in messaging-gateway chats alike; `/diff session` answers with the same reason. The TUI and Desktop behave the same: `/rollback list` still works while `/rollback diff` and `/rollback <N>` are refused with that reason. Local and SSH backends are unaffected. To point `terminal.cwd` at the container-side view of a mounted directory see [`terminal.docker_mount_cwd_to_workspace`](./configuration.md).- **Git availability** — if `git` is not found on `PATH`, checkpoints are transparently disabled.- **Directory scope** — Hermes skips overly broad directories (root `/`, home `$HOME`).