: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(devex): route each stamphog head once in always mode (#130823)
Julian Bezabbcf2cdbfa7
diff --git a/products/stamphog/README.md b/products/stamphog/README.mdindex 4d4e332dc722..531f74f01fb9 100644--- a/products/stamphog/README.md+++ b/products/stamphog/README.md@@ -183,7 +183,7 @@ A comment names the cut owners and why.`routing_mode` on the repo config decides when routing runs:- `off` (the default): never.-- `always`: when a PR opens ready for review or is marked ready. It never reads or waits for a verdict, and it routes bot and fork PRs too.+- `always`: when a PR opens ready for review or is marked ready. It never reads or waits for a verdict, and it routes bot and fork PRs too. Each head routes once, so a draft marked ready right after it opened is not routed twice.- `fallback`: owners are requested only when stamphog does not approve. If stamphog will not review the head (reviews disabled, a draft, bot or untrusted author, or label mode without the trigger label), routing runs at once, like `always`. Otherwise the head waits for the verdict:- An approval requests only the pinned owners of that head that no earlier routing of the PR requested, and says so in the comment. When there are none, it requests nobody.- A WAIT keeps waiting, because stamphog reviews again later. A WAIT on a head that was not waiting starts waiting there.diff --git a/products/stamphog/backend/logic/routing/triggers.py b/products/stamphog/backend/logic/routing/triggers.pyindex 61358a3c6cc9..26221caaa99f 100644--- a/products/stamphog/backend/logic/routing/triggers.py+++ b/products/stamphog/backend/logic/routing/triggers.py@@ -191,8 +191,11 @@ def _event_step(client: StamphogGitHubClient, state: _State, *, action: str, revhead_sha = _head_sha(pr)record = state.recordif record is not None and record.get("head_sha") == head_sha:- # ALWAYS routes once per head and action. FALLBACK routes once per head, whatever started it.- if mode == RoutingMode.FALLBACK or record.get("trigger") == action:+ # Both modes route once per head, whatever started it. The `opened` task reads the live pull+ # request, so it already routes a draft marked ready before the task ran, and the+ # `ready_for_review` delivery for that head must not request the same owners again. A waiting+ # record left by FALLBACK requested nobody, so ALWAYS still routes that head.+ if mode == RoutingMode.FALLBACK or record.get("status") != STATUS_WAITING:return Noneif mode == RoutingMode.FALLBACK and record is not None and record.get(FULL_ROUTED_HEAD):return Nonediff --git a/products/stamphog/backend/tests/test_routing_task.py b/products/stamphog/backend/tests/test_routing_task.pyindex 6d17aca8dcff..5a25875c26a5 100644--- a/products/stamphog/backend/tests/test_routing_task.py+++ b/products/stamphog/backend/tests/test_routing_task.py@@ -345,13 +345,23 @@ def test_a_refused_bulk_request_falls_back_to_single_requests(team, user, routinassert _run_log(team.id)["@carol"][0] == "refused"+ "second_action",+ [+ "opened",+ # A draft marked ready before the `opened` task ran routes on `opened`, then its ready delivery arrives.+ "ready_for_review",+ ],+)@pytest.mark.django_db(databases=PRODUCT_DATABASES)-def test_a_retry_for_the_same_head_requests_nobody_twice(team, user, routing_chain) -> None:+def test_a_second_delivery_for_the_same_head_requests_nobody_twice(+ second_action: str, team, user, routing_chain+) -> None:_setup(routing_chain, team, user)routing_chain.cut_model.answer = _CUT_BETA_route()- _route()+ _route(second_action)assert len(_writes(routing_chain, "request_reviewers")) == 1assert len(routing_chain.cut_model.calls) == 1