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:
committed by
Mark S.
parent
2ae47b3775
commit
a5d3c25664
@@ -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."""
|
||||
|
||||
23
tests/gateway/test_active_session_refusal_completion.py
Normal file
23
tests/gateway/test_active_session_refusal_completion.py
Normal 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
|
||||
Reference in New Issue
Block a user