Skip to content

The agent that grows with you

fix: launch YOLO seeds the bypass once so a later /yolo off sticks

Teknium2600a7ccdedd
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.py
index 0ead6438e85..98b5a3ec611 100644
--- a/gateway/run_turn_runner.py
+++ b/gateway/run_turn_runner.py
@@ -1042,8 +1042,8 @@ class TurnRunner(GatewayTurnProgressMixin, GatewaySessionAgentMixin):
from gateway.session_policy import policy_for_source
policy = policy_for_source(runner, ctx.source)
if policy and policy.yolo and ctx.session_key:
- from tools.approval import enable_session_yolo
- enable_session_yolo(ctx.session_key)
+ from tools.approval import apply_launch_yolo
+ apply_launch_yolo(ctx.session_key)
platform_key = policy.platform if policy else ("cli" if ctx.source.platform == Platform.LOCAL else ctx.source.platform.value)
combined_ephemeral = self._combined_ephemeral_prompt()
max_iterations = policy.max_turns if policy else _current_max_iterations()
diff --git a/tests/gateway/test_yolo_command.py b/tests/gateway/test_yolo_command.py
index 560e2a9ee46..bfc9be91e23 100644
--- a/tests/gateway/test_yolo_command.py
+++ b/tests/gateway/test_yolo_command.py
@@ -58,3 +58,36 @@ async def test_yolo_command_toggles_only_current_session(monkeypatch):
assert is_session_yolo_enabled(session_a) is False
assert os.environ.get("HERMES_YOLO_MODE") is None
+
+
+def test_launch_yolo_revocation_survives_the_next_turn(monkeypatch):
+ """`hermes chat --yolo` seeds the bypass once; a later `/yolo` off is not re-enabled per turn."""
+ from types import SimpleNamespace
+ import gateway.session_policy as session_policy
+ from gateway.run_turn_runner import TurnRunner
+ from gateway.turn_context import TurnContext
+
+ runner = _make_runner()
+ source = SessionSource(platform=Platform.LOCAL, chat_id="launch-yolo", user_id="u", chat_type="dm")
+ key = "agent:main:local:dm:launch-yolo"
+ monkeypatch.setattr(session_policy, "policy_for_source",
+ lambda _runner, _source: SimpleNamespace(yolo=True, platform="cli", max_turns=5))
+
+ def _stop(**_kw):
+ raise RuntimeError("stop after the yolo seam")
+ runner._resolve_session_agent_runtime = _stop
+ runner._pre_agent_fallback_notice = None
+ runner._get_system_prompt_for_channel = lambda *a, **k: ""
+
+ def turn():
+ TurnRunner(runner, TurnContext(source=source, session_key=key))._run_sync_scoped()
+
+ try:
+ turn()
+ assert is_session_yolo_enabled(key) is True
+ disable_session_yolo(key)
+ turn()
+ assert is_session_yolo_enabled(key) is False
+ finally:
+ from tools.approval import clear_session
+ clear_session(key)
diff --git a/tools/approval.py b/tools/approval.py
index 02d9581a2b0..ea0fcc92162 100644
--- a/tools/approval.py
+++ b/tools/approval.py
@@ -52,6 +52,9 @@ _lock = threading.Lock()
_pending: dict[str, dict] = {}
_session_approved: dict[str, set] = {}
_session_yolo: set[str] = set()
+# Session keys whose frozen launch YOLO (`hermes chat --yolo`) was already applied: the launch flag seeds
+# the bypass once, so a later `/yolo` off is not silently re-enabled by the next turn.
+_launch_yolo_applied: set[str] = set()
_permanent_approved: set = set()
# Routed multiplex profiles: one permanent allowlist per profile home (see ``_permanent_set``).
_permanent_approved_by_home: dict[str, set] = {}
@@ -283,6 +286,19 @@ def disable_session_yolo(session_key: str) -> None:
_set_session_yolo(session_key, False)
+def apply_launch_yolo(session_key: str) -> None:
+ """Seed a launch-time YOLO bypass once per session boundary. Called every turn of a ``--yolo``
+ route; only the first call (or the first after ``clear_session``) enables it, so a user's
+ later revocation sticks instead of lasting a single turn."""
+ if not session_key:
+ return
+ with _lock:
+ if session_key in _launch_yolo_applied:
+ return
+ _launch_yolo_applied.add(session_key)
+ _set_session_yolo(session_key, True)
+
+
def clear_session(session_key: str) -> None:
"""Remove all approval and yolo state for a given session."""
if not session_key:
@@ -290,6 +306,7 @@ def clear_session(session_key: str) -> None:
with _lock:
_session_approved.pop(session_key, None)
_session_yolo.discard(session_key)
+ _launch_yolo_applied.discard(session_key)
_pending.pop(session_key, None)
for entry in _gateway_queues.pop(session_key, []):
# Cancel blocked waits now so the old run unwinds instead of idling until timeout;