: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): preserve pending prompts on resume (#81972)
Alessandro Pogliaghi4cccff665629
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.pyindex 876a78554276..d3711b73d490 100644--- a/products/tasks/backend/facade/api.py+++ b/products/tasks/backend/facade/api.py@@ -384,6 +384,8 @@ _TASK_RUN_PUBLIC_STATE_KEYS = frozenset("initial_permission_mode","mode","model",+ "pending_user_artifact_ids",+ "pending_user_message","pr_authorship_mode","pr_base_branch","provider",diff --git a/products/tasks/backend/models.py b/products/tasks/backend/models.pyindex 8f88652d0c36..3b40494426a6 100644--- a/products/tasks/backend/models.py+++ b/products/tasks/backend/models.py@@ -1970,6 +1970,7 @@ class TaskRun(models.Model):state["handoff_resumed"] = Truestate["mode"] = "interactive"state.pop("pending_user_message", None)+ state.pop("pending_user_artifact_ids", None)state.pop("pending_user_message_id", None)state.pop("pending_user_message_ts", None)state.pop("sandbox_id", None)diff --git a/products/tasks/backend/tests/test_facade.py b/products/tasks/backend/tests/test_facade.pyindex 451ae59f0b37..28e5068d394e 100644--- a/products/tasks/backend/tests/test_facade.py+++ b/products/tasks/backend/tests/test_facade.py@@ -407,6 +407,33 @@ class TestFacadeReadsAndMappers(TestCase):self.assertNotIn("snapshot_kind", new_run.state)self.assertNotIn("snapshot_mount_path", new_run.state)+ def test_run_task_resume_exposes_pending_prompt_to_agent(self):+ task = self._make_task()+ previous_run = TaskRun.objects.create(+ task=task,+ team=self.team,+ status=TaskRun.Status.COMPLETED,+ )++ with patch("products.tasks.backend.facade.api._trigger_task_processing_workflow"):+ result = facade.run_task(+ task.id,+ self.team.id,+ self.user.id,+ validated_data={+ "mode": "interactive",+ "resume_from_run_id": str(previous_run.id),+ "pending_user_message": "Continue with the refactor",+ "pending_user_artifact_ids": [],+ },+ )++ assert result is not None and result.error is None+ new_run = task.runs.exclude(id=previous_run.id).get()+ detail = facade.get_task_run_detail(new_run.id, task.id, self.team.id)+ assert detail is not None+ self.assertEqual(detail.state["pending_user_message"], "Continue with the refactor")+@parameterized.expand([("ready", SandboxCustomImage.Status.READY, "posthog-sandbox-custom-1-abc:latest", True),diff --git a/products/tasks/backend/tests/test_models.py b/products/tasks/backend/tests/test_models.pyindex d7054dadd360..599015ed646a 100644--- a/products/tasks/backend/tests/test_models.py+++ b/products/tasks/backend/tests/test_models.py@@ -686,6 +686,8 @@ class TestTaskRun(TestCase):"sandbox_url": "https://old-sandbox.test","sandbox_jwt_kid": "old-key","snapshot_external_id": "snapshot-1",+ "pending_user_message": "Review the attachment",+ "pending_user_artifact_ids": ["artifact-1"],},)@@ -694,6 +696,8 @@ class TestTaskRun(TestCase):self.assertNotIn("sandbox_id", run.state)self.assertNotIn("sandbox_url", run.state)self.assertNotIn("sandbox_jwt_kid", run.state)+ self.assertNotIn("pending_user_message", run.state)+ self.assertNotIn("pending_user_artifact_ids", run.state)self.assertEqual(run.state["snapshot_external_id"], "snapshot-1")self.assertTrue(run.state["handoff_resumed"])