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): let the hogland flag win over the Modal VM-sandbox and allowlist flags (#92209)

Tom Owerse32c137adca4
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 2146ca82c0d9..fb01bd8f635e 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
@@ -858,15 +858,18 @@ def _resolve_sandbox_backend(
run_id: str,
state: dict | None,
task_runtime: str,
- use_modal_vm_sandbox: bool,
- use_modal_network_allowlist: bool,
custom_image_name: str | None,
) -> str:
"""Pick the sandbox provider for this run.
- Hogland only takes plain default-template ACP runs; anything needing a
- Modal-only feature (VM runtime, custom image, Pi runtime, Modal-level network
- allowlist) stays on Modal even with the flag on. Fails closed to Modal.
+ Hogland only takes plain default-template ACP runs. A custom image (hogland has
+ only the default golden template) or the Pi runtime are hard incapabilities —
+ hogland cannot run them, so they force Modal even with the flag on. The Modal
+ VM-sandbox and network-allowlist flags are runtime *preferences*, not
+ incapabilities: a run the hogland flag (or override) selects wins hogland over
+ them. The caller then forces both off so the run provisions as a plain hogland
+ box; egress stays enforced in-box by agentsh via the run's allowed_domains.
+ Fails closed to Modal.
"""
raw_override = (state or {}).get("sandbox_backend")
override = raw_override if isinstance(raw_override, str) and raw_override in ("modal", "hogland") else None
@@ -876,21 +879,21 @@ def _resolve_sandbox_backend(
log_with_activity_context("sandbox_backend_state_override", run_id=run_id, sandbox_backend="modal")
return "modal"
- # Hard gates: a "hogland" result (override OR flag) is only allowed when hogland can
- # actually run this run. These sit ahead of the override so a stale or forged `hogland`
- # carried across a cloud resume can't defeat the EU guard or the Modal-only
- # fallbacks and leave the run with unenforced egress.
+ # Hard gates: a "hogland" result (override OR flag) is only allowed when hogland is
+ # available (US region + configured URL/token) and can actually run this run (no
+ # custom image, no Pi runtime). These sit ahead of the override so a stale or forged
+ # `hogland` carried across a cloud resume can't defeat the EU guard or route an
+ # incapable run to hogland.
if not settings.HOGLAND_API_URL or not (settings.HOGLAND_API_TOKEN_FILE or settings.HOGLAND_API_TOKEN):
return "modal"
# Hogland runs in the US only; EU runs stay on Modal regardless of flag/override state.
if getattr(settings, "CLOUD_DEPLOYMENT", None) == "EU":
return "modal"
- if (
- use_modal_vm_sandbox
- or custom_image_name is not None
- or task_runtime == Task.Runtime.PI
- or use_modal_network_allowlist
- ):
+ # Hard hogland incapabilities: a custom image or the Pi runtime cannot run on the
+ # default golden template, so keep those on Modal even when the flag is on. The
+ # Modal VM-sandbox / network-allowlist flags are deliberately NOT gated here — a
+ # flagged run wins hogland over them (the caller forces both off for hogland runs).
+ if custom_image_name is not None or task_runtime == Task.Runtime.PI:
return "modal"
# Past the gates, a "hogland" override pins the run (the canary lever), no flag eval.
@@ -1361,10 +1364,16 @@ def get_task_processing_context(input: GetTaskProcessingContextInput) -> TaskPro
run_id=run_id,
state=state,
task_runtime=task.runtime,
- use_modal_vm_sandbox=use_modal_vm_sandbox,
- use_modal_network_allowlist=use_modal_network_allowlist,
custom_image_name=custom_image_name,
)
+ if sandbox_backend == "hogland":
+ # Hogland runs are plain default-template runs, so the Modal VM-runtime and
+ # network-allowlist preferences don't apply. Force both off so provisioning
+ # builds a DEFAULT_BASE hogland box (not a Modal VM_BASE config) and skips the
+ # Modal provider-layer allowlist. Egress stays enforced in-box by agentsh, which
+ # keys on the run's allowed_domains independently of use_modal_network_allowlist.
+ use_modal_vm_sandbox = False
+ use_modal_network_allowlist = False
emit_agent_log(
run_id,
"debug",
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 099326827842..7cfdbe2c6c4b 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
@@ -1472,6 +1472,30 @@ class TestGetTaskProcessingContextActivity:
assert result.use_modal_vm_sandbox is True
assert result.custom_image_name == "posthog-dev-stack"
+ @pytest.mark.django_db(transaction=True)
+ @override_settings(HOGLAND_API_URL="https://hogland.example", HOGLAND_API_TOKEN="hog-tok")
+ def test_hogland_run_forces_off_modal_vm_and_network_allowlist(self, activity_environment, test_task):
+ # A run that resolves to hogland must carry use_modal_vm_sandbox and
+ # use_modal_network_allowlist as False, so provisioning builds a plain hogland
+ # box instead of a Modal VM_BASE config with the Modal provider allowlist. The
+ # VM payload and the flag below would each set their value True; the force-off
+ # must still land both at False for a hogland run.
+ task_run = test_task.create_run()
+ input_data = GetTaskProcessingContextInput(run_id=str(task_run.id))
+
+ with (
+ patch(VM_FLAG_PAYLOAD_TARGET, return_value='{"default_base_origin_products": ["user_created"]}'),
+ patch(
+ "products.tasks.backend.temporal.process_task.activities.get_task_processing_context.posthoganalytics.feature_enabled",
+ return_value=True,
+ ),
+ ):
+ result = async_to_sync(activity_environment.run)(get_task_processing_context, input_data)
+
+ assert result.sandbox_backend == "hogland"
+ assert result.use_modal_vm_sandbox is False
+ assert result.use_modal_network_allowlist is False
+
@pytest.mark.django_db(transaction=True)
def test_get_task_processing_context_exposes_ci_prompt(self, activity_environment, test_task):
custom_prompt = "Re-run the failed mypy checks and push a fix."
@@ -1516,8 +1540,6 @@ class TestResolveSandboxBackend:
"run_id": "run-1",
"state": None,
"task_runtime": "acp",
- "use_modal_vm_sandbox": False,
- "use_modal_network_allowlist": False,
"custom_image_name": None,
}
kwargs.update(overrides)
@@ -1538,15 +1560,17 @@ class TestResolveSandboxBackend:
@pytest.mark.parametrize(
"overrides",
[
- {"use_modal_vm_sandbox": True},
{"custom_image_name": "posthog-sandbox-custom-x"},
{"task_runtime": "pi"},
- {"use_modal_network_allowlist": True},
],
- ids=["vm_runtime", "custom_image", "pi_runtime", "modal_network_allowlist"],
+ ids=["custom_image", "pi_runtime"],
)
@override_settings(**_HOGLAND_SETTINGS)
- def test_modal_only_features_fall_back_to_modal_even_with_the_flag_on(self, overrides):
+ def test_hard_incapabilities_fall_back_to_modal_even_with_the_flag_on(self, overrides):
+ # A custom image or the Pi runtime cannot run on hogland's default template, so
+ # they force Modal even with the flag on. The Modal VM-sandbox and
+ # network-allowlist preferences are deliberately not gated here — a flagged run
+ # wins hogland over them (covered by the caller force-off test).
assert self._resolve_with_flag(True, **overrides) == "modal"
@override_settings(**_HOGLAND_SETTINGS, CLOUD_DEPLOYMENT="EU")
@@ -1598,14 +1622,15 @@ class TestResolveSandboxBackend:
@pytest.mark.parametrize(
"overrides",
[
- {"use_modal_vm_sandbox": True},
{"custom_image_name": "img"},
- {"use_modal_network_allowlist": True},
+ {"task_runtime": "pi"},
],
- ids=["vm", "custom_image", "network_allowlist"],
+ ids=["custom_image", "pi_runtime"],
)
@override_settings(**_HOGLAND_SETTINGS)
- def test_hogland_override_cannot_defeat_modal_only_fallbacks(self, overrides):
+ def test_hogland_override_cannot_defeat_hard_incapabilities(self, overrides):
+ # A stale or forged hogland override surviving a cloud resume must not route a
+ # custom-image or Pi run to hogland — the capability gates sit ahead of the override.
assert self._resolve_with_flag(True, state={"sandbox_backend": "hogland"}, **overrides) == "modal"
@override_settings(**_HOGLAND_SETTINGS)