The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): the sidecar's rollback.restore refuses a non-boolean all
unsupportedpastels58e518e20ad7
diff --git a/tests/tui_gateway/test_rollback_restore_safe.py b/tests/tui_gateway/test_rollback_restore_safe.pyindex cd281067390..8a30e1d1f3e 100644--- a/tests/tui_gateway/test_rollback_restore_safe.py+++ b/tests/tui_gateway/test_rollback_restore_safe.py@@ -33,6 +33,38 @@ def test_rollback_restore_keeps_hand_edits_unless_all():assert calls == [(None, True), (None, True), (None, True), (None, False), ("a.py", False)]+def test_rollback_restore_refuses_a_non_boolean_all_before_touching_anything():+ """``all: "false"`` or ``all: 1`` is not ``true``: refused by name, like the owner, never read as+ an override. Nothing is restored and the history is not rewound."""+ calls = []++ class _Mgr:+ enabled = True+ unsupported_backend_reason = staticmethod(lambda task_id="default": None)++ def list_checkpoints(self, cwd):+ return [{"hash": "aaa111"}]++ def restore(self, cwd, target, file_path=None, safe=False):+ calls.append((file_path, safe))+ return {"success": True, "message": "done"}++ history = [{"role": "user", "content": "hi"}, {"role": "assistant", "content": "ok"}]+ try:+ for value in ("false", "true", 1, 0, [], {}):+ for extra in ({}, {"file_path": "a.py"}):+ session = _session(types.SimpleNamespace(_checkpoint_mgr=_Mgr()), history=list(history))+ server._sessions["sid"] = session+ resp = server.handle_request({"id": "1", "method": "rollback.restore",+ "params": {"session_id": "sid", "hash": "1", "all": value, **extra}})+ assert resp.get("error", {}).get("data") == {+ "reason": "invalid_params", "field": "all", "detail": "must be a boolean"}, (value, resp)+ assert session["history"] == history+ finally:+ server._sessions.pop("sid", None)+ assert calls == []++def _session(agent, **extra):return {"agent": agent,diff --git a/tui_gateway/methods_tools.py b/tui_gateway/methods_tools.pyindex c646bddc035..0666d6555ad 100644--- a/tui_gateway/methods_tools.py+++ b/tui_gateway/methods_tools.py@@ -1127,6 +1127,9 @@ def _(rid, params: dict, session) -> dict:target, file_path = params.get("hash", ""), params.get("file_path", "")if not target:return _err(rid, 4014, "hash required")+ if params.get("all") is not None and not isinstance(params["all"], bool): # the owner's rule: null is omitted+ return _err(rid, 4001, "invalid_params",+ data={"reason": "invalid_params", "field": "all", "detail": "must be a boolean"})# Full-history rollback mutates session history → rejected mid-turn (prompt.submit# would drop the agent's output or clobber it). File-scoped only touches disk.if not file_path and session.get("running"):@@ -1137,7 +1140,7 @@ def _(rid, params: dict, session) -> dict:return {"success": False, "error": reason}# A whole-tree restore keeps the user's hand-edits unless ``all`` (main's --all), as on the owner.result = mgr.restore(cwd, _resolve_checkpoint_hash(mgr, cwd, target), file_path=file_path or None,- safe=not file_path and not params.get("all"))+ safe=not file_path and params.get("all") is not True)if result.get("success") and not file_path:removed = 0with session["history_lock"]: