: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(signals): count one-click today resolves in the action and fixed labels (#117893)
posthog[bot]714ee641ce94
diff --git a/products/signals/dags/inbox_ranking/README.md b/products/signals/dags/inbox_ranking/README.mdindex fe1b324d83a1..6b0b4df21664 100644--- a/products/signals/dags/inbox_ranking/README.md+++ b/products/signals/dags/inbox_ranking/README.md@@ -246,9 +246,15 @@ Both regions read the same flag, so one override applies everywhere, if the regi| `dismiss_lowvalue` | Every report | 21 |`action` counts intent from every surface, not only the cloud inbox list.-A report is a positive when someone clicked an intent action in the inbox UI (create PR, implement, copy the prompt, discuss, open or view a PR, edit the reviewers, restore), or when a person or an external agent claimed it, linked a PR, left a note, discussed it in Slack, or resolved it with a reason.+A report is a positive when someone clicked an intent action in the inbox UI (create PR, implement, copy the prompt, discuss, open or view a PR, edit the reviewers, restore), or when a person or an external agent claimed it, linked a PR, left a note, discussed it in Slack, or resolved it.+A resolve counts when it carries a reason or when its `actor_kind` is `user` or `agent`, so the one-click Today resolve counts.Self-driving's own `task` and `system` writes do not count: they are internal operational work.-A resolve without a reason is the automatic resolve after a tracked PR merges, so it does not count either.+A resolve with no reason and no human actor is the automatic resolve after a tracked PR merges, so it does not count either.++`fixed` counts a resolve without a not-fixed reason, and a dismissal with a fixed reason.+A reason-less resolve by a `user` or an `agent` waits for a 24-hour grace window first.+It counts as fixed only when the window closed before the snapshot and no not-fixed reason arrived inside it as a `reason_added` row.+The label is dated from the resolve, and a reason after the window cannot take it back, so the label only grows.The Today home sends the same client events as the Inbox, with `surface: 'today'` and a `list` property (`briefing` or `sidebar_more`) on impressions and opens.Filter on `surface` where a metric must stay Inbox-only.diff --git a/products/signals/dags/inbox_ranking/dataset/dag.py b/products/signals/dags/inbox_ranking/dataset/dag.pyindex e9dbfbd3802f..d15486d8f20b 100644--- a/products/signals/dags/inbox_ranking/dataset/dag.py+++ b/products/signals/dags/inbox_ranking/dataset/dag.py@@ -155,7 +155,7 @@ from products.signals.dags.inbox_ranking.dataset.queries import (valid_report_uuids,)-FEATURE_SCHEMA_VERSION = 9+FEATURE_SCHEMA_VERSION = 10# Apart from FEATURE_SCHEMA_VERSION on purpose: the labels refresh sensor rewrites every labels# partition whose stamp is older than that one, and a user-grain change must not set it off.USER_INTERACTIONS_SCHEMA_VERSION = 1diff --git a/products/signals/dags/inbox_ranking/dataset/queries.py b/products/signals/dags/inbox_ranking/dataset/queries.pyindex b3f777ea6255..3475149b8c48 100644--- a/products/signals/dags/inbox_ranking/dataset/queries.py+++ b/products/signals/dags/inbox_ranking/dataset/queries.py@@ -26,6 +26,7 @@ from posthog.models import Teamfrom products.signals.dags.inbox_ranking.common import (FIXED_DISMISSAL_REASONS,+ HUMAN_ACTOR_KINDS,LABELS_EPOCH,LOW_VALUE_DISMISSAL_REASONS,NOT_FIXED_RESOLUTION_REASONS,@@ -378,16 +379,57 @@ GROUP BY report_id_WRONG_DISMISSAL_REASONS_SQL = ", ".join(f"'{reason}'" for reason in WRONG_DISMISSAL_REASONS)_NOT_FIXED_RESOLUTION_REASONS_SQL = ", ".join(f"'{reason}'" for reason in NOT_FIXED_RESOLUTION_REASONS)_FIXED_DISMISSAL_REASONS_SQL = ", ".join(f"'{reason}'" for reason in FIXED_DISMISSAL_REASONS)-# A transition that says the problem was real and is fixed, by anyone: a resolve without a not-fixed-# reason (a reason-less resolve is the PR-merge webhook), or a dismissal with a fixed reason.+_HUMAN_ACTOR_KINDS_SQL = ", ".join(f"'{kind}'" for kind in HUMAN_ACTOR_KINDS)+# A reason-less resolve that a person or an external agent asked for, such as the one-click Today+# resolve. The reason is optional there and arrives later as a `reason_added` row. A reason-less+# resolve with any other actor, or with no actor, is the automatic resolve after a tracked PR merges.+_HUMAN_REASONLESS_RESOLVE_SQL = (+ "toString(properties.status) = 'resolved' AND coalesce(toString(properties.dismissal_reason), '') = ''"+ " AND coalesce(toString(properties.actor_kind), '') IN (" + _HUMAN_ACTOR_KINDS_SQL + ")"+)+# A transition someone asked for: it carries a reason, or a person or an external agent made it.+_RESOLVE_INTENT_SQL = (+ "coalesce(toString(properties.dismissal_reason), '') != ''"+ " OR coalesce(toString(properties.actor_kind), '') IN (" + _HUMAN_ACTOR_KINDS_SQL + ")"+)+# The time a person has to add a not-fixed reason to a reason-less resolve before it counts as fixed.+# Today offers the reason right after the resolve, and the added reasons on the status stream arrive+# well inside this window.+HUMAN_RESOLVE_GRACE_HOURS = 24+# A `reason_added` row with no reason is a note-only update. It names no actor, so without this+# guard it reads as a PR-merge resolve and skips the grace window of the resolve it follows.+_NOTE_ONLY_UPDATE_SQL = (+ "coalesce(toString(properties.reason_added), '') = 'true'"+ " AND coalesce(toString(properties.dismissal_reason), '') = ''"+)+# A transition that says the problem was real and is fixed: a resolve without a not-fixed reason by+# the PR-merge webhook or with a reason, or a dismissal with a fixed reason. A human reason-less+# resolve waits for its grace window instead (`_HUMAN_RESOLVE_FIXED_TIMES_SQL`)._FIXED_TRANSITION_SQL = ("(toString(properties.status) = 'resolved' AND coalesce(toString(properties.dismissal_reason), '') NOT IN ("+ _NOT_FIXED_RESOLUTION_REASONS_SQL+ + ") AND NOT ("+ + _HUMAN_REASONLESS_RESOLVE_SQL+ + ") AND NOT ("+ + _NOTE_ONLY_UPDATE_SQL+ ")) OR (toString(properties.status) = 'suppressed' AND toString(properties.dismissal_reason) IN ("+ _FIXED_DISMISSAL_REASONS_SQL+ "))")_LOW_VALUE_DISMISSAL_REASONS_SQL = ", ".join(f"'{reason}'" for reason in LOW_VALUE_DISMISSAL_REASONS)+# The bucket's human reason-less resolves that are fixed: the grace window closed before the snapshot+# with no not-fixed reason added inside it. Each resolve is checked on its own, because a bucket can+# hold a resolve, a reopen and a second resolve. Every reason inside a closed window is already in the+# snapshot, so a later reason cannot take the label back and the label stays monotonic.+_HUMAN_RESOLVE_FIXED_TIMES_SQL = f"""arrayFilter(+ resolved_at -> resolved_at + INTERVAL {HUMAN_RESOLVE_GRACE_HOURS} HOUR <= toDateTime({{snapshot_end}})+ AND NOT arrayExists(+ reason_at -> reason_at >= resolved_at+ AND reason_at < resolved_at + INTERVAL {HUMAN_RESOLVE_GRACE_HOURS} HOUR,+ not_fixed_reason_times+ ),+ bucket_human_resolve_times+ )"""# The outcome a transition reaches, shared by the report-grain and user-grain status streams._STATUS_OUTCOME_SQL = """multiIf(@@ -486,21 +528,41 @@ SELECTbucket_first_wrong_dismissed_at,outcome = 'dismissed' AND event_team_id = latest_event_team_id) AS first_wrong_dismissed_at,- -- A resolve that carries a reason is a person or an agent marking the report done, from any- -- surface. A reason-less resolve is the automatic resolve after a tracked PR merges, so it is- -- not counted. Counted per bucket and dated by the bucket's first reasoned event, under the- -- same tenant restriction as the wrong-dismissal pair above. The action head reads this pair.+ -- A resolve that carries a reason, or that a person or an external agent asked for, is someone+ -- marking the report done, from any surface. The one-click Today resolve carries no reason but+ -- names its actor. A reason-less resolve with no human actor is the automatic resolve after a+ -- tracked PR merges, so it is not counted. Counted per bucket and dated by the bucket's first+ -- counted event, under the same tenant restriction as the wrong-dismissal pair above. The+ -- action head reads this pair.countIf(- outcome = 'resolved' AND bucket_reasoned = 1 AND event_team_id = latest_event_team_id+ outcome = 'resolved' AND bucket_resolve_intent = 1 AND event_team_id = latest_event_team_id) AS reasoned_resolution_count,minIf(- bucket_first_reasoned_at,+ bucket_first_resolve_intent_at,outcome = 'resolved' AND event_team_id = latest_event_team_id) AS first_reasoned_resolved_at,-- Cumulative and tenant-scoped like wrong_dismissal_count, so a reopen or a later re-dismissal- -- with another reason cannot take the label back. The fixed head reads this column.- countIf(bucket_fixed = 1 AND event_team_id = latest_event_team_id) AS fixed_count,- minIf(bucket_first_fixed_at, event_team_id = latest_event_team_id) AS first_fixed_at,+ -- with another reason cannot take the label back. A human reason-less resolve is dated from the+ -- resolve, not from the end of its grace window. The fixed head reads this column.+ countIf(+ (bucket_fixed = 1 OR notEmpty("""+ + _HUMAN_RESOLVE_FIXED_TIMES_SQL+ + """)) AND event_team_id = latest_event_team_id+ ) AS fixed_count,+ minIf(+ if(+ notEmpty("""+ + _HUMAN_RESOLVE_FIXED_TIMES_SQL+ + """) AND (bucket_first_fixed_at IS NULL OR arrayMin("""+ + _HUMAN_RESOLVE_FIXED_TIMES_SQL+ + """) < bucket_first_fixed_at),+ arrayMin("""+ + _HUMAN_RESOLVE_FIXED_TIMES_SQL+ + """),+ bucket_first_fixed_at+ ),+ event_team_id = latest_event_team_id+ ) AS first_fixed_at,-- The same cumulative count, timestamp and tenant restriction for the low-value reasons. The-- dismiss_lowvalue head reads this column.countIf(@@ -532,7 +594,13 @@ FROM (-- tenant is the tie-breaker so the selection is deterministic.argMax(coalesce(event_team_id, ''), tuple(last_timestamp, coalesce(event_team_id, ''))- ) OVER (PARTITION BY report_id) AS latest_event_team_id+ ) OVER (PARTITION BY report_id) AS latest_event_team_id,+ -- The not-fixed reasons added to this report, on every bucket row, so a human reason-less+ -- resolve can check its grace window. Partitioned by tenant, so a reason that names another+ -- team never takes a fixed label away.+ arrayFlatten(+ groupArray(bucket_not_fixed_reason_times) OVER (PARTITION BY report_id, event_team_id)+ ) AS not_fixed_reason_timesFROM (SELECTmin(events.timestamp) AS first_timestamp,@@ -564,10 +632,24 @@ FROM (+ """)), fromUnixTimestamp(0)) AS bucket_first_wrong_dismissed_at,-- coalesce is load-bearing: HogQL evaluates NULL != '' to true, so a reason-less event-- would otherwise count as reasoned.- max(coalesce(toString(properties.dismissal_reason), '') != '') AS bucket_reasoned,- nullIf(- minIf(events.timestamp, coalesce(toString(properties.dismissal_reason), '') != ''), fromUnixTimestamp(0)- ) AS bucket_first_reasoned_at,+ max("""+ + _RESOLVE_INTENT_SQL+ + """) AS bucket_resolve_intent,+ nullIf(minIf(events.timestamp, """+ + _RESOLVE_INTENT_SQL+ + """), fromUnixTimestamp(0)) AS bucket_first_resolve_intent_at,+ groupArrayIf(events.timestamp, """+ + _HUMAN_REASONLESS_RESOLVE_SQL+ + """) AS bucket_human_resolve_times,+ -- Only reasons added to a resolve: a reason added to a later dismissal says nothing about it.+ groupArrayIf(+ events.timestamp,+ coalesce(toString(properties.reason_added), '') = 'true'+ AND toString(properties.status) = 'resolved'+ AND toString(properties.dismissal_reason) IN ("""+ + _NOT_FIXED_RESOLUTION_REASONS_SQL+ + """)+ ) AS bucket_not_fixed_reason_times,max("""+ _FIXED_TRANSITION_SQL+ """) AS bucket_fixed,diff --git a/products/signals/dags/inbox_ranking/tests/test_dataset.py b/products/signals/dags/inbox_ranking/tests/test_dataset.pyindex a03f597d1a19..ceb90bbc9b23 100644--- a/products/signals/dags/inbox_ranking/tests/test_dataset.py+++ b/products/signals/dags/inbox_ranking/tests/test_dataset.py@@ -788,23 +788,30 @@ class TestStatusStream(ClickhouseTestMixin, BaseTest):reason: str | None = None,*,team_id: int | None = None,+ actor_kind: str | None = None,+ reason_added: bool = False,) -> None:+ properties: dict[str, Any] = {+ "report_id": UUID_A,+ "previous_status": previous,+ "status": status,+ "dismissal_reason": reason,+ "team_id": str(team_id or self.team.id),+ }+ if actor_kind is not None:+ properties["actor_kind"] = actor_kind+ if reason_added:+ properties["reason_added"] = True_create_event(team=self.team,event="signal_report_status_changed",distinct_id="team-2",timestamp=when,- properties={- "report_id": UUID_A,- "previous_status": previous,- "status": status,- "dismissal_reason": reason,- "team_id": str(team_id or self.team.id),- },+ properties=properties,)- def _status_row(self) -> dict[str, Any]:- rows = hogql_rows(STATUS_SQL, team=self.team, query_type="test", snapshot_end=SNAPSHOT_END)+ def _status_row(self, snapshot_end: datetime.datetime = SNAPSHOT_END) -> dict[str, Any]:+ rows = hogql_rows(STATUS_SQL, team=self.team, query_type="test", snapshot_end=snapshot_end)assert len(rows) == 1return dict(zip(STATUS_COLUMNS, rows[0][1:], strict=True))@@ -884,6 +891,104 @@ class TestStatusStream(ClickhouseTestMixin, BaseTest):assert row["fixed_count"] == expectedassert row["first_fixed_at"] == (T1 if expected else None)+ @parameterized.expand(+ [+ ("window_closed", T1, [], 1),+ ("window_open_at_snapshot", SNAPSHOT_END - datetime.timedelta(hours=1), [], 0),+ ("not_fixed_reason_inside_window", T1, [(datetime.timedelta(minutes=2), "wontfix_irrelevant", None)], 0),+ ("fixed_reason_inside_window", T1, [(datetime.timedelta(minutes=2), "fixed_outside_posthog", None)], 2),+ ("not_fixed_reason_after_window", T1, [(datetime.timedelta(hours=25), "analysis_wrong", None)], 1),+ ("not_fixed_reason_from_another_tenant", T1, [(datetime.timedelta(hours=1), "analysis_wrong", 999)], 1),+ ]+ )+ def test_human_reasonless_resolve_is_fixed_after_its_grace_window(self, _name, resolved_at, reasons, expected):+ # The one-click Today resolve carries no reason and names its actor. The reason it can get+ # later decides fixed, so it counts only when its window closed without a not-fixed reason.+ self._transition(resolved_at, "ready", "resolved", actor_kind="user")+ for offset, reason, team_id in reasons:+ self._transition(resolved_at + offset, "resolved", "resolved", reason, team_id=team_id, reason_added=True)+ # A later genuine transition keeps the report's own tenant the latest one.+ self._transition(BEFORE_CUTOFF + datetime.timedelta(hours=12), "resolved", "ready")++ row = self._status_row()+ assert row["reasoned_resolution_count"] >= 1+ assert row["first_reasoned_resolved_at"] == resolved_at+ assert row["fixed_count"] == expected+ assert row["first_fixed_at"] == (resolved_at if expected else None)++ @parameterized.expand(+ [+ (+ "note_only_update_is_not_a_fixed_resolve",+ [(2, "resolved", "resolved", None, True), (30, "resolved", "resolved", "analysis_wrong", True)],+ 0,+ None,+ ),+ (+ "dismissal_reason_does_not_block_a_resolve",+ [+ (3, "resolved", "ready", None, False),+ (4, "ready", "suppressed", None, False),+ (5, "suppressed", "suppressed", "analysis_wrong", True),+ ],+ 1,+ 0,+ ),+ (+ "second_resolve_in_the_bucket_is_fixed",+ [+ (1, "resolved", "resolved", "analysis_wrong", True),+ (2, "resolved", "ready", None, False),+ (4, "ready", "resolved", None, False),+ ],+ 1,+ 4,+ ),+ (+ "second_reason_in_the_bucket_blocks_it",+ [+ (1, "resolved", "resolved", "analysis_wrong", True),+ (2, "resolved", "ready", None, False),+ (4, "ready", "resolved", None, False),+ (5, "resolved", "resolved", "wrong_repo", True),+ ],+ 0,+ None,+ ),+ ]+ )+ def test_human_resolve_grace_window_reads_every_event_in_a_bucket(self, _name, events, expected, fixed_minute):+ # The resolves and reasons share ten-minute buckets, so a rule that keeps only a bucket's first+ # resolve or first reason, or counts a note-only update as a resolve, gets these wrong.+ resolved_at = SNAPSHOT_END - datetime.timedelta(hours=1)+ self._transition(resolved_at, "ready", "resolved", actor_kind="user")+ for minute, previous, status, reason, reason_added in events:+ self._transition(+ resolved_at + datetime.timedelta(minutes=minute),+ previous,+ status,+ reason,+ actor_kind=None if reason_added else "user",+ reason_added=reason_added,+ )++ row = self._status_row(SNAPSHOT_END + datetime.timedelta(days=2))+ assert row["fixed_count"] == expected+ assert row["first_fixed_at"] == (+ None if fixed_minute is None else resolved_at + datetime.timedelta(minutes=fixed_minute)+ )++ def test_human_reasonless_resolve_fixed_label_only_grows_across_partitions(self):+ resolved_at = SNAPSHOT_END - datetime.timedelta(hours=6)+ self._transition(resolved_at, "ready", "resolved", actor_kind="agent")+ self._transition(+ resolved_at + datetime.timedelta(days=2), "resolved", "resolved", "analysis_wrong", reason_added=True+ )++ rows = [self._status_row(SNAPSHOT_END + datetime.timedelta(days=offset)) for offset in range(4)]+ assert [row["fixed_count"] for row in rows] == [0, 1, 1, 1]+ assert [row["first_fixed_at"] for row in rows] == [None, resolved_at, resolved_at, resolved_at]+@parameterized.expand([(datetime.timedelta(hours=1),), (datetime.timedelta(minutes=1),)])def test_fixed_count_survives_a_reopen(self, gap):self._transition(T1, "ready", "resolved", None)@@ -919,11 +1024,21 @@ class TestStatusStream(ClickhouseTestMixin, BaseTest):# a dismissal the report's tenant never made.assert row["first_dismissed_server_at"] != T1- @parameterized.expand([("reasoned", "fixed_outside_posthog", 1), ("reasonless", None, 0), ("empty", "", 0)])- def test_only_a_reasoned_resolve_counts_as_a_reasoned_resolution(self, _name, reason, expected_count):- # A reason-less resolve is the automatic resolve after a tracked PR merges, not a person- # acting on the report.- self._transition(T1, "ready", "resolved", reason)+ @parameterized.expand(+ [+ ("reasoned", "fixed_outside_posthog", None, 1),+ ("reasonless", None, None, 0),+ ("empty", "", None, 0),+ ("reasonless_system", None, "system", 0),+ ("reasonless_task", None, "task", 0),+ ("reasonless_user", None, "user", 1),+ ("reasonless_agent", "", "agent", 1),+ ]+ )+ def test_a_resolve_counts_as_intent_when_reasoned_or_human(self, _name, reason, actor_kind, expected_count):+ # A reason-less resolve with no human actor is the automatic resolve after a tracked PR+ # merges. The one-click Today resolve has no reason but names a person.+ self._transition(T1, "ready", "resolved", reason, actor_kind=actor_kind)row = self._status_row()assert row["first_resolved_at"] == T1@@ -938,12 +1053,13 @@ class TestStatusStream(ClickhouseTestMixin, BaseTest):# timestamps so the latest-wins columns have one unambiguous winner.statuses = ("resolved", "suppressed", "failed", "potential")for offset, status in enumerate(statuses):- self._transition(T2 + datetime.timedelta(hours=offset), "ready", status)+ self._transition(T2 + datetime.timedelta(hours=offset), "ready", status, actor_kind="user")genuine_only = self._status_row()for status in statuses:for reason in ("analysis_wrong", "wontfix_irrelevant"):- self._transition(T1, "ready", status, reason, team_id=999)+ self._transition(T1, "ready", status, reason, team_id=999, actor_kind="user")+ self._transition(T1, status, status, reason, team_id=999, reason_added=True)assert self._status_row() == genuine_onlydiff --git a/products/signals/dags/inbox_ranking/training/heads.py b/products/signals/dags/inbox_ranking/training/heads.pyindex 38b9414397e9..6fd1da39039b 100644--- a/products/signals/dags/inbox_ranking/training/heads.py+++ b/products/signals/dags/inbox_ranking/training/heads.py@@ -178,8 +178,9 @@ HEADS: tuple[Head, ...] = (),# Which reports flagged a real problem that then got fixed, by anyone and on any surface? Reads# only the status stream: a tracked PR merge, a hand-marked fix, or a dismissal as already- # fixed all count. Fixes marked by hand arrive about two weeks after birth and many land later,- # so 30 days labels fewer late fixes as negatives than 21 did.+ # fixed all count. A one-click resolve counts after its grace window (`STATUS_SQL`). Fixes marked+ # by hand arrive about two weeks after birth and many land later, so 30 days labels fewer late+ # fixes as negatives than 21 did.Head(name="fixed",cohort=everyone,