Skip to content

The agent that grows with you

fix(gateway): log a retry of an already admitted send at info

Tekniume1509a99c07e
diff --git a/gateway/session_controls.py b/gateway/session_controls.py
index d96ec7c4b80..9f740c70553 100644
--- a/gateway/session_controls.py
+++ b/gateway/session_controls.py
@@ -52,16 +52,21 @@ def _log_refusal(profile, method, exc: RuntimeStoreError) -> None:
A refusal that names the check that fired is a launch diagnostic (warning). A bare reason code is
the client's own state: ``permission_denied`` on a submit, ``not_found``, ``session_busy`` are
routine, and a retrying client must not be able to flood the gateway log, so those stay at debug
- where they were silent before. The shape follows the gateway's own refusal log lines
- (``gateway/run_notifications.py``): what was refused, for which profile, and why."""
+ where they were silent before. ``field=request_id`` is a client's explicit retry of a send already
+ admitted (the dedupe working), so it is info: expected, never in errors.log. The shape follows the
+ gateway's own refusal log lines (``gateway/run_notifications.py``): what was refused, for which
+ profile, and why."""
line = '%s refused for profile=%s: %s%s%s'
args = (method, _profile_label(profile), exc.reason,
f' field={exc.field}' if getattr(exc, 'field', None) else '',
f' detail={exc.detail}' if getattr(exc, 'detail', None) else '')
- if exc.reason != 'session_busy' and (getattr(exc, 'field', None) or getattr(exc, 'detail', None)):
- logger.warning(line, *args)
- else:
+ field = getattr(exc, 'field', None)
+ if exc.reason == 'session_busy' or not (field or getattr(exc, 'detail', None)):
logger.debug(line, *args)
+ elif field == 'request_id':
+ logger.info(line, *args)
+ else:
+ logger.warning(line, *args)
# (method, error class) pairs whose traceback this process already logged.
diff --git a/tests/gateway/test_submission_row_identity.py b/tests/gateway/test_submission_row_identity.py
index 47803906613..bf74e21f724 100644
--- a/tests/gateway/test_submission_row_identity.py
+++ b/tests/gateway/test_submission_row_identity.py
@@ -42,3 +42,27 @@ async def test_the_admitted_turns_user_row_names_its_submission_id(tmp_path, mon
('send-1', {'submission_id': 'send-1'}, {}),
('send-2', {'title_preview': 'Notes', 'submission_id': 'send-2'}, {}),
]
+
+
+async def test_a_retry_of_an_admitted_id_is_an_info_line_never_an_error(tmp_path, monkeypatch, caplog):
+ """The client settles this refusal as the dedupe it is: errors.log must not report it as a failure."""
+ from gateway.session_controls import AuthorityConnection
+
+ async def answer(event):
+ return 'ok'
+ authority = await _authority(tmp_path, monkeypatch, answer)
+ connection = AuthorityConnection(authority, object(), {'user_id': 'owner'})
+ try:
+ await connection.dispatch({'id': 1, 'method': 'session.resume', 'params': {'session_id': 's'}})
+ for rid, text in ((2, 'look at this'), (3, 'look at this, edited')):
+ with caplog.at_level('DEBUG', logger='gateway.session_controls'):
+ reply = await connection.dispatch({'id': rid, 'method': 'prompt.submit', 'params': {
+ 'session_id': 's', 'submission_id': 'send-1', 'text': text}})
+ await authority.sessions['s'].task
+ finally:
+ await connection.close()
+
+ assert reply['error']['data']['field'] == 'request_id', reply
+ refusals = [r for r in caplog.records if 'refused for profile' in r.getMessage()]
+ assert [r.levelname for r in refusals] == ['INFO'], [(r.levelname, r.getMessage()) for r in refusals]