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.

feat(tasks): gate desktop workspace warmup (#83154)

Alessandro Pogliaghi9a1331cb8251
diff --git a/products/tasks/backend/constants.py b/products/tasks/backend/constants.py
index 225672c87fc3..86c5fe04284c 100644
--- a/products/tasks/backend/constants.py
+++ b/products/tasks/backend/constants.py
@@ -148,6 +148,7 @@ TASK_SESSION_UPLOAD_FORM_OVERHEAD_BYTES = 64 * 1024
STREAM_VIA_PROXY_FEATURE_FLAG = "tasks-stream-via-proxy"
OVERLAP_CLONE_BOOT_FEATURE_FLAG = "tasks-overlap-clone-boot"
+DESKTOP_WORKSPACE_WARM_FEATURE_FLAG = "task-cloud-desktop-workspace-warm"
# Kill switch: rtk command-output compression is on by default in cloud sandboxes;
# enabling this flag disables it fleet-wide — over any per-run override — without
# an image rebuild.
diff --git a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py
index fea2379e7729..1c219b0137d7 100644
--- a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py
+++ b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py
@@ -14,6 +14,7 @@ from products.tasks.backend.constants import (
AGENT_OTEL_TELEMETRY_STATE_KEY,
AGENT_PROXY_KEEP_STREAM_OPEN_FEATURE_FLAG,
CONTINUE_AS_NEW_FEATURE_FLAG,
+ DESKTOP_WORKSPACE_WARM_FEATURE_FLAG,
MODAL_NETWORK_ALLOWLIST_FEATURE_FLAG,
OVERLAP_CLONE_BOOT_FEATURE_FLAG,
RTK_DISABLED_FEATURE_FLAG,
@@ -110,6 +111,8 @@ class TaskProcessingContext:
# (request == limit). Captured at workflow start so it's stable across activity retries.
burstable_sandbox_resources_enabled: bool = True
overlap_clone_boot_enabled: bool = False
+ # Captured at workflow start so the warmup decision stays stable across retries.
+ desktop_workspace_warm_enabled: bool = False
# Captured at workflow start so the agent-proxy stream lifetime stays deterministic across retries.
agent_proxy_keep_stream_open: bool = False
# Set only when the run resolved to the VM runtime — custom images layer on the VM base.
@@ -616,6 +619,35 @@ def _is_overlap_clone_boot_enabled(
return enabled
+def _is_desktop_workspace_warm_enabled(
+ *,
+ distinct_id: str,
+ organization_id: str,
+ run_id: str,
+) -> bool:
+ try:
+ enabled = bool(
+ posthoganalytics.feature_enabled(
+ DESKTOP_WORKSPACE_WARM_FEATURE_FLAG,
+ distinct_id=distinct_id,
+ groups={"organization": organization_id},
+ group_properties={"organization": {"id": organization_id}},
+ only_evaluate_locally=False,
+ send_feature_flag_events=False,
+ )
+ )
+ except Exception as e:
+ log_with_activity_context("desktop_workspace_warm_flag_check_failed", run_id=run_id, error=str(e))
+ return False
+
+ log_with_activity_context(
+ "desktop_workspace_warm_flag_checked",
+ run_id=run_id,
+ desktop_workspace_warm_enabled=enabled,
+ )
+ return enabled
+
+
def _is_modal_network_allowlist_enabled(
*,
distinct_id: str,
@@ -966,6 +998,16 @@ def get_task_processing_context(input: GetTaskProcessingContextInput) -> TaskPro
"debug",
f"overlap_clone_boot_enabled: {overlap_clone_boot_enabled} for this task run",
)
+ desktop_workspace_warm_enabled = _is_desktop_workspace_warm_enabled(
+ distinct_id=distinct_id,
+ organization_id=organization_id,
+ run_id=run_id,
+ )
+ emit_agent_log(
+ run_id,
+ "debug",
+ f"desktop_workspace_warm_enabled: {desktop_workspace_warm_enabled} for this task run",
+ )
agent_proxy_keep_stream_open = _is_agent_proxy_keep_stream_open_enabled(
distinct_id=distinct_id,
organization_id=organization_id,
@@ -1040,6 +1082,7 @@ def get_task_processing_context(input: GetTaskProcessingContextInput) -> TaskPro
use_modal_network_allowlist=use_modal_network_allowlist,
burstable_sandbox_resources_enabled=burstable_sandbox_resources_enabled,
overlap_clone_boot_enabled=overlap_clone_boot_enabled,
+ desktop_workspace_warm_enabled=desktop_workspace_warm_enabled,
agent_proxy_keep_stream_open=agent_proxy_keep_stream_open,
custom_image_name=custom_image_name,
rtk_enabled=rtk_enabled,
diff --git a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py
index 1eb1ab2d5caa..ac94ca3b0443 100644
--- a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py
+++ b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py
@@ -175,7 +175,8 @@ def _prepare_posthog_desktop_cloud_task(ctx: TaskProcessingContext, sandbox: San
internal PostHog checkout that uses that image, after its final branch is in place.
"""
if (
- ctx.custom_image_name != DEV_STACK_IMAGE_NAME
+ not ctx.desktop_workspace_warm_enabled
+ or ctx.custom_image_name != DEV_STACK_IMAGE_NAME
or repository.casefold() != "posthog/posthog"
or sandbox.config.image_fallback
):
diff --git a/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.py b/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.py
index 30ab6ad74f20..f1a6154edce6 100644
--- a/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.py
+++ b/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.py
@@ -12,6 +12,7 @@ from posthog.models.user_integration import UserIntegration
from products.tasks.backend.constants import (
AGENT_PROXY_KEEP_STREAM_OPEN_FEATURE_FLAG,
CONTINUE_AS_NEW_FEATURE_FLAG,
+ DESKTOP_WORKSPACE_WARM_FEATURE_FLAG,
MODAL_VM_SANDBOX_FEATURE_FLAG,
RTK_DISABLED_FEATURE_FLAG,
SANDBOX_EVENT_INGEST_FEATURE_FLAG,
@@ -31,6 +32,7 @@ from products.tasks.backend.temporal.process_task.activities.get_task_processing
_is_agent_proxy_keep_stream_open_enabled,
_is_burstable_sandbox_resources_enabled,
_is_continue_as_new_enabled,
+ _is_desktop_workspace_warm_enabled,
_is_rtk_enabled,
_is_sandbox_event_ingest_enabled,
_resolve_modal_vm_sandbox,
@@ -80,6 +82,46 @@ def test_snapshot_resume_requires_a_resume_marker_and_snapshot(state: dict[str,
assert context.is_snapshot_resume is expected
[email protected]("flag_value,expected", [(True, True), (False, False), (None, False)])
+def test_desktop_workspace_warm_flag_uses_organization_rollout(flag_value, expected):
+ with patch(
+ "products.tasks.backend.temporal.process_task.activities.get_task_processing_context.posthoganalytics.feature_enabled",
+ return_value=flag_value,
+ ) as feature_enabled_mock:
+ assert (
+ _is_desktop_workspace_warm_enabled(
+ distinct_id="distinct-id",
+ organization_id="organization-id",
+ run_id="run-id",
+ )
+ is expected
+ )
+
+ feature_enabled_mock.assert_called_once_with(
+ DESKTOP_WORKSPACE_WARM_FEATURE_FLAG,
+ distinct_id="distinct-id",
+ groups={"organization": "organization-id"},
+ group_properties={"organization": {"id": "organization-id"}},
+ only_evaluate_locally=False,
+ send_feature_flag_events=False,
+ )
+
+
+def test_desktop_workspace_warm_flag_fails_closed():
+ with patch(
+ "products.tasks.backend.temporal.process_task.activities.get_task_processing_context.posthoganalytics.feature_enabled",
+ side_effect=RuntimeError("flag service failed"),
+ ):
+ assert (
+ _is_desktop_workspace_warm_enabled(
+ distinct_id="distinct-id",
+ organization_id="organization-id",
+ run_id="run-id",
+ )
+ is False
+ )
+
+
@pytest.mark.requires_secrets
class TestIsAgentOtelTelemetryEnabled:
@pytest.mark.parametrize(
diff --git a/products/tasks/backend/temporal/process_task/activities/tests/test_provision_sandbox.py b/products/tasks/backend/temporal/process_task/activities/tests/test_provision_sandbox.py
index 8e93047e9bf9..30c83ddef637 100644
--- a/products/tasks/backend/temporal/process_task/activities/tests/test_provision_sandbox.py
+++ b/products/tasks/backend/temporal/process_task/activities/tests/test_provision_sandbox.py
@@ -26,7 +26,9 @@ from products.tasks.backend.temporal.process_task.activities.provision_sandbox i
)
-def _context_for_desktop_bootstrap(*, image_name: str | None = "posthog-dev-stack") -> TaskProcessingContext:
+def _context_for_desktop_bootstrap(
+ *, image_name: str | None = "posthog-dev-stack", warm_enabled: bool = True
+) -> TaskProcessingContext:
return TaskProcessingContext(
task_id="task-id",
run_id="run-id",
@@ -38,6 +40,7 @@ def _context_for_desktop_bootstrap(*, image_name: str | None = "posthog-dev-stac
distinct_id="distinct-id",
state={},
custom_image_name=image_name,
+ desktop_workspace_warm_enabled=warm_enabled,
)
@@ -82,6 +85,19 @@ def test_skips_desktop_workspace_preparation_for_other_images_repositories_and_f
sandbox.execute.assert_not_called()
+def test_skips_desktop_workspace_preparation_when_warm_flag_is_off(mocker):
+ sandbox = mocker.Mock()
+ sandbox.config.image_fallback = None
+
+ _prepare_posthog_desktop_cloud_task(
+ _context_for_desktop_bootstrap(warm_enabled=False),
+ sandbox,
+ "posthog/posthog",
+ )
+
+ sandbox.execute.assert_not_called()
+
+
def test_desktop_workspace_preparation_failure_is_non_retryable(mocker):
from temporalio.exceptions import ApplicationError