: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): only fire PR babysitting follow-up when the PR is actionable (#71859)
Vojta Bartoš4b236b3a392e
diff --git a/posthog/models/github_integration_base.py b/posthog/models/github_integration_base.pyindex 8b0b8791b3b9..f2aeddfeb125 100644--- a/posthog/models/github_integration_base.py+++ b/posthog/models/github_integration_base.py@@ -827,7 +827,7 @@ class GitHubIntegrationBase:query($owner: String!, $repo: String!, $number: Int!) {repository(owner: $owner, name: $repo) {pullRequest(number: $number) {- number title url state isDraft mergeable updatedAt headRefName+ number title url state isDraft mergeable updatedAt headRefName headRefOidauthor { login }reviewDecisionreviewRequests(first: 50) {@@ -996,6 +996,7 @@ class GitHubIntegrationBase:"mergeable": self._map_mergeable(pr.get("mergeable")),"author_login": author,"head_branch": pr.get("headRefName"),+ "head_sha": pr.get("headRefOid"),"requested_reviewer_logins": reviewer_logins,"updated_at": pr.get("updatedAt"),}diff --git a/products/tasks/backend/temporal/patches.py b/products/tasks/backend/temporal/patches.pynew file mode 100644index 000000000000..fe77260fdfe0--- /dev/null+++ b/products/tasks/backend/temporal/patches.py@@ -0,0 +1,22 @@+"""Temporal patch gates shared by the task-run workflow stacks.++Patch IDs are scoped to a single workflow execution's history, so the legacy+``process-task`` workflow and the ``task-management`` orchestrator can share+one gate without colliding.+"""++from temporalio import workflow++# Gates the actionable-state check in the CI follow-up decision: a fingerprint+# change alone no longer wakes the agent — only failing CI or a changes-requested+# review does. Pre-rollout histories dispatched a follow-up on any change, so the+# marker keeps their replays deterministic. Standard two-step Temporal patch+# lifecycle: deprecate_patch once pre-rollout histories drain, then delete.+PATCH_ID_CI_FOLLOW_UP_ACTIONABLE_GATE = "tasks-ci-follow-up-actionable-gate"+++def ci_follow_up_actionable_gate() -> bool:+ # True outside a workflow so direct-invocation unit tests exercise the new path.+ if not workflow.in_workflow():+ return True+ return workflow.patched(PATCH_ID_CI_FOLLOW_UP_ACTIONABLE_GATE)diff --git a/products/tasks/backend/temporal/process_task/activities/get_pr_context.py b/products/tasks/backend/temporal/process_task/activities/get_pr_context.pyindex 42bdad0fa89e..372eb60e8e67 100644--- a/products/tasks/backend/temporal/process_task/activities/get_pr_context.py+++ b/products/tasks/backend/temporal/process_task/activities/get_pr_context.py@@ -27,6 +27,23 @@ class GetPrContextOutput:pr_url: strpr_state: strfingerprint: str+ # Defaults keep replay of pre-rollout activity results deserializable.+ ci_status: str = "none"+ changes_requested: bool = False+ unresolved_threads: int = 0+++def is_pr_actionable(pr: GetPrContextOutput) -> bool:+ """Whether a changed PR snapshot warrants waking the agent.++ Only failing CI or a changes-requested review gives the agent real work to+ do. Waking it for a green, pending, or check-less PR produces a "nothing to+ report" turn that spams the originating Slack thread and burns one of the+ limited CI follow-up repetitions. Pending needs no special handling: the+ head SHA and CI status are both in the fingerprint, so the settled state+ (which may be failing) registers as its own change on a later tick.+ """+ return pr.changes_requested or pr.ci_status == "failing"def compute_pr_fingerprint(pr: dict[str, Any]) -> str:@@ -41,12 +58,17 @@ def compute_pr_fingerprint(pr: dict[str, Any]) -> str:For the review signal we key on the boolean ``review_decision == "changes_requested"``rather than the raw decision: ``changes_requested`` is the only value that meansthe agent has code to fix, so an ``approved`` or ``review_required`` transition no- longer re-pokes it for nothing. Net effect: the follow-up re-fires only when CI- changes or a reviewer requests changes.+ longer re-pokes it for nothing.++ The head SHA is included so that a new commit failing with the same coarse+ ``ci_status`` as its predecessor still reads as a change — without it, an+ agent push that fails again would hash identically to the previous failure+ and the follow-up would never re-fire. The fingerprint only detects change;+ whether a change is worth firing on is decided by ``is_pr_actionable``."""changes_requested = pr.get("review_decision") == "changes_requested"fingerprint_source = "|".join(- [str(pr.get(key, "")) for key in ("url", "state", "ci_status")] + [str(changes_requested)]+ [str(pr.get(key, "")) for key in ("url", "state", "ci_status", "head_sha")] + [str(changes_requested)])return hashlib.sha256(fingerprint_source.encode()).hexdigest()@@ -129,4 +151,7 @@ def get_pr_context(input: GetPrContextInput) -> GetPrContextOutput | None:pr_url=pr_url,pr_state=pull_request.get("state", "unknown"),fingerprint=fingerprint,+ ci_status=pull_request.get("ci_status", "none"),+ changes_requested=pull_request.get("review_decision") == "changes_requested",+ unresolved_threads=pull_request.get("unresolved_threads", 0),)diff --git a/products/tasks/backend/temporal/process_task/activities/tests/test_get_pr_context.py b/products/tasks/backend/temporal/process_task/activities/tests/test_get_pr_context.pyindex e7a9de2476cc..3908ea1374ce 100644--- a/products/tasks/backend/temporal/process_task/activities/tests/test_get_pr_context.py+++ b/products/tasks/backend/temporal/process_task/activities/tests/test_get_pr_context.py@@ -45,6 +45,11 @@ class TestComputePrFingerprint:("ci_status", "pending", "failing"),("review_decision", None, "changes_requested"),("state", "open", "closed"),+ # A new head commit failing with the same coarse ci_status as its+ # predecessor must still read as a change — without the SHA, an agent+ # push that fails again would hash identically to the previous failure+ # and the follow-up would never re-fire.+ ("head_sha", "aaa111", "bbb222"),])def test_changes_when_actionable_field_changes(self, field, before, after):@@ -155,7 +160,7 @@ class TestGetPrContextActivity:"url": pr_url,"state": "open","ci_status": "failing",- "review_decision": None,+ "review_decision": "changes_requested","unresolved_threads": 1,}integration = MagicMock()@@ -169,6 +174,11 @@ class TestGetPrContextActivity:assert result.pr_url == pr_urlassert result.pr_state == "open"assert result.fingerprint == compute_pr_fingerprint(snapshot)+ # The actionable signals must flow through — the CI follow-up loop keys+ # its fire/skip decision on them.+ assert result.ci_status == "failing"+ assert result.changes_requested is True+ assert result.unresolved_threads == 1integration.get_pull_request_snapshot.assert_called_once_with(pr_url)@pytest.mark.django_dbdiff --git a/products/tasks/backend/temporal/process_task/tests/test_ci_follow_up_decision.py b/products/tasks/backend/temporal/process_task/tests/test_ci_follow_up_decision.pynew file mode 100644index 000000000000..7047a5f23381--- /dev/null+++ b/products/tasks/backend/temporal/process_task/tests/test_ci_follow_up_decision.py@@ -0,0 +1,126 @@+import uuid++import pytest+from unittest.mock import Mock++from products.tasks.backend.temporal.process_task import workflow as process_task_workflow_module+from products.tasks.backend.temporal.process_task.activities.get_pr_context import GetPrContextOutput+from products.tasks.backend.temporal.process_task.activities.get_task_processing_context import TaskProcessingContext+from products.tasks.backend.temporal.process_task.workflow import CIFollowUpDecision, ProcessTaskWorkflow++pytestmark = [pytest.mark.asyncio]+++class TestShouldRunCIFollowUpDecision:+ # Direct decision tests for ProcessTaskWorkflow's copy of the CI follow-up+ # gate (task_management has its own copy with an equivalent suite). Guards+ # against re-introducing "nothing to report" wake-ups: a fingerprint change+ # must only fire when the PR state is actionable.+ @pytest.mark.parametrize(+ "ci_status,changes_requested,expected_decision,expected_fingerprint",+ [+ # Actionable changes fire.+ ("failing", False, CIFollowUpDecision.FIRE, "fp-1"),+ ("passing", True, CIFollowUpDecision.FIRE, "fp-1"),+ # Non-actionable changes persist the fingerprint but stay quiet.+ # Pending needs no deferral: the settled state hashes differently+ # (CI status and head SHA are both in the fingerprint), so it still+ # registers as a change on a later tick.+ ("passing", False, CIFollowUpDecision.SKIP, "fp-1"),+ ("none", False, CIFollowUpDecision.SKIP, "fp-1"),+ ("pending", False, CIFollowUpDecision.SKIP, "fp-1"),+ ],+ )+ async def test_fingerprint_change_fires_only_when_actionable(+ self,+ monkeypatch,+ ci_status,+ changes_requested,+ expected_decision,+ expected_fingerprint,+ ):+ wf = ProcessTaskWorkflow()+ wf._context = TaskProcessingContext(+ task_id="task-1",+ run_id="run-1",+ team_id=1,+ team_uuid=str(uuid.uuid4()),+ organization_id=str(uuid.uuid4()),+ github_integration_id=1,+ repository="org/repo",+ distinct_id="user-1",+ )+ wf._pr_fingerprint = "fp-0"+ wf._pr_progress_emitted = True++ async def fake_execute_activity(activity_fn, *args, **kwargs):+ return GetPrContextOutput(+ pr_url="https://github.com/org/repo/pull/1",+ pr_state="open",+ fingerprint="fp-1",+ ci_status=ci_status,+ changes_requested=changes_requested,+ )++ monkeypatch.setattr(process_task_workflow_module.workflow, "execute_activity", fake_execute_activity)+ monkeypatch.setattr(process_task_workflow_module.workflow, "logger", Mock())++ decision = await wf._should_run_ci_follow_up()++ assert decision is expected_decision+ assert wf._pr_fingerprint == expected_fingerprint++ @pytest.mark.parametrize(+ "prev_threads,new_threads,fingerprint,expected_decision",+ [+ # New review threads are feedback — fire even when the fingerprint+ # hasn't moved.+ (0, 2, "fp-0", CIFollowUpDecision.FIRE),+ # Resolving threads is not feedback.+ (2, 1, "fp-0", CIFollowUpDecision.SKIP),+ # A green change with a stable thread count stays quiet.+ (2, 2, "fp-1", CIFollowUpDecision.SKIP),+ # A green change accompanied by new feedback fires.+ (0, 3, "fp-1", CIFollowUpDecision.FIRE),+ ],+ )+ async def test_new_review_threads_fire_follow_up(+ self,+ monkeypatch,+ prev_threads,+ new_threads,+ fingerprint,+ expected_decision,+ ):+ wf = ProcessTaskWorkflow()+ wf._context = TaskProcessingContext(+ task_id="task-1",+ run_id="run-1",+ team_id=1,+ team_uuid=str(uuid.uuid4()),+ organization_id=str(uuid.uuid4()),+ github_integration_id=1,+ repository="org/repo",+ distinct_id="user-1",+ )+ wf._pr_fingerprint = "fp-0"+ wf._pr_unresolved_threads = prev_threads+ wf._pr_progress_emitted = True++ async def fake_execute_activity(activity_fn, *args, **kwargs):+ return GetPrContextOutput(+ pr_url="https://github.com/org/repo/pull/1",+ pr_state="open",+ fingerprint=fingerprint,+ ci_status="passing",+ unresolved_threads=new_threads,+ )++ monkeypatch.setattr(process_task_workflow_module.workflow, "execute_activity", fake_execute_activity)+ monkeypatch.setattr(process_task_workflow_module.workflow, "logger", Mock())++ decision = await wf._should_run_ci_follow_up()++ assert decision is expected_decision+ # The count must track last-seen (not max) so post-resolve feedback re-fires.+ assert wf._pr_unresolved_threads == new_threadsdiff --git a/products/tasks/backend/temporal/process_task/tests/test_followup.py b/products/tasks/backend/temporal/process_task/tests/test_followup.pyindex b45a4546e9b8..3977998a8511 100644--- a/products/tasks/backend/temporal/process_task/tests/test_followup.py+++ b/products/tasks/backend/temporal/process_task/tests/test_followup.py@@ -197,6 +197,10 @@ def _mock_send_followup_records(input: SendFollowupToSandboxInput) -> None:@activity.defn(name="get_pr_context")def _mock_get_pr_context(_input) -> GetPrContextOutput | None:+ # Defaults to failing CI: a fingerprint change alone no longer dispatches a+ # follow-up — only an actionable state (failing CI or a changes-requested+ # review) does. Overridable per test via the "ci_status" key.+ ci_status = _pr_context_overrides.get("ci_status", "failing")behavior = _pr_context_overrides.get("behavior", "changing")if behavior == "missing":_pr_context_overrides["_call_count"] = _pr_context_overrides.get("_call_count", 0) + 1@@ -206,6 +210,7 @@ def _mock_get_pr_context(_input) -> GetPrContextOutput | None:pr_url="https://github.com/org/repo/pull/1",pr_state="closed",fingerprint="closed-fp",+ ci_status=ci_status,)if behavior == "unchanged":_pr_context_overrides["_call_count"] = _pr_context_overrides.get("_call_count", 0) + 1@@ -213,6 +218,7 @@ def _mock_get_pr_context(_input) -> GetPrContextOutput | None:pr_url="https://github.com/org/repo/pull/1",pr_state="open",fingerprint="stable-fp",+ ci_status=ci_status,)if behavior == "sequence":# Returns fingerprints from a configured list, repeating the last value@@ -225,6 +231,7 @@ def _mock_get_pr_context(_input) -> GetPrContextOutput | None:pr_url="https://github.com/org/repo/pull/1",pr_state="open",fingerprint=sequence[idx],+ ci_status=ci_status,)# Default "changing": unique fingerprint per call so CI follow-up always fires_pr_context_overrides["_call_count"] = _pr_context_overrides.get("_call_count", 0) + 1@@ -232,6 +239,7 @@ def _mock_get_pr_context(_input) -> GetPrContextOutput | None:pr_url="https://github.com/org/repo/pull/1",pr_state="open",fingerprint=f"fp-{_pr_context_overrides['_call_count']}",+ ci_status=ci_status,)diff --git a/products/tasks/backend/temporal/process_task/workflow.py b/products/tasks/backend/temporal/process_task/workflow.pyindex 059292293392..4a82b6557a6f 100644--- a/products/tasks/backend/temporal/process_task/workflow.py+++ b/products/tasks/backend/temporal/process_task/workflow.py@@ -20,7 +20,12 @@ from products.tasks.backend.constants import SNAPSHOT_KIND_FILESYSTEMfrom products.tasks.backend.error_telemetry import truncate_error_messagefrom products.tasks.backend.logic.services.sandbox import is_public_sandbox_repofrom products.tasks.backend.temporal.create_snapshot.workflow import CreateSnapshotForRepositoryInput-from products.tasks.backend.temporal.process_task.activities.get_pr_context import GetPrContextInput, get_pr_context+from products.tasks.backend.temporal.patches import ci_follow_up_actionable_gate+from products.tasks.backend.temporal.process_task.activities.get_pr_context import (+ GetPrContextInput,+ get_pr_context,+ is_pr_actionable,+)from .activities.cleanup_sandbox import (CleanupSandboxInput,@@ -114,6 +119,8 @@ class ResumedSandboxState:first_user_message_received: boolis_agent_design_enabled: boollast_active_time: Optional[str] # ISO8601, or None if never active+ # Defaulted so continue_as_new payloads from pre-rollout runs deserialize.+ pr_unresolved_threads: int = 0@dataclass@@ -269,6 +276,9 @@ class ProcessTaskWorkflow(PostHogWorkflow):# exception handler onto the right card.self._current_progress_step: Optional[tuple[str, str, str]] = Noneself._pr_fingerprint: Optional[str] = None+ # Last observed unresolved review-thread count. Starting at 0 means+ # feedback posted before the first poll still reads as new.+ self._pr_unresolved_threads: int = 0# Emit the "PR opened / keeping CI green" progress once, the first time we observe a PR — the# agent opens it mid-run and then keeps it green, so without this the UI dead-ends at "Started agent".self._pr_progress_emitted: bool = False@@ -481,18 +491,19 @@ class ProcessTaskWorkflow(PostHogWorkflow):},)return CIFollowUpDecision.SKIP- if self._pr_fingerprint != pr_context.fingerprint:- workflow.logger.info(- "PR context has changed, running CI follow-up",- extra={- "run_id": self.context.run_id,- "pr_url": pr_context.pr_url,- "pr_state": pr_context.pr_state,- },- )+ fingerprint_changed = self._pr_fingerprint != pr_context.fingerprint+ if not ci_follow_up_actionable_gate():+ # Legacy replay path: any fingerprint change fires; feedback is not consulted.+ if not fingerprint_changed:+ return CIFollowUpDecision.SKIPself._pr_fingerprint = pr_context.fingerprintreturn CIFollowUpDecision.FIRE- else:+ # New unresolved review threads are feedback for the agent, and comparing+ # against the last-seen count means its own thread replies (which never+ # resolve anything) can't re-trigger it.+ new_feedback = pr_context.unresolved_threads > self._pr_unresolved_threads+ self._pr_unresolved_threads = pr_context.unresolved_threads+ if not fingerprint_changed and not new_feedback:workflow.logger.info("PR context has not changed, skipping CI follow-up",extra={@@ -502,6 +513,22 @@ class ProcessTaskWorkflow(PostHogWorkflow):},)return CIFollowUpDecision.SKIP+ self._pr_fingerprint = pr_context.fingerprint+ fire = (fingerprint_changed and is_pr_actionable(pr_context)) or new_feedback+ workflow.logger.info(+ "PR context has changed, deciding CI follow-up",+ extra={+ "run_id": self.context.run_id,+ "pr_url": pr_context.pr_url,+ "pr_state": pr_context.pr_state,+ "ci_status": pr_context.ci_status,+ "changes_requested": pr_context.changes_requested,+ "unresolved_threads": pr_context.unresolved_threads,+ "new_feedback": new_feedback,+ "fire": fire,+ },+ )+ return CIFollowUpDecision.FIRE if fire else CIFollowUpDecision.SKIPasync def _dispatch_ci_follow_up(self) -> None:self._ci_repetitions += 1@@ -950,6 +977,7 @@ class ProcessTaskWorkflow(PostHogWorkflow):connect_token=self._sandbox_connect_token,ci_repetitions=self._ci_repetitions,pr_fingerprint=self._pr_fingerprint,+ pr_unresolved_threads=self._pr_unresolved_threads,pr_progress_emitted=self._pr_progress_emitted,first_user_message_received=self._first_user_message_received,is_agent_design_enabled=self._is_agent_design_enabled,@@ -961,6 +989,7 @@ class ProcessTaskWorkflow(PostHogWorkflow):self._is_agent_design_enabled = resumed.is_agent_design_enabledself._ci_repetitions = resumed.ci_repetitionsself._pr_fingerprint = resumed.pr_fingerprint+ self._pr_unresolved_threads = resumed.pr_unresolved_threadsself._pr_progress_emitted = resumed.pr_progress_emittedself._first_user_message_received = resumed.first_user_message_receivedself._last_active_time = datetime.fromisoformat(resumed.last_active_time) if resumed.last_active_time else Nonediff --git a/products/tasks/backend/temporal/task_management/tests/test_task_management_workflow.py b/products/tasks/backend/temporal/task_management/tests/test_task_management_workflow.pyindex ef9b4548c9b2..3f7e04acf274 100644--- a/products/tasks/backend/temporal/task_management/tests/test_task_management_workflow.py+++ b/products/tasks/backend/temporal/task_management/tests/test_task_management_workflow.py@@ -282,24 +282,95 @@ class TestShouldRunCIFollowUp:decision = await workflow._should_run_ci_follow_up()assert decision is CIFollowUpDecision.SKIP- async def test_returns_fire_when_fingerprint_changes_and_persists_it(self, monkeypatch, silent_workflow_logger):+ @pytest.mark.parametrize(+ "ci_status,changes_requested,expected_decision,expected_fingerprint",+ [+ # Actionable changes fire.+ ("failing", False, CIFollowUpDecision.FIRE, "fp-1"),+ ("passing", True, CIFollowUpDecision.FIRE, "fp-1"),+ # Non-actionable changes persist the fingerprint but stay quiet —+ # waking the agent here produced "nothing to report" Slack spam.+ # Pending needs no deferral: the settled state hashes differently+ # (CI status and head SHA are both in the fingerprint), so it still+ # registers as a change on a later tick.+ ("passing", False, CIFollowUpDecision.SKIP, "fp-1"),+ ("none", False, CIFollowUpDecision.SKIP, "fp-1"),+ ("pending", False, CIFollowUpDecision.SKIP, "fp-1"),+ ],+ )+ async def test_fingerprint_change_fires_only_when_actionable(+ self,+ monkeypatch,+ silent_workflow_logger,+ ci_status,+ changes_requested,+ expected_decision,+ expected_fingerprint,+ ):workflow = TaskManagementWorkflow()workflow._context = _build_context()+ workflow._pr_fingerprint = "fp-0"async def fake_execute_activity(activity_fn, *args, **kwargs):return GetPrContextOutput(pr_url="https://github.com/org/repo/pull/1",pr_state="open",fingerprint="fp-1",+ ci_status=ci_status,+ changes_requested=changes_requested,+ )++ monkeypatch.setattr(task_management_workflow_module.workflow, "execute_activity", fake_execute_activity)++ decision = await workflow._should_run_ci_follow_up()++ assert decision is expected_decision+ assert workflow._pr_fingerprint == expected_fingerprint++ @pytest.mark.parametrize(+ "prev_threads,new_threads,fingerprint,expected_decision",+ [+ # New review threads are feedback — fire even when the fingerprint+ # hasn't moved.+ (0, 2, "fp-0", CIFollowUpDecision.FIRE),+ # Resolving threads is not feedback.+ (2, 1, "fp-0", CIFollowUpDecision.SKIP),+ # A green change with a stable thread count stays quiet.+ (2, 2, "fp-1", CIFollowUpDecision.SKIP),+ # A green change accompanied by new feedback fires.+ (0, 3, "fp-1", CIFollowUpDecision.FIRE),+ ],+ )+ async def test_new_review_threads_fire_follow_up(+ self,+ monkeypatch,+ silent_workflow_logger,+ prev_threads,+ new_threads,+ fingerprint,+ expected_decision,+ ):+ workflow = TaskManagementWorkflow()+ workflow._context = _build_context()+ workflow._pr_fingerprint = "fp-0"+ workflow._pr_unresolved_threads = prev_threads++ async def fake_execute_activity(activity_fn, *args, **kwargs):+ return GetPrContextOutput(+ pr_url="https://github.com/org/repo/pull/1",+ pr_state="open",+ fingerprint=fingerprint,+ ci_status="passing",+ unresolved_threads=new_threads,)monkeypatch.setattr(task_management_workflow_module.workflow, "execute_activity", fake_execute_activity)decision = await workflow._should_run_ci_follow_up()- assert decision is CIFollowUpDecision.FIRE- # Fingerprint must persist so the next tick with the same fp returns SKIP.- assert workflow._pr_fingerprint == "fp-1"+ assert decision is expected_decision+ # The count must track last-seen (not max) so post-resolve feedback re-fires.+ assert workflow._pr_unresolved_threads == new_threadsasync def test_returns_skip_when_fingerprint_unchanged(self, monkeypatch, silent_workflow_logger):workflow = TaskManagementWorkflow()diff --git a/products/tasks/backend/temporal/task_management/workflow.py b/products/tasks/backend/temporal/task_management/workflow.pyindex 77f1fe781aab..45ea37d8c70e 100644--- a/products/tasks/backend/temporal/task_management/workflow.py+++ b/products/tasks/backend/temporal/task_management/workflow.py@@ -34,7 +34,12 @@ from products.tasks.backend.temporal.execute_sandbox.workflow import (ChildCompletionPayload,ExecuteSandboxInput,)-from products.tasks.backend.temporal.process_task.activities.get_pr_context import GetPrContextInput, get_pr_context+from products.tasks.backend.temporal.patches import ci_follow_up_actionable_gate+from products.tasks.backend.temporal.process_task.activities.get_pr_context import (+ GetPrContextInput,+ get_pr_context,+ is_pr_actionable,+)from products.tasks.backend.temporal.process_task.activities.get_task_processing_context import (GetTaskProcessingContextInput,TaskProcessingContext,@@ -199,6 +204,9 @@ class TaskManagementWorkflow(PostHogWorkflow):self._last_active_time: Optional[datetime] = Noneself._ci_repetitions: int = 0self._pr_fingerprint: Optional[str] = None+ # Last observed unresolved review-thread count. Starting at 0 means+ # feedback posted before the first poll still reads as new.+ self._pr_unresolved_threads: int = 0# ------------------------------------------------------------------# Input parsing@@ -640,6 +648,7 @@ class TaskManagementWorkflow(PostHogWorkflow):self._sandbox_alive = Falseself._ci_repetitions = 0self._pr_fingerprint = None+ self._pr_unresolved_threads = 0self._heartbeat_received = Falseself._last_active_time = None@@ -915,21 +924,39 @@ class TaskManagementWorkflow(PostHogWorkflow):pr_url=pr_context.pr_url,)return CIFollowUpDecision.SKIP- if self._pr_fingerprint != pr_context.fingerprint:+ fingerprint_changed = self._pr_fingerprint != pr_context.fingerprint+ if not ci_follow_up_actionable_gate():+ # Legacy replay path: any fingerprint change fires; feedback is not consulted.+ if not fingerprint_changed:+ return CIFollowUpDecision.SKIPself._pr_fingerprint = pr_context.fingerprint+ return CIFollowUpDecision.FIRE+ # New unresolved review threads are feedback for the agent, and comparing+ # against the last-seen count means its own thread replies (which never+ # resolve anything) can't re-trigger it.+ new_feedback = pr_context.unresolved_threads > self._pr_unresolved_threads+ self._pr_unresolved_threads = pr_context.unresolved_threads+ if not fingerprint_changed and not new_feedback:workflow.logger.info(- "task_management_ci_fire",+ "task_management_ci_skipped_pr_unchanged",run_id=self._run_id,pr_url=pr_context.pr_url,- repetitions=self._ci_repetitions,)- return CIFollowUpDecision.FIRE+ return CIFollowUpDecision.SKIP+ self._pr_fingerprint = pr_context.fingerprint+ fire = (fingerprint_changed and is_pr_actionable(pr_context)) or new_feedbackworkflow.logger.info(- "task_management_ci_skipped_pr_unchanged",+ "task_management_ci_decision",run_id=self._run_id,pr_url=pr_context.pr_url,+ ci_status=pr_context.ci_status,+ changes_requested=pr_context.changes_requested,+ unresolved_threads=pr_context.unresolved_threads,+ new_feedback=new_feedback,+ fire=fire,+ repetitions=self._ci_repetitions,)- return CIFollowUpDecision.SKIP+ return CIFollowUpDecision.FIRE if fire else CIFollowUpDecision.SKIPasync def _dispatch_ci_follow_up(self) -> None:self._ci_repetitions += 1