:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(ingress): ask for a redelivery when an ownership lookup fails (#102204)
Julian Bezf21a6f7ead69
diff --git a/.agents/skills/adding-inbound-webhooks/SKILL.md b/.agents/skills/adding-inbound-webhooks/SKILL.mdindex a2affa826781..0de77a05795d 100644--- a/.agents/skills/adding-inbound-webhooks/SKILL.md+++ b/.agents/skills/adding-inbound-webhooks/SKILL.md@@ -45,7 +45,7 @@ Rules that decide whether this works:- The handler runs synchronously inside the request. Enqueue a task for real work, the way stamphog and conversations do.- A handler that reads the database wraps the read in `bounded_statement_timeout(ms, models=...)` from `posthog.ingress.dispatch.database`, passing only the models the read actually uses. Opening an alias is itself unbounded, so naming one the read never touches can stall the delivery on connection setup.- An import-linter contract (`webhook consumers must only import facade`) holds the module to its own product's `facade/`. Reach product internals through the facade.-- A consumer whose resources are split across regions declares `ownership=`, pointing at a facade function that returns a `DeliveryOwnership`. Ingress forwards the signed request when the answer is `ELSEWHERE`, and dispatches locally either way. The lookup runs inside the request, so bound it with `bounded_statement_timeout(ms, models=...)`.+- A consumer whose resources are split across regions declares `ownership=`, pointing at a facade function that returns a `DeliveryOwnership`. Ingress forwards the signed request when the answer is `ELSEWHERE`, and dispatches locally either way. The lookup runs inside the request, so bound it with `bounded_statement_timeout(ms, models=...)`. Let a transient error out of the lookup rather than answering `LOCAL` or `UNDECIDED` through it: a lookup that raises asks a provider with `retry_status` for the delivery again, and a guessed answer receipts a delivery the other region never sees.Tests: extend the product's existing webhook test module rather than starting a parallel one.`products/stamphog/backend/tests/test_webhook_consumers.py` is the shape: drive the real view with a signed `RequestFactory` request and assert the enqueue, plus the event type the app does not register, the bad signature, the unparseable body, the non-POST, and the missing secret.@@ -62,7 +62,7 @@ Copy `github/` for the full shape, or `vapi/` for a small one.- `verify(request)` answers a `Verification`: the outcome, plus `facts`, whatever the scheme proved on the way. A scheme that validates a signed token puts its verified claims there and `deliveries` cross-checks the body against them; an HMAC scheme leaves it empty and `deliveries` ignores it.- `parse(request)` decodes the body, and defaults to JSON. Override it for a provider that posts a form, and raise `InvalidPayload` for a body it cannot read. Verification runs first and must, because reading `request.POST` consumes the request stream under ASGI.- `throttle_class` names a DRF throttle from `posthog.rate_limit`, run in front of verification. Set one when the endpoint is public and its verification is expensive, such as a JWT signing-key lookup.- - `retry_status` is the status answered instead of the receipt when ingress cannot vouch that the delivery was accepted: the forward to the owning region failed, a consumer raised, or the budget skipped a consumer. Set it when the provider redelivers on a non-2xx, and leave it `None` when it does not, because the non-2xx then only loses the delivery. A retry replays the delivery against every consumer on the endpoint, and dedup is what stops the ones that already accepted it from running twice.+ - `retry_status` is the status answered instead of the receipt when ingress cannot vouch that the delivery was accepted: an ownership lookup failed, the forward to the owning region failed, a consumer raised, or the budget skipped a consumer. Set it when the provider redelivers on a non-2xx, and leave it `None` when it does not, because the non-2xx then only loses the delivery. A retry replays the delivery against every consumer on the endpoint, and dedup is what stops the ones that already accepted it from running twice.- A `build_<provider>_provider(...)` function returning it. Secrets and verifiers a product owns are **passed into this builder**, never imported: nothing under `posthog/ingress/` may import a product.### Picking a schemediff --git a/posthog/ingress/README.md b/posthog/ingress/README.mdindex 9ad300471640..1ecc0538164e 100644--- a/posthog/ingress/README.md+++ b/posthog/ingress/README.md@@ -95,7 +95,7 @@ If a provider's protocol needs the response body to say something, the incarnatiA verification that could not run is its own answer rather than a verdict: a scheme with a network step returns `UNAVAILABLE` when that step fails on transport, and the view answers 503 with outcome `verify_unavailable`, so a sender that retries a server error sends the delivery again.What the transport does decide is whether it can vouch that the delivery was taken.-It cannot when the forward to the owning region failed, when a consumer raised, or when the budget skipped a consumer — in each case some of the work never ran.+It cannot when an ownership lookup failed, when the forward to the owning region failed, when a consumer raised, or when the budget skipped a consumer — in each case some of the work never ran, or ingress cannot tell whether it ran in the right region.A provider that redelivers on a non-2xx sets `retry_status` on its incarnation, and the view then answers that status with outcome `retry_requested` instead of the receipt, so the provider sends the delivery again.A provider that does not redeliver leaves it at `None` and keeps the receipt, because a non-2xx buys it nothing.That is still the transport deciding, on whether the work ran at all, rather than a consumer choosing an answer: a consumer cannot ask for a retry, and a delivery no consumer is registered for is accepted by construction.@@ -179,6 +179,8 @@ A consumer whose resources are split by region declares `ownership`, a callable- `ELSEWHERE` — the other region holds it. The request is forwarded.- `UNDECIDED` — nothing in the delivery says, so nothing is forwarded.+A fourth value, `FAILED`, is the dispatcher's own: a consumer never answers it, and it records a lookup that raised.+Every delivery in the request is assessed first, and the request is then forwarded **once**, when any consumer answered `ELSEWHERE`.One forward per request rather than per delivery, because the unit being replayed is the HTTP request.Local dispatch runs either way: a consumer that answered `ELSEWHERE` no-ops on its own, and the other consumers on the endpoint are unaffected.@@ -188,7 +190,15 @@ The receiving region reads which region it is off the connection it receives, soThe ownership lookup runs inside the request, before dispatch, and inside the same wall-clock budget.A lookup that reads the database must be bounded with `bounded_statement_timeout(ms, models=...)`.-A lookup that raises is logged, captured, counted as `failed` and treated as `UNDECIDED`, so one consumer cannot cost the delivery the receipt it earned by signing.++A lookup that raises is logged, captured and counted as `failed`, and it rules no region out.+On a provider that sets `retry_status` the view answers that status with outcome `retry_requested`, before the forward and before any consumer runs.+Local dispatch alone would otherwise receipt the delivery: the consumer's own lookup runs again inside the handler, correctly finds nothing local, the handler returns, and the region that owns the delivery never sees it.+Nothing has claimed a dedup mark at that point, so the redelivery is processed in full, and the lookups it asks again decide the forward then.+A provider that does not redeliver keeps the delivery instead: the failure counts as `UNDECIDED`, local dispatch runs, and the request is receipted, because a non-2xx there would only lose the local run as well.++An ownership lookup should therefore let a transient error out rather than answering `LOCAL` or `UNDECIDED` through it.+A guess is what turns a dropped connection into a lost delivery.What crosses is the raw signed body, except for a provider that signs the form rather than the body.Reading that form consumes the request stream and leaves no raw bytes, so the forward rebuilds the fields and the files and drops the original `Content-Type`, which names the boundary of a body that is gone.diff --git a/posthog/ingress/contracts.py b/posthog/ingress/contracts.pyindex 6a4844928321..414439e1d8f9 100644--- a/posthog/ingress/contracts.py+++ b/posthog/ingress/contracts.py@@ -14,6 +14,9 @@ class DeliveryOwnership(Enum):LOCAL = "local" # this region holds the resource; dispatch hereELSEWHERE = "elsewhere" # the resource lives in the other region; forward the requestUNDECIDED = "undecided" # nothing in the delivery says; dispatch here, forward nothing+ # The lookup raised, so it ruled no region out. A consumer never answers this one: the+ # dispatcher records it, and the transport asks a provider that redelivers to send again.+ FAILED = "failed"@frozen@@ -52,7 +55,9 @@ class WebhookConsumer:dedup: bool = True# A consumer whose resources are split by region answers where this delivery's resource lives,# and ingress forwards the signed request when the answer is elsewhere. A lookup inside must be- # bounded (`bounded_statement_timeout`): it runs in the request, before dispatch.+ # bounded (`bounded_statement_timeout`): it runs in the request, before dispatch. Let a+ # transient error out rather than answering local or undecided through it: a raised lookup asks+ # a provider that redelivers for the delivery again, and a guess loses it.ownership: Callable[[WebhookDelivery], DeliveryOwnership] | None = None@@ -65,6 +70,19 @@ class ProviderSpec:event_types: frozenset[str]+@frozen+class DeliveryOwnershipAnswers:+ """What the consumers that declare an ownership lookup said about one delivery.++ The two names carry different decisions. `elsewhere_consumers` forwards the signed request to+ the other region. `failed_consumers` says a lookup did not answer, which leaves the owning+ region unknown, so a provider that redelivers is asked for the delivery again.+ """++ elsewhere_consumers: tuple[str, ...] = ()+ failed_consumers: tuple[str, ...] = ()++@frozenclass DeliveryDispatch:"""What the dispatcher can vouch for after one delivery's consumers ran.diff --git a/posthog/ingress/dispatch/dispatcher.py b/posthog/ingress/dispatch/dispatcher.pyindex 902b975f1f6c..11b1733da289 100644--- a/posthog/ingress/dispatch/dispatcher.py+++ b/posthog/ingress/dispatch/dispatcher.py@@ -5,7 +5,13 @@ import timeimport structlogfrom posthog.exceptions_capture import capture_exception-from posthog.ingress.contracts import DeliveryDispatch, DeliveryOwnership, WebhookConsumer, WebhookDelivery+from posthog.ingress.contracts import (+ DeliveryDispatch,+ DeliveryOwnership,+ DeliveryOwnershipAnswers,+ WebhookConsumer,+ WebhookDelivery,+)from posthog.ingress.dispatch.budget import DeliveryBudget, delivery_budget_secondsfrom posthog.ingress.dispatch.dedup import DeliveryClaim, DeliveryDedupfrom posthog.ingress.dispatch.registry import ConsumerRegistry@@ -101,8 +107,8 @@ class WebhookDispatcher:try:answer = consumer.ownership(delivery)except Exception as error:- # Isolated like a handler is: a consumer that cannot answer must not cost the delivery- # the receipt it already earned by signing, nor stop another consumer from answering.+ # Isolated like a handler is: one consumer that cannot answer never stops another from+ # answering. What it costs the request is the transport's call, in the view.logger.exception("ingress_ownership_failed",provider=delivery.provider,@@ -111,35 +117,31 @@ class WebhookDispatcher:delivery_id=delivery.delivery_id,)capture_exception(error)- observe_ownership(provider=delivery.provider, consumer=consumer.name, outcome="failed")- return DeliveryOwnership.UNDECIDED+ answer = DeliveryOwnership.FAILEDobserve_ownership(provider=delivery.provider, consumer=consumer.name, outcome=answer.value)return answer- def ownership_of(self, delivery: WebhookDelivery) -> tuple[DeliveryOwnership, tuple[str, ...]]:- """Where this delivery's resource lives, and which consumers said it lives elsewhere.+ def ownership_of(self, delivery: WebhookDelivery) -> DeliveryOwnershipAnswers:+ """Which consumers said this delivery's resource lives elsewhere, and whose lookup failed.Any one consumer answering `ELSEWHERE` is enough to forward the request, because theforward is the whole request rather than one consumer's share of it. A `LOCAL` answerchanges nothing: local dispatch runs either way."""- answers: list[DeliveryOwnership] = []elsewhere: list[str] = []+ failed: list[str] = []for consumer in self._registry.consumers_for(provider=delivery.provider, app=delivery.app, event_type=delivery.event_type):if consumer.ownership is None:continueanswer = self._ask_ownership(consumer, delivery)- answers.append(answer)if answer is DeliveryOwnership.ELSEWHERE:elsewhere.append(consumer.name)+ elif answer is DeliveryOwnership.FAILED:+ failed.append(consumer.name)- if elsewhere:- return DeliveryOwnership.ELSEWHERE, tuple(elsewhere)- if DeliveryOwnership.LOCAL in answers:- return DeliveryOwnership.LOCAL, ()- return DeliveryOwnership.UNDECIDED, ()+ return DeliveryOwnershipAnswers(elsewhere_consumers=tuple(elsewhere), failed_consumers=tuple(failed))def dispatch(self, delivery: WebhookDelivery, *, budget: DeliveryBudget | None = None) -> DeliveryDispatch:"""Run this delivery's consumers, and answer which of them did not accept it.diff --git a/posthog/ingress/observability/metrics.py b/posthog/ingress/observability/metrics.pyindex c42e4b64f0b4..7bf2a872c3c0 100644--- a/posthog/ingress/observability/metrics.py+++ b/posthog/ingress/observability/metrics.py@@ -27,7 +27,8 @@ DeliveryOutcome = Literal[ConsumerOutcome = Literal["succeeded", "failed", "deduped", "budget_exceeded", "in_flight"]# What a consumer answered when asked which region owns the delivery's resource; `failed` is the-# lookup raising, which counts as undecided.+# lookup raising, which asks a provider that redelivers for the delivery again and counts as+# undecided on one that does not.OwnershipOutcome = Literal["local", "elsewhere", "undecided", "failed"]# What the owning region answered the replayed request: `rejected` is a non-2xx, `failed` is thediff --git a/posthog/ingress/test/test_dispatcher.py b/posthog/ingress/test/test_dispatcher.pyindex a93fe4c5d69e..ada9617b8d30 100644--- a/posthog/ingress/test/test_dispatcher.py+++ b/posthog/ingress/test/test_dispatcher.py@@ -8,7 +8,13 @@ from django.test import SimpleTestCase, override_settingsfrom parameterized import parameterized-from posthog.ingress.contracts import DeliveryOwnership, ProviderSpec, WebhookConsumer, WebhookDelivery+from posthog.ingress.contracts import (+ DeliveryOwnership,+ DeliveryOwnershipAnswers,+ ProviderSpec,+ WebhookConsumer,+ WebhookDelivery,+)from posthog.ingress.dispatch.budget import DEFAULT_DELIVERY_BUDGET_SECONDS, DeliveryBudget, delivery_budget_secondsfrom posthog.ingress.dispatch.dedup import DeliveryClaim, DeliveryDedupfrom posthog.ingress.dispatch.dispatcher import WebhookDispatcher@@ -223,37 +229,34 @@ class TestDeliveryDedup(SimpleTestCase):class TestDeliveryOwnership(SimpleTestCase):@parameterized.expand([- ("nobody_declares_one", [], DeliveryOwnership.UNDECIDED, ()),- ("every_answer_is_local", [DeliveryOwnership.LOCAL] * 2, DeliveryOwnership.LOCAL, ()),+ ("nobody_declares_one", [], DeliveryOwnershipAnswers()),+ ("every_answer_is_local", [DeliveryOwnership.LOCAL] * 2, DeliveryOwnershipAnswers()),("one_elsewhere_decides_the_request",[DeliveryOwnership.LOCAL, DeliveryOwnership.ELSEWHERE],- DeliveryOwnership.ELSEWHERE,- ("consumer-1",),+ DeliveryOwnershipAnswers(elsewhere_consumers=("consumer-1",)),),("a_lookup_that_raises_leaves_the_others_deciding",[RuntimeError("lookup failed"), DeliveryOwnership.ELSEWHERE],- DeliveryOwnership.ELSEWHERE,- ("consumer-1",),+ DeliveryOwnershipAnswers(elsewhere_consumers=("consumer-1",), failed_consumers=("consumer-0",)),),(- "a_lookup_that_raises_alone_is_undecided",+ "a_lookup_that_raises_is_named_rather_than_read_as_an_answer",[RuntimeError("lookup failed")],- DeliveryOwnership.UNDECIDED,- (),+ DeliveryOwnershipAnswers(failed_consumers=("consumer-0",)),),])- def test_any_consumer_answering_elsewhere_forwards_the_request(- self, _name: str, answers: list, expected: DeliveryOwnership, expected_names: tuple[str, ...]+ def test_the_answers_name_who_forwards_the_request_and_whose_lookup_failed(+ self, _name: str, answers: list, expected: DeliveryOwnershipAnswers) -> None:consumers = [_consumer(f"consumer-{index}", Mock(), ownership=_ownership(answer)) for index, answer in enumerate(answers)]with patch("posthog.ingress.dispatch.dispatcher.capture_exception"):- self.assertEqual(_dispatcher(consumers).ownership_of(_delivery()), (expected, expected_names))+ self.assertEqual(_dispatcher(consumers).ownership_of(_delivery()), expected)def test_a_consumer_without_an_ownership_lookup_is_never_asked(self) -> None:asked = Mock(return_value=DeliveryOwnership.LOCAL)diff --git a/posthog/ingress/test/test_views.py b/posthog/ingress/test/test_views.pyindex 95e5d2fb9793..0df068e9af62 100644--- a/posthog/ingress/test/test_views.py+++ b/posthog/ingress/test/test_views.py@@ -21,6 +21,7 @@ from rest_framework.throttling import BaseThrottle, ScopedRateThrottlefrom posthog.ingress.contracts import (DeliveryDispatch,DeliveryOwnership,+ DeliveryOwnershipAnswers,ProviderSpec,WebhookConsumer,WebhookDelivery,@@ -112,7 +113,7 @@ class TestWebhookView(SimpleTestCase):def setUp(self) -> None:self.factory = RequestFactory()self.dispatcher = Mock()- self.dispatcher.ownership_of.return_value = (DeliveryOwnership.UNDECIDED, ())+ self.dispatcher.ownership_of.return_value = DeliveryOwnershipAnswers()self.dispatcher.dispatch.return_value = DeliveryDispatch()patcher = patch("posthog.ingress.views.get_dispatcher", return_value=self.dispatcher)patcher.start()@@ -438,27 +439,91 @@ class TestRegionalForwarding(_DispatchingViewTestCase):@parameterized.expand([- ("elsewhere_forwards_once", DeliveryOwnership.ELSEWHERE, 1, 0),- ("local_forwards_nothing", DeliveryOwnership.LOCAL, 0, 0),- ("undecided_forwards_nothing", DeliveryOwnership.UNDECIDED, 0, 0),- ("a_lookup_that_raises_counts_as_undecided", RAISES, 0, 1),+ ("elsewhere_forwards_once", DeliveryOwnership.ELSEWHERE, 1),+ ("local_forwards_nothing", DeliveryOwnership.LOCAL, 0),+ ("undecided_forwards_nothing", DeliveryOwnership.UNDECIDED, 0),])def test_the_ownership_answer_decides_the_forward_and_never_the_local_dispatch(- self, _name: str, answer: object, forwards: int, captures: int+ self, _name: str, answer: object, forwards: int) -> None:view = self._view([_consumer(GITHUB_SPEC, name="probe", handler=self.handler, answer=answer)])+ with patch("posthog.regions.PRIMARY_REGION_DOMAIN", "testserver"):+ response = view(self._github_request())++ self.assertEqual(response.status_code, 202)+ self.assertEqual(self.requests.call_count, forwards)+ self.handler.assert_called_once()++ @parameterized.expand(+ [+ ("a_provider_that_redelivers_asks_for_one", _RedeliveringGitHubProvider, 502, "retry_requested", 0),+ ("a_provider_that_does_not_dispatches_locally", GitHubProvider, 202, "accepted", 1),+ ]+ )+ def test_a_failed_ownership_lookup_answers_what_the_provider_needs_to_redeliver(+ self, _name: str, provider_class: type[GitHubProvider], status: int, outcome: str, dispatched: int+ ) -> None:+ view = self._view(+ [_consumer(GITHUB_SPEC, name="probe", handler=self.handler, answer=RAISES)],+ provider=provider_class("posthog"),+ )+with (patch("posthog.regions.PRIMARY_REGION_DOMAIN", "testserver"),patch("posthog.ingress.dispatch.dispatcher.capture_exception") as capture,+ patch("posthog.ingress.views.observe_delivery") as observe,):response = view(self._github_request())- self.assertEqual(response.status_code, 202)- self.assertEqual(self.requests.call_count, forwards)+ self.assertEqual(response.status_code, status)+ self.assertEqual([call.kwargs["outcome"] for call in observe.call_args_list], [outcome])+ # The delivery may belong to the other region, so a local run that finds nothing to do must+ # not receipt it where the provider would send it again.+ self.assertEqual(self.handler.call_count, dispatched)+ self.requests.assert_not_called()+ capture.assert_called_once()++ def test_a_failed_lookup_asks_for_the_delivery_again_rather_than_forwarding_on_what_is_left(self) -> None:+ elsewhere = Mock()+ view = self._view(+ [+ _consumer(GITHUB_SPEC, name="alpha", handler=self.handler, answer=RAISES),+ _consumer(GITHUB_SPEC, name="zulu", handler=elsewhere, answer=DeliveryOwnership.ELSEWHERE),+ ],+ provider=_RedeliveringGitHubProvider("posthog"),+ )++ with (+ patch("posthog.regions.PRIMARY_REGION_DOMAIN", "testserver"),+ patch("posthog.ingress.dispatch.dispatcher.capture_exception"),+ ):+ response = view(self._github_request())++ self.assertEqual(response.status_code, 502)+ # The redelivery asks every lookup again and forwards then, so forwarding now would send+ # the same request to the other region twice.+ self.requests.assert_not_called()+ self.handler.assert_not_called()+ elsewhere.assert_not_called()++ def test_the_delivery_the_provider_sends_again_is_not_deduped_away(self) -> None:+ provider = _RedeliveringGitHubProvider("posthog")+ unanswered = self._view(+ [_consumer(GITHUB_SPEC, name="probe", handler=self.handler, answer=RAISES)], provider=provider+ )++ with patch("posthog.ingress.dispatch.dispatcher.capture_exception"):+ self.assertEqual(unanswered(self._github_request()).status_code, 502)++ answered = self._view(+ [_consumer(GITHUB_SPEC, name="probe", handler=self.handler, answer=DeliveryOwnership.LOCAL)],+ provider=provider,+ )++ self.assertEqual(answered(self._github_request()).status_code, 202)self.handler.assert_called_once()- self.assertEqual(capture.call_count, captures)@parameterized.expand([diff --git a/posthog/ingress/views.py b/posthog/ingress/views.pyindex 9ac575decb95..5632236bf784 100644--- a/posthog/ingress/views.py+++ b/posthog/ingress/views.py@@ -10,7 +10,6 @@ import structlogfrom rest_framework.request import Request as DRFRequestfrom rest_framework.throttling import ScopedRateThrottle-from posthog.ingress.contracts import DeliveryOwnershipfrom posthog.ingress.dispatch.budget import DeliveryBudget, delivery_budget_secondsfrom posthog.ingress.dispatch.forward import forward_to_secondary_regionfrom posthog.ingress.dispatch.loading import get_dispatcher@@ -45,6 +44,20 @@ def _throttle_refusal(provider: WebhookProvider, request: HttpRequest) -> HttpRereturn response+def _retry_refusal(provider: WebhookProvider, consumers: list[str]) -> HttpResponse:+ """The status a provider that redelivers needs, for a delivery ingress cannot vouch for."""+ # The dispatcher already logged and captured the failure itself, so this only says the request+ # is not being receipted, and which consumers cost it that.+ logger.warning(+ "ingress_delivery_retry_requested",+ provider=provider.provider,+ app=provider.app,+ consumers=consumers,+ )+ observe_delivery(provider=provider.provider, app=provider.app, outcome="retry_requested")+ return HttpResponse("Delivery not accepted", status=provider.retry_status)++def build_webhook_view(provider: WebhookProvider) -> Callable[[HttpRequest], HttpResponse]:"""A Django view for one provider app.@@ -123,10 +136,20 @@ def build_webhook_view(provider: WebhookProvider) -> Callable[[HttpRequest], Httbudget = DeliveryBudget(delivery_budget_seconds())elsewhere: dict[str, None] = {}+ unanswered: dict[str, None] = {}for delivery in deliveries:- ownership, consumers = dispatcher.ownership_of(delivery)- if ownership is DeliveryOwnership.ELSEWHERE:- elsewhere.update(dict.fromkeys(consumers))+ answers = dispatcher.ownership_of(delivery)+ elsewhere.update(dict.fromkeys(answers.elsewhere_consumers))+ unanswered.update(dict.fromkeys(answers.failed_consumers))++ if unanswered and provider.retry_status is not None:+ # A lookup that did not answer rules no region out, so this region cannot tell whether+ # the other one owns the delivery. Dispatching locally would run every consumer, find+ # nothing to do, and receipt a delivery the owning region never sees. Asking for the+ # delivery again runs the lookups again, and it happens here, before the forward and+ # before any consumer claims a dedup mark that would swallow the redelivery.+ return _retry_refusal(provider, list(unanswered))+if elsewhere:if is_primary_region(request):# Once for the request, not once per delivery: what is replayed is the signed body.@@ -155,16 +178,7 @@ def build_webhook_view(provider: WebhookProvider) -> Callable[[HttpRequest], Httunaccepted.update(dict.fromkeys(dispatched.unaccepted_consumers))if unaccepted and provider.retry_status is not None:- # The dispatcher already logged and captured each consumer's own failure, so this- # only says the request is not being receipted, and which consumers cost it that.- logger.warning(- "ingress_delivery_retry_requested",- provider=provider.provider,- app=provider.app,- consumers=list(unaccepted),- )- observe_delivery(provider=provider.provider, app=provider.app, outcome="retry_requested")- return HttpResponse("Delivery not accepted", status=provider.retry_status)+ return _retry_refusal(provider, list(unaccepted))observe_delivery(provider=provider.provider, app=provider.app, outcome="accepted")return HttpResponse(status=provider.success_status)