: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(tasks): hide merged PRs from code home (#71990)
Peter Kirkham4a02f1342e1f
diff --git a/products/tasks/backend/logic/code_workstreams/grouping.py b/products/tasks/backend/logic/code_workstreams/grouping.pyindex 56f0f26f4560..cec5a34a0e68 100644--- a/products/tasks/backend/logic/code_workstreams/grouping.py+++ b/products/tasks/backend/logic/code_workstreams/grouping.py@@ -27,6 +27,7 @@ class TaskInput:branch: Optional[str] = Nonebase_branch: Optional[str] = Nonecloud_pr_url: Optional[str] = None+ cloud_pr_merged: bool = Falsefolder_path: Optional[str] = Nonequick_action: Optional[str] = None@@ -177,6 +178,9 @@ def build_workstreams(pr_url = urlbreak+ if any(t.cloud_pr_merged and t.cloud_pr_url == pr_url for t in group_tasks):+ continue+branch = _feature_branch(head)last_activity_at = head.last_activity_at@@ -192,6 +196,9 @@ def build_workstreams())+ if "done" in situations:+ continue+workstream = Workstream(id=key,repo_name=head.repo_name,diff --git a/products/tasks/backend/logic/code_workstreams/test_grouping.py b/products/tasks/backend/logic/code_workstreams/test_grouping.pyindex 8515323d9480..d5af79a8d384 100644--- a/products/tasks/backend/logic/code_workstreams/test_grouping.py+++ b/products/tasks/backend/logic/code_workstreams/test_grouping.py@@ -244,3 +244,20 @@ def test_quick_action_is_carried_onto_workstream_task():result = build_workstreams([task], {task.id: _pr(ci_status="failing")}, NOW)ws = result.needs_attention[0]assert ws.tasks[0].quick_action == "Fix CI"+++ "task,pr_by_task",+ [+ (_task(), {"t1": _pr(state="merged")}),+ (+ _task(cloud_pr_url="https://github.com/posthog/posthog/pull/1", cloud_pr_merged=True),+ {},+ ),+ ],+)+def test_merged_pr_is_omitted_from_active_workstreams(task, pr_by_task):+ result = build_workstreams([task], pr_by_task, NOW)++ assert not result.needs_attention+ assert not result.in_progressdiff --git a/products/tasks/backend/temporal/code_workstreams/activities/rebuild_workstreams.py b/products/tasks/backend/temporal/code_workstreams/activities/rebuild_workstreams.pyindex ec7f84e17703..f05ece255fec 100644--- a/products/tasks/backend/temporal/code_workstreams/activities/rebuild_workstreams.py+++ b/products/tasks/backend/temporal/code_workstreams/activities/rebuild_workstreams.py@@ -62,6 +62,21 @@ def _pr_url_from_run(run: Optional[TaskRun]) -> Optional[str]:return (run.output or {}).get("pr_url") if run and run.output else None+def _task_pr_is_merged(task: Task, pr_url: Optional[str]) -> bool:+ if not pr_url:+ return False+ for run in task.runs.all():+ output = run.output+ if (+ run.team_id == task.team_id+ and isinstance(output, dict)+ and output.get("pr_url") == pr_url+ and output.get("pr_merged") is True+ ):+ return True+ return False++def _task_to_input(task: Task) -> tuple[TaskInput, Optional[str]]:run: Optional[TaskRun] = task.latest_runlast_activity = run.updated_at if run else task.updated_at@@ -78,6 +93,7 @@ def _task_to_input(task: Task) -> tuple[TaskInput, Optional[str]]:branch=run.branch if run else None,base_branch=state.pr_base_branch,cloud_pr_url=cloud_pr_url,+ cloud_pr_merged=_task_pr_is_merged(task, cloud_pr_url),folder_path=None,quick_action=state.home_quick_action,),diff --git a/products/tasks/backend/temporal/code_workstreams/test_rebuild_workstreams.py b/products/tasks/backend/temporal/code_workstreams/test_rebuild_workstreams.pyindex 067763f63e05..878b6b5357df 100644--- a/products/tasks/backend/temporal/code_workstreams/test_rebuild_workstreams.py+++ b/products/tasks/backend/temporal/code_workstreams/test_rebuild_workstreams.py@@ -1,6 +1,8 @@import randomfrom collections import Counterfrom datetime import UTC, datetime, timedelta+from types import SimpleNamespace+from typing import castimport pytestfrom freezegun import freeze_time@@ -10,13 +12,16 @@ from django.utils import timezonefrom posthog.models import Organization, Team, User-from products.tasks.backend.models import CodePrSnapshot, Task, TaskRun+from products.tasks.backend.models import CodePrSnapshot, CodeWorkstream, Task, TaskRunfrom products.tasks.backend.temporal.code_workstreams.activities import rebuild_workstreamsfrom products.tasks.backend.temporal.code_workstreams.activities.rebuild_workstreams import (+ RebuildTeamWorkstreamsInput,_branch_resolution_pref,_build_pr_input,_repo_from_pr_url,_select_recent_task_ids,+ _task_to_input,+ rebuild_team_workstreams,)from products.tasks.backend.temporal.code_workstreams.constants import ACTIVITY_WINDOWfrom products.tasks.backend.temporal.process_task.utils import parse_run_state@@ -68,6 +73,46 @@ def test_repo_from_pr_url(pr_url, expected):assert _repo_from_pr_url(pr_url) == expected+def test_task_to_input_preserves_merge_signal_from_older_run():+ pr_url = "https://github.com/org/repo/pull/1"+ merged_run = SimpleNamespace(+ id="merged-run",+ team_id=1,+ created_at=datetime(2026, 5, 30, tzinfo=UTC),+ updated_at=datetime(2026, 5, 30, tzinfo=UTC),+ status=TaskRun.Status.COMPLETED,+ branch=None,+ state={},+ output={"pr_url": pr_url, "pr_merged": True},+ )+ latest_run = SimpleNamespace(+ id="latest-run",+ team_id=1,+ created_at=datetime(2026, 5, 31, tzinfo=UTC),+ updated_at=datetime(2026, 5, 31, tzinfo=UTC),+ status=TaskRun.Status.COMPLETED,+ branch=None,+ state={},+ output={"pr_url": pr_url},+ )+ task = cast(+ Task,+ SimpleNamespace(+ id="task-id",+ team_id=1,+ title="Task",+ updated_at=datetime(2026, 5, 31, tzinfo=UTC),+ repository=None,+ latest_run=latest_run,+ runs=SimpleNamespace(all=lambda: [merged_run, latest_run]),+ ),+ )++ task_input, _ = _task_to_input(task)++ assert task_input.cloud_pr_merged is True++def test_build_pr_input_carries_head_branch():pr = _build_pr_input(_snapshot(head_branch="feat/x"), set())assert pr.head_branch == "feat/x"@@ -243,3 +288,23 @@ def test_select_recent_task_ids_ignores_tasks_that_cannot_form_workstreams():assert branch_task.id in selectedassert pr_task.id in selectedassert selected.isdisjoint({t.id for t in junk})+++@freeze_time("2026-06-01")+def test_rebuild_omits_run_with_merged_pr_without_snapshot():+ org = _org()+ team = _team(org)+ user = _user(org)+ _task_with_run_at(+ team,+ user,+ timezone.now() - timedelta(days=10),+ branch=None,+ output={"pr_url": "https://github.com/org/repo/pull/1", "pr_merged": True},+ )++ result = rebuild_team_workstreams(RebuildTeamWorkstreamsInput(team_id=team.id))++ assert result.workstreams == 0+ assert not CodeWorkstream.objects.for_team(team.id).filter(user=user).exists()