: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): gate the turn-ended wake behind its replay patch (#100003)
Alessandro Pogliaghi299c43eeb9bc
diff --git a/products/tasks/backend/temporal/process_task/tests/test_workflow.py b/products/tasks/backend/temporal/process_task/tests/test_workflow.pyindex 2e4ee6db6d18..7d351fa03c68 100644--- a/products/tasks/backend/temporal/process_task/tests/test_workflow.py+++ b/products/tasks/backend/temporal/process_task/tests/test_workflow.py@@ -1724,19 +1724,26 @@ class TestProcessTaskWorkflowUnit:assert inactivity_mock.await_args is not Noneassert inactivity_mock.await_args.args[0] == timedelta(seconds=expected_seconds)- async def test_turn_end_wakes_the_wait_so_the_short_idle_window_re_arms(self, monkeypatch):+ @pytest.mark.parametrize("patched", [True, False])+ async def test_turn_end_wakes_the_wait_only_once_the_patch_is_recorded(self, monkeypatch, patched):workflow = ProcessTaskWorkflow()workflow._context = _build_context(github_integration_id=123)-- async def fake_wait_condition(condition):- assert condition()-- monkeypatch.setattr(process_task_workflow_module.workflow, "wait_condition", fake_wait_condition)+ monkeypatch.setattr(process_task_workflow_module.workflow, "in_workflow", Mock(return_value=True))+ monkeypatch.setattr(process_task_workflow_module.workflow, "patched", Mock(return_value=patched))await workflow.agent_state_changed(False)- assert await workflow._wait_for_task_external_event() == process_task_workflow_module.TaskEvent.SIGNAL_RECEIVEDassert workflow._end_of_turn_received is True+ assert workflow._turn_ended_received is patched+ if patched:++ async def fake_wait_condition(condition):+ assert condition()++ monkeypatch.setattr(process_task_workflow_module.workflow, "wait_condition", fake_wait_condition)+ assert (+ await workflow._wait_for_task_external_event() == process_task_workflow_module.TaskEvent.SIGNAL_RECEIVED+ )@pytest.mark.parametrize("outcome, expected",diff --git a/products/tasks/backend/temporal/process_task/workflow.py b/products/tasks/backend/temporal/process_task/workflow.pyindex c096816255f2..51bd5dc19b65 100644--- a/products/tasks/backend/temporal/process_task/workflow.py+++ b/products/tasks/backend/temporal/process_task/workflow.py@@ -3290,7 +3290,7 @@ class ProcessTaskWorkflow(PostHogWorkflow):async def agent_state_changed(self, agent_active: bool) -> None:self._agent_active = agent_activeself._end_of_turn_received = not agent_active- if not agent_active:+ if not agent_active and _turn_opens_on_dispatch():self._turn_ended_received = True@temporalio.workflow.signal