: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): support Pi cloud configuration (#77284)
Jonathan Mielooe3e823dc6ddf
diff --git a/posthog/settings/web.py b/posthog/settings/web.pyindex 5fee3c070657..2de7e99ca8f9 100644--- a/posthog/settings/web.py+++ b/posthog/settings/web.py@@ -614,6 +614,18 @@ SPECTACULAR_SETTINGS = {# TaskRunUpdate.status and ExperimentFlagCleanupTask.run_status."RunStatusEnum": ["not_started", "queued", "in_progress", "completed", "failed", "cancelled"],"TaskRunEnvironmentEnum": "products.tasks.backend.models.TaskRun.Environment",+ "ReasoningEffortEnum": ["low", "medium", "high", "xhigh", "max", "ultracode", None],+ "TaskRunReasoningEffortEnum": [+ "off",+ "minimal",+ "low",+ "medium",+ "high",+ "xhigh",+ "max",+ "ultracode",+ None,+ ],"ModelEnum": "products.batch_exports.backend.models.batch_export.BatchExport.Model","RecurrenceIntervalEnum": "products.reminders.backend.models.reminder.Reminder.RecurrenceInterval","ScannerModelEnum": "products.replay_vision.backend.models.replay_scanner.ScannerModel",diff --git a/products/tasks/backend/presentation/serializers.py b/products/tasks/backend/presentation/serializers.pyindex 4646d94edbcd..e30ed8abd893 100644--- a/products/tasks/backend/presentation/serializers.py+++ b/products/tasks/backend/presentation/serializers.py@@ -59,6 +59,32 @@ from products.tasks.backend.facade.run_config import (logger = logging.getLogger(__name__)+PI_THINKING_LEVEL_CHOICES = ("off", "minimal", "low", "medium", "high", "xhigh", "max")+TASK_RUN_REASONING_EFFORT_CHOICES = [+ "off",+ "minimal",+ *(effort.value for effort in PUBLIC_REASONING_EFFORTS),+]+++def _is_pi_task_run_request(context: dict[str, Any]) -> bool:+ view = context.get("view")+ request = context.get("request")+ team = context.get("team")+ task_id = getattr(view, "kwargs", {}).get("parent_lookup_task_id")+ user_id = getattr(getattr(request, "user", None), "id", None)++ if task_id is None or team is None:+ return False++ task_runtime = tasks_facade.task_runtime(+ task_id,+ team.id,+ user_id,+ for_control=True,+ )+ return task_runtime == tasks_facade.TaskRuntime.PI+def _capture_rejected_reasoning_effort(context: dict[str, Any],@@ -293,7 +319,7 @@ class TaskRunDetailSerializer(DataclassSerializer):allow_null=True, required=False, help_text="Configured LLM model identifier for this run.")reasoning_effort = serializers.ChoiceField(- choices=[effort.value for effort in PUBLIC_REASONING_EFFORTS],+ choices=TASK_RUN_REASONING_EFFORT_CHOICES,allow_null=True,required=False,help_text="Configured reasoning effort for this run when the selected model supports it.",@@ -2225,7 +2251,7 @@ class TaskRunBootstrapCreateRequestSerializer(PR_AUTHORSHIP_MODE_CHOICES = [mode.value for mode in PrAuthorshipMode]RUN_SOURCE_CHOICES = [source.value for source in RunSource]RUNTIME_ADAPTER_CHOICES = [adapter.value for adapter in RuntimeAdapter]- REASONING_EFFORT_CHOICES = [effort.value for effort in PUBLIC_REASONING_EFFORTS]+ REASONING_EFFORT_CHOICES = TASK_RUN_REASONING_EFFORT_CHOICESenvironment = serializers.ChoiceField(choices=[environment.value for environment in tasks_facade.TaskRunEnvironment],@@ -2347,6 +2373,21 @@ class TaskRunBootstrapCreateRequestSerializer(errors["relayed_mcp_servers"] = collision_errorinitial_permission_mode = attrs.get("initial_permission_mode")runtime_adapter = attrs.get("runtime_adapter")+ is_pi_task = _is_pi_task_run_request(self.context)+ if is_pi_task:+ pi_incompatible_fields = ("runtime_adapter", "context_window", "fast_mode", "initial_permission_mode")+ for field in pi_incompatible_fields:+ if attrs.get(field) is not None:+ errors[field] = "This field cannot be used with a Pi task."++ reasoning_effort = attrs.get("reasoning_effort")+ if reasoning_effort is not None and reasoning_effort not in PI_THINKING_LEVEL_CHOICES:+ errors["reasoning_effort"] = "This thinking level is not supported by Pi."++ if errors:+ raise serializers.ValidationError(errors)+ return attrs+if initial_permission_mode is not None:if runtime_adapter is None:errors["initial_permission_mode"] = "This field requires runtime_adapter to be set."diff --git a/products/tasks/backend/temporal/process_task/utils.py b/products/tasks/backend/temporal/process_task/utils.pyindex 0e1b422cf13d..c70f072acdd5 100644--- a/products/tasks/backend/temporal/process_task/utils.py+++ b/products/tasks/backend/temporal/process_task/utils.py@@ -76,6 +76,8 @@ class LLMProvider(StrEnum):class ReasoningEffort(StrEnum):+ OFF = "off"+ MINIMAL = "minimal"LOW = "low"MEDIUM = "medium"HIGH = "high"diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.pyindex 3c5cd8d78ff6..9d76a20f8861 100644--- a/products/tasks/backend/tests/test_api.py+++ b/products/tasks/backend/tests/test_api.py@@ -2365,6 +2365,52 @@ class TestTaskAPI(BaseTaskAPITest):self.assertEqual(task_run.state["auto_publish"], True)mock_workflow.assert_not_called()+ @parameterized.expand([("high",), ("off",)])+ def test_create_run_endpoint_accepts_pi_model_selection(self, thinking_level: str):+ task = self.create_task(runtime=Task.Runtime.PI)++ response = self.client.post(+ f"/api/projects/@current/tasks/{task.id}/runs/",+ {+ "environment": "cloud",+ "model": "gpt-5.6-terra",+ "reasoning_effort": thinking_level,+ },+ format="json",+ )++ self.assertEqual(response.status_code, status.HTTP_201_CREATED)+ task_run = TaskRun.objects.get(id=response.json()["id"])+ self.assertEqual(task_run.state["model"], "gpt-5.6-terra")+ self.assertEqual(task_run.state["reasoning_effort"], thinking_level)++ @parameterized.expand(+ [+ ("runtime_adapter", {"runtime_adapter": "codex"}),+ ("context_window", {"context_window": "1m"}),+ ("fast_mode", {"fast_mode": True}),+ ("initial_permission_mode", {"initial_permission_mode": "plan"}),+ ("reasoning_effort", {"reasoning_effort": "ultracode"}),+ ]+ )+ def test_create_run_endpoint_rejects_invalid_configuration_for_pi(+ self, field: str, pi_incompatible_config: dict[str, str | bool]+ ) -> None:+ task = self.create_task(runtime=Task.Runtime.PI)++ response = self.client.post(+ f"/api/projects/@current/tasks/{task.id}/runs/",+ {+ "environment": "cloud",+ "model": "gpt-5.6-terra",+ **pi_incompatible_config,+ },+ format="json",+ )++ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)+ self.assertEqual(response.json()["attr"], field)+# is_url_allowed resolves DNS for real in CI, and example.com subdomains don't resolve.@patch("products.tasks.backend.presentation.serializers.is_url_allowed", return_value=(True, None))@patch("products.tasks.backend.temporal.client.execute_task_processing_workflow")diff --git a/products/tasks/frontend/generated/api.schemas.ts b/products/tasks/frontend/generated/api.schemas.tsindex 397cf9452115..9d95243358b3 100644--- a/products/tasks/frontend/generated/api.schemas.ts+++ b/products/tasks/frontend/generated/api.schemas.ts@@ -1345,6 +1345,30 @@ export const TaskRunDetailDTOProviderEnumApi = {Openai: 'openai',} as const+/**+ * * `off` - off+ * * `minimal` - minimal+ * * `low` - low+ * * `medium` - medium+ * * `high` - high+ * * `xhigh` - xhigh+ * * `max` - max+ * * `ultracode` - ultracode+ */+export type TaskRunReasoningEffortEnumApi =+ (typeof TaskRunReasoningEffortEnumApi)[keyof typeof TaskRunReasoningEffortEnumApi]++export const TaskRunReasoningEffortEnumApi = {+ Off: 'off',+ Minimal: 'minimal',+ Low: 'low',+ Medium: 'medium',+ High: 'high',+ Xhigh: 'xhigh',+ Max: 'max',+ Ultracode: 'ultracode',+} as const+export interface TaskRunArtifactMetadataApi {/*** Name of the local skill included in a skill_bundle artifact.@@ -1439,13 +1463,15 @@ export interface TaskRunDetailDTOApi {model?: string | null/** Configured reasoning effort for this run when the selected model supports it.*+ * * `off` - off+ * * `minimal` - minimal* * `low` - low* * `medium` - medium* * `high` - high* * `xhigh` - xhigh* * `max` - max* * `ultracode` - ultracode */- reasoning_effort?: ReasoningEffortEnumApi | null+ reasoning_effort?: TaskRunReasoningEffortEnumApi | null/*** Presigned S3 URL for log access (valid for 1 hour).* @nullable@@ -2622,13 +2648,15 @@ export interface TaskRunBootstrapCreateRequestApi {model?: string/** Reasoning effort to request for models that expose an effort control.*+ * * `off` - off+ * * `minimal` - minimal* * `low` - low* * `medium` - medium* * `high` - high* * `xhigh` - xhigh* * `max` - max* * `ultracode` - ultracode */- reasoning_effort?: ReasoningEffortEnumApi+ reasoning_effort?: TaskRunReasoningEffortEnumApi/** Context window size for models that support the 1M window.** * `200k` - 200kdiff --git a/products/tasks/frontend/generated/api.zod.ts b/products/tasks/frontend/generated/api.zod.tsindex 455cc3c1d11f..bdc99b4c0d2e 100644--- a/products/tasks/frontend/generated/api.zod.ts+++ b/products/tasks/frontend/generated/api.zod.ts@@ -2324,13 +2324,13 @@ export const TasksRunsCreateBody = /* @__PURE__ */ zod),model: zod.string().optional().describe('LLM model identifier to run in the selected runtime.'),reasoning_effort: zod- .enum(['low', 'medium', 'high', 'xhigh', 'max', 'ultracode'])+ .enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultracode']).describe(- '\* `low` - low\n\* `medium` - medium\n\* `high` - high\n\* `xhigh` - xhigh\n\* `max` - max\n\* `ultracode` - ultracode'+ '\* `off` - off\n\* `minimal` - minimal\n\* `low` - low\n\* `medium` - medium\n\* `high` - high\n\* `xhigh` - xhigh\n\* `max` - max\n\* `ultracode` - ultracode').optional().describe(- 'Reasoning effort to request for models that expose an effort control.\n\n\* `low` - low\n\* `medium` - medium\n\* `high` - high\n\* `xhigh` - xhigh\n\* `max` - max\n\* `ultracode` - ultracode'+ 'Reasoning effort to request for models that expose an effort control.\n\n\* `off` - off\n\* `minimal` - minimal\n\* `low` - low\n\* `medium` - medium\n\* `high` - high\n\* `xhigh` - xhigh\n\* `max` - max\n\* `ultracode` - ultracode'),context_window: zod.enum(['200k', '1m'])diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 5b99f1ede4bc..80f19a0cbc82 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -48378,6 +48378,30 @@ export namespace Schemas {Openai: 'openai',} as const;+ /**+ * * `off` - off+ * * `minimal` - minimal+ * * `low` - low+ * * `medium` - medium+ * * `high` - high+ * * `xhigh` - xhigh+ * * `max` - max+ * * `ultracode` - ultracode+ */+ export type TaskRunReasoningEffortEnum = typeof TaskRunReasoningEffortEnum[keyof typeof TaskRunReasoningEffortEnum];+++ export const TaskRunReasoningEffortEnum = {+ Off: 'off',+ Minimal: 'minimal',+ Low: 'low',+ Medium: 'medium',+ High: 'high',+ Xhigh: 'xhigh',+ Max: 'max',+ Ultracode: 'ultracode',+ } as const;+export interface TaskRunArtifactMetadata {/*** Name of the local skill included in a skill_bundle artifact.@@ -48472,13 +48496,15 @@ export namespace Schemas {model?: string | null;/** Configured reasoning effort for this run when the selected model supports it.*+ * * `off` - off+ * * `minimal` - minimal* * `low` - low* * `medium` - medium* * `high` - high* * `xhigh` - xhigh* * `max` - max* * `ultracode` - ultracode */- reasoning_effort?: ReasoningEffortEnum | null;+ reasoning_effort?: TaskRunReasoningEffortEnum | null;/*** Presigned S3 URL for log access (valid for 1 hour).* @nullable@@ -72116,13 +72142,15 @@ export namespace Schemas {model?: string;/** Reasoning effort to request for models that expose an effort control.*+ * * `off` - off+ * * `minimal` - minimal* * `low` - low* * `medium` - medium* * `high` - high* * `xhigh` - xhigh* * `max` - max* * `ultracode` - ultracode */- reasoning_effort?: ReasoningEffortEnum;+ reasoning_effort?: TaskRunReasoningEffortEnum;/** Context window size for models that support the 1M window.** * `200k` - 200k