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.

chore(tasks): use the shared temporal heartbeaters (#90518)

Arno Hillenc586f3efb08d
diff --git a/products/tasks/backend/temporal/bake_dev_stack_image/activities.py b/products/tasks/backend/temporal/bake_dev_stack_image/activities.py
index 238b9206b11e..9710b44a9652 100644
--- a/products/tasks/backend/temporal/bake_dev_stack_image/activities.py
+++ b/products/tasks/backend/temporal/bake_dev_stack_image/activities.py
@@ -1,4 +1,3 @@
-import asyncio
import logging
from dataclasses import dataclass
from typing import Any, Literal
@@ -6,6 +5,8 @@ from typing import Any, Literal
from asgiref.sync import sync_to_async
from temporalio import activity
+from posthog.temporal.common.heartbeat import Heartbeater
+
from products.tasks.backend.logic.services.dev_stack_image import (
DEV_STACK_IMAGE_NAME,
DevStackImageBakeError,
@@ -16,7 +17,9 @@ from products.tasks.backend.temporal.observability import log_activity_execution
logger = logging.getLogger(__name__)
-BAKE_HEARTBEAT_INTERVAL_SECONDS = 30
+# `Heartbeater` divides the activity's heartbeat timeout by this factor, so 6 against the
+# workflow's 3-minute timeout gives a 30-second interval.
+BAKE_HEARTBEAT_FACTOR = 6
@dataclass
@@ -35,18 +38,7 @@ async def bake_and_publish_dev_stack_image(input: BakeDevStackImageInput) -> str
Heartbeats while the sync bake blocks so worker failures are detected within the
workflow's heartbeat timeout.
"""
- stop_heartbeat = asyncio.Event()
-
- async def _heartbeat_loop() -> None:
- while True:
- try:
- await asyncio.wait_for(stop_heartbeat.wait(), timeout=BAKE_HEARTBEAT_INTERVAL_SECONDS)
- return
- except TimeoutError:
- activity.heartbeat()
-
- heartbeat_task = asyncio.create_task(_heartbeat_loop())
- try:
+ async with Heartbeater(factor=BAKE_HEARTBEAT_FACTOR):
with log_activity_execution("bake_and_publish_dev_stack_image", **input.to_log_context()):
try:
image_id = await sync_to_async(bake_dev_stack_image, thread_sensitive=False)(input.publish_name)
@@ -58,6 +50,3 @@ async def bake_and_publish_dev_stack_image(input: BakeDevStackImageInput) -> str
raise
observe_dev_stack_image_bake("succeeded", trigger=input.trigger)
return image_id
- finally:
- stop_heartbeat.set()
- await heartbeat_task
diff --git a/products/tasks/backend/temporal/bake_dev_stack_image/test_bake_dev_stack_image_activities.py b/products/tasks/backend/temporal/bake_dev_stack_image/test_bake_dev_stack_image_activities.py
index ac2bb910627f..80a744ee0efc 100644
--- a/products/tasks/backend/temporal/bake_dev_stack_image/test_bake_dev_stack_image_activities.py
+++ b/products/tasks/backend/temporal/bake_dev_stack_image/test_bake_dev_stack_image_activities.py
@@ -1,4 +1,6 @@
-import time
+import threading
+import dataclasses
+from datetime import timedelta
import pytest
from unittest.mock import patch
@@ -16,23 +18,27 @@ async def test_bake_activity_heartbeats_while_the_sync_bake_blocks() -> None:
# Without heartbeats, a worker crash mid-bake goes undetected until the 3-hour
# start_to_close (~6h across both attempts) instead of the heartbeat timeout.
env = ActivityEnvironment()
- heartbeats: list[tuple] = []
- env.on_heartbeat = lambda *details: heartbeats.append(details)
-
- def slow_bake(publish_name: str) -> str:
- time.sleep(0.3)
+ # The heartbeat interval is derived from this timeout, and the default is None (no
+ # heartbeating at all), so a short real timeout is what makes the loop tick here.
+ env.info = dataclasses.replace(env.info, heartbeat_timeout=timedelta(seconds=0.06))
+ heartbeat_seen = threading.Event()
+ env.on_heartbeat = lambda *details: heartbeat_seen.set()
+
+ # Recorded from inside the bake so the assertion can't be satisfied by the single
+ # heartbeat the context manager emits on exit.
+ heartbeat_during_bake: list[bool] = []
+
+ def blocking_bake(publish_name: str) -> str:
+ heartbeat_during_bake.append(heartbeat_seen.wait(timeout=10))
return "im-1"
- with (
- patch("products.tasks.backend.temporal.bake_dev_stack_image.activities.BAKE_HEARTBEAT_INTERVAL_SECONDS", 0.01),
- patch(
- "products.tasks.backend.temporal.bake_dev_stack_image.activities.bake_dev_stack_image",
- side_effect=slow_bake,
- ),
+ with patch(
+ "products.tasks.backend.temporal.bake_dev_stack_image.activities.bake_dev_stack_image",
+ side_effect=blocking_bake,
):
result = await env.run(
bake_and_publish_dev_stack_image, BakeDevStackImageInput(publish_name="posthog-dev-stack")
)
assert result == "im-1"
- assert heartbeats
+ assert heartbeat_during_bake == [True]
diff --git a/products/tasks/backend/temporal/process_task/activities/send_followup_to_sandbox.py b/products/tasks/backend/temporal/process_task/activities/send_followup_to_sandbox.py
index ca5ff944c9c7..0b627241dcac 100644
--- a/products/tasks/backend/temporal/process_task/activities/send_followup_to_sandbox.py
+++ b/products/tasks/backend/temporal/process_task/activities/send_followup_to_sandbox.py
@@ -1,6 +1,4 @@
import time
-import threading
-import contextvars
from dataclasses import dataclass
from enum import StrEnum
from typing import Any, NoReturn
@@ -12,6 +10,7 @@ from temporalio.exceptions import ApplicationError
from posthog.dataclasses import frozen
from posthog.models.integration import Integration
from posthog.models.user_integration import ReauthorizationRequired, UserIntegration
+from posthog.temporal.common.heartbeat_sync import HeartbeaterSync
from posthog.temporal.common.utils import close_db_connections
from posthog.temporal.oauth import PosthogMcpScopes
@@ -96,7 +95,9 @@ DENIAL_BRAKE_CONSUMED_REQUEST_ID_KEY = "followup_denial_brake_request_id"
# attempt, detected via heartbeat timeout) and for delivery-unknown failures.
# Application failures that write an error sentinel raise non-retryable.
SEND_FOLLOWUP_MAX_ATTEMPTS = 3
-SEND_FOLLOWUP_HEARTBEAT_INTERVAL_SECONDS = 15
+# `HeartbeaterSync` divides the activity's heartbeat timeout by this factor, so 4 against the
+# 1-minute timeout both callers set gives a 15-second interval.
+SEND_FOLLOWUP_HEARTBEAT_FACTOR = 4
STEER_DECLINED_OUTCOME = "steer_declined"
STEER_DECLINE_REASON_UNREPORTED = "unreported"
STEER_DECLINE_REASON_ACTOR_MISMATCH = "actor_mismatch"
@@ -132,23 +133,8 @@ def send_followup_to_sandbox(input: SendFollowupToSandboxInput) -> str | None:
so a worker restart is detected within the heartbeat timeout instead of
the 35-minute start_to_close.
"""
- stop_heartbeat = threading.Event()
- heartbeat_ctx = contextvars.copy_context()
-
- def _heartbeat_loop() -> None:
- while not stop_heartbeat.wait(SEND_FOLLOWUP_HEARTBEAT_INTERVAL_SECONDS):
- try:
- activity.heartbeat()
- except Exception:
- return
-
- heartbeat_thread = threading.Thread(target=lambda: heartbeat_ctx.run(_heartbeat_loop), daemon=True)
- heartbeat_thread.start()
- try:
+ with HeartbeaterSync(factor=SEND_FOLLOWUP_HEARTBEAT_FACTOR, logger=logger):
return _deliver_followup(input)
- finally:
- stop_heartbeat.set()
- heartbeat_thread.join(timeout=2)
def _current_attempt() -> int:
diff --git a/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py b/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py
index 24ee99c03e2e..7a1a48f740f2 100644
--- a/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py
+++ b/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py
@@ -4,6 +4,7 @@ from posthog.test.base import BaseTest
from unittest.mock import MagicMock, patch
from parameterized import parameterized
+from temporalio.testing import ActivityEnvironment
from products.tasks.backend.logic.stream.redis_stream import (
TASK_RUN_STREAM_WATCHED_TIMEOUT,
@@ -97,7 +98,9 @@ class TestSendFollowupToSandbox(BaseTest):
data={"result": {"stopReason": "max_tokens"}},
)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-123", message="hello"))
+ ActivityEnvironment().run(
+ send_followup_to_sandbox, SendFollowupToSandboxInput(run_id="run-123", message="hello")
+ )
event = mock_publish.call_args.args[1]
self.assertEqual(event["notification"]["params"]["stopReason"], "max_tokens")
@@ -140,13 +143,14 @@ class TestSendFollowupToSandbox(BaseTest):
return_value=None,
),
):
- send_followup_to_sandbox(
+ ActivityEnvironment().run(
+ send_followup_to_sandbox,
SendFollowupToSandboxInput(
run_id="run-123",
message="change direction",
actor_user_id=42,
steer=True,
- )
+ ),
)
mock_refresh_sandbox_mcp.assert_not_called()
diff --git a/products/tasks/backend/temporal/process_task/tests/test_send_followup_to_sandbox.py b/products/tasks/backend/temporal/process_task/tests/test_send_followup_to_sandbox.py
index d42aa861fb34..e93b3b927227 100644
--- a/products/tasks/backend/temporal/process_task/tests/test_send_followup_to_sandbox.py
+++ b/products/tasks/backend/temporal/process_task/tests/test_send_followup_to_sandbox.py
@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch
from django.core.cache import cache
from temporalio.exceptions import ApplicationError
+from temporalio.testing import ActivityEnvironment
from posthog.models.user_integration import ReauthorizationRequired
@@ -45,6 +46,11 @@ def _clear_session_cache():
cache.clear()
+def _run_activity(activity_input: SendFollowupToSandboxInput) -> str | None:
+ """The activity opens `HeartbeaterSync`, which needs a Temporal activity context."""
+ return ActivityEnvironment().run(send_followup_to_sandbox, activity_input)
+
+
def _make_mcp_config(name: str = "posthog", token: str = "tok") -> McpServerConfig:
return McpServerConfig(
type="http",
@@ -735,7 +741,7 @@ class TestSendFollowupActivityRefreshOrdering:
_patches["refresh"].side_effect = _record_refresh
_patches["user_msg"].side_effect = _record_user_msg
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", posthog_mcp_scopes="full"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", posthog_mcp_scopes="full"))
assert call_order == ["refresh", "user_message"]
@@ -749,7 +755,7 @@ class TestSendFollowupActivityRefreshOrdering:
_patches[gate].return_value = reason
with pytest.raises(RuntimeError, match=reason):
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
_patches["user_msg"].assert_not_called()
@@ -764,7 +770,7 @@ class TestSendFollowupActivityRefreshOrdering:
),
pytest.raises(ApplicationError) as excinfo,
):
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
assert str(excinfo.value) == SANDBOX_STOPPED_MESSAGE
assert excinfo.value.non_retryable
@@ -775,7 +781,7 @@ class TestSendFollowupActivityRefreshOrdering:
_patches["task_run"].state = {"cancel_requested_at": "2026-01-01T00:00:00+00:00"}
with pytest.raises(ApplicationError) as excinfo:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
assert str(excinfo.value) == RUN_STOPPING_MESSAGE
assert excinfo.value.non_retryable
@@ -791,7 +797,7 @@ class TestSendFollowupActivityRefreshOrdering:
_patches["task_run"].status = _patches["task_run_cls"].Status.CANCELLED
with pytest.raises(ApplicationError) as excinfo:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
assert str(excinfo.value) == RUN_STOPPING_MESSAGE
assert excinfo.value.non_retryable
@@ -804,7 +810,7 @@ class TestSendFollowupActivityRefreshOrdering:
_patches["refresh_github"].return_value = SandboxRebindFailure.SANDBOX_NOT_RUNNING
with pytest.raises(ApplicationError) as excinfo:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
assert str(excinfo.value) == SANDBOX_STOPPED_MESSAGE
assert excinfo.value.non_retryable
@@ -813,7 +819,7 @@ class TestSendFollowupActivityRefreshOrdering:
def test_scopes_flow_from_input_to_refresh(self, _patches):
_patches["user_msg"].return_value = CommandResult(success=True, status_code=200)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", posthog_mcp_scopes="full"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", posthog_mcp_scopes="full"))
_patches["refresh"].assert_called_once()
args, _kwargs = _patches["refresh"].call_args
@@ -832,7 +838,7 @@ class TestSendFollowupActivityRefreshOrdering:
"products.tasks.backend.temporal.process_task.activities.send_followup_to_sandbox.get_task_run_credential_user"
) as mock_resolve:
mock_resolve.return_value = MagicMock(id=99)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", actor_user_id=99))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", actor_user_id=99))
resolved_state = mock_resolve.call_args.args[1]
assert resolved_state["slack_actor_user_id"] == 99
@@ -853,7 +859,7 @@ class TestSendFollowupActivityRefreshOrdering:
) as mock_resolve:
new_actor = MagicMock(id=99)
mock_resolve.return_value = new_actor
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1", message="hi", actor_user_id=99, context={"actor_slack_user_id": "U_BOB"}
)
@@ -872,7 +878,7 @@ class TestSendFollowupActivityRefreshOrdering:
def test_non_slack_delivery_does_not_stamp(self, _patches):
_patches["user_msg"].return_value = CommandResult(success=True, status_code=200)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", actor_user_id=99))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", actor_user_id=99))
_patches["task_run_cls"].update_state_atomic.assert_not_called()
_patches["refresh_store_skills"].assert_not_called()
@@ -880,7 +886,7 @@ class TestSendFollowupActivityRefreshOrdering:
def test_default_scope_is_read_only(self, _patches):
_patches["user_msg"].return_value = CommandResult(success=True, status_code=200)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
args, _kwargs = _patches["refresh"].call_args
assert args[1] == "read_only"
@@ -889,9 +895,7 @@ class TestSendFollowupActivityRefreshOrdering:
_patches["task_run"].state = {"sandbox_id": "sandbox-1"}
_patches["task_run"].task.created_by_id = 42
- outcome = send_followup_to_sandbox(
- SendFollowupToSandboxInput(run_id="run-1", message="hi", actor_user_id=99, steer=True)
- )
+ outcome = _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", actor_user_id=99, steer=True))
assert outcome == STEER_DECLINED_OUTCOME
_patches["conn_token"].assert_not_called()
@@ -960,7 +964,7 @@ class TestSendFollowupTurnTimeout:
success=False, status_code=504, error="Sandbox request timed out", retryable=True, turn_in_flight=True
)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi"))
_patches["error"].assert_not_called()
_patches["turn_complete"].assert_not_called()
@@ -971,7 +975,7 @@ class TestSendFollowupTurnTimeout:
)
with pytest.raises(ApplicationError, match="retryable failure") as exc_info:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is False
_patches["error"].assert_not_called()
@@ -983,7 +987,7 @@ class TestSendFollowupTurnTimeout:
)
with pytest.raises(ApplicationError, match="send_followup failed") as exc_info:
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1",
message="hi",
@@ -1011,7 +1015,7 @@ class TestSendFollowupTurnTimeout:
),
pytest.raises(ApplicationError, match="The model response could not be completed") as exc_info,
):
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is True
_patches["error"].assert_called_once_with(
@@ -1032,7 +1036,7 @@ class TestSendFollowupTurnTimeout:
)
with pytest.raises(ApplicationError, match="retryable failure") as exc_info:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is False
_patches["error"].assert_not_called()
@@ -1054,7 +1058,7 @@ class TestSendFollowupTurnTimeout:
)
with pytest.raises(ApplicationError, match="retryable failure") as exc_info:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is False
_patches["error"].assert_not_called()
@@ -1072,7 +1076,7 @@ class TestSendFollowupTurnTimeout:
)
with pytest.raises(ApplicationError) as exc_info:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is True
_patches["error"].assert_called_once()
@@ -1091,7 +1095,7 @@ class TestSendFollowupTurnTimeout:
)
with pytest.raises(ApplicationError, match="ede_diagnostic") as exc_info:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is True
_patches["error"].assert_called_once_with("run-1", DENIED_PERMISSION_STOP_MESSAGE, False, False, "user_created")
@@ -1114,13 +1118,13 @@ class TestSendFollowupTurnTimeout:
),
pytest.raises(ApplicationError, match="retryable failure") as steer_failure,
):
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1", message="wait", message_id="m-steer", actor_user_id=42, steer=True
)
)
with pytest.raises(ApplicationError) as base_failure:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-base"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-base"))
assert steer_failure.value.non_retryable is False
assert base_failure.value.non_retryable is True
@@ -1143,9 +1147,7 @@ class TestSendFollowupTurnTimeout:
verdicts = []
for message_id in ("m-1", "m-2"):
with pytest.raises(ApplicationError) as exc_info:
- send_followup_to_sandbox(
- SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id=message_id)
- )
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id=message_id))
verdicts.append(exc_info.value.non_retryable)
assert verdicts == [True, False]
@@ -1159,7 +1161,7 @@ class TestSendFollowupTurnTimeout:
)
with pytest.raises(ApplicationError, match="delivery unknown") as exc_info:
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is False
_patches["error"].assert_not_called()
@@ -1177,7 +1179,7 @@ class TestSendFollowupTurnTimeout:
),
pytest.raises(ApplicationError, match="send_followup failed") as exc_info,
):
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
assert exc_info.value.non_retryable is True
_patches["error"].assert_called_once()
@@ -1193,7 +1195,7 @@ class TestSendFollowupTurnTimeout:
data={"result": {"duplicate": True, "stopReason": "duplicate_delivery"}},
)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
_patches["error"].assert_not_called()
_patches["turn_complete"].assert_not_called()
@@ -1210,7 +1212,7 @@ class TestSendFollowupTurnTimeout:
"products.tasks.backend.temporal.process_task.activities.send_followup_to_sandbox.get_sandbox_mcp_session_user",
return_value=42,
):
- outcome = send_followup_to_sandbox(
+ outcome = _run_activity(
SendFollowupToSandboxInput(
run_id="run-1",
message="hi",
@@ -1228,7 +1230,7 @@ class TestSendFollowupTurnTimeout:
def test_message_id_forwarded_to_sandbox(self, _patches):
_patches["user_msg"].return_value = CommandResult(success=True, status_code=200)
- send_followup_to_sandbox(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
+ _run_activity(SendFollowupToSandboxInput(run_id="run-1", message="hi", message_id="m-1"))
_, kwargs = _patches["user_msg"].call_args
assert kwargs["message_id"] == "m-1"
@@ -1311,7 +1313,7 @@ class TestPeerDeliveryMode:
_patches["bound_actor"].return_value = (bound, "")
_patches["user_msg"].return_value = CommandResult(success=True, status_code=200)
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1",
message="peer ping",
@@ -1334,7 +1336,7 @@ class TestPeerDeliveryMode:
# (the marker lives half the token lifetime), so an unconfirmed identity
# must never run a peer turn on the sandbox's residual credentials.
with pytest.raises(ApplicationError) as excinfo:
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1", message="peer ping", message_id="m-1", context=self._peer_context()
)
@@ -1351,7 +1353,7 @@ class TestPeerDeliveryMode:
_patches["task_run"].state = {"cancel_requested_at": "2026-01-01T00:00:00+00:00"}
with pytest.raises(ApplicationError) as excinfo:
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1", message="peer ping", message_id="m-1", context=self._peer_context()
)
@@ -1371,7 +1373,7 @@ class TestPeerDeliveryMode:
_patches[refresh_key].return_value = SandboxRebindFailure.REFRESH_SESSION_FAILED
with pytest.raises(ApplicationError) as excinfo:
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1", message="peer ping", message_id="m-1", context=self._peer_context()
)
@@ -1390,7 +1392,7 @@ class TestPeerDeliveryMode:
)
with pytest.raises(ApplicationError) as excinfo:
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1", message="peer ping", message_id="m-1", context=self._peer_context()
)
@@ -1409,7 +1411,7 @@ class TestPeerDeliveryMode:
success=True, status_code=200, data={"result": {"duplicate": True}}
)
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1", message="peer ping", message_id="m-1", context=self._peer_context()
)
@@ -1425,7 +1427,7 @@ class TestPeerDeliveryMode:
_patches["resolve_actor"].return_value = MagicMock(id=42, distinct_id="u42")
_patches["user_msg"].return_value = CommandResult(success=True, status_code=200)
- send_followup_to_sandbox(
+ _run_activity(
SendFollowupToSandboxInput(
run_id="run-1",
message="hi",