: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
feat(stamphog): let a team opt out of the daily digest alone (#94900)
Tue Haulunded49499b0b7c
diff --git a/docs/internal/ownership-model-proposal.md b/docs/internal/ownership-model-proposal.mdindex 3ff866d92ecd..d890b7f03d0f 100644--- a/docs/internal/ownership-model-proposal.md+++ b/docs/internal/ownership-model-proposal.md@@ -142,6 +142,10 @@ Every value is a string starting with `#`, or `false` to mean "no channel, don't- `slack` — where the people are. This is the channel a human is pointed at.- `notifications` — where automation posts. It falls back to `slack`, so a team that never separates the two keeps one entry, and `notifications: false` keeps automation out without hiding the team's channel from people.+`notifications` may also be a mapping of producer name to channel, so a team can silence or redirect one bot on its own.+A producer the mapping does not name falls through to `slack`.+Only a producer the schema knows may be named, so a typo is a lint error rather than an opt-out that never applies.+```yaml# owners.yaml (repo root only)teams:@@ -153,6 +157,10 @@ teams:quiet-team:slack: '#team-quiet'notifications: false+ digest-free-team:+ slack: '#team-digest-free'+ notifications:+ stamphog: falsesome-retired-team:slack: false```diff --git a/owners.yaml b/owners.yamlindex 9c779b7830ec..ef5e0d488db3 100644--- a/owners.yaml+++ b/owners.yaml@@ -26,6 +26,11 @@ teams:# PostHog Desktop's channel kept the name it was created under.team-posthog-code:slack: '#team-desktop'+ # The derived '#team-replay' is right; the entry exists only to drop the daily+ # stamphog digest, which the team reads on the PRs themselves.+ team-replay:+ notifications:+ stamphog: falserules:- match: Dockerfile.llm-analyticsowners: team-ai-observabilitydiff --git a/products/stamphog/backend/logic/channel_resolution.py b/products/stamphog/backend/logic/channel_resolution.pyindex be1e28ed660f..42b69e6a655b 100644--- a/products/stamphog/backend/logic/channel_resolution.py+++ b/products/stamphog/backend/logic/channel_resolution.py@@ -33,7 +33,7 @@ from django.db.models import Qimport structlogfrom posthog_owners.resolver import Purpose, TeamChannel, team_channel, teams_registry-from posthog_owners.schema import TeamEntry+from posthog_owners.schema import Producer, TeamEntryfrom posthog.dataclasses import frozenfrom posthog.models.integration import Integration, SlackIntegration@@ -52,6 +52,8 @@ _OWNERS_FILE_PATH = "owners.yaml"# The digest is automation, so it asks the registry where automation posts rather than where the# team's people are. That falls back to the people channel when a team never separates the two._CHANNEL_PURPOSE: Purpose = "notifications"+# Named so a team can keep the daily digest out of its channel while other bots keep posting there.+_PRODUCER: Producer = "stamphog"# Slack channel flags that mark a channel as shared beyond this workspace. Routing maps a GitHub# team slug onto a Slack channel by name, or by a registry entry. A shared channel with that name@@ -235,7 +237,7 @@ def _registry_answer(context: RoutingContext, slug: str, repository: str) -> Teablock, which no repository has a reason to write."""registry = context.registry_by_repo.get(repository) or context.inherited_registry- return team_channel(slug, registry, _CHANNEL_PURPOSE)+ return team_channel(slug, registry, _CHANNEL_PURPOSE, _PRODUCER)def resolve_destination(context: RoutingContext, audience_key: str, repository: str) -> Destination | None:diff --git a/products/stamphog/backend/tests/test_digest.py b/products/stamphog/backend/tests/test_digest.pyindex eec7e778a037..75c9279dc0de 100644--- a/products/stamphog/backend/tests/test_digest.py+++ b/products/stamphog/backend/tests/test_digest.py@@ -409,6 +409,11 @@ def test_a_repo_with_no_registry_inherits_one(team) -> None:"context_kwargs,reason",[({"registry_by_repo": {REPO: {AUDIENCE: TeamEntry(notifications=False)}}}, "silenced_by_config"),+ # A team that silences this digest alone keeps its channel for every other bot.+ (+ {"registry_by_repo": {REPO: {AUDIENCE: TeamEntry(slack="#team-apm", notifications={"stamphog": False})}}},+ "silenced_by_config",+ ),({"channels_by_name": {}}, "no_channel_of_that_name"),],)diff --git a/tools/owners/posthog_owners/resolver.py b/tools/owners/posthog_owners/resolver.pyindex 01048cacb533..24e8c9263588 100644--- a/tools/owners/posthog_owners/resolver.py+++ b/tools/owners/posthog_owners/resolver.py@@ -15,7 +15,7 @@ from pathlib import Pathfrom typing import Literal, Protocol, TypedDictfrom .matcher import compile_pattern, normalize_path-from .schema import UNSET, OwnersFile, TeamEntry, _Unset, parse_owners_file, parse_product_yaml_as_owners+from .schema import UNSET, OwnersFile, Producer, TeamEntry, _Unset, parse_owners_file, parse_product_yaml_as_ownersOWNERS_FILENAME = "owners.yaml"PRODUCT_FILENAME = "product.yaml"@@ -25,9 +25,9 @@ PRODUCT_FILENAME = "product.yaml"class TeamChannel:"""Where a team's Slack messages go, and how that was decided.- ``declared`` separates an explicit ``teams:`` entry from the derived ``#<slug>``: a caller- routing real messages usually treats a declaration as a decision to honor and a derivation as- a guess to verify, and cannot tell them apart from ``channel`` alone.+ ``declared`` separates an answer for this purpose and producer from the derived ``#<slug>``: a+ caller routing real messages usually treats a declaration as a decision to honor and a+ derivation as a guess to verify, and cannot tell them apart from ``channel`` alone."""channel: str | None@@ -41,14 +41,21 @@ Purpose = Literal["slack", "notifications"]DEFAULT_PURPOSE: Purpose = "slack"-def team_channel(slug: str, teams: Mapping[str, TeamEntry], purpose: Purpose = DEFAULT_PURPOSE) -> TeamChannel:+def team_channel(+ slug: str,+ teams: Mapping[str, TeamEntry],+ purpose: Purpose = DEFAULT_PURPOSE,+ producer: Producer | None = None,+) -> TeamChannel:"""The Slack channel for a team slug and a purpose, else the derived ``#<slug>``.``purpose`` is "slack" (where people are) or "notifications" (where automation posts)."notifications" falls back to "slack", so a team that never separates automation from people- keeps one channel and one entry. A per-producer form, so a team can silence one bot without- silencing all of them, is an additive change here later: it widens what a key may hold, and- callers keep the call they already make.+ keeps one channel and one entry.++ ``producer`` names the automation asking, and only matters when the team declared a per-producer+ ``notifications`` mapping. A mapping that does not name the producer falls through to ``slack``,+ so silencing one bot leaves the others where they were.A declared ``false`` means the team has no channel for that purpose, which is different fromhaving no entry. The first is an answer and stops the lookup; the second falls through.@@ -56,7 +63,11 @@ def team_channel(slug: str, teams: Mapping[str, TeamEntry], purpose: Purpose = Dentry = teams.get(slug)if entry is not None:candidates = (entry.notifications, entry.slack) if purpose == "notifications" else (entry.slack,)- for value in candidates:+ for candidate in candidates:+ if isinstance(candidate, Mapping):+ value = candidate.get(producer) if producer is not None else None+ else:+ value = candidateif value is not None:# Schema only admits `false`; any bool means "no channel".return TeamChannel(channel=value if isinstance(value, str) else None, declared=True)diff --git a/tools/owners/posthog_owners/schema.py b/tools/owners/posthog_owners/schema.pyindex 41e7a66b3ed8..25452c90df95 100644--- a/tools/owners/posthog_owners/schema.py+++ b/tools/owners/posthog_owners/schema.py@@ -7,9 +7,10 @@ treated as empty), every other field ignored.from __future__ import annotations+from collections.abc import Mappingfrom dataclasses import dataclass, fieldfrom pathlib import Path-from typing import TypeGuard+from typing import Literal, TypeGuard, get_argsimport yaml@@ -23,6 +24,12 @@ CHANGEME_SLUG = "team-CHANGEME"_TOP_LEVEL_KEYS = {"version", "owners", "status", "inherit", "rules", "teams"}_RULE_KEYS = {"match", "owners", "status", "inherit"}_TEAMS_ENTRY_KEYS = {"slack", "notifications"}+# Automation that posts to a team's notifications channel and can be silenced on its own. A+# producer must be named here to be nameable in `notifications:`. Lint reports a typo where lint+# runs; where it does not, an unreadable mapping silences rather than posts (see _validate_teams).+Producer = Literal["stamphog"]+PRODUCERS = frozenset(get_args(Producer))+_KNOWN_PRODUCERS = ", ".join(sorted(PRODUCERS))@dataclass(frozen=True)@@ -32,12 +39,16 @@ class TeamEntry:``slack`` is where people are. ``notifications`` is where automation posts, and it falls backto ``slack`` when a team never separates the two.+ ``notifications`` may also be a mapping of producer name to channel, so a team can silence or+ redirect one bot without doing it to all of them. A producer the mapping does not name falls+ through to ``slack``.+``None`` means the key was not declared, which is not the same as ``False``. The first fallsthrough to the next step of the lookup; the second is a decision that there is no channel."""slack: str | bool | None = None- notifications: str | bool | None = None+ notifications: str | bool | Mapping[str, str | bool] | None = Noneclass _Unset:@@ -111,6 +122,27 @@ def _is_valid_slack(raw: object) -> TypeGuard[str | bool]:return raw is False or (isinstance(raw, str) and raw.startswith("#"))+def _validate_producer_map(+ value: dict[object, object], where: str, key: str, errors: list[str]+) -> dict[str, str | bool]:+ """The producers a ``notifications:`` mapping names, without the entries it rejects."""+ if key != "notifications":+ errors.append(f"{where}: '{key}' takes a single channel, not a per-producer mapping")+ return {}+ if not value:+ errors.append(f"{where}: '{key}' mapping names no producer")+ return {}+ declared: dict[str, str | bool] = {}+ for producer, raw in value.items():+ if not isinstance(producer, str) or producer not in PRODUCERS:+ errors.append(f"{where}: unknown producer '{producer}' (known: {_KNOWN_PRODUCERS})")+ elif _is_valid_slack(raw):+ declared[producer] = raw+ else:+ errors.append(f"{where}: '{producer}' must be a string starting with '#' or false")+ return declared++def _validate_teams(value: object, errors: list[str]) -> dict[str, TeamEntry]:"""Validate the root-only ``teams:`` registry, a mapping of team slug to its channels.@@ -133,10 +165,19 @@ def _validate_teams(value: object, errors: list[str]) -> dict[str, TeamEntry]:if not isinstance(entry, dict):errors.append(f"{where}: entry must be a mapping with a {known_keys} key")continue- declared: dict[str, str | bool] = {}+ declared: dict[str, str | bool | Mapping[str, str | bool]] = {}for key, raw in entry.items():if not isinstance(key, str) or key not in _TEAMS_ENTRY_KEYS:errors.append(f"{where}: unknown field '{key}'")+ elif isinstance(raw, dict):+ per_producer = _validate_producer_map(raw, where, key, errors)+ if per_producer:+ declared[key] = per_producer+ elif key == "notifications":+ # A mapping we could not read silences the producer. Dropping the key would+ # post to the channel the team asked to be left out of, and a repo we read+ # this file from over the API runs no lint of ours.+ declared[key] = Falseelif _is_valid_slack(raw):declared[key] = rawelse:diff --git a/tools/owners/tests/test_owners.py b/tools/owners/tests/test_owners.pyindex 3fc0f0680181..eccd6fa002d9 100644--- a/tools/owners/tests/test_owners.py+++ b/tools/owners/tests/test_owners.py@@ -282,6 +282,10 @@ def test_teams_registry_is_root_only(tmp_path: Path) -> None:("teams:\n team-a: '#a'\n", "entry must be a mapping"),("teams:\n '@alice':\n slack: '#a'\n", "not @handles"),("teams:\n 123:\n slack: '#a'\n", "slug must be a string"),+ ("teams:\n team-a:\n slack:\n stamphog: false\n", "takes a single channel"),+ ("teams:\n team-a:\n notifications:\n nosuchbot: false\n", "unknown producer 'nosuchbot'"),+ ("teams:\n team-a:\n notifications:\n stamphog: 'no-hash'\n", "'stamphog' must be a string"),+ ("teams:\n team-a:\n notifications: {}\n", "mapping names no producer"),],)def test_teams_registry_invalid_shapes(tmp_path: Path, teams_yaml: str, needle: str) -> None:@@ -316,12 +320,42 @@ def test_team_channel_falls_back_by_purpose(assert (resolved.channel, resolved.declared) == (channel, declared)+ "notifications,producer,channel,declared",+ [+ # Silencing one producer leaves every other reader on the people channel, which is the+ # whole point of the per-producer form over `notifications: false`.+ ({"stamphog": False}, "stamphog", None, True),+ ({"stamphog": False}, None, "#team-a", True),+ ({"stamphog": "#bots-a"}, "stamphog", "#bots-a", True),+ # A scalar answers every producer, so naming one must not move the channel.+ ("#bots-a", "stamphog", "#bots-a", True),+ (False, "stamphog", None, True),+ ],+)+def test_team_channel_resolves_per_producer(+ notifications: str | bool | dict[str, str | bool], producer: str | None, channel: str | None, declared: bool+) -> None:+ entry = TeamEntry(slack="#team-a", notifications=notifications)+ resolved = team_channel("team-a", {"team-a": entry}, "notifications", producer)+ assert (resolved.channel, resolved.declared) == (channel, declared)++def test_team_channel_derives_for_an_unregistered_slug() -> None:assert team_channel("team-b", {"team-a": TeamEntry(slack="#a")}, "notifications") == team_channel("team-b", {}, "notifications")+def test_an_unreadable_producer_map_registers_as_silence(tmp_path: Path) -> None:+ # Dropping the key instead would fall through to the derived channel, so a typo in a repo our+ # lint never reads would post the digest the team asked to be left out of.+ text = "version: 1\nowners: []\nteams:\n team-a:\n notifications:\n stamphogg: false\n"+ file, errors = parse_owners_file(text, path=tmp_path / "owners.yaml", directory="")+ assert any("unknown producer" in e for e in errors)+ assert file is not None and file.teams == {"team-a": TeamEntry(notifications=False)}++def test_teams_registry_pins_file_as_non_simple(tmp_path: Path) -> None:text = "version: 1\nowners: [team-a]\nteams:\n team-a:\n slack: '#a'\n"file, _ = parse_owners_file(text, path=tmp_path / "owners.yaml", directory="")