: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): stop the boot telemetry flush from spinning on finished tasks (#126339)
Alessandro Pogliaghi8db407b39d8d
diff --git a/products/tasks/backend/temporal/process_task/tests/test_workflow.py b/products/tasks/backend/temporal/process_task/tests/test_workflow.pyindex e91afb85f4ba..74dbbd484224 100644--- a/products/tasks/backend/temporal/process_task/tests/test_workflow.py+++ b/products/tasks/backend/temporal/process_task/tests/test_workflow.py@@ -1525,6 +1525,43 @@ async def test_boot_milestone_contains_only_timing_and_runtime_dimensions()[email protected]("scheduled_during_flush", [False, True])+async def test_flush_boot_telemetry_drains_finished_and_late_milestones(monkeypatch, scheduled_during_flush):+ workflow_instance = ProcessTaskWorkflow()+ workflow_instance._context = _build_context(github_integration_id=123)+ workflow_instance._sandbox_id_for_cleanup = "sandbox-123"+ workflow_instance._chain_started_at = datetime(2026, 8, 28, 10, 0, tzinfo=UTC)+ workflow_instance._agent_ready_at = datetime(2026, 8, 28, 10, 0, 20, tzinfo=UTC)+ tracked: list[str] = []++ async def track(event_name: str, properties: dict[str, Any]) -> None:+ tracked.append(event_name)+ if scheduled_during_flush and event_name == "agent_first_command_dispatched":+ workflow_instance._schedule_boot_milestone("agent_first_activity_observed")++ monkeypatch.setattr(workflow_instance, "_track_boot_milestone", track)+ monkeypatch.setattr(process_task_workflow_module, "record_agent_boot_milestone_ms", Mock())+ monkeypatch.setattr(+ process_task_workflow_module.workflow,+ "now",+ Mock(return_value=datetime(2026, 8, 28, 10, 0, 21, tzinfo=UTC)),+ )++ workflow_instance._schedule_boot_milestone("agent_first_command_dispatched")+ if not scheduled_during_flush:+ (task,) = workflow_instance._boot_telemetry_tasks+ while not task.done():+ await asyncio.sleep(0)+ await workflow_instance._flush_boot_telemetry_tasks()++ assert workflow_instance._boot_telemetry_tasks == []+ expected = ["agent_first_command_dispatched"]+ if scheduled_during_flush:+ expected.append("agent_first_activity_observed")+ assert tracked == expected++@pytest.mark.parametrize("timing_enabled", [False, True])@pytest.mark.parametrize(("same_run_resume", "requested_at"),diff --git a/products/tasks/backend/temporal/process_task/workflow.py b/products/tasks/backend/temporal/process_task/workflow.pyindex e4a23fc7ad82..41e5a07b40c8 100644--- a/products/tasks/backend/temporal/process_task/workflow.py+++ b/products/tasks/backend/temporal/process_task/workflow.py@@ -2636,7 +2636,6 @@ class ProcessTaskWorkflow(PostHogWorkflow):self._boot_milestones_before_ready.append((event_name, now))task = asyncio.create_task(self._track_boot_milestone(event_name, properties))self._boot_telemetry_tasks.append(task)- task.add_done_callback(self._boot_telemetry_tasks.remove)def _record_boot_milestone_sample(self, event_name: str, since_agent_ready_ms: int) -> None:record_agent_boot_milestone_ms(@@ -2685,7 +2684,10 @@ class ProcessTaskWorkflow(PostHogWorkflow):async def _flush_boot_telemetry_tasks(self) -> None:while self._boot_telemetry_tasks:- await asyncio.gather(*tuple(self._boot_telemetry_tasks))+ pending = [task for task in self._boot_telemetry_tasks if not task.done()]+ self._boot_telemetry_tasks.clear()+ if pending:+ await asyncio.gather(*pending)async def _report_sandbox_deadline_outcome(self, *, outcome: str, reason: str | None, duration: timedelta) -> None:"""Report how a sandbox deadline resolved, for the rollout's metrics.