fix(gateway): publish message.complete for an active-session refusal

ActiveSessionRefusal could not be copied, so publishing the completion of a
refused turn raised and the client waited forever.

Row LC-33.

Refs #143547

Co-authored-by: AJ Isaacs <ajisaacs27@gmail.com>
This commit is contained in:
unsupportedpastels
2026-10-23 14:35:53 +00:00
committed by Mark S.
parent 2ae47b3775
commit a5d3c25664
2 changed files with 28 additions and 0 deletions

View File

@@ -127,6 +127,11 @@ class ActiveSessionRefusal(str):
obj.reason = reason
return obj
def __getnewargs_ex__(self) -> tuple[tuple[str, str], dict[str, Any]]:
# copy/pickle rebuild via __new__: without the reason, publishing a refused turn's
# message.complete (deepcopy of the payload) raises and the viewer hangs.
return (str(self), self.reason), {}
def format_refusal_stderr(message: str) -> str:
"""Keep the refusal contract across the one-shot CLI subprocess boundary."""

View File

@@ -0,0 +1,23 @@
"""A refused turn still ends with message.complete, so the viewer never hangs."""
from types import SimpleNamespace
from gateway.session_events import SessionEvents
from gateway.session_settlement_recovery import _publish_completion
from hermes_cli.active_sessions import MAX_CONCURRENT_SESSIONS, ActiveSessionRefusal
def test_refused_turn_publishes_completion_with_its_reason():
stream = SessionEvents()
received = []
stream.observers.add(received.append)
live = SimpleNamespace(controls=SimpleNamespace(snapshot=lambda *a: None), event_stream=stream)
refusal = ActiveSessionRefusal('Too many active sessions.', MAX_CONCURRENT_SESSIONS)
_publish_completion(SimpleNamespace(runner=None), live, SimpleNamespace(session_id='s'),
{'admission_id': 'a1', 'request_id': 'r1'}, {'outcome': 'failed'}, refusal, None)
[frame] = received
payload = frame['params']['payload']
assert frame['params']['type'] == 'message.complete'
assert payload['text'] == 'Too many active sessions.'
assert payload['text'].reason == MAX_CONCURRENT_SESSIONS