: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 a long workflow id from blocking hogland sandboxes (#92909)
posthog[bot]d03e26674eed
diff --git a/products/tasks/backend/logic/services/hogland_sandbox.py b/products/tasks/backend/logic/services/hogland_sandbox.pyindex 402a9eac46e6..a192c6817ed6 100644--- a/products/tasks/backend/logic/services/hogland_sandbox.py+++ b/products/tasks/backend/logic/services/hogland_sandbox.py@@ -76,6 +76,13 @@ HOGLAND_GOLDEN_CPU_CORES = 4.0HOGLAND_GOLDEN_MEMORY_GB = 16.0HOGLAND_GOLDEN_DISK_GB = 64.0+# Hogland rejects a create whose tags carry a `key=value` entry longer than this. The+# tag dict is shared with Modal, which has no such limit, so a task workflow id (a+# dispatch prefix plus two uuids) overruns it on its own. Keep the head of an oversized+# value: the ids it ends with already travel as their own task_id/task_run_id tags,+# so what a long workflow id adds is the prefix in front of them.+HOGLAND_MAX_TAG_LENGTH = 64+# `create()` blocks until the box is running; a cold boot on a fresh Karpenter node# can take minutes, and `exec` calls legitimately run up to the caller's# timeout_seconds (default 10 minutes). One generous read timeout covers both —@@ -95,6 +102,16 @@ _STATIC_BOX_ENV = {}+def _to_box_tags(metadata: dict[str, str] | None) -> list[str]:+ tags: list[str] = []+ for key, value in (metadata or {}).items():+ budget = HOGLAND_MAX_TAG_LENGTH - len(key) - 1+ if budget <= 0:+ continue+ tags.append(f"{key}={value[:budget]}")+ return tags++@lru_cache(maxsize=4)def _cached_client(base_url: str, token: str) -> Hogland:# trust_env=False keeps the in-cluster PrivateLink call off the egress proxy, which@@ -228,7 +245,7 @@ class HoglandSandbox(AgentServerLaunchMixin):config.image_fallback = Noneenv = {**_STATIC_BOX_ENV, **(config.environment_variables or {})}- tags = [f"{key}={value}" for key, value in (config.metadata or {}).items()]+ tags = _to_box_tags(config.metadata)try:client = get_hogland_client()diff --git a/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py b/products/tasks/backend/logic/services/tests/test_hogland_sandbox.pyindex d339c5b666e9..ff50af35ab85 100644--- a/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py+++ b/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py@@ -93,6 +93,18 @@ class TestHoglandSandboxCreate:assert sandbox.id == "box-abc123def456"assert config.snapshot_restored is False+ def test_create_bounds_tags_to_the_hogland_length_limit(self):+ # Hogland rejects the whole create when any tag exceeds 64 characters, and a task+ # workflow id is longer than that on its own.+ workflow_id = f"task-processing-{'a' * 36}-{'b' * 36}"+ config = SandboxConfig(name="sandbox-task-1", metadata={"task_id": "t1", "workflow_id": workflow_id})+ _sandbox, client = self._create(config)++ tags = client.create.call_args.kwargs["tags"]+ assert all(len(tag) <= 64 for tag in tags)+ assert "task_id=t1" in tags+ assert f"workflow_id={workflow_id[:52]}" in tags+def test_create_records_the_read_back_box_shape_for_the_ledger(self):# The box ignores per-task overrides, so the ledger must reflect the shape the box# actually delivered, read back from box.view.spec — not the requested override anddiff --git a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.pyindex 7ffd35a2c959..84acd48b8885 100644--- a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py+++ b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py@@ -574,9 +574,10 @@ def _build_sandbox_tags(prepared: PrepareSandboxForRepositoryOutput,use_vm_sandbox: bool,) -> dict[str, str]:- """Tags forwarded to the Modal sandbox so it can be traced back when debugging.+ """Tags forwarded to the sandbox so it can be traced back when debugging.- Modal tag values must be strings; None values are dropped so we don't emit empty tags.+ Tag values must be strings; None values are dropped so we don't emit empty tags.+ Hogland also caps each tag at 64 characters and truncates on its side."""tags: dict[str, str | int | None] = {"task_id": ctx.task_id,