: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
feat(tasks): notify loop channels when a loop run's pr opens, merges or closes (#106354)
posthog[bot]1d8344138942
diff --git a/products/tasks/backend/facade/loops.py b/products/tasks/backend/facade/loops.pyindex 809773b89b19..b5f1644a53fa 100644--- a/products/tasks/backend/facade/loops.py+++ b/products/tasks/backend/facade/loops.py@@ -75,7 +75,7 @@ MAX_FIX_ITERATIONS_CEILING = 10DEFAULT_POSTHOG_MCP_SCOPES = "read_only"POSTHOG_MCP_SCOPES_CHOICES = ("read_only", "full")NOTIFICATION_CHANNELS = ("push", "email", "slack")-NOTIFICATION_EVENTS = ("run_completed", "run_failed", "pr_created", "needs_attention")+NOTIFICATION_EVENTS = ("run_completed", "run_failed", "pr_created", "pr_merged", "pr_closed", "needs_attention")ALLOWED_GITHUB_TRIGGER_EVENTS = ("issues", "issue_comment", "pull_request", "push")MAX_LOOP_REPOSITORIES = 1diff --git a/products/tasks/backend/logic/services/loop_runs.py b/products/tasks/backend/logic/services/loop_runs.pyindex c5f4647a5e10..60326c84494a 100644--- a/products/tasks/backend/logic/services/loop_runs.py+++ b/products/tasks/backend/logic/services/loop_runs.py@@ -970,3 +970,58 @@ def dispatch_loop_run_terminal_notification(loop_id: str, team_id: int, event: sif isinstance(final_message, str) and final_message:payload = {**payload, "report": final_message}dispatch_loop_event(loop, event, payload)+++LOOP_PR_EVENTS = ("pr_created", "pr_merged", "pr_closed")+LOOP_NOTIFIED_PR_EVENTS_STATE_KEY = "loop_notified_pr_events"+_LOOP_PR_EVENT_BODIES = {+ "pr_created": "Opened {pr_url}",+ "pr_merged": "Merged {pr_url}",+ "pr_closed": "Closed without merging: {pr_url}",+}+++def dispatch_loop_pr_notification(run_id: str, event: str, pr_url: str) -> bool:+ """Notify a loop's channels that one of its runs opened, merged, or closed a PR.++ Returns True when the event went out. Each ``(event, pr_url)`` goes out once per run, because+ GitHub can redeliver a webhook.+ """+ if event not in LOOP_PR_EVENTS:+ return False+ task_run = TaskRun.objects.select_related("task").filter(id=run_id).first()+ if task_run is None:+ return False+ state = task_run.state if isinstance(task_run.state, dict) else {}+ loop_id = task_run.task.loop_id or state.get("loop_id")+ if not loop_id:+ return False+ # Scoped to the run's team for the same reason as handle_loop_run_terminal: run state is+ # writable through the run-update endpoint.+ loop = Loop.objects.for_team(task_run.team_id, canonical=True).filter(id=loop_id).first()+ if loop is None:+ return False++ dedupe_key = f"{event}:{pr_url}"+ with transaction.atomic():+ locked = TaskRun.objects.select_for_update().get(id=task_run.id)+ locked_state = locked.state if isinstance(locked.state, dict) else {}+ notified = locked_state.get(LOOP_NOTIFIED_PR_EVENTS_STATE_KEY)+ notified = notified if isinstance(notified, list) else []+ if dedupe_key in notified:+ return False+ locked.state = {**locked_state, LOOP_NOTIFIED_PR_EVENTS_STATE_KEY: [*notified, dedupe_key]}+ locked.save(update_fields=["state", "updated_at"])++ dispatch_loop_event(+ loop,+ event,+ {+ "task_id": str(task_run.task_id),+ "task_run_id": str(task_run.id),+ "url": pr_url,+ "body": _LOOP_PR_EVENT_BODIES[event].format(pr_url=pr_url),+ "dedupe_key": dedupe_key,+ },+ )+ return Truediff --git a/products/tasks/backend/loop_notifications.py b/products/tasks/backend/loop_notifications.pyindex c88fa7d06c32..ec0e3af6ef53 100644--- a/products/tasks/backend/loop_notifications.py+++ b/products/tasks/backend/loop_notifications.py@@ -9,7 +9,8 @@ Celery task and Temporal activity contexts alike, no request assumed.(all optional): ``title`` / ``body`` override the generated copy, ``url``links to the run or PR, ``task_id`` / ``task_run_id`` identify the run forpush deep-linking and email idempotency, ``report`` is the run's final agent-message, delivered in email and Slack bodies.+message, delivered in email and Slack bodies. ``dedupe_key`` replaces the run id in the email+idempotency key, for events that can happen more than once per run."""from typing import Any@@ -49,6 +50,8 @@ _EVENT_DEFAULTS: dict[str, tuple[str, str]] = {"run_completed": ("finished", "The run finished successfully."),"run_failed": ("failed", "The run failed. Check the run for details."),"pr_created": ("opened a PR", "A new pull request was opened."),+ "pr_merged": ("had a PR merged", "A pull request from this loop was merged."),+ "pr_closed": ("had a PR closed", "A pull request from this loop was closed without merging."),"needs_attention": ("needs attention", "This loop needs your attention."),}@@ -155,7 +158,8 @@ def _send_email(if not is_email_available():returntry:- campaign_key = f"loop_run_summary:{loop.id}:{payload.get('task_run_id') or payload.get('fire_key') or event}"+ dedupe_key = payload.get("dedupe_key") or payload.get("task_run_id") or payload.get("fire_key") or event+ campaign_key = f"loop_run_summary:{loop.id}:{dedupe_key}"template_context = {"loop_name": loop.name,"event_title": title,diff --git a/products/tasks/backend/tasks/tasks.py b/products/tasks/backend/tasks/tasks.pyindex 9e50bceb753e..8e3aa8456c32 100644--- a/products/tasks/backend/tasks/tasks.py+++ b/products/tasks/backend/tasks/tasks.py@@ -63,3 +63,13 @@ def resume_workflow_step_for_run_deferred(run_id: str) -> None:@shared_task(ignore_result=True)def notify_slack_thread_pr_closed(run_id: str, pr_url: str, merged: bool = False) -> None:post_pr_closed_slack_update(run_id, pr_url, merged=merged)+++# No retries: the run records the event before it goes out, so a retry finds it and sends nothing.+@shared_task(ignore_result=True)+def dispatch_loop_pr_notification_task(run_id: str, event: str, pr_url: str) -> None:+ from products.tasks.backend.logic.services.loop_runs import ( # noqa: PLC0415 (keep temporalio off the celery import path)+ dispatch_loop_pr_notification,+ )++ dispatch_loop_pr_notification(run_id, event, pr_url)diff --git a/products/tasks/backend/tests/test_loop_notifications.py b/products/tasks/backend/tests/test_loop_notifications.pyindex cd31b316f8a2..a4f7132e3bb9 100644--- a/products/tasks/backend/tests/test_loop_notifications.py+++ b/products/tasks/backend/tests/test_loop_notifications.py@@ -249,6 +249,20 @@ class TestDispatchLoopEventEmailReport(LoopNotificationsTestCase):template_context = mock_email_message_cls.call_args.kwargs["template_context"]self.assertEqual(template_context["report"], expected_report)+ @patch(f"{LOOP_NOTIFICATIONS_MODULE}.create_notification")+ @patch(f"{LOOP_NOTIFICATIONS_MODULE}.is_email_available", return_value=True)+ @patch(f"{LOOP_NOTIFICATIONS_MODULE}.EmailMessage")+ def test_pr_event_email_does_not_share_the_run_email_key(+ self, mock_email_message_cls, _mock_email_available, _mock_create_notification+ ):+ loop = self.create_loop(notifications={"email": {"enabled": True, "events": ["run_completed", "pr_merged"]}})++ dispatch_loop_event(loop, "run_completed", {"task_run_id": "run-1"})+ dispatch_loop_event(loop, "pr_merged", {"task_run_id": "run-1", "dedupe_key": "pr_merged:https://x/pull/1"})++ campaign_keys = [call.kwargs["campaign_key"] for call in mock_email_message_cls.call_args_list]+ self.assertEqual(len(set(campaign_keys)), 2)+class TestDispatchLoopEventSlackReport(LoopNotificationsTestCase):def setUp(self):diff --git a/products/tasks/backend/tests/test_loop_runs.py b/products/tasks/backend/tests/test_loop_runs.pyindex 8e1bf0275f1f..7625588aa170 100644--- a/products/tasks/backend/tests/test_loop_runs.py+++ b/products/tasks/backend/tests/test_loop_runs.py@@ -20,6 +20,7 @@ from products.tasks.backend.logic.services.loop_runs import (LOOP_RATE_CAP_PER_DAY,LOOP_TEAM_RATE_CAP_PER_DAY,TRIGGER_CONTEXT_MAX_BYTES,+ dispatch_loop_pr_notification,fire_loop,handle_loop_run_terminal,render_context_target_block,@@ -1169,3 +1170,46 @@ class TestTerminalizeUnstartedTaskRun(LoopRunsTestCase):"run_failed",{"task_id": str(task_run.task_id), "task_run_id": str(task_run.id), "status": TaskRun.Status.FAILED},)+++class TestDispatchLoopPrNotification(LoopRunsTestCase):+ PR_URL = "https://github.com/posthog/posthog/pull/42"++ def make_run(self, team: Team, *, loop: Loop | None = None, state_loop_id: str | None = None) -> TaskRun:+ task = Task.objects.create(+ team=team,+ created_by=self.user,+ title="Loop run",+ description="d",+ origin_product=Task.OriginProduct.LOOP,+ loop=loop,+ )+ return task.create_run(mode="background", extra_state={"loop_id": state_loop_id} if state_loop_id else None)++ @patch(f"{LOOP_RUNS_MODULE}.dispatch_loop_event")+ def test_sends_each_pr_event_once_per_run(self, mock_dispatch):+ loop = self.create_loop()+ run = self.make_run(self.team, loop=loop)++ sent = [+ dispatch_loop_pr_notification(str(run.id), "pr_merged", self.PR_URL),+ dispatch_loop_pr_notification(str(run.id), "pr_merged", self.PR_URL),+ dispatch_loop_pr_notification(str(run.id), "pr_created", self.PR_URL),+ ]++ self.assertEqual(sent, [True, False, True])+ first_loop, first_event, first_payload = mock_dispatch.call_args_list[0].args+ self.assertEqual((first_loop.id, first_event), (loop.id, "pr_merged"))+ self.assertEqual(first_payload["url"], self.PR_URL)+ self.assertEqual(first_payload["body"], f"Merged {self.PR_URL}")+ self.assertEqual(first_payload["dedupe_key"], f"pr_merged:{self.PR_URL}")++ @parameterized.expand([("run_outside_a_loop", False), ("forged_loop_id_from_another_team", True)])+ @patch(f"{LOOP_RUNS_MODULE}.dispatch_loop_event")+ def test_sends_nothing_without_a_loop_in_the_runs_team(self, _name, forge_loop_id, mock_dispatch):+ other_team = Team.objects.create(organization=self.organization, name="Other Team")+ victim_loop = self.create_loop()+ run = self.make_run(other_team, state_loop_id=str(victim_loop.id) if forge_loop_id else None)++ self.assertFalse(dispatch_loop_pr_notification(str(run.id), "pr_closed", self.PR_URL))+ mock_dispatch.assert_not_called()diff --git a/products/tasks/backend/tests/test_webhooks.py b/products/tasks/backend/tests/test_webhooks.pyindex ae60c2cbe0da..ab80fcd290b0 100644--- a/products/tasks/backend/tests/test_webhooks.py+++ b/products/tasks/backend/tests/test_webhooks.py@@ -25,7 +25,7 @@ from posthog.models.user_integration import UserIntegrationfrom products.signals.backend.implementation_pr import fetch_implementation_pr_state_for_reportsfrom products.signals.backend.models import SignalActorKind, SignalReport, SignalReportAssignment, SignalReportTaskfrom products.tasks.backend.facade.api import find_signal_implementation_run-from products.tasks.backend.models import Task, TaskRun, TaskThreadMessage+from products.tasks.backend.models import Loop, Task, TaskRun, TaskThreadMessagefrom products.tasks.backend.webhooks import _task_run_scope_team_ids, find_task_run@@ -580,6 +580,51 @@ class TestGitHubPRWebhook(TestCase):if expected_enqueues:mock_delay.assert_called_once_with(str(run.id), pr_url, merged=merged)+ @parameterized.expand(+ [+ ("opened", "opened", False, True, "pr_created"),+ ("merged", "closed", True, True, "pr_merged"),+ ("closed", "closed", False, True, "pr_closed"),+ ("closed_outside_a_loop", "closed", False, False, None),+ ]+ )+ @patch("posthog.ingress.github.provider.get_instance_setting")+ @patch("posthog.github.pull_request_events.posthoganalytics.capture")+ def test_pr_event_on_loop_run_queues_loop_notification(+ self, _name, action, merged, in_loop, expected_event, _mock_capture, mock_get_secret+ ):+ mock_get_secret.return_value = self.webhook_secret+ pr_url = "https://github.com/posthog/posthog/pull/795"+ loop = Loop(team=self.team, created_by=self.user, name="Nightly", instructions="i", runtime_adapter="claude")+ loop.save()+ task = Task.objects.create(+ team=self.team,+ created_by=self.user,+ title="Loop task",+ description="",+ origin_product=Task.OriginProduct.LOOP if in_loop else Task.OriginProduct.USER_CREATED,+ repository="posthog/posthog",+ loop=loop if in_loop else None,+ )+ run = TaskRun.objects.create(+ task=task,+ team=self.team,+ status=TaskRun.Status.COMPLETED,+ state={"verified_pr_urls": [pr_url]},+ output={"pr_url": pr_url},+ )+ payload = {"action": action, "pull_request": {"html_url": pr_url, "merged": merged}}++ with patch("products.tasks.backend.tasks.tasks.dispatch_loop_pr_notification_task.delay") as mock_delay:+ with self.captureOnCommitCallbacks(execute=True):+ response = self._make_webhook_request(payload)++ self.assertEqual(response.status_code, 202)+ if expected_event:+ mock_delay.assert_called_once_with(str(run.id), expected_event, pr_url)+ else:+ mock_delay.assert_not_called()+@patch("posthog.ingress.github.provider.get_instance_setting")@patch("posthog.github.pull_request_events.posthoganalytics.capture")def test_pr_closed_cancel_failure_keeps_webhook_successful(self, _mock_capture, mock_get_secret):diff --git a/products/tasks/backend/webhooks.py b/products/tasks/backend/webhooks.pyindex 140388ba751a..05f901d82dc8 100644--- a/products/tasks/backend/webhooks.py+++ b/products/tasks/backend/webhooks.py@@ -310,6 +310,11 @@ def handle_pull_request_event(payload: dict) -> None:if action == "closed" and task_run and pr_url in claimed_pr_urls:_notify_slack_thread_on_close(task_run, pr_url, merged=merged)+ # Re-read after the backstop, which can bind a just-opened PR to the run.+ if analytics_event in {"pr_created", "pr_merged", "pr_closed"} and task_run is not None:+ if pr_url in read_pr_urls(task_run.output if isinstance(task_run.output, dict) else {}):+ _notify_loop_on_pr_event(task_run, analytics_event, pr_url)+def handle_pull_request_review_event(payload: dict) -> None:"""Process a verified pull_request_review webhook event.@@ -535,6 +540,29 @@ def _notify_slack_thread_on_close(task_run: TaskRun, pr_url: str, *, merged: bootransaction.on_commit(_enqueue)+def _notify_loop_on_pr_event(task_run: TaskRun, event: str, pr_url: str) -> None:+ """Queue the loop notification for a PR a loop run opened, merged, or closed.++ The in-memory check keeps runs outside any loop off the queue. Best-effort: the webhook must+ stay 2xx if the broker is down.+ """+ state = task_run.state if isinstance(task_run.state, dict) else {}+ if not task_run.task.loop_id and not state.get("loop_id"):+ return++ def _enqueue() -> None:+ try:+ from products.tasks.backend.tasks.tasks import ( # noqa: PLC0415 — keeps the Celery task module off the webhook import path+ dispatch_loop_pr_notification_task,+ )++ dispatch_loop_pr_notification_task.delay(str(task_run.id), event, pr_url)+ except Exception:+ logger.warning("github_pr_webhook_loop_pr_enqueue_failed", run_id=str(task_run.id), exc_info=True)++ transaction.on_commit(_enqueue)++def _record_run_output_field(task_run: TaskRun, key: str, value: str | bool, failure_log_event: str) -> bool:"""Idempotently merge ``{key: value}`` into a run's ``output`` JSON under a row lock.diff --git a/products/tasks/frontend/generated/api.schemas.ts b/products/tasks/frontend/generated/api.schemas.tsindex 016da7993de0..e8b54e0c95e8 100644--- a/products/tasks/frontend/generated/api.schemas.ts+++ b/products/tasks/frontend/generated/api.schemas.ts@@ -344,6 +344,8 @@ export interface LoopConnectorsApi {* * `run_completed` - run_completed* * `run_failed` - run_failed* * `pr_created` - pr_created+ * * `pr_merged` - pr_merged+ * * `pr_closed` - pr_closed* * `needs_attention` - needs_attention*/export type EventsEnumApi = (typeof EventsEnumApi)[keyof typeof EventsEnumApi]@@ -352,6 +354,8 @@ export const EventsEnumApi = {RunCompleted: 'run_completed',RunFailed: 'run_failed',PrCreated: 'pr_created',+ PrMerged: 'pr_merged',+ PrClosed: 'pr_closed',NeedsAttention: 'needs_attention',} as const@@ -363,7 +367,7 @@ export type LoopNotificationChannelApiParams = { [key: string]: unknown }export interface LoopNotificationChannelApi {/** Whether this channel is active. */enabled?: boolean- /** Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention. */+ /** Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention. */events?: EventsEnumApi[]/** Channel-specific parameters, e.g. Slack's `integration_id` and `channel`. */params?: LoopNotificationChannelApiParamsdiff --git a/products/tasks/frontend/generated/api.zod.ts b/products/tasks/frontend/generated/api.zod.tsindex 6725fe751133..582452838bb2 100644--- a/products/tasks/frontend/generated/api.zod.ts+++ b/products/tasks/frontend/generated/api.zod.ts@@ -169,14 +169,21 @@ export const LoopsCreateBody = /* @__PURE__ */ zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -194,14 +201,21 @@ export const LoopsCreateBody = /* @__PURE__ */ zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -219,14 +233,21 @@ export const LoopsCreateBody = /* @__PURE__ */ zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -470,14 +491,21 @@ export const LoopsPartialUpdateBody = /* @__PURE__ */ zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -495,14 +523,21 @@ export const LoopsPartialUpdateBody = /* @__PURE__ */ zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -520,14 +555,21 @@ export const LoopsPartialUpdateBody = /* @__PURE__ */ zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex ffcef9bcf6c8..7268510bac20 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -38862,6 +38862,8 @@ export namespace Schemas {* * `run_completed` - run_completed* * `run_failed` - run_failed* * `pr_created` - pr_created+ * * `pr_merged` - pr_merged+ * * `pr_closed` - pr_closed* * `needs_attention` - needs_attention*/export type EventsEnum = typeof EventsEnum[keyof typeof EventsEnum];@@ -38871,6 +38873,8 @@ export namespace Schemas {RunCompleted: 'run_completed',RunFailed: 'run_failed',PrCreated: 'pr_created',+ PrMerged: 'pr_merged',+ PrClosed: 'pr_closed',NeedsAttention: 'needs_attention',} as const;@@ -57089,7 +57093,7 @@ export namespace Schemas {export interface LoopNotificationChannel {/** Whether this channel is active. */enabled?: boolean;- /** Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention. */+ /** Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention. */events?: EventsEnum[];/** Channel-specific parameters, e.g. Slack's `integration_id` and `channel`. */params?: LoopNotificationChannelParams;diff --git a/services/mcp/src/generated/tasks/api.ts b/services/mcp/src/generated/tasks/api.tsindex c66f1c985bc0..9fdc159d2c5b 100644--- a/services/mcp/src/generated/tasks/api.ts+++ b/services/mcp/src/generated/tasks/api.ts@@ -193,14 +193,21 @@ export const LoopsCreateBody = () => zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -218,14 +225,21 @@ export const LoopsCreateBody = () => zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -243,14 +257,21 @@ export const LoopsCreateBody = () => zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -508,14 +529,21 @@ export const LoopsPartialUpdateBody = () => zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -533,14 +561,21 @@ export const LoopsPartialUpdateBody = () => zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())@@ -558,14 +593,21 @@ export const LoopsPartialUpdateBody = () => zodevents: zod.array(zod- .enum(['run_completed', 'run_failed', 'pr_created', 'needs_attention'])+ .enum([+ 'run_completed',+ 'run_failed',+ 'pr_created',+ 'pr_merged',+ 'pr_closed',+ 'needs_attention',+ ]).describe(- '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `needs_attention` - needs_attention'+ '\* `run_completed` - run_completed\n\* `run_failed` - run_failed\n\* `pr_created` - pr_created\n\* `pr_merged` - pr_merged\n\* `pr_closed` - pr_closed\n\* `needs_attention` - needs_attention')).optional().describe(- 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.'+ 'Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.'),params: zod.record(zod.string(), zod.unknown())diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-create-prepare.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-create-prepare.jsonindex 2bd7d499a6b8..e7253c5bbdce 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-create-prepare.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-create-prepare.json@@ -135,10 +135,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"@@ -163,10 +170,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"@@ -191,10 +205,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-partial-update.jsonindex 296485e7bbff..50a06f6824c5 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-partial-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-partial-update.json@@ -134,10 +134,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"@@ -162,10 +169,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"@@ -190,10 +204,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-review.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-review.jsonindex 2bd7d499a6b8..e7253c5bbdce 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-review.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/loops-review.json@@ -135,10 +135,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"@@ -163,10 +170,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"@@ -191,10 +205,17 @@"type": "boolean"},"events": {- "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, needs_attention.",+ "description": "Event kinds this channel notifies on. One or more of: run_completed, run_failed, pr_created, pr_merged, pr_closed, needs_attention.","items": {- "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `needs_attention` - needs_attention",- "enum": ["run_completed", "run_failed", "pr_created", "needs_attention"],+ "description": "* `run_completed` - run_completed\n* `run_failed` - run_failed\n* `pr_created` - pr_created\n* `pr_merged` - pr_merged\n* `pr_closed` - pr_closed\n* `needs_attention` - needs_attention",+ "enum": [+ "run_completed",+ "run_failed",+ "pr_created",+ "pr_merged",+ "pr_closed",+ "needs_attention"+ ],"type": "string"},"type": "array"