diff --git a/apps/api/src/services/telegram_gateway.py b/apps/api/src/services/telegram_gateway.py index cb4e62e3d..3e31688f2 100644 --- a/apps/api/src/services/telegram_gateway.py +++ b/apps/api/src/services/telegram_gateway.py @@ -6469,6 +6469,14 @@ class TelegramGateway: if destination_binding: sent_receipt["destination_binding"] = destination_binding return sent_receipt + if existing_row.get("send_status") == "pending": + return { + "status": "reserved", + "run_id": str(delivery_run_id), + "message_id": str(existing_row["message_id"]), + "durable_reservation_committed": True, + "reused_pending_reservation": True, + } return { "status": "pending_unknown", "run_id": str(delivery_run_id), diff --git a/apps/api/tests/test_ansible_verified_closure.py b/apps/api/tests/test_ansible_verified_closure.py index 7d72d19bd..0f690761b 100644 --- a/apps/api/tests/test_ansible_verified_closure.py +++ b/apps/api/tests/test_ansible_verified_closure.py @@ -738,7 +738,7 @@ async def test_projection_stays_open_until_durable_telegram_readback( @pytest.mark.asyncio -async def test_controlled_result_pending_reservation_never_resends_provider( +async def test_controlled_result_pending_reservation_retries_provider_send( monkeypatch: pytest.MonkeyPatch, ) -> None: class _Response: @@ -779,9 +779,11 @@ async def test_controlled_result_pending_reservation_never_resends_provider( "message_id": "00000000-0000-0000-0000-000000000202", }, { - "status": "pending_unknown", + "status": "reserved", "run_id": "00000000-0000-0000-0000-000000000201", "message_id": "00000000-0000-0000-0000-000000000202", + "durable_reservation_committed": True, + "reused_pending_reservation": True, }, ] ) @@ -806,13 +808,15 @@ async def test_controlled_result_pending_reservation_never_resends_provider( _controlled_result_payload(), ) - assert client.post_count == 1 + assert client.post_count == 2 assert first["_awooop_provider_send_performed"] is True assert first["_awooop_outbound_mirror_acknowledged"] is False - assert second["ok"] is False - assert second["_awooop_provider_send_performed"] is False - assert second["_awooop_delivery_status"] == "pending_unknown" - finalize.assert_awaited_once() + assert second["ok"] is True + assert second["_awooop_provider_send_performed"] is True + assert second["_awooop_delivery_status"] == ( + "provider_sent_durable_receipt_pending" + ) + assert finalize.await_count == 2 @pytest.mark.asyncio