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): let repo-less warm requests carry a github integration (#91163)

Jake Ruthc6e2e5834bcf
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index d55a4b2d70b1..cf0fd783c310 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -6342,7 +6342,8 @@ def warm_task_sandbox(
(``Throttled``). The caller treats ``None`` as "no warm run; fall through to a cold create+run".
When present, ``github_integration_id`` must already be re-scoped to ``team_id`` by the caller
- (see :func:`resolve_team_github_integration_id`). Repository-less warms omit it.
+ (see :func:`resolve_team_github_integration_id`). A repository requires it; a repository-less warm
+ may carry it so the Run boots with the same GitHub credentials a repo-less create would get.
"""
from rest_framework.exceptions import ( # noqa: PLC0415 — keep DRF exception types off the api import path
PermissionDenied,
@@ -6368,7 +6369,12 @@ def warm_task_sandbox(
github_integration = Integration.objects.filter(
id=github_integration_id, team_id=team_id, kind="github"
).first()
- if bool(normalized_repositories) != bool(github_integration):
+ # An integration id that does not resolve to this team's GitHub integration is never warmed on, and
+ # a repository cannot be cloned without one. An integration without a repository is fine: the
+ # create path stores that pair too, and reuse matches on the integration id.
+ if github_integration_id is not None and github_integration is None:
+ return None
+ if normalized_repositories and github_integration is None:
return None
sandbox_environment = None
if sandbox_environment_id is not None:
diff --git a/products/tasks/backend/presentation/serializers.py b/products/tasks/backend/presentation/serializers.py
index e6411708eb69..2d2dcf38574c 100644
--- a/products/tasks/backend/presentation/serializers.py
+++ b/products/tasks/backend/presentation/serializers.py
@@ -3290,7 +3290,11 @@ class WarmTaskRequestSerializer(serializers.Serializer):
required=False,
default=None,
allow_null=True,
- help_text="Primary key of the team's GitHub integration to clone with when a repository is selected.",
+ help_text=(
+ "Primary key of the team's GitHub integration. Required when a repository is selected (it is "
+ "what the sandbox clones with). Accepted without a repository too: the warm Run then boots "
+ "with that integration's GitHub credentials, matching a repo-less create that carries it."
+ ),
)
branch = serializers.CharField(
required=False,
@@ -3369,10 +3373,12 @@ class WarmTaskRequestSerializer(serializers.Serializer):
return normalized
def validate(self, attrs):
- if bool(attrs.get("repository")) != bool(attrs.get("github_integration")):
- raise serializers.ValidationError(
- "Repository and GitHub integration must either both be provided or both be omitted."
- )
+ # A repository needs an integration to clone with. The reverse is allowed: the create path
+ # accepts and stores an integration on a repo-less task, and the sandbox uses it to mint a
+ # GitHub token, so a repo-less warm must carry the same integration to boot with the same
+ # credentials and to match that create on reuse.
+ if attrs.get("repository") and not attrs.get("github_integration"):
+ raise serializers.ValidationError("GitHub integration is required when a repository is provided.")
# Warming starts the agent on this model, so it bills like a run and gates like one.
model_access_error = get_model_access_error(attrs.get("model"), distinct_id=request_distinct_id(self.context))
diff --git a/products/tasks/backend/tests/test_warm_facade.py b/products/tasks/backend/tests/test_warm_facade.py
index 7dd0df2f9e30..6516d77758b0 100644
--- a/products/tasks/backend/tests/test_warm_facade.py
+++ b/products/tasks/backend/tests/test_warm_facade.py
@@ -189,20 +189,40 @@ class TestWarmTaskSandbox(APIBaseTest):
initial_permission_mode="plan",
)
+ @parameterized.expand(
+ [
+ ("without_integration", False),
+ # The PostHog AI composer sends the team's integration even with no repo picked.
+ ("with_integration", True),
+ ]
+ )
@patch("products.tasks.backend.presentation.views.api.TaskViewSet._warm_enabled", return_value=True)
@patch("products.tasks.backend.facade.api.warm_task_sandbox")
- def test_warm_endpoint_accepts_repo_less_request(self, mock_warm, _mock_warm_enabled):
+ def test_warm_endpoint_accepts_repo_less_request(self, _name, with_integration, mock_warm, _mock_warm_enabled):
mock_warm.return_value = None
+ integration_id = self.integration.id if with_integration else None
response = self.client.post(
"/api/projects/@current/tasks/warm/",
- {"repository": None, "github_integration": None, "branch": None},
+ {"repository": None, "github_integration": integration_id, "branch": None},
format="json",
)
assert response.status_code == 200, response.content
assert mock_warm.call_args.kwargs["repository"] is None
- assert mock_warm.call_args.kwargs["github_integration_id"] is None
+ assert mock_warm.call_args.kwargs["github_integration_id"] == integration_id
+
+ @patch("products.tasks.backend.presentation.views.api.TaskViewSet._warm_enabled", return_value=True)
+ @patch("products.tasks.backend.facade.api.warm_task_sandbox")
+ def test_warm_endpoint_rejects_repository_without_integration(self, mock_warm, _mock_warm_enabled):
+ response = self.client.post(
+ "/api/projects/@current/tasks/warm/",
+ {"repository": "posthog/posthog", "github_integration": None, "branch": "main"},
+ format="json",
+ )
+
+ assert response.status_code == 400, response.content
+ mock_warm.assert_not_called()
@patch("products.tasks.backend.presentation.views.api.TaskViewSet._warm_enabled", return_value=True)
def test_warm_endpoint_rejects_duplicate_repositories(self, _mock_warm_enabled):
@@ -326,17 +346,25 @@ class TestWarmTaskSandbox(APIBaseTest):
assert task.description == ""
assert task.runs.filter(id=result.run_id).exists()
- def test_births_repo_less_draft_and_returns_warm_dto(self):
+ @parameterized.expand(
+ [
+ ("without_integration", False),
+ ("with_integration", True),
+ ]
+ )
+ def test_births_repo_less_draft_and_returns_warm_dto(self, _name, with_integration):
def fake_warm(self_warmer, **kwargs):
run = self_warmer.task.create_run(mode="interactive", extra_state={"await_user_message": True})
return WarmResult(run=run, just_created=True)
+ integration_id = self.integration.id if with_integration else None
with patch(f"{WARM_SRC}.warm", autospec=True, side_effect=fake_warm):
- result = self._warm(repository=None, github_integration_id=None, branch=None)
+ result = self._warm(repository=None, github_integration_id=integration_id, branch=None)
assert result is not None
task = Task.objects.get(id=result.task_id)
assert task.repository is None
+ assert task.github_integration_id == integration_id
def test_births_multi_repository_draft(self):
def fake_warm(self_warmer, **kwargs):
@@ -504,6 +532,7 @@ class TestCreateTaskWarmReuse(APIBaseTest):
created_by=None,
extra_state: dict[str, Any] | None = None,
origin_product=Task.OriginProduct.USER_CREATED,
+ github_integration: Integration | None = None,
) -> tuple[Task, TaskRun]:
task = Task.objects.create(
team=self.team,
@@ -513,7 +542,7 @@ class TestCreateTaskWarmReuse(APIBaseTest):
created_by=created_by or self.user,
repository=repository,
repositories=repositories or ([repository] if repository else []),
- github_integration=self.integration if repository else None,
+ github_integration=github_integration or (self.integration if repository else None),
)
run = task.create_run(
mode="interactive",
@@ -661,10 +690,19 @@ class TestCreateTaskWarmReuse(APIBaseTest):
assert str(dto.id) != str(warm_task.id)
- def test_reuses_matching_repo_less_warm_task(self):
- warm_task, run = self._warm_run(repository=None, branch=None)
+ @parameterized.expand(
+ [
+ ("without_integration", False),
+ # The PostHog AI composer submits a repo-less task with the team's integration attached;
+ # the warm it booted seconds earlier carries the same pair and must be the run it lands on.
+ ("with_integration", True),
+ ]
+ )
+ def test_reuses_matching_repo_less_warm_task(self, _name, with_integration):
+ integration = self.integration if with_integration else None
+ warm_task, run = self._warm_run(repository=None, branch=None, github_integration=integration)
with patch(f"{FACADE}.signal_task_run_user_message", return_value=True):
- dto = self._create(repository=None, github_integration=None, branch=None)
+ dto = self._create(repository=None, github_integration=integration, branch=None)
assert str(dto.id) == str(warm_task.id)
run.refresh_from_db()
diff --git a/products/tasks/frontend/generated/api.schemas.ts b/products/tasks/frontend/generated/api.schemas.ts
index 8f69fa8063d3..946a6da10a1c 100644
--- a/products/tasks/frontend/generated/api.schemas.ts
+++ b/products/tasks/frontend/generated/api.schemas.ts
@@ -4682,7 +4682,7 @@ export interface WarmTaskRequestApi {
*/
repositories?: string[]
/**
- * Primary key of the team's GitHub integration to clone with when a repository is selected.
+ * Primary key of the team's GitHub integration. Required when a repository is selected (it is what the sandbox clones with). Accepted without a repository too: the warm Run then boots with that integration's GitHub credentials, matching a repo-less create that carries it.
* @nullable
*/
github_integration?: number | null
diff --git a/products/tasks/frontend/generated/api.zod.ts b/products/tasks/frontend/generated/api.zod.ts
index fa8e46daf377..b8ed65b373ec 100644
--- a/products/tasks/frontend/generated/api.zod.ts
+++ b/products/tasks/frontend/generated/api.zod.ts
@@ -3401,7 +3401,9 @@ export const TasksWarmCreateBody = /* @__PURE__ */ zod
github_integration: zod
.number()
.nullish()
- .describe("Primary key of the team's GitHub integration to clone with when a repository is selected."),
+ .describe(
+ "Primary key of the team's GitHub integration. Required when a repository is selected (it is what the sandbox clones with). Accepted without a repository too: the warm Run then boots with that integration's GitHub credentials, matching a repo-less create that carries it."
+ ),
branch: zod
.string()
.max(tasksWarmCreateBodyBranchMax)
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index b3f8a45d8687..5f8870fc05b5 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -85925,7 +85925,7 @@ export namespace Schemas {
*/
repositories?: string[];
/**
- * Primary key of the team's GitHub integration to clone with when a repository is selected.
+ * Primary key of the team's GitHub integration. Required when a repository is selected (it is what the sandbox clones with). Accepted without a repository too: the warm Run then boots with that integration's GitHub credentials, matching a repo-less create that carries it.
* @nullable
*/
github_integration?: number | null;