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.

feat(signals): add viewed objects to the activity summary input (#121380)

posthog[bot]da492be577e1
diff --git a/products/signals/backend/activity_summary/inputs.py b/products/signals/backend/activity_summary/inputs.py
index 80c3e449a239..f94771e5de24 100644
--- a/products/signals/backend/activity_summary/inputs.py
+++ b/products/signals/backend/activity_summary/inputs.py
@@ -1,23 +1,27 @@
-"""Read one user's own tasks and activity log rows in one project, from in-region Postgres."""
+"""Read one user's own tasks, activity log rows and views in one project, from in-region Postgres."""
import datetime
from collections.abc import Iterable
from django.db.models.fields.json import KeyTextTransform, KeyTransform
-from posthog.models import ActivityLog
+from posthog.models import ActivityLog, FileSystem, FileSystemViewLog
+from posthog.models.file_system.file_system import split_path
from products.dashboards.backend.facade.api import dashboards_by_insight
from products.signals.backend.activity_summary.render import (
MAX_ACTIVITY_ROWS_PER_PERSON,
MAX_TASKS_PER_PERSON,
+ MAX_VIEW_ROWS_PER_PERSON,
NOISY_ACTIVITY_SCOPES,
SANDBOX_PROMPT_TITLE_PREFIX,
+ SCENE_VIEW_TYPE,
SCOUT_CLIENT_PREFIX,
ActivityItem,
Parent,
ParentLookup,
TaskItem,
+ ViewItem,
)
from products.tasks.backend.facade.user_task_summaries import list_user_task_summaries
@@ -89,3 +93,44 @@ def activity_parents(team_id: int, activity: Iterable[ActivityItem]) -> ParentLo
)
for insight_id, dashboards in dashboards_by_insight(insight_ids, team_id=team_id).items()
}
+
+
+def user_views(team_id: int, user_id: int, start: datetime.datetime, end: datetime.datetime) -> list[ViewItem]:
+ """The objects and scenes the user last opened in [start, end), newest `MAX_VIEW_ROWS_PER_PERSON` first.
+
+ A view log row keeps one object's latest view and the days of the views before it, so each item
+ carries the days from `start` on. An object gets its name and creator from its file system entry."""
+ rows = list(
+ FileSystemViewLog.objects.filter(team_id=team_id, user_id=user_id, viewed_at__gte=start, viewed_at__lt=end)
+ .exclude(type="folder")
+ .order_by("-viewed_at")
+ .values_list("type", "ref", "viewed_at", "view_days")[:MAX_VIEW_ROWS_PER_PERSON]
+ )
+ keys = {(view_type, ref) for view_type, ref, _, _ in rows if view_type != SCENE_VIEW_TYPE}
+ entries: dict[tuple[str, str | None], tuple[str, int | None]] = {}
+ if keys:
+ for view_type, ref, path, creator_id in (
+ FileSystem.objects.filter(
+ team_id=team_id, type__in={key[0] for key in keys}, ref__in={key[1] for key in keys}
+ )
+ .exclude(shortcut=True)
+ .values_list("type", "ref", "path", "created_by_id")
+ ):
+ if (view_type, ref) in keys and (segments := split_path(path)):
+ entries[(view_type, ref)] = (segments[-1], creator_id)
+ first_day = start.astimezone(datetime.UTC).date()
+ items: list[ViewItem] = []
+ for view_type, ref, viewed_at, view_days in rows:
+ days = {day for day in view_days or () if day >= first_day} or {viewed_at.astimezone(datetime.UTC).date()}
+ name, created_by_id = entries.get((view_type, ref), (None, None))
+ items.append(
+ ViewItem(
+ at=viewed_at,
+ type=view_type,
+ ref=ref,
+ name=name,
+ days=tuple(sorted(days)),
+ not_theirs=created_by_id is not None and created_by_id != user_id,
+ )
+ )
+ return items
diff --git a/products/signals/backend/activity_summary/logic.py b/products/signals/backend/activity_summary/logic.py
index 3e011fe3a75c..783e9a78842f 100644
--- a/products/signals/backend/activity_summary/logic.py
+++ b/products/signals/backend/activity_summary/logic.py
@@ -12,7 +12,7 @@ from django.utils import timezone
from posthog.dataclasses import frozen
from posthog.models import Team
-from products.signals.backend.activity_summary.inputs import activity_parents, user_activity, user_tasks
+from products.signals.backend.activity_summary.inputs import activity_parents, user_activity, user_tasks, user_views
from products.signals.backend.activity_summary.prompt import PROMPT_VERSION, summary_text
from products.signals.backend.activity_summary.render import (
DEFAULT_LIMITS,
@@ -170,11 +170,13 @@ def update_activity_summary(
start = _input_start(stored.input_watermark if stored else None, now, limits.window_days)
tasks = user_tasks(team_id, user_id, start, now)
activity = user_activity(team_id, user_id, start, now)
+ views = user_views(team_id, user_id, start, now)
rendered = build_input(
tasks,
activity,
as_of=now,
seed=sampling_seed(now.date().isoformat(), team_id, user_id),
+ views=views,
limits=limits,
parents=activity_parents(team_id, activity),
)
@@ -190,11 +192,12 @@ def update_activity_summary(
inputs_used: dict[str, Any] = {
"tasks": rendered.n_tasks,
"activity_lines": rendered.n_activity_lines,
+ "view_lines": rendered.n_view_lines,
"input_chars": rendered.input_chars,
"drops": rendered.drops,
"limits": dataclasses.asdict(limits),
}
- watermark = max([task.at for task in tasks] + [item.at for item in activity])
+ watermark = max([task.at for task in tasks] + [item.at for item in activity] + [view.at for view in views])
previous = stored.summary if stored is not None else None
model = DEFAULT_MODEL
outcome = summarize(
diff --git a/products/signals/backend/activity_summary/prompt.py b/products/signals/backend/activity_summary/prompt.py
index 3e1e7447176e..e3e2324cc93f 100644
--- a/products/signals/backend/activity_summary/prompt.py
+++ b/products/signals/backend/activity_summary/prompt.py
@@ -11,7 +11,7 @@ from typing import Any
from products.signals.backend.activity_summary.render import SUMMARY_MAX_WORDS, cap_line
-PROMPT_VERSION = 3
+PROMPT_VERSION = 4
MAX_FOCUS_AREAS = 6
MAX_PRODUCTS = 10
@@ -25,8 +25,8 @@ DEFAULT_STRENGTH = "low"
_NULL_STRINGS = frozenset({"", "none", "null", "n/a", "na", "nil"})
_SYSTEM_PROMPT = """You maintain a short summary of what one person has been working on in one PostHog project.
-You get their previous summary, if any, and a sample of their recent activity in up to two sections: tasks they gave to PostHog AI or the Slack agent, and things they created or changed in PostHog, with the reason their coding agent gave when an agent made the change.
-Update the summary to reflect what they are focused on now. Keep what is still true, drop what has gone quiet, and add what is new. Weigh themes that repeat across sections above one-off items. Treat bulk changes of the same kind as one theme, not a list.
+You get their previous summary, if any, and a sample of their recent activity in up to three sections: tasks they gave to PostHog AI or the Slack agent, things they created or changed in PostHog, with the reason their coding agent gave when an agent made the change, and things they opened in PostHog.
+Update the summary to reflect what they are focused on now. Keep what is still true, drop what has gone quiet, and add what is new. Weigh themes that repeat across sections above one-off items. Treat what they open on many days as part of their work, even when they changed nothing. Treat bulk changes of the same kind as one theme, not a list.
Name concrete products, features, metrics, pipelines and workflows. Never write generic phrases like "data analysis".
Write about the work, not the person: no names, emails, IDs, secrets, or quotes from the input. Open with the work itself.
Return JSON: `summary` (at most {max_words} words), `focus_areas` (up to 6, each with `topic`, `strength` high, medium or low, and `last_seen` as YYYY-MM-DD), `products`, and `recent_shift` (one sentence, or null).
diff --git a/products/signals/backend/activity_summary/render.py b/products/signals/backend/activity_summary/render.py
index 3c12c100f4b7..324eef2c99bb 100644
--- a/products/signals/backend/activity_summary/render.py
+++ b/products/signals/backend/activity_summary/render.py
@@ -27,7 +27,7 @@ SUMMARY_MAX_WORDS = 60
# Bump on any code change to the filters, the default caps, the sampling or the rendered layout, so summaries
# stay comparable. Limits from the flag payload go into `inputs_used` instead.
-RENDER_VERSION = 5
+RENDER_VERSION = 6
WINDOW_DAYS = 28
RECENCY_HALF_LIFE_DAYS = 7
@@ -37,6 +37,7 @@ CHARS_PER_TOKEN = 4
# query applies the noise filters before this limit, so bulk agent writes cannot fill it.
MAX_TASKS_PER_PERSON = 200
MAX_ACTIVITY_ROWS_PER_PERSON = 1000
+MAX_VIEW_ROWS_PER_PERSON = 500
# Units one source may keep from a single UTC day, newest first, so one busy afternoon cannot fill a section.
MAX_UNITS_PER_DAY = 3
@@ -45,6 +46,7 @@ ACTIVITY_LINES = 15
# Activity lines one UTC day may keep while other days have lines to show. A third of the section
# leaves a busy day several lines and the rest of the window most of the slots.
MAX_ACTIVITY_LINES_PER_DAY = 5
+VIEW_LINES = 15
# Per-line caps, so one runaway title or intent cannot take the budget. With the default caps a full
# prompt section stays under SECTIONS_MAX_CHARS; the hard stop is the backstop when the caps change.
TASK_LINE_CHARS = 260
@@ -55,6 +57,7 @@ MAX_TAG_CHARS = 30
ACTIVITY_LINE_CHARS = 220
ACTIVITY_NAME_CHARS = 70
ACTIVITY_INTENT_CHARS = 100
+VIEW_LINE_CHARS = 160
SECTIONS_MAX_CHARS = 8000
# Hidden reasoning tokens count against the cap too, so a cap near the answer size truncates answers.
MAX_COMPLETION_TOKENS = 4000
@@ -68,6 +71,7 @@ MIN_BARE_TITLE_WORDS = 8
TASKS_HEADER = "Tasks the person gave to PostHog AI or the Slack agent ([tags] goal):"
ACTIVITY_HEADER = "Things the person created or changed in PostHog (agent: why their coding agent did it):"
+VIEWS_HEADER = "Things the person opened in PostHog, by type (days: distinct days in the window; not theirs: someone else made it):"
# Helper tasks that a task spawns for itself, such as repository selection, carry the parent's origin.
SANDBOX_PROMPT_TITLE_PREFIX = "[sandbox_prompt:"
@@ -94,6 +98,44 @@ _DIGIT = re.compile(r"\d")
_LETTER = re.compile(r"[A-Za-z]")
_WHITESPACE = re.compile(r"\s+")
+# A view log row of this type records a page, and its ref is the frontend scene id.
+SCENE_VIEW_TYPE = "scene"
+# The product of each scene id prefix. A prefix matches its plural and any longer scene id of the
+# same product, such as "ErrorTrackingIssue". Other scenes, such as settings, the home page or a new
+# tab, say nothing about the work.
+_SCENE_PRODUCTS: tuple[tuple[str, str], ...] = (
+ ("Insight|SavedInsight|ProductAnalytics", "Product analytics"),
+ ("Dashboard", "Dashboards"),
+ ("WebAnalytics", "Web analytics"),
+ ("Replay|SessionRecording|SessionSummaries", "Session replay"),
+ ("Heatmap", "Heatmaps"),
+ ("ErrorTracking", "Error tracking"),
+ ("Experiment", "Experiments"),
+ ("FeatureFlag", "Feature flags"),
+ ("EarlyAccessFeature", "Early access features"),
+ ("Survey", "Surveys"),
+ ("ProductTour", "Product tours"),
+ ("Notebook", "Notebooks"),
+ ("Cohort", "Cohorts"),
+ ("Person|Group", "Persons and groups"),
+ ("Action|EventDefinition|PropertyDefinition|DataManagement", "Data management"),
+ ("SQLEditor|DataWarehouse|Sources|Models", "Data warehouse"),
+ ("Pipeline|Destination|Transformation|HogFunction|BatchExport", "Data pipelines"),
+ ("Workflow|Broadcast", "Workflows"),
+ ("AIObservability", "AI observability"),
+ ("MCPAnalytics", "MCP analytics"),
+ ("Logs", "Logs"),
+ ("Tracing", "Tracing"),
+ ("Endpoint", "Endpoints"),
+ ("RevenueAnalytics", "Revenue analytics"),
+ ("CustomerAnalytics", "Customer analytics"),
+ ("Inbox", "Inbox"),
+ ("Canvas", "Canvases"),
+)
+_SCENE_PATTERNS: tuple[tuple[re.Pattern[str], str], ...] = tuple(
+ (re.compile(rf"^(?:{prefixes})s?(?:[A-Z]|$)"), product) for prefixes, product in _SCENE_PRODUCTS
+)
+
def _limit(default: int, *, max_value: int) -> Any:
return dataclasses.field(default=default, metadata={"max_value": max_value})
@@ -109,6 +151,8 @@ class RenderLimits:
task_lines: int = _limit(TASK_LINES, max_value=50)
activity_lines: int = _limit(ACTIVITY_LINES, max_value=50)
max_activity_lines_per_day: int = _limit(MAX_ACTIVITY_LINES_PER_DAY, max_value=50)
+ view_lines: int = _limit(VIEW_LINES, max_value=50)
+ view_line_chars: int = _limit(VIEW_LINE_CHARS, max_value=1000)
max_units_per_day: int = _limit(MAX_UNITS_PER_DAY, max_value=20)
sections_max_chars: int = _limit(SECTIONS_MAX_CHARS, max_value=32000)
task_line_chars: int = _limit(TASK_LINE_CHARS, max_value=1000)
@@ -132,6 +176,7 @@ class Drop(StrEnum):
SCOUT_CLIENT = "scout_client"
AUTO_NAMED_OBJECT = "auto_named_object"
UNNAMED_OBJECT = "unnamed_object"
+ GENERIC_SCENE = "generic_scene"
DUPLICATE = "duplicate"
GROUPED_INTO_PARENT = "grouped_into_parent"
BURST_CAP = "burst_cap"
@@ -175,6 +220,20 @@ class Parent:
ParentLookup = Mapping[tuple[str, str], Sequence[Parent]]
+@frozen
+class ViewItem:
+ """One object or scene the person opened, with the days they opened it.
+
+ `name` is None for a scene, and for an object that has no file system entry."""
+
+ at: datetime.datetime
+ type: str
+ ref: str
+ name: str | None
+ days: tuple[datetime.date, ...]
+ not_theirs: bool = False
+
+
@frozen
class Unit:
"""One rendered line, dated by its latest activity."""
@@ -198,8 +257,10 @@ class RenderedInput:
text: str
n_tasks: int
n_activity_lines: int
+ n_view_lines: int
task_chars: int
activity_chars: int
+ view_chars: int
input_chars: int
input_tokens_estimate: int
drops: dict[str, int]
@@ -209,7 +270,7 @@ class RenderedInput:
@property
def units(self) -> int:
- return self.n_tasks + self.n_activity_lines
+ return self.n_tasks + self.n_activity_lines + self.n_view_lines
def _mask_token(match: re.Match[str]) -> str:
@@ -510,6 +571,72 @@ def activity_units(
return sorted((Unit(at=line.at, text=line.text) for line in kept), key=lambda unit: (unit.at, unit.text))
+def scene_product(scene_id: str) -> str | None:
+ for pattern, product in _SCENE_PATTERNS:
+ if pattern.match(scene_id):
+ return product
+ return None
+
+
+def _scope_of(view_type: str) -> str:
+ """The activity log scope of a file system type, such as "FeatureFlag" for "feature_flag"."""
+ return "".join(word.capitalize() for word in view_type.split("/")[0].split("_"))
+
+
+def _days(count: int) -> str:
+ return f"{count} day" if count == 1 else f"{count} days"
+
+
+def view_units(
+ views: Iterable[ViewItem],
+ activity: Iterable[ActivityItem],
+ drops: Counter[str],
+ limits: RenderLimits = DEFAULT_LIMITS,
+) -> list[Unit]:
+ """One line per opened object and one per product of the opened scenes, the most opened first.
+
+ An object line also counts the days the person edited it, matched to their activity rows by
+ scope and name. These lines skip the per-day burst cap."""
+ edit_days: dict[tuple[str, str], set[datetime.date]] = {}
+ for item in activity:
+ if item.name and not (item.client or "").startswith(SCOUT_CLIENT_PREFIX):
+ edit_days.setdefault((item.scope, item.name.strip()), set()).add(_day(item.at))
+ ranked: list[tuple[int, datetime.datetime, str]] = []
+ scenes: dict[str, tuple[datetime.datetime, set[datetime.date]]] = {}
+ for view in views:
+ if view.type == SCENE_VIEW_TYPE:
+ product = scene_product(view.ref)
+ if product is None:
+ drops[Drop.GENERIC_SCENE] += 1
+ continue
+ at, days = scenes.get(product, (view.at, set()))
+ scenes[product] = (max(at, view.at), days | set(view.days))
+ continue
+ name = (view.name or "").strip()
+ if not name:
+ drops[Drop.UNNAMED_OBJECT] += 1
+ continue
+ if _AUTO_NAME.search(name):
+ drops[Drop.AUTO_NAMED_OBJECT] += 1
+ continue
+ opened = len(set(view.days))
+ name_text = cap_line(clean_text(name, ACTIVITY_NAME_CHARS * 2), ACTIVITY_NAME_CHARS)
+ facts = [f"opened {_days(opened)}", f"last {_day(view.at).isoformat()}"]
+ if edited := len(edit_days.get((_scope_of(view.type), name), ())):
+ facts.append(f"edited {_days(edited)}")
+ if view.not_theirs:
+ facts.append("not theirs")
+ label = view.type.split("/")[0].replace("_", " ").capitalize()
+ ranked.append((opened, view.at, f'- {label} "{name_text}": {", ".join(facts)}'))
+ for product, (at, days) in scenes.items():
+ ranked.append((len(days), at, f"- {product} pages: opened {_days(len(days))}, last {_day(at).isoformat()}"))
+ ranked.sort(key=lambda entry: (-entry[0], -entry[1].timestamp(), entry[2]))
+ if len(ranked) > limits.view_lines:
+ drops[Drop.SAMPLE_CAP] += len(ranked) - limits.view_lines
+ units = [Unit(at=at, text=cap_line(text, limits.view_line_chars)) for _, at, text in ranked[: limits.view_lines]]
+ return sorted(units, key=lambda unit: (unit.at, unit.text))
+
+
def dedupe_latest(units: Iterable[Unit], drops: Counter[str]) -> list[Unit]:
"""One unit per distinct text, the latest one, in chronological order."""
latest: dict[str, Unit] = {}
@@ -585,6 +712,7 @@ def build_input(
*,
as_of: datetime.datetime,
seed: int,
+ views: Iterable[ViewItem] = (),
limits: RenderLimits = DEFAULT_LIMITS,
parents: ParentLookup | None = None,
) -> RenderedInput | None:
@@ -592,27 +720,33 @@ def build_input(
Order: the named filters, then the burst cap, then the recency-weighted sample, then the hard
budget, so the sample is drawn from clean units only. `parents` groups activity lines under the
- objects that hold them."""
+ objects that hold them. The views section shows its lines grouped by type after the budget,
+ because the budget drops the oldest unit of a section first."""
drops: Counter[str] = Counter()
+ activity = list(activity)
task_pool = burst_cap(dedupe_latest(task_units(tasks, drops, limits), drops), drops, limits.max_units_per_day)
capped_before = drops[Drop.SAMPLE_CAP] + drops[Drop.BURST_CAP]
activity_lines = activity_units(activity, drops, parents, limits)
# Lines that `activity_units` dropped for its line cap or its per-day cap.
activity_pool = len(activity_lines) + drops[Drop.SAMPLE_CAP] + drops[Drop.BURST_CAP] - capped_before
- if not task_pool and not activity_lines:
+ view_lines = view_units(views, activity, drops, limits)
+ if not task_pool and not activity_lines and not view_lines:
return None
chosen_tasks = sample_units(task_pool, limit=limits.task_lines, as_of=as_of, seed=seed)
drops[Drop.SAMPLE_CAP] += len(task_pool) - len(chosen_tasks)
- sections = [(TASKS_HEADER, chosen_tasks), (ACTIVITY_HEADER, activity_lines)]
+ sections = [(TASKS_HEADER, chosen_tasks), (ACTIVITY_HEADER, activity_lines), (VIEWS_HEADER, view_lines)]
enforce_budget(sections, drops, limits.sections_max_chars)
+ sections[2] = (VIEWS_HEADER, sorted(sections[2][1], key=lambda unit: unit.text))
rendered = [_section(header, units) for header, units in sections]
text = "\n\n".join(part for part in rendered if part)
return RenderedInput(
text=text,
n_tasks=len(sections[0][1]),
n_activity_lines=len(sections[1][1]),
+ n_view_lines=len(sections[2][1]),
task_chars=len(rendered[0]),
activity_chars=len(rendered[1]),
+ view_chars=len(rendered[2]),
input_chars=len(text),
input_tokens_estimate=estimate_tokens(len(text)),
drops={str(reason): count for reason, count in sorted(drops.items()) if count},
diff --git a/products/signals/backend/test/test_activity_summary_render.py b/products/signals/backend/test/test_activity_summary_render.py
index 2ef7afa7d3a3..0f7db9c48bd4 100644
--- a/products/signals/backend/test/test_activity_summary_render.py
+++ b/products/signals/backend/test/test_activity_summary_render.py
@@ -28,12 +28,14 @@ from products.signals.backend.activity_summary.render import (
MAX_UNITS_PER_DAY,
TASK_LINES,
TASKS_HEADER,
+ VIEWS_HEADER,
ActivityItem,
Drop,
Parent,
RenderLimits,
TaskItem,
Unit,
+ ViewItem,
activity_units,
build_input,
burst_cap,
@@ -41,6 +43,7 @@ from products.signals.backend.activity_summary.render import (
sample_units,
sampling_seed,
task_units,
+ view_units,
)
from products.signals.backend.activity_summary.summaries import PIPELINE_DISTINCT_ID, SummaryPrices, cost_usd, summarize
@@ -74,6 +77,13 @@ QUALITY = Parent(scope="Dashboard", item_id="10", name="Quality review")
GROWTH = Parent(scope="Dashboard", item_id="11", name="Growth overview")
+def _view(
+ view_type: str, ref: str, name: str | None = None, days: int = 1, days_ago: float = 1, not_theirs: bool = False
+) -> ViewItem:
+ opened = tuple(sorted(_at(days_ago + n).date() for n in range(days)))
+ return ViewItem(at=_at(days_ago), type=view_type, ref=ref, name=name, days=opened, not_theirs=not_theirs)
+
+
@parameterized.expand(
[
(
@@ -334,12 +344,16 @@ def test_sampling_is_deterministic_and_favors_recent_units() -> None:
assert sum(1 for age in picked_ages if age < 7) > sum(1 for age in picked_ages if age >= 21)
-def test_build_input_renders_the_two_sections_in_order() -> None:
+def test_build_input_renders_the_three_sections_in_order() -> None:
rendered = build_input(
[_task("why", summary="Asked: why did signups drop?", tags=("growth",), days_ago=3)],
[_change("Dashboard", "created", "Growth overview", days_ago=1)],
as_of=AS_OF,
seed=1,
+ views=[
+ _view("insight", "abc", "Weekly signups", days_ago=1),
+ _view("dashboard", "9", "Growth overview", days=3, days_ago=2),
+ ],
)
assert rendered is not None
@@ -350,11 +364,44 @@ def test_build_input_renders_the_two_sections_in_order() -> None:
"",
ACTIVITY_HEADER,
'- 2026-10-18 created Dashboard "Growth overview"',
+ "",
+ VIEWS_HEADER,
+ '- Dashboard "Growth overview": opened 3 days, last 2026-10-17, edited 1 day',
+ '- Insight "Weekly signups": opened 1 day, last 2026-10-18',
]
)
- assert (rendered.n_tasks, rendered.n_activity_lines, rendered.units) == (1, 1, 2)
+ assert (rendered.n_tasks, rendered.n_activity_lines, rendered.n_view_lines, rendered.units) == (1, 1, 2, 4)
assert rendered.input_chars == len(rendered.text)
assert build_input([_task("root cause")], [], as_of=AS_OF, seed=1) is None
+ assert build_input([], [], as_of=AS_OF, seed=1, views=[_view("scene", "Settings")]) is None
+
+
+def test_view_units_name_products_count_edits_and_drop_what_says_nothing() -> None:
+ drops: Counter[str] = Counter()
+ views = [
+ _view("scene", "ErrorTrackingIssue", days=2),
+ _view("scene", "ErrorTracking", days=3, days_ago=2),
+ _view("scene", "Settings"),
+ _view("scene", "ProjectHomepage"),
+ _view("insight", "abc", "Weekly signups", days=5, not_theirs=True),
+ _view("feature_flag", "7", "new-checkout", days=2),
+ _view("notebook", "n1", "Daily report 2026-10-18"),
+ _view("dashboard", "9", None),
+ ]
+ activity = [
+ _change("FeatureFlag", "updated", "new-checkout", days_ago=1),
+ _change("FeatureFlag", "updated", "new-checkout", days_ago=1.5),
+ _change("FeatureFlag", "updated", "new-checkout", days_ago=3, client="scout:feature-flags"),
+ ]
+
+ units = view_units(views, activity, drops)
+
+ assert sorted(unit.text for unit in units) == [
+ "- Error tracking pages: opened 4 days, last 2026-10-18",
+ '- Feature flag "new-checkout": opened 2 days, last 2026-10-18, edited 2 days',
+ '- Insight "Weekly signups": opened 5 days, last 2026-10-18, not theirs',
+ ]
+ assert dict(drops) == {Drop.GENERIC_SCENE: 2, Drop.AUTO_NAMED_OBJECT: 1, Drop.UNNAMED_OBJECT: 1}
@parameterized.expand(
diff --git a/products/signals/backend/test/test_activity_summary_update.py b/products/signals/backend/test/test_activity_summary_update.py
index f88ecb4a22dc..217bf84155c4 100644
--- a/products/signals/backend/test/test_activity_summary_update.py
+++ b/products/signals/backend/test/test_activity_summary_update.py
@@ -8,7 +8,7 @@ from unittest.mock import patch
from parameterized import parameterized
-from posthog.models import ActivityLog
+from posthog.models import ActivityLog, FileSystem, FileSystemViewLog, User
from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
@@ -88,6 +88,43 @@ class TestUpdateActivitySummary(BaseTest):
assert "Signup funnel" not in next_sent.split("Recent activity")[1]
assert "Builds the signup funnel." in next_sent
+ def test_a_person_who_only_reads_gets_a_summary_from_what_they_opened(self) -> None:
+ other = User.objects.create_and_join(self.organization, "[email protected]", None)
+ for ref, name, creator in [("abc", "Weekly signups", other), ("def", "Churn by plan", self.user)]:
+ FileSystem.objects.create(
+ team=self.team, type="insight", ref=ref, path=f"Unfiled/{name}", created_by=creator
+ )
+ views = [
+ ("insight", "abc", 2),
+ ("insight", "def", 1.5),
+ ("scene", "Experiments", 1),
+ ("scene", "Settings", 0.5),
+ ]
+ for view_type, ref, days_ago in views:
+ viewed_at = NOW - datetime.timedelta(days=days_ago)
+ FileSystemViewLog.objects.create(
+ team=self.team,
+ user=self.user,
+ type=view_type,
+ ref=ref,
+ viewed_at=viewed_at,
+ view_days=[viewed_at.date()],
+ )
+ llm = FakeLLM([ANSWER])
+
+ result = self._update(llm)
+
+ assert result.status == UpdateStatus.OK
+ assert result.rendered_input is not None
+ assert '- Insight "Weekly signups": opened 1 day, last 2026-10-17, not theirs' in result.rendered_input
+ assert '- Insight "Churn by plan": opened 1 day, last 2026-10-18\n' in result.rendered_input
+ assert "- Experiments pages: opened 1 day, last 2026-10-18" in result.rendered_input
+ stored = self._stored()
+ assert stored is not None
+ assert stored.inputs_used["view_lines"] == 3
+ assert stored.inputs_used["drops"] == {"generic_scene": 1}
+ assert stored.input_watermark == NOW - datetime.timedelta(days=0.5)
+
def test_limits_reach_the_model_call_and_the_stored_inputs(self) -> None:
self._changes(3, days_ago=2)
self._change("Old funnel", days_ago=10)