Skip to content

: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.

fix(stamphog): drop the unused digest-only mode (#83134)

Julian Bez6f0a78baa2f6
diff --git a/products/stamphog/README.md b/products/stamphog/README.md
index 434b26e21cdd..18deac742ddd 100644
--- a/products/stamphog/README.md
+++ b/products/stamphog/README.md
@@ -15,7 +15,7 @@ There is one non-webhook entry: **self-driving inbox PRs**. When a self-driving
## The digest
-Independently of reviews, a repo can enable a daily Slack digest of its merged PRs (`backend/tasks/digest.py`): merges are stamped with an audience (author's GitHub team, or a channel the repo declares under `digest:` in `.stamphog/policy.yml`), summarized with a small model, and posted per channel. Review-enabled repos digest only stamphog-approved merges; digest-only repos (review off) digest every merge.
+On top of reviews, a repo can enable a daily Slack digest of its merged PRs (`backend/tasks/digest.py`): merges are stamped with an audience (author's GitHub team, or a channel the repo declares under `digest:` in `.stamphog/policy.yml`), summarized with a small model, and posted per channel. Only stamphog-approved merges are digested, so the digest needs reviews enabled for the repo.
## Configuration
diff --git a/products/stamphog/backend/logic/channel_resolution.py b/products/stamphog/backend/logic/channel_resolution.py
index c9de8eae32c8..bfcbcdf2604d 100644
--- a/products/stamphog/backend/logic/channel_resolution.py
+++ b/products/stamphog/backend/logic/channel_resolution.py
@@ -67,9 +67,6 @@ def _declared_repo_channel_name(team_id: int, audience_key: str) -> str | None:
digest-enabled, or hasn't declared a channel.
"""
repository = audience_key[len(_REPO_AUDIENCE_PREFIX) :]
- # Gate on digest_enabled only, not review `enabled`: a digest-only repo (review off, digest on)
- # still stamps merges with a "repo:" audience, so its declared channel must resolve or those PRs
- # never get delivered.
# Writer pin: this gate decides an enabled channel plus the immediate Slack post — a lagged
# reader returning a stale digest_enabled=True row would post a digest the user just opted out of.
repo_config = (
diff --git a/products/stamphog/backend/presentation/serializers.py b/products/stamphog/backend/presentation/serializers.py
index 9e166798f6b9..67313523dc31 100644
--- a/products/stamphog/backend/presentation/serializers.py
+++ b/products/stamphog/backend/presentation/serializers.py
@@ -1,5 +1,7 @@
"""DRF serializers for stamphog."""
+from typing import Any
+
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field, extend_schema_serializer
from rest_framework import serializers
@@ -69,6 +71,22 @@ class StamphogRepoConfigSerializer(serializers.ModelSerializer):
raise serializers.ValidationError("Trigger label cannot be blank.")
return value
+ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
+ # The digest reports what stamphog approved, so it has nothing to report without the review
+ # path running. PATCH sends only changed fields, so fall back to the stored values.
+ attrs = super().validate(attrs)
+ enabled = attrs.get("enabled", getattr(self.instance, "enabled", True))
+ if enabled:
+ return attrs
+ if attrs.get("digest_enabled"):
+ raise serializers.ValidationError(
+ {"digest_enabled": "Digests report what stamphog approved, so they need 'enabled' set to true."}
+ )
+ # Turning reviews off takes the digest with it rather than failing the write — the same
+ # pairing the soft-delete tombstone applies, and the Enabled toggle sends only `enabled`.
+ attrs["digest_enabled"] = False
+ return attrs
+
class Meta:
model = StamphogRepoConfig
fields = [
@@ -104,7 +122,10 @@ class StamphogRepoConfigSerializer(serializers.ModelSerializer):
},
"digest_enabled": {
"required": False,
- "help_text": "Whether merged PRs on this repo are captured for the daily Slack digest.",
+ "help_text": (
+ "Whether merged PRs on this repo are captured for the daily Slack digest. Requires "
+ "'enabled', since the digest reports what stamphog approved."
+ ),
},
"review_mode": {
"required": False,
diff --git a/products/stamphog/backend/tasks/tasks.py b/products/stamphog/backend/tasks/tasks.py
index 0361466c602e..636b89f114de 100644
--- a/products/stamphog/backend/tasks/tasks.py
+++ b/products/stamphog/backend/tasks/tasks.py
@@ -573,10 +573,7 @@ def _record_merged_pull_request(payload: dict[str, Any], delivery_id: str) -> No
if not repo_config:
logger.info("stamphog_merged_pr_repo_not_configured", repo=repo, installation_id=installation_id)
return
- # A digest-only repo (digest_enabled=True, review enabled=False) still needs its merges captured,
- # otherwise the daily digest has nothing to send. Gate the merge path on either flag; the digest
- # eligibility below still requires digest_enabled specifically.
- if not (repo_config.enabled or repo_config.digest_enabled):
+ if not repo_config.enabled:
logger.info("stamphog_merged_pr_repo_disabled", repo=repo)
return
@@ -622,10 +619,7 @@ def _record_merged_pull_request(payload: dict[str, Any], delivery_id: str) -> No
)
.exists()
)
- # Review-disabled repos can't have approved runs by construction, so digest-only mode
- # (digest on, review off) admits every merge — gating those on approval would silently
- # keep digest-only repos out of Slack forever.
- if repo_config.digest_enabled and (approved or not repo_config.enabled):
+ if repo_config.digest_enabled and approved:
pr_obj.audience_key = resolve_audience_key(repo_config, pr)
update_fields.append("audience_key")
else:
diff --git a/products/stamphog/backend/tests/test_api.py b/products/stamphog/backend/tests/test_api.py
index c1dc39743ad9..4cc0e0087d0e 100644
--- a/products/stamphog/backend/tests/test_api.py
+++ b/products/stamphog/backend/tests/test_api.py
@@ -2,6 +2,7 @@ from posthog.test.base import APIBaseTest
from unittest.mock import patch
from django.core import signing
+from django.test import SimpleTestCase
from parameterized import parameterized
from rest_framework import status
@@ -13,6 +14,7 @@ from posthog.models.utils import generate_random_token_personal
from products.stamphog.backend.facade.enums import ReviewRunStatus
from products.stamphog.backend.models import DigestChannel, PullRequest, ReviewRun, StamphogRepoConfig
+from products.stamphog.backend.presentation.serializers import StamphogRepoConfigSerializer
from products.stamphog.backend.presentation.views import _INSTALL_STATE_SALT
from products.stamphog.backend.tests.conftest import PRODUCT_DATABASES, StamphogTeamScopedTestMixin
@@ -168,6 +170,41 @@ class TestStamphogRepoConfigAPI(StamphogTeamScopedTestMixin, APIBaseTest):
assert mine.digest_enabled is False
assert in_flight.status == ReviewRunStatus.SUPERSEDED
+ def test_cannot_enable_digest_without_reviews(self) -> None:
+ # Wiring guard for the serializer matrix below: the viewset must actually reject the
+ # combination. A digest-on/review-off repo captures no merges at all, so it would look
+ # configured and silently never post.
+ response = self.client.post(self.url, {"repository": "PostHog/quiet", "enabled": False, "digest_enabled": True})
+ assert response.status_code == status.HTTP_400_BAD_REQUEST, response.content
+ assert not StamphogRepoConfig.objects.unscoped().filter(repository="PostHog/quiet").exists()
+
+
+class TestStamphogRepoConfigSerializerValidation(SimpleTestCase):
+ @parameterized.expand(
+ [
+ ("create", None, {"repository": "PostHog/posthog", "enabled": False, "digest_enabled": True}),
+ (
+ "enable_digest_on_review_off_repo",
+ StamphogRepoConfig(enabled=False, digest_enabled=False),
+ {"digest_enabled": True},
+ ),
+ ]
+ )
+ def test_asking_for_digest_without_reviews_is_rejected(
+ self, _name: str, instance: StamphogRepoConfig | None, data: dict
+ ) -> None:
+ serializer = StamphogRepoConfigSerializer(instance=instance, data=data, partial=instance is not None)
+ assert not serializer.is_valid()
+ assert "digest_enabled" in serializer.errors
+
+ def test_disabling_reviews_clears_the_digest(self) -> None:
+ # The Enabled toggle PATCHes only `enabled`, so rejecting the write would leave an admin
+ # unable to turn reviews off on any digest-enabled repo, with a generic failure toast.
+ instance = StamphogRepoConfig(enabled=True, digest_enabled=True)
+ serializer = StamphogRepoConfigSerializer(instance=instance, data={"enabled": False}, partial=True)
+ assert serializer.is_valid(), serializer.errors
+ assert serializer.validated_data["digest_enabled"] is False
+
class TestReviewRunAPI(StamphogTeamScopedTestMixin, APIBaseTest):
databases = PRODUCT_DATABASES
diff --git a/products/stamphog/backend/tests/test_integration.py b/products/stamphog/backend/tests/test_integration.py
index 751e0819c149..861f356891a2 100644
--- a/products/stamphog/backend/tests/test_integration.py
+++ b/products/stamphog/backend/tests/test_integration.py
@@ -1165,33 +1165,25 @@ def test_superseded_refusal_does_not_hand_off_to_reviewhog(team, stamphog_chain:
@pytest.mark.parametrize(
- "review_enabled,approved_at_sha,expected_audience_key",
+ "approved_at_sha,expected_audience_key",
[
- (True, "sha-merged", "team-devex"),
- (True, None, ""),
- (True, "sha-earlier", ""),
- # Digest-only mode (review off, digest on): approvals can't exist by construction, so
- # every merge is digest-eligible — gating on approval would keep these repos out of
- # Slack forever.
- (False, None, "team-devex"),
+ ("sha-merged", "team-devex"),
+ (None, ""),
+ ("sha-earlier", ""),
],
- ids=["approved_at_merged_head", "never_approved", "approved_at_earlier_head", "digest_only_needs_no_approval"],
+ ids=["approved_at_merged_head", "never_approved", "approved_at_earlier_head"],
)
@pytest.mark.django_db(databases=PRODUCT_DATABASES)
def test_merged_pr_digest_eligibility_gate(
team,
stamphog_chain: StamphogChain,
- review_enabled: bool,
approved_at_sha: str | None,
expected_audience_key: str,
) -> None:
# Regression guard: the approved-head_sha eligibility gate plus the author -> GitHub-team
# audience cascade. Merge facts are always recorded, but audience_key is stamped (via the
- # cascade) only when a stamphog-approved run exists at the exact merged head SHA — or the
- # repo is digest-only, where no approval can exist.
+ # cascade) only when a stamphog-approved run exists at the exact merged head SHA.
repo_config = _repo_config(team.id)
- if not review_enabled:
- StamphogRepoConfig.objects.for_team(team.id).filter(id=repo_config.id).update(enabled=False)
author, merged_head = "devex-dev", "sha-merged"
stamphog_chain.recorder.teams_by_login[author] = ["team-devex"]
_make_pr_with_review(team.id, repo_config, number=101, author=author, approved_at_sha=approved_at_sha)
diff --git a/products/stamphog/backend/tests/test_tasks.py b/products/stamphog/backend/tests/test_tasks.py
index fa255850aa49..c4021dcfcadd 100644
--- a/products/stamphog/backend/tests/test_tasks.py
+++ b/products/stamphog/backend/tests/test_tasks.py
@@ -378,14 +378,14 @@ def test_disabled_repo_config_is_a_noop(team, repo_config):
@pytest.mark.parametrize(
"enabled,digest_enabled,expect_capture",
- [(False, True, True), (True, False, True), (False, False, False)],
- ids=["digest_only_captures", "review_only_captures", "fully_disabled_drops"],
+ [(True, True, True), (True, False, True), (False, True, False), (False, False, False)],
+ ids=["review_and_digest_captures", "review_only_captures", "review_off_drops", "fully_disabled_drops"],
)
@pytest.mark.django_db(databases=PRODUCT_DATABASES)
-def test_merge_capture_gates_on_either_flag(team, repo_config, enabled, digest_enabled, expect_capture):
- # A merged PR must be captured whenever review OR digest is on — a digest-only repo (review off,
- # digest on) still needs its merges recorded or the daily digest has nothing to send. Only a fully
- # disabled repo drops the merge. Regression: the merge path used to gate on review `enabled` alone.
+def test_merge_capture_gates_on_review_enabled(team, repo_config, enabled, digest_enabled, expect_capture):
+ # Merge facts are recorded for every review-enabled repo, digest or not, because the digest gate
+ # further down only decides whether audience_key gets stamped. A review-disabled repo drops the
+ # merge outright, digest_enabled notwithstanding — nothing downstream can use it.
with team_scope(team.id):
repo_config.enabled = enabled
repo_config.digest_enabled = digest_enabled
diff --git a/products/stamphog/frontend/generated/api.schemas.ts b/products/stamphog/frontend/generated/api.schemas.ts
index 60056a7820ff..9d002aeba032 100644
--- a/products/stamphog/frontend/generated/api.schemas.ts
+++ b/products/stamphog/frontend/generated/api.schemas.ts
@@ -232,7 +232,7 @@ export interface StamphogRepoConfigApi {
enabled?: boolean
/** Provider app installation ID that authorizes API calls for this repo. Set only by the verified sync_installation flow; ignored on direct writes. */
readonly installation_id: string
- /** Whether merged PRs on this repo are captured for the daily Slack digest. */
+ /** Whether merged PRs on this repo are captured for the daily Slack digest. Requires 'enabled', since the digest reports what stamphog approved. */
digest_enabled?: boolean
/** When reviews run: 'all' reviews every pull request (the default); 'label' reviews only pull requests carrying the trigger label, mirroring the Action's opt-in flow.
*
@@ -273,7 +273,7 @@ export interface PatchedStamphogRepoConfigApi {
enabled?: boolean
/** Provider app installation ID that authorizes API calls for this repo. Set only by the verified sync_installation flow; ignored on direct writes. */
readonly installation_id?: string
- /** Whether merged PRs on this repo are captured for the daily Slack digest. */
+ /** Whether merged PRs on this repo are captured for the daily Slack digest. Requires 'enabled', since the digest reports what stamphog approved. */
digest_enabled?: boolean
/** When reviews run: 'all' reviews every pull request (the default); 'label' reviews only pull requests carrying the trigger label, mirroring the Action's opt-in flow.
*
diff --git a/products/stamphog/frontend/generated/api.zod.ts b/products/stamphog/frontend/generated/api.zod.ts
index 020e51134514..44a27eb362d4 100644
--- a/products/stamphog/frontend/generated/api.zod.ts
+++ b/products/stamphog/frontend/generated/api.zod.ts
@@ -144,7 +144,9 @@ export const StamphogRepoConfigsCreateBody = /* @__PURE__ */ zod.object({
digest_enabled: zod
.boolean()
.optional()
- .describe('Whether merged PRs on this repo are captured for the daily Slack digest.'),
+ .describe(
+ "Whether merged PRs on this repo are captured for the daily Slack digest. Requires 'enabled', since the digest reports what stamphog approved."
+ ),
review_mode: zod
.enum(['all', 'label'])
.describe('\* `all` - all\n\* `label` - label')
@@ -183,7 +185,9 @@ export const StamphogRepoConfigsUpdateBody = /* @__PURE__ */ zod.object({
digest_enabled: zod
.boolean()
.optional()
- .describe('Whether merged PRs on this repo are captured for the daily Slack digest.'),
+ .describe(
+ "Whether merged PRs on this repo are captured for the daily Slack digest. Requires 'enabled', since the digest reports what stamphog approved."
+ ),
review_mode: zod
.enum(['all', 'label'])
.describe('\* `all` - all\n\* `label` - label')
@@ -223,7 +227,9 @@ export const StamphogRepoConfigsPartialUpdateBody = /* @__PURE__ */ zod.object({
digest_enabled: zod
.boolean()
.optional()
- .describe('Whether merged PRs on this repo are captured for the daily Slack digest.'),
+ .describe(
+ "Whether merged PRs on this repo are captured for the daily Slack digest. Requires 'enabled', since the digest reports what stamphog approved."
+ ),
review_mode: zod
.enum(['all', 'label'])
.describe('\* `all` - all\n\* `label` - label')
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 333ecb97338d..e3c39cc64c96 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -51800,7 +51800,7 @@ export namespace Schemas {
enabled?: boolean;
/** Provider app installation ID that authorizes API calls for this repo. Set only by the verified sync_installation flow; ignored on direct writes. */
readonly installation_id: string;
- /** Whether merged PRs on this repo are captured for the daily Slack digest. */
+ /** Whether merged PRs on this repo are captured for the daily Slack digest. Requires 'enabled', since the digest reports what stamphog approved. */
digest_enabled?: boolean;
/** When reviews run: 'all' reviews every pull request (the default); 'label' reviews only pull requests carrying the trigger label, mirroring the Action's opt-in flow.
*
@@ -60298,7 +60298,7 @@ export namespace Schemas {
enabled?: boolean;
/** Provider app installation ID that authorizes API calls for this repo. Set only by the verified sync_installation flow; ignored on direct writes. */
readonly installation_id?: string;
- /** Whether merged PRs on this repo are captured for the daily Slack digest. */
+ /** Whether merged PRs on this repo are captured for the daily Slack digest. Requires 'enabled', since the digest reports what stamphog approved. */
digest_enabled?: boolean;
/** When reviews run: 'all' reviews every pull request (the default); 'label' reviews only pull requests carrying the trigger label, mirroring the Action's opt-in flow.
*