Skip to content

The agent that grows with you

fix(gateway): preserve revoked launch YOLO across owner restart

David Dudok de Wit53e73da8f202
diff --git a/gateway/run_turn_prepare.py b/gateway/run_turn_prepare.py
index 955dde7f2d9..881c14efa2b 100644
--- a/gateway/run_turn_prepare.py
+++ b/gateway/run_turn_prepare.py
@@ -632,9 +632,9 @@ class GatewayTurnPrepareMixin:
``(_PreparedTurn, env_tokens)``; a ``str`` first element is a reply to send instead of
running (history unreadable); ``None`` drops the turn (inbound text rejected)."""
from gateway.run import _load_gateway_config
- from tools.approval_yolo import restore_session_yolo
+ from tools.approval_yolo import restore_gateway_yolo
_was_auto_reset, _is_new_session = await self._hmwa_open_session(session_entry, session_key, source)
- restore_session_yolo(session_key, session_entry.yolo is True) # a restarted gateway's set starts empty
+ restore_gateway_yolo(session_key, session_entry.yolo is True)
context = build_session_context(source, self.config, session_entry)
# Session context variables for tools (task-local, concurrency-safe)
_session_env_tokens = self._set_session_env(context)
diff --git a/gateway/session_busy_controls.py b/gateway/session_busy_controls.py
index f979d206b1e..eb0973f202b 100644
--- a/gateway/session_busy_controls.py
+++ b/gateway/session_busy_controls.py
@@ -79,7 +79,7 @@ async def yolo_config(connection, ref, params, write):
never HERMES_YOLO_MODE or approvals.mode. A ``--yolo`` launch is seeded first, so revoking it
here is not re-enabled by the next turn's launch seeding. The write goes through the shared
``tools.approval_yolo.toggle_session_yolo`` contract on the route's persisted copy
- (``SessionEntry.yolo``, re-armed every turn by ``restore_session_yolo``), like the messaging
+ (``SessionEntry.yolo``, restored by ``restore_gateway_yolo``), like the messaging
``/yolo``: persisted before the live flip, so an OFF here is not revived by the next turn."""
value = params.get('value')
if write and value is not None and str(value).strip().lower() not in _YOLO_WORDS:
@@ -91,10 +91,13 @@ async def yolo_config(connection, ref, params, write):
live = connection.authority.sessions[ref.session_id]
runner = connection.authority.runner
policy = policy_for_source(runner, live.source)
- if policy is not None and policy.yolo:
- apply_launch_yolo(live.route)
store = getattr(runner, 'session_store', None)
entry = await runner.async_session_store.lookup_by_session_key(live.route) if store is not None else None
+ if entry is not None:
+ from tools.approval_yolo import restore_gateway_yolo
+ restore_gateway_yolo(live.route, entry.yolo is True)
+ elif policy is not None and policy.yolo:
+ apply_launch_yolo(live.route)
# After a restart only the persisted copy is set until the next turn re-arms it: still ON.
persisted = getattr(entry, 'yolo', False) is True
enabled = is_session_yolo_enabled(live.route) or persisted
diff --git a/gateway/session_local.py b/gateway/session_local.py
index 08feb7cdd4c..b55a0344016 100644
--- a/gateway/session_local.py
+++ b/gateway/session_local.py
@@ -161,7 +161,7 @@ def create_local_session(authority, actor, params, *, trusted_policy=None, trust
# Same clock as every other routing entry: the recovery sweeps compare against a
# naive cutoff, and one aware entry aborts the whole iteration.
now = _now()
- entry = SessionEntry(route, sid, now, now, origin=source, platform=Platform.LOCAL)
+ entry = SessionEntry(route, sid, now, now, origin=source, platform=Platform.LOCAL, yolo=policy.yolo)
commit_local_session(authority.db, epoch=authority.epoch, receipt={
'profile_id': authority.profile_id, 'principal_id': actor.subject, 'request_id': request_id,
'session_id': sid, 'route': route, 'entry': entry.to_dict(), 'policy': asdict(policy)})
diff --git a/gateway/session_managed_worker.py b/gateway/session_managed_worker.py
index c4d23321f90..28212061f5f 100644
--- a/gateway/session_managed_worker.py
+++ b/gateway/session_managed_worker.py
@@ -72,12 +72,13 @@ def _session_yolo(authority, route, policy):
"""The route's bypass as the in-process turn arms it on the owner, the one place a revocation
is recorded: a ``--yolo`` launch seeded once per boundary, then the persisted ``/yolo`` copy."""
from tools.approval import is_session_yolo_enabled
- from tools.approval_yolo import apply_launch_yolo, restore_session_yolo
- if policy.yolo:
- apply_launch_yolo(route)
+ from tools.approval_yolo import apply_launch_yolo, restore_gateway_yolo
store = getattr(authority.runner, 'session_store', None)
- if store is not None:
- restore_session_yolo(route, getattr(store.lookup_by_session_key(route), 'yolo', False) is True)
+ entry = store.lookup_by_session_key(route) if store is not None else None
+ if entry is not None:
+ restore_gateway_yolo(route, entry.yolo is True)
+ elif policy.yolo:
+ apply_launch_yolo(route)
return is_session_yolo_enabled(route)
diff --git a/tests/gateway/test_yolo_restart_revocation.py b/tests/gateway/test_yolo_restart_revocation.py
new file mode 100644
index 00000000000..89a740b5441
--- /dev/null
+++ b/tests/gateway/test_yolo_restart_revocation.py
@@ -0,0 +1,51 @@
+"""An explicitly revoked --yolo launch stays off in a fresh gateway interpreter."""
+import subprocess
+import sys
+
+
+def test_persisted_off_is_not_overridden_by_frozen_launch_after_restart(tmp_path):
+ from gateway.config import GatewayConfig, Platform
+ from gateway.session import SessionStore, SessionSource
+ store = SessionStore(sessions_dir=tmp_path, config=GatewayConfig())
+ store._db = None
+ source = SessionSource(platform=Platform.LOCAL, chat_id='revoked', user_id='human')
+ entry = store.get_or_create_session(source)
+ store.set_session_yolo(entry.session_key, True)
+ store.set_session_yolo(entry.session_key, False)
+ probe = '''
+import sys
+from pathlib import Path
+from gateway.config import GatewayConfig
+from gateway.session import SessionStore
+from types import SimpleNamespace
+from gateway.session_managed_worker import _session_yolo
+from tools.approval import is_session_yolo_enabled
+store = SessionStore(sessions_dir=Path(sys.argv[1]), config=GatewayConfig())
+store._db = None
+entry = store.lookup_by_session_key(sys.argv[2])
+assert entry is not None and entry.yolo is False
+_session_yolo(SimpleNamespace(runner=SimpleNamespace(session_store=store)),
+ entry.session_key, SimpleNamespace(yolo=True))
+assert not is_session_yolo_enabled(entry.session_key), 'revoked launch was re-enabled'
+'''
+ result = subprocess.run([sys.executable, '-c', probe, str(tmp_path), entry.session_key],
+ capture_output=True, text=True, timeout=30)
+ assert result.returncode == 0, result.stdout + result.stderr
+
+
+def test_live_toggle_survives_failed_persistence_after_initial_restore():
+ from tools.approval import clear_session, is_session_yolo_enabled
+ from tools.approval_yolo import restore_gateway_yolo, toggle_session_yolo
+ key = 'gateway-yolo-persistence-failure'
+ def unavailable(enabled):
+ raise OSError('routing store unavailable')
+ try:
+ restore_gateway_yolo(key, False)
+ toggle_session_yolo(key, True, persist=unavailable)
+ restore_gateway_yolo(key, False)
+ assert is_session_yolo_enabled(key) is True
+ toggle_session_yolo(key, False, persisted=True, persist=unavailable)
+ restore_gateway_yolo(key, True)
+ assert is_session_yolo_enabled(key) is False
+ finally:
+ clear_session(key)
diff --git a/tools/approval_yolo.py b/tools/approval_yolo.py
index 995e0fff27f..cfcdbec4274 100644
--- a/tools/approval_yolo.py
+++ b/tools/approval_yolo.py
@@ -71,6 +71,17 @@ def apply_launch_yolo(session_key: str) -> None:
approval.enable_session_yolo(session_key)
+def restore_gateway_yolo(session_key: str, persisted: bool) -> None:
+ """Restore the authoritative routing value, including OFF, before frozen launch seeding."""
+ if not session_key:
+ return
+ with approval._lock:
+ if session_key in approval._launch_yolo_applied:
+ return # after restoration, the live toggle remains authoritative in this process
+ approval._launch_yolo_applied.add(session_key)
+ (approval._session_yolo.add if persisted else approval._session_yolo.discard)(session_key)
+
+
def transfer_session_yolo(old_key: str, new_key: str) -> None:
"""Move the live bypass when the conversation continues under a new id (compression rotation, /branch).
The new row records it at creation (``with_session_yolo``), so nothing is written here."""