: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): stop marking stack layer reports as promoted (#108241)
posthog[bot]c90de8835b7c
diff --git a/products/signals/ARCHITECTURE.md b/products/signals/ARCHITECTURE.mdindex c65d318e614d..8c0fa78280ee 100644--- a/products/signals/ARCHITECTURE.md+++ b/products/signals/ARCHITECTURE.md@@ -1152,7 +1152,7 @@ All events use `distinct_id = team.uuid` and `groups(organization, team)`. Per-s- `signal_report_quota_paused` — a quota gate observed the team's org over its self-driving credits limit (+ `stage`: `promotion` | `summary_entry` | `pre_repo_selection` | `pre_research` | `autostart` | `manual_create` | `task_create` | `implementation_run`, `enforced`, `report_id`). See Billing limit enforcement- `signal_report_daily_limit_paused` — a gate paused work because the team hit its `max_reports_per_day` (+ `stage`: `ingestion` | `scout_run` | `promotion` | `summary_entry` | `pre_repo_selection` | `pre_research`, `limit`, `reports_today`, `report_id` nullable). See Per-team daily report limit- `signal_report_free_trial_paused` — a gate held back a pull request because the team's org is on a Self-driving free trial (+ `stage`: `autostart` | `manual_create` | `task_create` | `task_run`, `report_id` nullable). See Self-driving free trial-- `signal_report_started` — report run began (+ `report_id`, `signal_count`, `run_count`, `source_products`)+- `signal_report_started` — report run began (+ `report_id`, `signal_count`, `run_count`, `source_products`). `mark_report_in_progress_activity` fires it when a summary run moves the report from `candidate` to `in_progress`. A promoted report (`promoted_at` set) does not always get it: the `summary_entry` quota and daily-limit gate, or a deferred empty signal fetch, returns before that step and leaves the report `candidate`. A born-visible report does not fire it at creation. A scout report can fire it later, when grouping matches a new signal to the report through its backing signals and starts re-research. Custom-agent and stack-layer reports have no backing signals, so they never fire it- `signals_repo_research_started` / `signals_repo_research_completed` — repo selection stage (+ `report_id`, `result`: `reused` | `selected` | `no_repo` | `failed`, optional `failure_reason`: `no_github_integration` | `agentic_activity_error`)- `signal_report_completed` — terminal per run (+ `result`: `ready` | `failed` | `pending_input` | `not_actionable`, optional `failure_reason`)- `signals_autostart_steering_attached` — an implementation task was created (+ `report_id`, `task_id`, `notes_attached`, `scratchpad_available`, `memory_protocol`, `nudge_rendered`). Fires on every auto-start, so the share carrying fleet steering is readable. See Auto-Start Flow@@ -1486,7 +1486,7 @@ The implementation path checks these gates again under the report lock before ta**Plan roll-up** (`backend/plan_rollup.py`). A `part_of` child carries the work and closes on its own pull request; the plan usually carries nothing of its own, so without the roll-up it sits in the inbox forever after the last step lands. When every live step of a plan is closed, the plan takes their verdict: resolved when at least one resolved, suppressed when they all were, untouched while any step is open. A deleted step is not a verdict and is dropped. Deleting a step also triggers the check. A plan that becomes ready checks its own steps, so completion can follow a failed attempt during research. Each plan is locked before the check reads and updates its state. The walk continues through plans that are already closed. Archiving a resolved plan is refused, for the same reason `_apply_pr_report_state` refuses it. The walk continues up a plan of plans, bounded by `MAX_PLAN_ROLLUP_LEVELS`, which tracks the `MAX_REPORT_LINK_GRAPH_LEVELS` depth `validated_report_link_write` accepts: a hierarchy the write path allows but the walk stops short of would leave its top plan open, with every step that could retrigger the walk already closed. A plan with a pending replacement is skipped like any other report, and that read, like the pull request read beside it, is pinned to the writer because a replacement written moments earlier must not read as absent. A plan a person pressed Implement on does carry its own pull request, and while that pull request is open, draft, or unknown the steps decide nothing: resolving on their verdict would hide a plan whose own work is still in flight, and archiving on it would send the dismissal receiver to close that pull request. It is hooked on `SignalReport`'s status change (`receivers.roll_up_plan_parents_when_report_closes`) rather than on the pull request webhook, so a merged pull request, a manual resolve, a bulk state change and an MCP state write all reach it. Plenty of steps close with no pull request at all. A `part_of` row written on a step that already closed runs the check too, from the link write path, because that write announces no status change of its own.-**Stacked plans** (`backend/stack_plan.py`). Research can return an optional `layers` plan on `ReportPresentationOutput`: two to six layers, each with a title, a scope, and the index of an earlier layer it depends on. A forward reference falls back to the previous layer, so the order is always acyclic. When the pass settles ready, `mark_report_ready_activity` creates one ready child report per layer in the same transaction. Each child gets the scope as its summary, the plan's latest safety, actionability, priority, repository and reviewer judgments, a `part_of` link to the plan, and a `depends_on` link to its dependency. A plan that already has children keeps them on a re-research. The plan itself is held by the `plan_parent` gate, and its settle-point auto-start then starts the layers whose dependencies already have a pull request. After that, each pull request sync on a report queues `start_dependent_stack_layers`, which starts the waiting layers. A layer whose dependency has an open or draft pull request starts on that dependency's automation branch, and the run state carries `stack_base_branch`, so the task launch protects that branch as the PR base instead of the base of the dependency's PR. A merged dependency leaves the layer on the default base. Replacing a whole stack after a lower layer is superseded, a server-side GitHub stack link, and a collapsed inbox list are not built yet.+**Stacked plans** (`backend/stack_plan.py`). Research can return an optional `layers` plan on `ReportPresentationOutput`: two to six layers, each with a title, a scope, and the index of an earlier layer it depends on. A forward reference falls back to the previous layer, so the order is always acyclic. When the pass settles ready, `mark_report_ready_activity` creates one ready child report per layer in the same transaction. Each child gets the scope as its summary, the plan's latest safety, actionability, priority, repository and reviewer judgments, a `part_of` link to the plan, and a `depends_on` link to its dependency. A layer is born ready without `promoted_at`, like a scout report: it runs no research, so it fires no `signal_report_started`, and the inbox ranking spine takes it in through its born-visible branch. A plan that already has children keeps them on a re-research. The plan itself is held by the `plan_parent` gate, and its settle-point auto-start then starts the layers whose dependencies already have a pull request. After that, each pull request sync on a report queues `start_dependent_stack_layers`, which starts the waiting layers. A layer whose dependency has an open or draft pull request starts on that dependency's automation branch, and the run state carries `stack_base_branch`, so the task launch protects that branch as the PR base instead of the base of the dependency's PR. A merged dependency leaves the layer on the default base. Replacing a whole stack after a lower layer is superseded, a server-side GitHub stack link, and a collapsed inbox list are not built yet.**The recurrence chain** (`backend/recurrence.py`) reads incoming `recurrence_of` edges to follow a forked report to its current live successor.diff --git a/products/signals/backend/ranking/inventory.py b/products/signals/backend/ranking/inventory.pyindex 8d59a1a3d20d..c7f89a4774fe 100644--- a/products/signals/backend/ranking/inventory.py+++ b/products/signals/backend/ranking/inventory.py@@ -10,8 +10,8 @@ from django.db.models import Qfrom products.signals.backend.models import SignalReport-# Statuses a report can be authored straight into and still be in the inbox (`create_scout_report`-# and `create_custom_agent_ready_report`), which is how a report reaches the spine without a+# Statuses a report can be authored straight into and still be in the inbox (`create_scout_report`,+# `create_custom_agent_ready_report` and `create_layer_reports`), which is how a report reaches the spine without a# promotion. Suppressed and deleted are absent on purpose: authored-then-hidden is not inventory.BORN_VISIBLE_STATUSES = (SignalReport.Status.READY,@@ -33,7 +33,7 @@ def spine_report_filter(snapshot_end: datetime.datetime) -> Q:"""Reports that were in the inbox before the cutoff.Two ways in, because not every visible report was promoted: the pipeline promotes a `potential`- report and stamps promoted_at, but the scout and custom-agent authoring paths create a report+ report and stamps promoted_at, but the scout, custom-agent and stack-layer paths create a reportalready in a visible status and never stamp it. Keying only on promotion dropped everydirectly-authored report until a user happened to interact with it, biasing the inventory towardreports that already had engagement — the wrong bias for a ranking model. A never-promoted reportdiff --git a/products/signals/backend/stack_plan.py b/products/signals/backend/stack_plan.pyindex 7f12afaca6de..17ee53b72b9a 100644--- a/products/signals/backend/stack_plan.py+++ b/products/signals/backend/stack_plan.py@@ -117,9 +117,10 @@ def create_layer_reports(status=SignalReport.Status.READY,title=layer.title,summary=_layer_summary(parent=parent, layer=layer, index=index, total=len(layers)),- promoted_at=now,# Born directly in a visible status without `transition_to`, which stamps this for- # pipeline reports, so the daily report limit counts the layer from creation.+ # pipeline reports, so the daily report limit counts the layer from creation. No+ # `promoted_at`: a layer runs no research, so it never fires `signal_report_started`,+ # and lifecycle monitoring expects that event from every promoted report.first_visible_at=now,billing_exempt_reason=billing_exempt_reason,)diff --git a/products/signals/backend/test/test_stack_plan.py b/products/signals/backend/test/test_stack_plan.pyindex d4e6d7020b90..3f87f4db2afb 100644--- a/products/signals/backend/test/test_stack_plan.py+++ b/products/signals/backend/test/test_stack_plan.py@@ -159,6 +159,8 @@ class TestStackPlan(BaseTest):"feat(x): ui",]assert all(child.status == SignalReport.Status.READY for child in children.values())+ # A promoted report is expected to emit `signal_report_started`, and a layer never runs research.+ assert all(child.promoted_at is None for child in children.values())for index, child_id in enumerate(child_ids):links = outgoing_links(team_id=self.team.id, report_id=child_id)assert [(edge.kind, edge.target_id) for edge in links if edge.kind == ReportLinkKind.PART_OF] == [