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(signals): label the top_events window so a capture gap is not read as low volume (#68764)

posthog[bot]d4236c856dce
diff --git a/products/signals/backend/scout_harness/profile/builders.py b/products/signals/backend/scout_harness/profile/builders.py
index 6b8b458a3170..83adec4bf22e 100644
--- a/products/signals/backend/scout_harness/profile/builders.py
+++ b/products/signals/backend/scout_harness/profile/builders.py
@@ -70,7 +70,7 @@ logger = logging.getLogger(__name__)
# rows whose `source_version` doesn't match the current build, so adding a new key here
# (or restructuring an existing one) without bumping the version would silently mix old
# and new shapes in the cache.
-INVENTORY_SOURCE_VERSION = "v8"
+INVENTORY_SOURCE_VERSION = "v9"
# Top-events ClickHouse query bounds. 7d is short enough to spot recent bursts and long
# enough to stabilize counts on low-traffic teams; 50 covers the long tail without
@@ -743,17 +743,27 @@ def _recent_reviewer_corrections(team: Team) -> dict[str, Any]:
def _top_events(team: Team) -> list[dict[str, Any]] | None:
"""Top events by count over the lookback window, with reach + burst signals.
- For each of the top 50 events in the last 7 days:
- - `count` — total occurrences in the window
+ Every count here is over a rolling `TOP_EVENTS_LOOKBACK_DAYS`-day window, *not*
+ lifetime. Each row carries `window_days` so that's un-missable: a capture gap can
+ collapse a real, high-volume project's in-window counts to near-zero, and without
+ the window on the payload a scout keying a "no data worth watching" close-out on
+ `top_events` thinness can't tell a project that just went dark from one that never
+ had traffic. When the counts look thin, rule out a capture gap (compare to a
+ trailing baseline via a direct `execute-sql`) before concluding low-volume.
+
+ For each of the top 50 events in the window:
+ - `window_days` — the rolling window every count/timestamp below is measured over.
+ - `count` — total occurrences in the window (windowed, not lifetime).
- `distinct_users` — `uniq(person_id)`; reach. Distinguishes a high-count event
from one power user vs from many users.
- - `recent_24h_count` — count in the last 24h. Compare to `count / 7` to spot
- bursts: ratio well above 1/7 means the event is concentrated in the last day.
+ - `recent_24h_count` — count in the last 24h. Compare to `count / window_days` to
+ spot bursts: a ratio well above `1 / window_days` means the event is
+ concentrated in the last day.
- `recent_24h_users` — `uniq(person_id)` over the last 24h. A burst across many
users is qualitatively different from one user looping.
- - `first_seen` / `last_seen` — both *within the window*. Recent `first_seen`
- suggests a new event type or fresh burst; near-window-edge `first_seen` just
- means it's been around at least that long (the window can't tell you the
+ - `first_seen_in_window` / `last_seen_in_window` — both *within the window*. Recent
+ `first_seen_in_window` suggests a new event type or fresh burst; near-window-edge
+ just means it's been around at least that long (the window can't tell you the
true first-ever timestamp).
Returns `None` rather than `[]` if the query fails or times out, so the agent can
@@ -796,13 +806,14 @@ def _top_events(team: Team) -> list[dict[str, Any]] | None:
rows = response.results or []
return [
{
+ "window_days": TOP_EVENTS_LOOKBACK_DAYS,
"event": row[0],
"count": int(row[1]),
"distinct_users": int(row[2]),
"recent_24h_count": int(row[3]),
"recent_24h_users": int(row[4]),
- "first_seen": row[5].isoformat() if row[5] else None,
- "last_seen": row[6].isoformat() if row[6] else None,
+ "first_seen_in_window": row[5].isoformat() if row[5] else None,
+ "last_seen_in_window": row[6].isoformat() if row[6] else None,
}
for row in rows
]
diff --git a/products/signals/backend/scout_harness/profile/schema.py b/products/signals/backend/scout_harness/profile/schema.py
index 51c202a997b4..976ac59d092c 100644
--- a/products/signals/backend/scout_harness/profile/schema.py
+++ b/products/signals/backend/scout_harness/profile/schema.py
@@ -261,13 +261,17 @@ class BusinessKnowledge(_Section):
class TopEvent(_Section):
+ # `window_days` rides on every row (not the block, since `top_events` is a flat list)
+ # so a scout can't read a `count` without seeing that it's windowed, not lifetime — a
+ # thin count during a capture gap must not read as a genuinely low-volume project.
+ window_days: int
event: str
count: int
distinct_users: int
recent_24h_count: int
recent_24h_users: int
- first_seen: str | None
- last_seen: str | None
+ first_seen_in_window: str | None
+ last_seen_in_window: str | None
class Inventory(_Section):
diff --git a/products/signals/backend/scout_harness/serializers.py b/products/signals/backend/scout_harness/serializers.py
index d32075c37df7..069f04346e2f 100644
--- a/products/signals/backend/scout_harness/serializers.py
+++ b/products/signals/backend/scout_harness/serializers.py
@@ -910,8 +910,20 @@ class RecentDashboardEntrySerializer(serializers.Serializer):
class TopEventEntrySerializer(serializers.Serializer):
"""One row in `inventory.top_events`."""
+ window_days = serializers.IntegerField(
+ help_text=(
+ "Rolling lookback window (in days) that every count and timestamp on this row "
+ "is measured over — these are windowed figures, NOT lifetime totals. A capture "
+ "gap can collapse a real, high-volume project's in-window counts to near-zero, "
+ "so a thin `count` here does not by itself mean the project is low-volume: rule "
+ "out an ingestion gap (compare against a trailing baseline via a direct "
+ "`execute-sql`) before closing out a surface as unused."
+ ),
+ )
event = serializers.CharField(help_text="Event name as captured.")
- count = serializers.IntegerField(help_text="Number of occurrences in the lookback window (last 7 days).")
+ count = serializers.IntegerField(
+ help_text="Number of occurrences within the last `window_days` (windowed, not lifetime)."
+ )
distinct_users = serializers.IntegerField(
help_text=(
"`uniq(person_id)` over the window — reach. Distinguishes a high-count "
@@ -920,8 +932,9 @@ class TopEventEntrySerializer(serializers.Serializer):
)
recent_24h_count = serializers.IntegerField(
help_text=(
- "Count in just the last 24 hours. Compare to `count / 7` to spot bursts: "
- "a ratio well above 1/7 means the event is concentrated in the last day."
+ "Count in just the last 24 hours. Compare to `count / window_days` to spot "
+ "bursts: a ratio well above `1 / window_days` means the event is concentrated "
+ "in the last day."
),
)
recent_24h_users = serializers.IntegerField(
@@ -930,19 +943,18 @@ class TopEventEntrySerializer(serializers.Serializer):
"users is qualitatively different from one user in a loop."
),
)
- first_seen = serializers.CharField(
+ first_seen_in_window = serializers.CharField(
allow_null=True,
help_text=(
- "ISO-8601 timestamp of the earliest occurrence within the lookback window. "
- "Compare to the window start to spot new event types: `first_seen` close to "
- "`now` ⇒ likely new or recently bursting; close to the window edge ⇒ has "
- "been around at least that long (the window can't tell you when the event "
- "*truly* first appeared)."
+ "ISO-8601 timestamp of the earliest occurrence within the `window_days` window. "
+ "Compare to the window start to spot new event types: close to `now` ⇒ likely "
+ "new or recently bursting; close to the window edge ⇒ has been around at least "
+ "that long (the window can't tell you when the event *truly* first appeared)."
),
)
- last_seen = serializers.CharField(
+ last_seen_in_window = serializers.CharField(
allow_null=True,
- help_text="ISO-8601 timestamp of the most recent occurrence within the lookback window.",
+ help_text="ISO-8601 timestamp of the most recent occurrence within the `window_days` window.",
)
@@ -1353,11 +1365,16 @@ class ProjectProfileInventorySerializer(serializers.Serializer):
child=TopEventEntrySerializer(),
allow_null=True,
help_text=(
- "Top ~50 events by count over the last 7 days, with first/last seen "
- "timestamps within the window. `null` if the underlying ClickHouse query "
- "failed or timed out (distinct from `[]`, which means the team has no "
- "captures in the window). Use the gap between `first_seen` and `now` to "
- "spot new event types or recent bursts."
+ "Top ~50 events by count over a recent rolling window (each row carries "
+ "`window_days`), with first/last seen timestamps within that window. These "
+ "are WINDOWED counts, not lifetime totals: a capture gap can collapse a "
+ "real, high-volume project's counts to near-zero here, so rule out an "
+ "ingestion gap (compare against a trailing baseline via a direct "
+ "`execute-sql`) before reading thinness as a genuinely low-volume project. "
+ "`null` if the underlying ClickHouse query failed or timed out (distinct "
+ "from `[]`, which means the team has no captures in the window). Use the gap "
+ "between `first_seen_in_window` and `now` to spot new event types or recent "
+ "bursts."
),
)
diff --git a/products/signals/backend/test/test_scout_harness_profile.py b/products/signals/backend/test/test_scout_harness_profile.py
index f372ca27f8aa..8e5b787e8df5 100644
--- a/products/signals/backend/test/test_scout_harness_profile.py
+++ b/products/signals/backend/test/test_scout_harness_profile.py
@@ -6,10 +6,12 @@ Layered top-down: builder source-readers → `compute_project_profile` end-to-en
from __future__ import annotations
-from datetime import timedelta
+from datetime import UTC, datetime, timedelta
+from types import SimpleNamespace
from uuid import uuid4
from posthog.test.base import BaseTest
+from unittest.mock import MagicMock, patch
from django.utils import timezone
@@ -35,6 +37,7 @@ from products.signals.backend.scout_harness.profile import INVENTORY_SOURCE_VERS
from products.signals.backend.scout_harness.profile.builders import (
RECENT_ACTIVITY_WINDOW_DAYS,
REVIEWER_CORRECTIONS_WINDOW_DAYS,
+ TOP_EVENTS_LOOKBACK_DAYS,
_business_knowledge,
_emit_eligibility,
_existing_inbox_reports,
@@ -56,6 +59,7 @@ from products.signals.backend.scout_harness.profile.builders import (
_recent_reviewer_corrections,
_recent_surveys,
_signal_source_configs,
+ _top_events,
)
from products.signals.backend.scout_harness.tools.profile import (
PROFILE_TTL,
@@ -730,6 +734,29 @@ class TestBusinessKnowledge(BaseTest):
assert result["total_count"] == 0
+class TestTopEvents(BaseTest):
+ @patch("products.signals.backend.scout_harness.profile.builders.execute_hogql_query")
+ def test_rows_carry_window_days_and_windowed_timestamps(self, mock_query: MagicMock) -> None:
+ # Every count/timestamp is over a rolling window, not lifetime — the row must carry
+ # `window_days` and window-scoped timestamp keys so a scout can't misread a thin
+ # in-window count (e.g. during a capture gap) as a genuinely low-volume project.
+ seen = datetime(2026, 7, 1, tzinfo=UTC)
+ mock_query.return_value = SimpleNamespace(results=[["$pageview", 207000, 12000, 40, 30, seen, seen]])
+
+ assert _top_events(self.team) == [
+ {
+ "window_days": TOP_EVENTS_LOOKBACK_DAYS,
+ "event": "$pageview",
+ "count": 207000,
+ "distinct_users": 12000,
+ "recent_24h_count": 40,
+ "recent_24h_users": 30,
+ "first_seen_in_window": seen.isoformat(),
+ "last_seen_in_window": seen.isoformat(),
+ }
+ ]
+
+
class TestBuildInventory(BaseTest):
def test_returns_a_validated_inventory_with_all_sections(self) -> None:
inventory = build_inventory(self.team)
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index 9f9b7eb1a726..203c34070c64 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -1480,26 +1480,28 @@ export interface RecentActionsApi {
* One row in `inventory.top_events`.
*/
export interface TopEventEntryApi {
+ /** Rolling lookback window (in days) that every count and timestamp on this row is measured over — these are windowed figures, NOT lifetime totals. A capture gap can collapse a real, high-volume project's in-window counts to near-zero, so a thin `count` here does not by itself mean the project is low-volume: rule out an ingestion gap (compare against a trailing baseline via a direct `execute-sql`) before closing out a surface as unused. */
+ window_days: number
/** Event name as captured. */
event: string
- /** Number of occurrences in the lookback window (last 7 days). */
+ /** Number of occurrences within the last `window_days` (windowed, not lifetime). */
count: number
/** `uniq(person_id)` over the window — reach. Distinguishes a high-count event firing on one power user from one firing on many users. */
distinct_users: number
- /** Count in just the last 24 hours. Compare to `count / 7` to spot bursts: a ratio well above 1/7 means the event is concentrated in the last day. */
+ /** Count in just the last 24 hours. Compare to `count / window_days` to spot bursts: a ratio well above `1 / window_days` means the event is concentrated in the last day. */
recent_24h_count: number
/** `uniq(person_id)` over just the last 24 hours. A burst across many users is qualitatively different from one user in a loop. */
recent_24h_users: number
/**
- * ISO-8601 timestamp of the earliest occurrence within the lookback window. Compare to the window start to spot new event types: `first_seen` close to `now` ⇒ likely new or recently bursting; close to the window edge ⇒ has been around at least that long (the window can't tell you when the event *truly* first appeared).
+ * ISO-8601 timestamp of the earliest occurrence within the `window_days` window. Compare to the window start to spot new event types: close to `now` ⇒ likely new or recently bursting; close to the window edge ⇒ has been around at least that long (the window can't tell you when the event *truly* first appeared).
* @nullable
*/
- first_seen: string | null
+ first_seen_in_window: string | null
/**
- * ISO-8601 timestamp of the most recent occurrence within the lookback window.
+ * ISO-8601 timestamp of the most recent occurrence within the `window_days` window.
* @nullable
*/
- last_seen: string | null
+ last_seen_in_window: string | null
}
/**
@@ -1551,7 +1553,7 @@ export interface ProjectProfileInventoryApi {
/** Action orientation: total + the 5 most recently updated actions — useful to anchor agent reasoning about what the team treats as a meaningful interaction. */
recent_actions: RecentActionsApi
/**
- * Top ~50 events by count over the last 7 days, with first/last seen timestamps within the window. `null` if the underlying ClickHouse query failed or timed out (distinct from `[]`, which means the team has no captures in the window). Use the gap between `first_seen` and `now` to spot new event types or recent bursts.
+ * Top ~50 events by count over a recent rolling window (each row carries `window_days`), with first/last seen timestamps within that window. These are WINDOWED counts, not lifetime totals: a capture gap can collapse a real, high-volume project's counts to near-zero here, so rule out an ingestion gap (compare against a trailing baseline via a direct `execute-sql`) before reading thinness as a genuinely low-volume project. `null` if the underlying ClickHouse query failed or timed out (distinct from `[]`, which means the team has no captures in the window). Use the gap between `first_seen_in_window` and `now` to spot new event types or recent bursts.
* @nullable
*/
top_events: TopEventEntryApi[] | null
diff --git a/products/signals/skills/authoring-scouts/references/scout-anatomy.md b/products/signals/skills/authoring-scouts/references/scout-anatomy.md
index e83fbb754922..b267ca4297a6 100644
--- a/products/signals/skills/authoring-scouts/references/scout-anatomy.md
+++ b/products/signals/skills/authoring-scouts/references/scout-anatomy.md
@@ -66,6 +66,7 @@ The fleet's specialists all share this shape:
2. **Quick close-out.** A cheap early-exit so a quiet run costs almost nothing: if the watched event is absent from the profile's `top_events` or sitting at baseline (no fresh 24h activity), write one scratchpad entry and stop.
This keeps idle scouts cheap.
+ `top_events` counts are windowed (each row carries `window_days`), not lifetime — a project whose ingestion recently went dark reads identically to one that never had traffic. Before closing out a busy-looking project as empty on `top_events` thinness alone, rule out a capture gap with a direct `execute-sql` over a longer window (e.g. 30d); only close out when the low volume holds there.
```text
key: not-in-use:<scope>:team{team_id} # if the surface is absent entirely
diff --git a/products/signals/skills/signals-scout-observability-gaps/SKILL.md b/products/signals/skills/signals-scout-observability-gaps/SKILL.md
index 30f18b0fc0e4..1da2b73ba32e 100644
--- a/products/signals/skills/signals-scout-observability-gaps/SKILL.md
+++ b/products/signals/skills/signals-scout-observability-gaps/SKILL.md
@@ -27,7 +27,8 @@ You author reports directly via the report channel (`signals-scout-emit-report`
## Quick close-out: is this team big enough to have gaps?
-If `top_events` in the project profile is null or shows fewer than ~5 events firing above 100/day, the project is too quiet for observability-gap analysis to surface real recommendations. Write one scratchpad entry:
+If `top_events` in the project profile is null or shows fewer than ~5 events firing above 100/day, the project is too quiet for observability-gap analysis to surface real recommendations.
+`top_events` counts are windowed (each row carries `window_days`), not lifetime, so before closing out on thinness rule out a capture gap: a project whose ingestion recently went dark reads identically to one that never had traffic. If the counts look suspiciously thin for a team that otherwise looks active (configured integrations, saved insights, recent activity), confirm with a direct `execute-sql` over a longer window (e.g. 30d) rather than trusting the profile snapshot — a temporary gap is a capture problem for another surface, not a genuine absence of volume. Only when the low volume holds across that wider window, write one scratchpad entry:
- key: `not-applicable:observability_gaps:team{team_id}`
- content: brief note ("checked at {timestamp}, top_events count <5 above 100/day, too quiet for gap analysis")
diff --git a/products/signals/skills/signals-scout-product-analytics/SKILL.md b/products/signals/skills/signals-scout-product-analytics/SKILL.md
index ba23c5c1121e..cd8493cb330e 100644
--- a/products/signals/skills/signals-scout-product-analytics/SKILL.md
+++ b/products/signals/skills/signals-scout-product-analytics/SKILL.md
@@ -44,6 +44,8 @@ You can't scan a whole project in one run. Your leverage is a **durable watchlis
If `signals-scout-project-profile-get` shows `product_analytics` is **not** in `products_in_use`, **or** there are no saved funnel/retention/lifecycle insights (check via the `system.insights` search below) **and** `top_events` is too thin to infer even one activation flow (fewer than ~3 discrete business events above ~100/day), this team has no behavioral flow to score yet. Write one `not-in-use:product_analytics:team{team_id}` scratchpad entry and close out empty. Re-running with the same key idempotently refreshes the timestamp.
+Before closing out on `top_events` thinness, rule out a capture gap: its counts are windowed (each row carries `window_days`), not lifetime, so a project whose ingestion recently went dark reads identically to one that never had a flow. If the events look thin for a team that otherwise looks active, confirm with a direct `execute-sql` over a longer window (e.g. 30d) before concluding there's no flow — a recent capture cliff is a volume problem for another surface, not an absence of behavior to score.
+
## How a run works
Cycle between these moves; skip what's not useful. Spend the bulk of a run on **exploit** (re-scoring due watchlist flows) and a smaller slice on **explore** (finding new flows), so coverage compounds across runs instead of restarting cold.
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index c8985a78e647..7c25cda51384 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -45821,26 +45821,28 @@ export namespace Schemas {
* One row in `inventory.top_events`.
*/
export interface TopEventEntry {
+ /** Rolling lookback window (in days) that every count and timestamp on this row is measured over — these are windowed figures, NOT lifetime totals. A capture gap can collapse a real, high-volume project's in-window counts to near-zero, so a thin `count` here does not by itself mean the project is low-volume: rule out an ingestion gap (compare against a trailing baseline via a direct `execute-sql`) before closing out a surface as unused. */
+ window_days: number;
/** Event name as captured. */
event: string;
- /** Number of occurrences in the lookback window (last 7 days). */
+ /** Number of occurrences within the last `window_days` (windowed, not lifetime). */
count: number;
/** `uniq(person_id)` over the window — reach. Distinguishes a high-count event firing on one power user from one firing on many users. */
distinct_users: number;
- /** Count in just the last 24 hours. Compare to `count / 7` to spot bursts: a ratio well above 1/7 means the event is concentrated in the last day. */
+ /** Count in just the last 24 hours. Compare to `count / window_days` to spot bursts: a ratio well above `1 / window_days` means the event is concentrated in the last day. */
recent_24h_count: number;
/** `uniq(person_id)` over just the last 24 hours. A burst across many users is qualitatively different from one user in a loop. */
recent_24h_users: number;
/**
- * ISO-8601 timestamp of the earliest occurrence within the lookback window. Compare to the window start to spot new event types: `first_seen` close to `now` ⇒ likely new or recently bursting; close to the window edge ⇒ has been around at least that long (the window can't tell you when the event *truly* first appeared).
+ * ISO-8601 timestamp of the earliest occurrence within the `window_days` window. Compare to the window start to spot new event types: close to `now` ⇒ likely new or recently bursting; close to the window edge ⇒ has been around at least that long (the window can't tell you when the event *truly* first appeared).
* @nullable
*/
- first_seen: string | null;
+ first_seen_in_window: string | null;
/**
- * ISO-8601 timestamp of the most recent occurrence within the lookback window.
+ * ISO-8601 timestamp of the most recent occurrence within the `window_days` window.
* @nullable
*/
- last_seen: string | null;
+ last_seen_in_window: string | null;
}
/**
@@ -45892,7 +45894,7 @@ export namespace Schemas {
/** Action orientation: total + the 5 most recently updated actions — useful to anchor agent reasoning about what the team treats as a meaningful interaction. */
recent_actions: RecentActions;
/**
- * Top ~50 events by count over the last 7 days, with first/last seen timestamps within the window. `null` if the underlying ClickHouse query failed or timed out (distinct from `[]`, which means the team has no captures in the window). Use the gap between `first_seen` and `now` to spot new event types or recent bursts.
+ * Top ~50 events by count over a recent rolling window (each row carries `window_days`), with first/last seen timestamps within that window. These are WINDOWED counts, not lifetime totals: a capture gap can collapse a real, high-volume project's counts to near-zero here, so rule out an ingestion gap (compare against a trailing baseline via a direct `execute-sql`) before reading thinness as a genuinely low-volume project. `null` if the underlying ClickHouse query failed or timed out (distinct from `[]`, which means the team has no captures in the window). Use the gap between `first_seen_in_window` and `now` to spot new event types or recent bursts.
* @nullable
*/
top_events: TopEventEntry[] | null;