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

TurnRunner re-enabled the frozen `hermes chat --yolo` launch bypass at the
start of every turn, so revoking it with `/yolo` (or config.set yolo) only
lasted until the next message. The launch flag now seeds the session bypass
once per session boundary (tools.approval.apply_launch_yolo); clear_session
resets the marker so a fresh boundary of a --yolo route is seeded again.

(cherry picked from commit 3228512e1b28b13ba4241864ef2e8f4c5e68aee1)
This commit is contained in:
Teknium
2026-10-06 14:38:46 -07:00
parent 7e62d683a6
commit 2600a7ccde
3 changed files with 52 additions and 2 deletions

View File

@@ -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()

View File

@@ -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)

View File

@@ -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;