Skip to content

The agent that grows with you

fix(gateway): a messaging follow-up past the queue cap gets a plain notice

Teknium428a3e0cf008
diff --git a/gateway/session_ingress.py b/gateway/session_ingress.py
index e0f9c5a80d5..4a4ba6deec8 100644
--- a/gateway/session_ingress.py
+++ b/gateway/session_ingress.py
@@ -20,7 +20,13 @@ busy_acceptance = ContextVar('busy_acceptance', default=None)
async def admit_message(authority, event):
accepted = busy_acceptance.get()
busy_acceptance.set(None) # the drain task this schedules must not inherit the busy caller's future
- receipt = await authority.admit_native(event)
+ try:
+ receipt = await authority.admit_native(event)
+ except RuntimeStoreError as exc:
+ if exc.reason != 'queue_full':
+ raise
+ # Nothing was committed (main's busy-queue cap): say so instead of a generic turn error.
+ return '⏳ Too many messages are already waiting in this conversation; send this again after the current reply.'
if receipt.status == 'terminal':
return None
# Only the delivery waiter is process-local; execution reads the committed snapshot.
diff --git a/tests/gateway/test_admission_queue_cap_notice.py b/tests/gateway/test_admission_queue_cap_notice.py
new file mode 100644
index 00000000000..70d7e7497b1
--- /dev/null
+++ b/tests/gateway/test_admission_queue_cap_notice.py
@@ -0,0 +1,24 @@
+"""A messaging follow-up past the FIFO cap gets a plain queue_full notice, not a turn error (N62)."""
+import pytest
+
+from gateway.platforms.event import MessageEvent
+from gateway.session_contract import Submission
+from gateway.session_ingress import admit_message
+from hermes_state_runtime import ADMISSION_QUEUE_MAX, list_session_admissions
+from tests.gateway.test_session_authority_cancel_settlement import ACTOR, REF, _authority, _submit
+
+
+async def test_messaging_overflow_is_answered_with_a_queue_full_notice(tmp_path, monkeypatch):
+ db, authority = _authority(tmp_path, monkeypatch)
+ monkeypatch.setattr(authority, '_schedule', lambda ref: None) # the running turn never drains
+
+ async def admit_native(event):
+ return await authority.submit(ACTOR, Submission(event.text, REF, {'text': event.text}, 'queue'))
+ monkeypatch.setattr(authority, 'admit_native', admit_native)
+ with db:
+ for n in range(ADMISSION_QUEUE_MAX):
+ await _submit(authority, f'r{n}')
+ reply = await admit_message(authority, MessageEvent(text='overflow', source=authority.sessions['s'].source))
+ assert reply is not None and 'Too many messages' in reply, reply
+ assert len(list_session_admissions(db, session_id='s')) == ADMISSION_QUEUE_MAX