Skip to content

: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.

fix(tasks): deprecate followup-queue patch in signal handler (#58238)

Alessandro Pogliaghi5933482fa815
diff --git a/products/tasks/backend/temporal/process_task/tests/test_workflow.py b/products/tasks/backend/temporal/process_task/tests/test_workflow.py
index 23ee9ac70048..dfa3edb9a90b 100644
--- a/products/tasks/backend/temporal/process_task/tests/test_workflow.py
+++ b/products/tasks/backend/temporal/process_task/tests/test_workflow.py
@@ -277,8 +277,9 @@ class TestProcessTaskWorkflow:
class TestProcessTaskWorkflowUnit:
async def test_send_followup_message_can_arrive_before_context_is_loaded(self, monkeypatch):
logger = Mock()
+ deprecate_patch = Mock()
monkeypatch.setattr(process_task_workflow_module.workflow, "logger", logger)
- monkeypatch.setattr(process_task_workflow_module.workflow, "patched", Mock(return_value=True))
+ monkeypatch.setattr(process_task_workflow_module.workflow, "deprecate_patch", deprecate_patch)
workflow = ProcessTaskWorkflow()
await workflow.send_followup_message("first", ["artifact-1"])
@@ -288,6 +289,8 @@ class TestProcessTaskWorkflowUnit:
PendingFollowup(message="first", artifact_ids=["artifact-1"]),
PendingFollowup(message="second", artifact_ids=["artifact-2"]),
]
+ assert workflow._pending_followup is None
+ deprecate_patch.assert_called_with(process_task_workflow_module._PATCH_ID_FOLLOWUP_QUEUE)
logger.info.assert_any_call(
"send_followup_signal_received",
run_id=None,
@@ -302,19 +305,6 @@ class TestProcessTaskWorkflowUnit:
)
assert logger.info.call_count == 2
- async def test_send_followup_message_preserves_legacy_single_slot_before_patch(self, monkeypatch):
- logger = Mock()
- monkeypatch.setattr(process_task_workflow_module.workflow, "logger", logger)
- monkeypatch.setattr(process_task_workflow_module.workflow, "patched", Mock(return_value=False))
- workflow = ProcessTaskWorkflow()
-
- await workflow.send_followup_message("first", ["artifact-1"])
- await workflow.send_followup_message("second", ["artifact-2"])
-
- assert workflow._pending_followup == PendingFollowup(message="second", artifact_ids=["artifact-2"])
- assert workflow._pending_followups == []
- assert logger.info.call_count == 2
-
@pytest.mark.parametrize(
"state, expected",
[
diff --git a/products/tasks/backend/temporal/process_task/workflow.py b/products/tasks/backend/temporal/process_task/workflow.py
index c7d432b5aa2b..ba5bf03f4859 100644
--- a/products/tasks/backend/temporal/process_task/workflow.py
+++ b/products/tasks/backend/temporal/process_task/workflow.py
@@ -131,6 +131,15 @@ After fixing, commit and push so CI can re-run.
# 2. Second cleanup PR (after another full drain): delete this helper and
# `_PATCH_ID_CI_FOLLOW_UP_PR_CONTEXT`.
_PATCH_ID_CI_FOLLOW_UP_PR_CONTEXT = "tasks-ci-follow-up-pr-context"
+
+# The follow-up queue patch swapped the single-slot `_pending_followup` for a
+# `_pending_followups` list inside the `send_followup_message` signal handler.
+# Calling `workflow.patched(...)` from a signal handler is unsafe: signals can
+# land in different workflow-task boundaries across replays (rolling deploys,
+# sticky-cache eviction, worker restarts), which leaves the patch marker in
+# history with no matching command on replay (TMPRL1100). Switch to
+# `deprecate_patch(...)` so the marker is treated as compatible regardless of
+# which workflow task records it. Same two-step lifecycle as above.
_PATCH_ID_FOLLOWUP_QUEUE = "tasks-follow-up-message-queue"
@@ -930,10 +939,13 @@ class ProcessTaskWorkflow(PostHogWorkflow):
artifact_count=len(artifact_ids or []),
)
pending_followup = PendingFollowup(message=message, artifact_ids=artifact_ids or [])
- if workflow.patched(_PATCH_ID_FOLLOWUP_QUEUE):
- self._pending_followups.append(pending_followup)
- else:
- self._pending_followup = pending_followup
+ # Always queue. `deprecate_patch` accepts existing non-deprecated
+ # markers from workflows that ran the prior `workflow.patched(...)`
+ # gate, so this is safe to deploy alongside in-flight workflows. The
+ # consumption loop in `run()` still drains a stray `_pending_followup`
+ # for defense in depth, but new code never sets it.
+ workflow.deprecate_patch(_PATCH_ID_FOLLOWUP_QUEUE)
+ self._pending_followups.append(pending_followup)
async def _send_followup_to_sandbox(self, message: str | None, artifact_ids: list[str]) -> None:
workflow.logger.info(