Skip to content

The agent that grows with you

fix(gateway): a lost webhook delivery settles instead of pausing its route

Tekniumb73e31229f25
diff --git a/gateway/session_unattended_unknown.py b/gateway/session_unattended_unknown.py
index 2c82452d1aa..a5587ce89f1 100644
--- a/gateway/session_unattended_unknown.py
+++ b/gateway/session_unattended_unknown.py
@@ -3,8 +3,9 @@
A turn lost across an owner restart is fenced ``unknown`` and pauses its session's FIFO, because
only the person who sent it knows whether to resend it. An automation delivery has no such person:
a cron run (``CRON_PRINCIPAL_ID``), a process completion or heartbeat (``automation:<route>``,
-``local_automation_v1``, or a native envelope's ``automation`` block). Pausing on it stalls every
-message queued behind it until an operator notices (a Bot Chat sat ten hours behind one).
+``local_automation_v1``, a native envelope's ``automation`` block) or a webhook delivery
+(``webhook_delivery``). Pausing on it stalls every message queued behind it until an operator
+notices (a Bot Chat sat ten hours behind one).
Such a row settles through the same fenced resolution a person's Discard uses
(``resolve_unknown_session_input``): terminal ``interrupted``, never requeued or replayed, with a
@@ -25,7 +26,9 @@ def is_unattended(row) -> bool:
if principal == CRON_PRINCIPAL_ID or principal.startswith('automation:'):
return True
payload = row.get('payload') or {}
- return 'local_automation_v1' in payload or 'automation' in (payload.get('native_text_v1') or {})
+ native = payload.get('native_text_v1') or {}
+ # A webhook delivery: the provider already got its 202 and nobody can be asked to resend it.
+ return 'local_automation_v1' in payload or 'automation' in native or 'webhook_delivery' in native
def _unattended_unknown(rows):
diff --git a/tests/gateway/test_unknown_automation_settles.py b/tests/gateway/test_unknown_automation_settles.py
index 204cb6a04a7..bebcf4bcc91 100644
--- a/tests/gateway/test_unknown_automation_settles.py
+++ b/tests/gateway/test_unknown_automation_settles.py
@@ -80,6 +80,16 @@ async def _cron_head(authority, _actor, _ref):
return row['admission_id']
+async def _webhook_head(authority, _actor, _ref):
+ # A webhook delivery: a messaging principal and a native envelope carrying its delivery
+ # destination, no automation block. The provider already got its 202; nobody can resend it.
+ row = admit_session_input(authority.db, epoch=authority.epoch, principal_id='messaging:[null,"webhook","r",null,null]',
+ session_id='s', request_id='delivery-1', payload={'text': 'HEAD', 'native_text_v1': {
+ 'event': {'message_id': 'delivery-1'}, 'webhook_delivery': {'deliver': 'log'},
+ 'webhook_route': 'digest'}})
+ return row['admission_id']
+
+
async def _person_head(authority, actor, ref):
receipt = await authority.submit(actor, Submission('head', ref, {'text': 'HEAD'}, 'queue'))
return receipt.admission_id
@@ -91,7 +101,8 @@ def _statuses(db):
@pytest.mark.asyncio
[email protected]('admit_head', [_automation_head, _cron_head], ids=['local_automation_v1', 'cron'])
[email protected]('admit_head', [_automation_head, _cron_head, _webhook_head],
+ ids=['local_automation_v1', 'cron', 'webhook_delivery'])
async def test_unknown_automation_settles_interrupted_and_fifo_moves_on(tmp_path, monkeypatch, admit_head):
executed = []
store, authority, head_id, follower_id = await _lost_head_then_restart(tmp_path, monkeypatch, executed, admit_head)