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): exclude archived flags from scout project profile (#70732)

posthog[bot]b6331a0d5932
diff --git a/products/signals/backend/scout_harness/profile/builders.py b/products/signals/backend/scout_harness/profile/builders.py
index dd41c1f3bb39..fbc2e8d53b51 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 = "v9"
+INVENTORY_SOURCE_VERSION = "v10"
# 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
@@ -409,8 +409,13 @@ def _recent_feature_flags(team: Team) -> dict[str, Any]:
answers "could a user be hitting this code path?" — which is the question worth
distinguishing from "does this flag exist?" Sort by `updated_at`, which captures
both creation and rollout-percentage changes.
+
+ Excludes archived flags to match the live roster: the `feature-flag-get-all`
+ (list) endpoint hides archived flags by default, so counting them here would let
+ a scout read a stale inventory that disagrees with the current roster after a flag
+ is archived. (Soft-deleted flags are already excluded via `deleted=False`.)
"""
- qs = FeatureFlag.objects.filter(team=team, deleted=False)
+ qs = FeatureFlag.objects.filter(team=team, deleted=False, archived=False)
total = qs.count()
active = qs.filter(active=True).count()
recent = qs.order_by("-updated_at")[:RECENT_ENTITY_LIMIT].values("id", "key", "name", "active", "updated_at")
diff --git a/products/signals/backend/test/test_scout_harness_profile.py b/products/signals/backend/test/test_scout_harness_profile.py
index 02ae8f8fc6f5..9e5ca00a68e6 100644
--- a/products/signals/backend/test/test_scout_harness_profile.py
+++ b/products/signals/backend/test/test_scout_harness_profile.py
@@ -363,8 +363,11 @@ class TestRecentFeatureFlags(BaseTest):
FeatureFlag.objects.create(team=self.team, key="a", name="A", active=True, created_by=self.user)
FeatureFlag.objects.create(team=self.team, key="b", name="B", active=False, created_by=self.user)
FeatureFlag.objects.create(team=self.team, key="c", name="C", active=True, deleted=True, created_by=self.user)
+ # `d` is archived (always disabled) — hidden from the live roster by default, so it
+ # must not be counted here either.
+ FeatureFlag.objects.create(team=self.team, key="d", name="D", active=False, archived=True, created_by=self.user)
result = _recent_feature_flags(self.team)
- # `c` is soft-deleted — excluded from total.
+ # `c` is soft-deleted and `d` is archived — both excluded from total.
assert result["total_count"] == 2
assert result["active_count"] == 1
keys = {row["key"] for row in result["recent"]}