Skip to content

The agent that grows with you

fix(gateway): build /diff session and /rollback checkpoints from a local session's policy

yoniebanse89706c0202b
diff --git a/gateway/slash_commands.py b/gateway/slash_commands.py
index 82b7ccbd922..0ac48d59724 100644
--- a/gateway/slash_commands.py
+++ b/gateway/slash_commands.py
@@ -230,11 +230,15 @@ class GatewaySlashCommandsMixin(
from gateway.run import _telegramize_command_mentions
return _telegramize_command_mentions(text, getattr(getattr(event, "source", None), "platform", None))
- def _checkpoint_manager(self):
- """A CheckpointManager from gateway config, or None when checkpoints are disabled."""
+ def _checkpoint_manager(self, source=None):
+ """A CheckpointManager from a local session's frozen policy, else gateway config; None when disabled."""
from gateway.run import _checkpoint_agent_kwargs, _load_gateway_config
+ from gateway.session_authorities import active_authority
+ from gateway.session_policy import policy_for_source
from tools.checkpoint_manager import CheckpointManager
- cp = _checkpoint_agent_kwargs(_load_gateway_config())
+ policy = policy_for_source(self, source) if source is not None else None
+ cp = _checkpoint_agent_kwargs(policy.config(active_authority(self), secrets=False) if policy
+ else _load_gateway_config())
if not cp["checkpoints_enabled"]:
return None
# AIAgent kwargs are ``checkpoint_<field>``; CheckpointManager takes the bare field names.
@@ -718,7 +722,7 @@ class GatewaySlashCommandsMixin(
async def _handle_rollback_command(self, event: MessageEvent) -> str:
"""Handle /rollback command — list or restore filesystem checkpoints."""
from tools.checkpoint_manager import format_checkpoint_list
- mgr = self._checkpoint_manager()
+ mgr = self._checkpoint_manager(event.source)
if mgr is None:
return t("gateway.rollback.not_enabled")
cwd = self._terminal_cwd()
@@ -769,7 +773,7 @@ class GatewaySlashCommandsMixin(
cwd = self._terminal_cwd()
if mode == "session":
# Cumulative checkpoint-baseline diff.
- mgr = self._checkpoint_manager()
+ mgr = self._checkpoint_manager(event.source)
if mgr is None:
return t("gateway.diff.not_enabled")
if reason := mgr.unsupported_backend_reason(): # host baseline is not this session's tree
diff --git a/tests/agent/test_tool_executor_checkpoint_paths.py b/tests/agent/test_tool_executor_checkpoint_paths.py
index 0e64210de01..519a5ba3640 100644
--- a/tests/agent/test_tool_executor_checkpoint_paths.py
+++ b/tests/agent/test_tool_executor_checkpoint_paths.py
@@ -131,7 +131,7 @@ async def test_container_session_refuses_host_rollback_on_every_surface(tmp_path
assert "docker" in "".join(capsys.readouterr())
runner = object.__new__(gateway_run.GatewayRunner)
- runner._checkpoint_manager = lambda: manager
+ runner._checkpoint_manager = lambda source=None: manager
source = SessionSource(platform=Platform.TELEGRAM, user_id="u", chat_id="c", user_name="t", chat_type="dm")
for text in ("/rollback 1", "/rollback 1 --all"):
assert "docker" in await runner._handle_rollback_command(MessageEvent(text=text, source=source))