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): route off-pin posthog_ai sandbox runs to the ai-gateway (#125736)

Jonathan Mieloo3abdbba220cc
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 f3d1d34ca785..0f4744d209e8 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
@@ -57,6 +57,7 @@ from products.tasks.backend.logic.services.agentsh import (
_get_debug_only_ports,
enforced_egress_domains,
)
+from products.tasks.backend.logic.services.gateway_model_pin import model_allowed_by_product_pin
from products.tasks.backend.logic.services.network_policy import (
EffectiveNetworkPolicy,
NetworkPolicyValidationError,
@@ -263,7 +264,13 @@ class TaskProcessingContext:
@property
def model(self) -> str | None:
value = (self.state or {}).get("model")
- return value if isinstance(value, str) else None
+ if not isinstance(value, str):
+ return None
+ if self.origin_product == Task.OriginProduct.POSTHOG_AI and not model_allowed_by_product_pin(
+ "posthog_ai", value
+ ):
+ return None
+ return value
@property
def reasoning_effort(self) -> str | None:
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 0d63763b28e3..78c090bd49cd 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
@@ -124,6 +124,36 @@ def test_snapshot_resume_requires_a_resume_marker_and_snapshot(state: dict[str,
assert context.is_snapshot_resume is expected
+ "origin_product,model,expected",
+ [
+ ("posthog_ai", "deepseek-ai/deepseek-v4-flash-0731", None),
+ ("posthog_ai", "zai-org/glm-5.3", None),
+ ("posthog_ai", "claude-opus-5-5", "claude-opus-5-5"),
+ ("posthog_ai", "gpt-6-sol", "gpt-6-sol"),
+ ("user_created", "deepseek-ai/deepseek-v4-flash-0731", "deepseek-ai/deepseek-v4-flash-0731"),
+ ("posthog_ai", None, None),
+ ],
+)
+def test_posthog_ai_run_drops_a_model_outside_its_gateway_pin(
+ origin_product: str, model: str | None, expected: str | None
+):
+ context = TaskProcessingContext(
+ task_id="task-id",
+ run_id="run-id",
+ team_id=1,
+ team_uuid="team-uuid",
+ organization_id="organization-id",
+ github_integration_id=None,
+ repository=None,
+ distinct_id="distinct-id",
+ origin_product=origin_product,
+ state={"model": model},
+ )
+
+ assert context.model == expected
+
+
@pytest.mark.parametrize("flag_value,expected", [(True, True), (False, False), (None, False)])
def test_desktop_workspace_warm_flag_uses_organization_rollout(flag_value, expected):
assert (