: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(subscriptions): add hourly frequency option (#58418)
Paul D'Ambraa345212e3aca
diff --git a/ee/api/subscription.py b/ee/api/subscription.pyindex ae63a319ddbc..1b5d389f356d 100644--- a/ee/api/subscription.py+++ b/ee/api/subscription.py@@ -26,7 +26,11 @@ from temporalio.exceptions import WorkflowAlreadyStartedErrorfrom posthog.api.forbid_destroy_model import ForbidDestroyModelfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.shared import UserBasicSerializer-from posthog.constants import SUBSCRIPTION_AI_SUMMARY_PROMPT_GUIDE_FEATURE_FLAG_KEY, AvailableFeature+from posthog.constants import (+ SUBSCRIPTION_AI_SUMMARY_PROMPT_GUIDE_FEATURE_FLAG_KEY,+ SUBSCRIPTION_HOURLY_FREQUENCY_FEATURE_FLAG_KEY,+ AvailableFeature,+)from posthog.event_usage import groupsfrom posthog.exceptions import QuotaLimitExceededfrom posthog.exceptions_capture import capture_exception@@ -48,6 +52,7 @@ from ee.tasks.subscriptions.subscription_utils import DEFAULT_MAX_ASSET_COUNTSUMMARY_QUOTA_CACHE_TTL_SECONDS = 60SUMMARY_CAP_HIT_DEDUPE_TTL_SECONDS = 600+HOURLY_CAP_HIT_DEDUPE_TTL_SECONDS = 600def _summary_quota_cache_key(organization_id) -> str:@@ -58,6 +63,10 @@ def _summary_cap_hit_dedupe_key(organization_id) -> str:return f"subscription:summary_cap_hit:org:{organization_id}"+def _hourly_cap_hit_dedupe_key(organization_id) -> str:+ return f"subscription:hourly_cap_hit:org:{organization_id}"++def _count_active_summaries(organization) -> int:"""Count subscriptions with summary_enabled=True (and not soft-deleted) acrossevery team in this organization. Single source of truth for both the cap-check@@ -158,7 +167,12 @@ class SubscriptionSerializer(serializers.ModelSerializer):"target_value": {"help_text": "Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or full URL for webhook."},- "frequency": {"help_text": "How often to deliver: daily, weekly, monthly, or yearly."},+ "frequency": {+ "help_text": (+ "How often to deliver: hourly, daily, weekly, monthly, or yearly. "+ "Hourly is feature-flagged and limited to one active subscription per organization."+ )+ },"interval": {"help_text": "Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Default 1."},@@ -284,6 +298,17 @@ class SubscriptionSerializer(serializers.ModelSerializer):organization = self.context["get_organization"]()self._validate_summary_enabled_org_limit(organization)+ # Hourly frequency is feature-flagged and capped at one active+ # subscription per organization. Fire whenever the row is *becoming*+ # an active hourly subscription (frequency=hourly AND enabled=True AND+ # deleted=False) but wasn't before — catches creates, frequency+ # changes, re-enables, and undeletes.+ if self._is_becoming_active_hourly(attrs):+ organization = self.context["get_organization"]()+ if not self._hourly_frequency_feature_enabled():+ raise exceptions.PermissionDenied("Hourly subscriptions are not enabled for this organization.")+ self._validate_hourly_org_limit(organization)+return attrsdef _is_becoming_active_summary(self, attrs: dict) -> bool:@@ -347,12 +372,78 @@ class SubscriptionSerializer(serializers.ModelSerializer):# Telemetry must never poison the validation path.pass- def _prompt_guide_feature_enabled(self) -> bool:- """Evaluate the prompt-guide feature flag for the caller's organization.+ def _is_becoming_active_hourly(self, attrs: dict) -> bool:+ pre_frequency = self.instance.frequency if self.instance else None+ pre_enabled = self.instance.enabled if self.instance else True+ pre_deleted = self.instance.deleted if self.instance else False+ post_frequency = attrs.get("frequency", pre_frequency)+ post_enabled = attrs.get("enabled", pre_enabled)+ post_deleted = attrs.get("deleted", pre_deleted)- Scoped by organization (not user) so the gate is stable across a team's+ pre_active_hourly = (+ pre_frequency == Subscription.SubscriptionFrequency.HOURLY and pre_enabled and not pre_deleted+ )+ post_active_hourly = (+ post_frequency == Subscription.SubscriptionFrequency.HOURLY and post_enabled and not post_deleted+ )+ return post_active_hourly and not pre_active_hourly++ def _validate_hourly_org_limit(self, organization) -> None:+ existing = Subscription.objects.filter(+ team__organization_id=organization.id,+ frequency=Subscription.SubscriptionFrequency.HOURLY,+ enabled=True,+ deleted=False,+ )+ if self.instance is not None:+ existing = existing.exclude(pk=self.instance.pk)+ if existing.exists():+ self._capture_hourly_cap_hit(organization)+ raise ValidationError(+ {+ "frequency": [+ "Only one active hourly subscription is allowed per organization. "+ "Disable or delete the existing hourly subscription before adding another."+ ]+ }+ )++ def _capture_hourly_cap_hit(self, organization) -> None:+ # Rate-limited to one event per org per 10 minutes so a misbehaving+ # client retrying in a loop doesn't spam the analytics stream. Within+ # that window the user-visible 400 still fires every time.+ dedupe_key = _hourly_cap_hit_dedupe_key(organization.id)+ if cache.get(dedupe_key):+ return+ cache.set(dedupe_key, True, HOURLY_CAP_HIT_DEDUPE_TTL_SECONDS)++ request = self.context.get("request")+ distinct_id = (+ str(request.user.distinct_id)+ if request and getattr(request, "user", None) and getattr(request.user, "distinct_id", None)+ else f"team_{self.context.get('team_id')}"+ )+ try:+ posthoganalytics.capture(+ distinct_id=distinct_id,+ event="subscription_hourly_cap_hit",+ properties={+ "team_id": self.context.get("team_id"),+ "organization_id": str(organization.id),+ "is_create": self.instance is None,+ },+ groups={"organization": str(organization.id)},+ )+ except Exception:+ # Telemetry must never poison the validation path.+ pass++ def _evaluate_feature_flag(self, flag_key: str) -> bool:+ """Evaluate a feature flag for the caller's organization.++ Scoped by organization (not user) so gates are stable across a team'smembers. `only_evaluate_locally=False` so we respect server-side cohort- / property conditions — this isn't on a hot path.+ / property conditions — these checks aren't on a hot path."""request = self.context.get("request")if not request or not getattr(request, "user", None) or not getattr(request.user, "distinct_id", None):@@ -361,7 +452,7 @@ class SubscriptionSerializer(serializers.ModelSerializer):org_id = str(organization.id) if organization else ""return bool(posthoganalytics.feature_enabled(- SUBSCRIPTION_AI_SUMMARY_PROMPT_GUIDE_FEATURE_FLAG_KEY,+ flag_key,str(request.user.distinct_id),groups={"organization": org_id},group_properties={"organization": {"id": org_id}},@@ -369,6 +460,12 @@ class SubscriptionSerializer(serializers.ModelSerializer):))+ def _hourly_frequency_feature_enabled(self) -> bool:+ return self._evaluate_feature_flag(SUBSCRIPTION_HOURLY_FREQUENCY_FEATURE_FLAG_KEY)++ def _prompt_guide_feature_enabled(self) -> bool:+ return self._evaluate_feature_flag(SUBSCRIPTION_AI_SUMMARY_PROMPT_GUIDE_FEATURE_FLAG_KEY)+def _validate_dashboard_export_subscription(self, attrs):dashboard = attrs.get("dashboard") or (self.instance.dashboard if self.instance else None)if dashboard is None:diff --git a/ee/api/test/test_subscription.py b/ee/api/test/test_subscription.pyindex e62c27ac2ead..5baadad48556 100644--- a/ee/api/test/test_subscription.py+++ b/ee/api/test/test_subscription.py@@ -596,6 +596,74 @@ class TestSubscriptionTemporal(APILicensedTest):assert response.status_code == status.HTTP_403_FORBIDDENassert "AI summary context" in response.json()["detail"]+ @parameterized.expand(+ [+ ("flag_disabled_rejects", False, status.HTTP_403_FORBIDDEN, "Hourly subscriptions"),+ ("flag_enabled_allows", True, status.HTTP_201_CREATED, "hourly"),+ ]+ )+ def test_hourly_subscription_create_respects_feature_flag(+ self,+ _case_name: str,+ flag_value: bool,+ expected_status: int,+ expected_fragment: str,+ ):+ with patch("ee.api.subscription.posthoganalytics.feature_enabled", return_value=flag_value):+ response = self._create_subscription(frequency="hourly")++ assert response.status_code == expected_status, response.content+ if expected_status == status.HTTP_201_CREATED:+ assert response.json()["frequency"] == expected_fragment+ else:+ assert expected_fragment in response.json()["detail"]++ def test_cannot_create_second_active_hourly_subscription_in_org(self):+ with patch("ee.api.subscription.posthoganalytics.feature_enabled", return_value=True):+ first = self._create_subscription(frequency="hourly", title="first hourly")+ assert first.status_code == status.HTTP_201_CREATED++ second = self._create_subscription(frequency="hourly", title="second hourly")++ assert second.status_code == status.HTTP_400_BAD_REQUEST+ assert "Only one active hourly subscription" in str(second.json())++ def test_can_replace_hourly_subscription_after_disable(self):+ with patch("ee.api.subscription.posthoganalytics.feature_enabled", return_value=True):+ first = self._create_subscription(frequency="hourly", title="first hourly")+ assert first.status_code == status.HTTP_201_CREATED++ # Disable the first hourly subscription — it should free up the org slot.+ patch_response = self.client.patch(+ f"/api/projects/{self.team.id}/subscriptions/{first.json()['id']}",+ {"enabled": False},+ )+ assert patch_response.status_code == status.HTTP_200_OK++ second = self._create_subscription(frequency="hourly", title="second hourly")++ assert second.status_code == status.HTTP_201_CREATED++ def test_hourly_cap_hit_emits_telemetry(self):+ cache.clear()+ with (+ patch("ee.api.subscription.posthoganalytics.feature_enabled", return_value=True),+ patch("ee.api.subscription.posthoganalytics.capture") as mock_capture,+ ):+ first = self._create_subscription(frequency="hourly", title="first hourly")+ assert first.status_code == status.HTTP_201_CREATED++ second = self._create_subscription(frequency="hourly", title="second hourly")+ assert second.status_code == status.HTTP_400_BAD_REQUEST++ cap_hit_calls = [+ c for c in mock_capture.call_args_list if c.kwargs.get("event") == "subscription_hourly_cap_hit"+ ]+ assert len(cap_hit_calls) == 1+ props = cap_hit_calls[0].kwargs["properties"]+ assert props["organization_id"] == str(self.organization.id)+ assert props["is_create"] is True+def _seed_active_summary_subscriptions(self, count: int) -> list[Subscription]:# Build raw rows so we can place an org over its tier cap to exercise# grandfathering paths without going through the enforced API.diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex f9d34bd9f23f..f4ba6569b91b 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -2546,7 +2546,8 @@ export const TargetTypeEnumApi = {} as const/**- * * `daily` - Daily+ * * `hourly` - Hourly+ * `daily` - Daily* `weekly` - Weekly* `monthly` - Monthly* `yearly` - Yearly@@ -2555,6 +2556,7 @@ export type SubscriptionFrequencyEnumApi =(typeof SubscriptionFrequencyEnumApi)[keyof typeof SubscriptionFrequencyEnumApi]export const SubscriptionFrequencyEnumApi = {+ Hourly: 'hourly',Daily: 'daily',Weekly: 'weekly',Monthly: 'monthly',@@ -2612,8 +2614,9 @@ export interface SubscriptionApi {target_type: TargetTypeEnumApi/** Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or full URL for webhook. */target_value: string- /** How often to deliver: daily, weekly, monthly, or yearly.+ /** How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.+ * `hourly` - Hourly* `daily` - Daily* `weekly` - Weekly* `monthly` - Monthly@@ -2742,8 +2745,9 @@ export interface PatchedSubscriptionApi {target_type?: TargetTypeEnumApi/** Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or full URL for webhook. */target_value?: string- /** How often to deliver: daily, weekly, monthly, or yearly.+ /** How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.+ * `hourly` - Hourly* `daily` - Daily* `weekly` - Weekly* `monthly` - Monthlydiff --git a/frontend/src/generated/core/api.zod.ts b/frontend/src/generated/core/api.zod.tsindex 3ff64fe1b813..3adc0145ca77 100644--- a/frontend/src/generated/core/api.zod.ts+++ b/frontend/src/generated/core/api.zod.ts@@ -2594,10 +2594,12 @@ export const SubscriptionsCreateBody = /* @__PURE__ */ zod'Recipient(s): comma-separated email addresses for email, Slack channel name\/ID for slack, or full URL for webhook.'),frequency: zod- .enum(['daily', 'weekly', 'monthly', 'yearly'])- .describe('\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly')+ .enum(['hourly', 'daily', 'weekly', 'monthly', 'yearly']).describe(- 'How often to deliver: daily, weekly, monthly, or yearly.\n\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'+ '\* `hourly` - Hourly\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'+ )+ .describe(+ 'How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.\n\n\* `hourly` - Hourly\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'),interval: zod.number()@@ -2700,10 +2702,12 @@ export const SubscriptionsUpdateBody = /* @__PURE__ */ zod'Recipient(s): comma-separated email addresses for email, Slack channel name\/ID for slack, or full URL for webhook.'),frequency: zod- .enum(['daily', 'weekly', 'monthly', 'yearly'])- .describe('\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly')+ .enum(['hourly', 'daily', 'weekly', 'monthly', 'yearly'])+ .describe(+ '\* `hourly` - Hourly\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'+ ).describe(- 'How often to deliver: daily, weekly, monthly, or yearly.\n\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'+ 'How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.\n\n\* `hourly` - Hourly\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'),interval: zod.number()@@ -2808,11 +2812,13 @@ export const SubscriptionsPartialUpdateBody = /* @__PURE__ */ zod'Recipient(s): comma-separated email addresses for email, Slack channel name\/ID for slack, or full URL for webhook.'),frequency: zod- .enum(['daily', 'weekly', 'monthly', 'yearly'])- .describe('\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly')+ .enum(['hourly', 'daily', 'weekly', 'monthly', 'yearly'])+ .describe(+ '\* `hourly` - Hourly\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'+ ).optional().describe(- 'How often to deliver: daily, weekly, monthly, or yearly.\n\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'+ 'How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.\n\n\* `hourly` - Hourly\n\* `daily` - Daily\n\* `weekly` - Weekly\n\* `monthly` - Monthly\n\* `yearly` - Yearly'),interval: zod.number()diff --git a/frontend/src/lib/components/Subscriptions/subscriptionLogic.ts b/frontend/src/lib/components/Subscriptions/subscriptionLogic.tsindex cfadb8acf6e1..729ee5e781bd 100644--- a/frontend/src/lib/components/Subscriptions/subscriptionLogic.ts+++ b/frontend/src/lib/components/Subscriptions/subscriptionLogic.ts@@ -192,7 +192,7 @@ export const subscriptionLogic = kea<subscriptionLogicType>([setSubscriptionValue: ({ name, value }) => {const key = Array.isArray(name) ? name[0] : nameif (key === 'frequency') {- if (value === 'daily') {+ if (value === 'daily' || value === 'hourly') {actions.setSubscriptionValues({bysetpos: null,byweekday: null,diff --git a/frontend/src/lib/components/Subscriptions/utils.tsx b/frontend/src/lib/components/Subscriptions/utils.tsxindex da0f68c90a2a..50c847af854e 100644--- a/frontend/src/lib/components/Subscriptions/utils.tsx+++ b/frontend/src/lib/components/Subscriptions/utils.tsx@@ -1,7 +1,7 @@import { RRule } from 'rrule'import { IconLetter } from '@posthog/icons'-import { LemonSelectOptionLeaf, LemonSelectOptions } from '@posthog/lemon-ui'+import { LemonSelectOption, LemonSelectOptionLeaf, LemonSelectOptions } from '@posthog/lemon-ui'import { IconSlack } from 'lib/lemon-ui/icons'import { range } from 'lib/utils'@@ -43,17 +43,29 @@ export const targetTypeOptions: LemonSelectOptions<'email' | 'slack'> = [export const intervalOptions: LemonSelectOptions<number> = range(1, 13).map((x) => ({ value: x, label: x.toString() }))-export const frequencyOptionsSingular: LemonSelectOptions<'daily' | 'weekly' | 'monthly'> = [+export type FrequencyOptionValue = 'hourly' | 'daily' | 'weekly' | 'monthly'++// Typed as the concrete `LemonSelectOption[]` (not the `LemonSelectOptions` union of+// `Section[] | Option[]`) so callers can `[...hourly, ...daily-monthly]` without+// the union widening to `(Section | Option)[]` and losing assignability.+export const frequencyOptionsSingular: LemonSelectOption<FrequencyOptionValue>[] = [{ value: 'daily', label: 'day' },{ value: 'weekly', label: 'week' },{ value: 'monthly', label: 'month' },]-export const frequencyOptionsPlural: LemonSelectOptions<'daily' | 'weekly' | 'monthly'> = [+export const frequencyOptionsPlural: LemonSelectOption<FrequencyOptionValue>[] = [{ value: 'daily', label: 'days' },{ value: 'weekly', label: 'weeks' },{ value: 'monthly', label: 'months' },]+export const hourlyFrequencyOptionSingular: LemonSelectOption<FrequencyOptionValue>[] = [+ { value: 'hourly', label: 'hour' },+]+export const hourlyFrequencyOptionPlural: LemonSelectOption<FrequencyOptionValue>[] = [+ { value: 'hourly', label: 'hours' },+]+export const weekdayOptions: LemonSelectOptionLeaf<'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday'>[] = [@@ -96,6 +108,7 @@ const RRULE_WEEKDAY_MAP: Record<string, (typeof RRule)['MO']> = {}const RRULE_FREQ_MAP: Record<string, number> = {+ hourly: RRule.HOURLY,daily: RRule.DAILY,weekly: RRule.WEEKLY,monthly: RRule.MONTHLY,diff --git a/frontend/src/lib/components/Subscriptions/views/EditSubscription.tsx b/frontend/src/lib/components/Subscriptions/views/EditSubscription.tsxindex 5700cd0f64a8..fe3f8ed33daf 100644--- a/frontend/src/lib/components/Subscriptions/views/EditSubscription.tsx+++ b/frontend/src/lib/components/Subscriptions/views/EditSubscription.tsx@@ -11,6 +11,7 @@ import { UserActivityIndicator } from 'lib/components/UserActivityIndicator/Userimport { usersLemonSelectOptions } from 'lib/components/UserSelectItem'import { FEATURE_FLAGS } from 'lib/constants'import { dayjs } from 'lib/dayjs'+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { integrationsLogic } from 'lib/integrations/integrationsLogic'import { SlackChannelPicker, SlackNotConfiguredBanner } from 'lib/integrations/SlackIntegrationHelpers'import { LemonBanner } from 'lib/lemon-ui/LemonBanner'@@ -37,6 +38,8 @@ import {frequencyOptionsPlural,frequencyOptionsSingular,getNextDeliveryDate,+ hourlyFrequencyOptionPlural,+ hourlyFrequencyOptionSingular,intervalOptions,monthlyWeekdayOptions,targetTypeOptions,@@ -81,9 +84,18 @@ export function EditSubscription({const { deleteSubscription } = useActions(subscriptionslogic)const { slackIntegrations, integrations } = useValues(integrationsLogic)const { dataProcessingAccepted } = useValues(maxGlobalLogic)+ const hourlySubscriptionsEnabled = useFeatureFlag('SUBSCRIPTION_HOURLY_FREQUENCY')const emailDisabled = !preflight?.email_service_available+ // Show the hourly option whenever the feature flag is on for this user/org, OR+ // when the subscription being edited is already hourly (so the user can read /+ // modify a value that was created when the flag was on).+ const showHourlyOption = hourlySubscriptionsEnabled || subscription?.frequency === 'hourly'+ const frequencyOptions = subscription?.interval === 1 ? frequencyOptionsSingular : frequencyOptionsPlural+ const hourlyOption = subscription?.interval === 1 ? hourlyFrequencyOptionSingular : hourlyFrequencyOptionPlural+ const availableFrequencyOptions = showHourlyOption ? [...hourlyOption, ...frequencyOptions] : frequencyOptions+// For new subscriptions, show InsightSelector immediately (useEffect will auto-select)// For editing, wait until subscription data has loaded from API (target_type exists)// We check target_type instead of dashboard_export_insights because old subscriptions@@ -346,13 +358,7 @@ export function EditSubscription({<LemonSelect options={intervalOptions} /></LemonField><LemonField name="frequency">- <LemonSelect- options={- subscription.interval === 1- ? frequencyOptionsSingular- : frequencyOptionsPlural- }- />+ <LemonSelect options={availableFrequencyOptions} /></LemonField>{subscription.frequency === 'weekly' && (@@ -416,7 +422,7 @@ export function EditSubscription({</LemonField></>)}- <span>by</span>+ <span>{subscription.frequency === 'hourly' ? 'starting at' : 'by'}</span><LemonField name="start_date">{({ value, onChange }) => (<LemonSelectdiff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex ba6ecfe211d0..40d69ec97499 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -464,6 +464,7 @@ export const FEATURE_FLAGS = {SQL_EDITOR_VIM_MODE: 'sql-editor-vim-mode', // owner: @arthurdedeusSSE_DASHBOARDS: 'sse-dashboards', // owner: @aspicer #team-analytics-platformSUBSCRIPTION_AI_SUMMARY_PROMPT_GUIDE: 'subscription-ai-summary-prompt-guide', // owner: #team-analytics-platform, gates the per-subscription prompt guide textarea+ SUBSCRIPTION_HOURLY_FREQUENCY: 'subscription-hourly-frequency', // owner: #team-analytics-platform, gates hourly subscription frequency (one active hourly subscription per org)SURVEY_HEADLINE_SUMMARY: 'survey-headline-summary', // owner: @adboio #team-surveysSURVEYS_ERROR_TRACKING_CROSS_SELL: 'surveys-in-error-tracking', // owner: @adboio #team-surveysSURVEYS_FORM_BUILDER: 'surveys-form-builder', // owner: @adboio #team-surveysdiff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 0e3d43bffb34..2185caed1d1c 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -5036,7 +5036,7 @@ export interface SubscriptionType {integration_id?: number | nulltarget_type: stringtarget_value: string- frequency: 'daily' | 'weekly' | 'monthly' | 'yearly'+ frequency: 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly'interval: numberbyweekday: WeekdayType[] | nullbysetpos: number | nulldiff --git a/posthog/constants.py b/posthog/constants.pyindex 2c9f2f381616..8caf90ffe1e9 100644--- a/posthog/constants.py+++ b/posthog/constants.py@@ -315,6 +315,7 @@ PRODUCT_TOUR_TARGETING_FLAG_PREFIX = "product-tour-targeting-"# Server-side evaluation via posthoganalytics; keep in sync with frontend FEATURE_FLAGS.HACKATHONS_SUBSCRIPTIONS_FEATURE_FLAG_KEY = "hackathons_subscriptions"SUBSCRIPTION_AI_SUMMARY_PROMPT_GUIDE_FEATURE_FLAG_KEY = "subscription-ai-summary-prompt-guide"+SUBSCRIPTION_HOURLY_FREQUENCY_FEATURE_FLAG_KEY = "subscription-hourly-frequency"EXPERIMENTS_SYNC_QUERIES_FEATURE_FLAG_KEY = "experiments-sync-queries"GENERATED_DASHBOARD_PREFIX = "Generated Dashboard"diff --git a/posthog/migrations/1153_subscription_hourly_frequency.py b/posthog/migrations/1153_subscription_hourly_frequency.pynew file mode 100644index 000000000000..3a71d7bb7b40--- /dev/null+++ b/posthog/migrations/1153_subscription_hourly_frequency.py@@ -0,0 +1,22 @@+from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [("posthog", "1152_fix_device_bucketing_persist_across_auth")]++ operations = [+ migrations.AlterField(+ model_name="subscription",+ name="frequency",+ field=models.CharField(+ choices=[+ ("hourly", "Hourly"),+ ("daily", "Daily"),+ ("weekly", "Weekly"),+ ("monthly", "Monthly"),+ ("yearly", "Yearly"),+ ],+ max_length=10,+ ),+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex d9eb0d0664a7..bda98e00146d 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1152_fix_device_bucketing_persist_across_auth+1153_subscription_hourly_frequencydiff --git a/posthog/models/subscription.py b/posthog/models/subscription.pyindex e744f24ad20c..70cbb6e138da 100644--- a/posthog/models/subscription.py+++ b/posthog/models/subscription.py@@ -8,7 +8,7 @@ from django.db.models.signals import post_savefrom django.dispatch import receiverfrom django.utils import timezone-from dateutil.rrule import DAILY, FR, MO, MONTHLY, SA, SU, TH, TU, WE, WEEKLY, YEARLY, rrule+from dateutil.rrule import DAILY, FR, HOURLY, MO, MONTHLY, SA, SU, TH, TU, WE, WEEKLY, YEARLY, rrulefrom posthog.exceptions_capture import capture_exceptionfrom posthog.jwt import PosthogJwtAudience, decode_jwt, encode_jwt@@ -51,6 +51,7 @@ class Subscription(models.Model):WEBHOOK = "webhook"class SubscriptionFrequency(models.TextChoices):+ HOURLY = "hourly"DAILY = "daily"WEEKLY = "weekly"MONTHLY = "monthly"@@ -68,6 +69,7 @@ class Subscription(models.Model):RRULE_FIELDS = {"frequency", "count", "interval", "start_date", "until_date", "bysetpos", "byweekday"}_FREQ_MAP: dict[str, int] = {+ SubscriptionFrequency.HOURLY: HOURLY,SubscriptionFrequency.DAILY: DAILY,SubscriptionFrequency.WEEKLY: WEEKLY,SubscriptionFrequency.MONTHLY: MONTHLY,@@ -225,6 +227,7 @@ class Subscription(models.Model):def summary(self):try:human_frequency = {+ "hourly": "hour","daily": "day","weekly": "week","monthly": "month",diff --git a/posthog/models/web_preaggregated/__snapshots__/test_web_pre_aggregated_timezones.ambr b/posthog/models/web_preaggregated/__snapshots__/test_web_pre_aggregated_timezones.ambrindex e461a33f00bd..4b5357d3c7ce 100644--- a/posthog/models/web_preaggregated/__snapshots__/test_web_pre_aggregated_timezones.ambr+++ b/posthog/models/web_preaggregated/__snapshots__/test_web_pre_aggregated_timezones.ambr@@ -473,15 +473,7 @@events__session.session_id AS session_id,any(events__session.`$is_bounce`) AS is_bounce,min(events__session.`$start_timestamp`) AS start_timestamp- FROM- (SELECT events.`$session_id_uuid`,- events.distinct_id,- events.event,- events.person_id,- events.`mat_$browser`,- events.timestamp- FROM events- WHERE and(equals(events.team_id, 99999), greaterOrEquals(toDate(events.timestamp), '2024-01-14'), lessOrEquals(toDate(events.timestamp), '2024-01-18'))) AS events+ FROM eventsLEFT JOIN(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,if(ifNull(equals(uniqMerge(raw_sessions.pageview_uniq), 0), 0), NULL, not(or(ifNull(greater(uniqMerge(raw_sessions.pageview_uniq), 1), 0), ifNull(greater(uniqMerge(raw_sessions.autocapture_uniq), 0), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'America/Sao_Paulo')), max(toTimeZone(raw_sessions.max_timestamp, 'America/Sao_Paulo'))), 10)))) AS `$is_bounce`,@@ -497,7 +489,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(or(and(greaterOrEquals(toTimeZone(events.timestamp, 'America/Sao_Paulo'), assumeNotNull(toDateTime('2024-01-15 00:00:00', 'America/Sao_Paulo'))), lessOrEquals(toTimeZone(events.timestamp, 'America/Sao_Paulo'), assumeNotNull(toDateTime('2024-01-16 23:59:59', 'America/Sao_Paulo')))), 0), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), 1)+ WHERE and(equals(events.team_id, 99999), and(or(and(greaterOrEquals(toTimeZone(events.timestamp, 'America/Sao_Paulo'), assumeNotNull(toDateTime('2024-01-15 00:00:00', 'America/Sao_Paulo'))), lessOrEquals(toTimeZone(events.timestamp, 'America/Sao_Paulo'), assumeNotNull(toDateTime('2024-01-16 23:59:59', 'America/Sao_Paulo')))), 0), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), 1))GROUP BY session_id,breakdown_value)GROUP BY `context.columns.breakdown_value`@@ -627,7 +619,15 @@events__session.session_id AS session_id,any(events__session.`$is_bounce`) AS is_bounce,min(events__session.`$start_timestamp`) AS start_timestamp- FROM events+ FROM+ (SELECT events.`$session_id_uuid`,+ events.distinct_id,+ events.event,+ events.person_id,+ events.`mat_$browser`,+ events.timestamp+ FROM events+ WHERE and(equals(events.team_id, 99999), greaterOrEquals(toDate(events.timestamp), '2024-01-13'), lessOrEquals(toDate(events.timestamp), '2024-01-17'))) AS eventsLEFT JOIN(SELECT toString(reinterpretAsUUID(bitOr(bitShiftLeft(raw_sessions.session_id_v7, 64), bitShiftRight(raw_sessions.session_id_v7, 64)))) AS session_id,if(ifNull(equals(uniqMerge(raw_sessions.pageview_uniq), 0), 0), NULL, not(or(ifNull(greater(uniqMerge(raw_sessions.pageview_uniq), 1), 0), ifNull(greater(uniqMerge(raw_sessions.autocapture_uniq), 0), 0), greaterOrEquals(dateDiff('second', min(toTimeZone(raw_sessions.min_timestamp, 'Europe/Berlin')), max(toTimeZone(raw_sessions.max_timestamp, 'Europe/Berlin'))), 10)))) AS `$is_bounce`,@@ -643,7 +643,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING ifNull(equals(tupleElement(argMax(tuple(person_distinct_id_overrides.is_deleted), person_distinct_id_overrides.version), 1), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 99999), and(or(and(greaterOrEquals(toTimeZone(events.timestamp, 'Europe/Berlin'), assumeNotNull(toDateTime('2024-01-15 00:00:00', 'Europe/Berlin'))), lessOrEquals(toTimeZone(events.timestamp, 'Europe/Berlin'), assumeNotNull(toDateTime('2024-01-16 23:59:59', 'Europe/Berlin')))), 0), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), 1))+ WHERE and(or(and(greaterOrEquals(toTimeZone(events.timestamp, 'Europe/Berlin'), assumeNotNull(toDateTime('2024-01-15 00:00:00', 'Europe/Berlin'))), lessOrEquals(toTimeZone(events.timestamp, 'Europe/Berlin'), assumeNotNull(toDateTime('2024-01-16 23:59:59', 'Europe/Berlin')))), 0), or(equals(events.event, '$pageview'), equals(events.event, '$screen')), 1)GROUP BY session_id,breakdown_value)GROUP BY `context.columns.breakdown_value`diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex ff79df530e69..403d24e5d9f4 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -22867,7 +22867,8 @@ export namespace Schemas {} as const;/**- * * `daily` - Daily+ * * `hourly` - Hourly+ * `daily` - Daily* `weekly` - Weekly* `monthly` - Monthly* `yearly` - Yearly@@ -22876,6 +22877,7 @@ export namespace Schemas {export const SubscriptionFrequencyEnum = {+ Hourly: 'hourly',Daily: 'daily',Weekly: 'weekly',Monthly: 'monthly',@@ -22933,8 +22935,9 @@ export namespace Schemas {target_type: TargetTypeEnum;/** Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or full URL for webhook. */target_value: string;- /** How often to deliver: daily, weekly, monthly, or yearly.+ /** How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.+ * `hourly` - Hourly* `daily` - Daily* `weekly` - Weekly* `monthly` - Monthly@@ -28437,8 +28440,9 @@ export namespace Schemas {target_type?: TargetTypeEnum;/** Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or full URL for webhook. */target_value?: string;- /** How often to deliver: daily, weekly, monthly, or yearly.+ /** How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.+ * `hourly` - Hourly* `daily` - Daily* `weekly` - Weekly* `monthly` - Monthlydiff --git a/services/mcp/src/generated/core/api.ts b/services/mcp/src/generated/core/api.tsindex 35fc8f329375..1cee0985fca3 100644--- a/services/mcp/src/generated/core/api.ts+++ b/services/mcp/src/generated/core/api.ts@@ -344,10 +344,12 @@ export const SubscriptionsCreateBody = /* @__PURE__ */ zod'Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or full URL for webhook.'),frequency: zod- .enum(['daily', 'weekly', 'monthly', 'yearly'])- .describe('* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly')+ .enum(['hourly', 'daily', 'weekly', 'monthly', 'yearly']).describe(- 'How often to deliver: daily, weekly, monthly, or yearly.\n\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly'+ '* `hourly` - Hourly\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly'+ )+ .describe(+ 'How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.\n\n* `hourly` - Hourly\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly'),interval: zod.number()@@ -470,11 +472,13 @@ export const SubscriptionsPartialUpdateBody = /* @__PURE__ */ zod'Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or full URL for webhook.'),frequency: zod- .enum(['daily', 'weekly', 'monthly', 'yearly'])- .describe('* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly')+ .enum(['hourly', 'daily', 'weekly', 'monthly', 'yearly'])+ .describe(+ '* `hourly` - Hourly\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly'+ ).optional().describe(- 'How often to deliver: daily, weekly, monthly, or yearly.\n\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly'+ 'How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.\n\n* `hourly` - Hourly\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly'),interval: zod.number()diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-create.jsonindex f20d97e171df..8adcda26e8d6 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-create.json@@ -71,8 +71,8 @@"type": "boolean"},"frequency": {- "description": "How often to deliver: daily, weekly, monthly, or yearly.\n\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly",- "enum": ["daily", "weekly", "monthly", "yearly"],+ "description": "How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.\n\n* `hourly` - Hourly\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly",+ "enum": ["hourly", "daily", "weekly", "monthly", "yearly"],"type": "string"},"insight": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-partial-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-partial-update.jsonindex 333edf1f7dab..30f90b021bb9 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-partial-update.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/common/subscriptions-partial-update.json@@ -70,8 +70,8 @@"type": "boolean"},"frequency": {- "description": "How often to deliver: daily, weekly, monthly, or yearly.\n\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly",- "enum": ["daily", "weekly", "monthly", "yearly"],+ "description": "How often to deliver: hourly, daily, weekly, monthly, or yearly. Hourly is feature-flagged and limited to one active subscription per organization.\n\n* `hourly` - Hourly\n* `daily` - Daily\n* `weekly` - Weekly\n* `monthly` - Monthly\n* `yearly` - Yearly",+ "enum": ["hourly", "daily", "weekly", "monthly", "yearly"],"type": "string"},"id": {