Skip to content

The agent that grows with you

fix(gateway): a settled not-sent receipt states only what settle serialized

unsupportedpastelsf9b364611488
diff --git a/gateway/session_bot.py b/gateway/session_bot.py
index 96996b40e31..2940375171f 100644
--- a/gateway/session_bot.py
+++ b/gateway/session_bot.py
@@ -704,7 +704,12 @@ async def _settle(connection, params):
sent": with no receipt and no admission row for ``bot:<id>``, a terminal ``refused`` receipt
bound to the full identity is written, and every later ``deliver`` of the id answers with it
instead of admitting. An admitted id gets its receipt; an in-flight pin stays unknown. Only the
- Bot DM tool calls this, so cron's same-id retries of a refusal are unchanged."""
+ Bot DM tool calls this, so cron's same-id retries of a refusal are unchanged.
+
+ The writer is not re-checked: it may release between the refusal and this call, and "nothing
+ was admitted" is all that is serialized here. So the receipt claims only that, and any
+ ``session:submit`` principal of the profile can settle an id it never delivered: the trust
+ ``deliver`` already grants it over that id."""
authority, actor = connection.authority, connection.actor
home, key, message, author, category = _delivery_params(authority, actor, params)
async with mailbox_lock(authority):
@@ -733,7 +738,7 @@ def _not_sent_record(authority, actor, home, key, message, author, category):
from gateway.session_automation import automation_notification_metadata
record = dict(delivery_id=key, profile_home=str(home), session_id=authority.db.get_compression_tip(row['id']),
principal_id=actor.subject, message=message, status='failed', refused=True, reply='',
- error='Bot Chat is held by another session writer', reason='runtime_coordination_required')
+ error='Settled as not sent after a session-writer refusal', reason='runtime_coordination_required')
record.update(automation_notification_metadata({'notification_category': category}))
if author is not None:
record['author'] = dict(author)
diff --git a/tests/gateway/test_bot_dm_held_by_session_writer.py b/tests/gateway/test_bot_dm_held_by_session_writer.py
index 29aed02123e..bbf5b8a241a 100644
--- a/tests/gateway/test_bot_dm_held_by_session_writer.py
+++ b/tests/gateway/test_bot_dm_held_by_session_writer.py
@@ -224,6 +224,21 @@ async def test_an_older_owner_without_the_marker_stays_ambiguous(held, monkeypat
assert [path.name for path in held.dm_dir.glob('*.live.json')], 'an unproven refusal keeps its intent'
+async def test_a_settled_receipt_states_only_what_settle_serialized(held):
+ """``settle`` doesn't re-check the writer (it may release between the refusal and the settle),
+ so the stored receipt says the id was settled as not sent, never that a writer held the chat."""
+ from tools.bot_live_delivery import find_canonical_live_owner, read_delivery_result, settle_held_delivery
+ held.release()
+ delivery_id = 'd' * 64
+ answer = await asyncio.to_thread(settle_held_delivery, held.home, find_canonical_live_owner(held.home),
+ 'ping', delivery_id=delivery_id)
+ assert answer['refused'] is True and answer['reason'] == 'runtime_coordination_required', answer
+ receipt = read_delivery_result(held.home, delivery_id)
+ assert 'held' not in receipt['error'] and 'not sent' in receipt['error'], receipt
+ assert _admissions(held) == [] and held.executed == []
+
+
@pytest.mark.asyncio
async def test_a_refusal_alone_leaves_the_id_open_for_a_same_id_retry(held):
"""Only the Bot DM tool's settle records a not-sent disposition. A producer that retries its