: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(flags): warn when a lifecycle reads flag calls past retention (#125172)
Phil Haack85c3e53dcae0
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex f321b5260d93..1815b121aabe 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -13287,9 +13287,13 @@ snapshots:scenes-app-insights-flag-called-rebuild-banner--insight-on-flag-calls--light:hash: v1.k794b7964.e667a70f89bbba0a7d5bc3166f2bf3a42a17845518e994975944ee2a31aaee0a.fshegHwDj7O7_Gwl8j5eof7QXffqbc_yldQxsNlkUpQscenes-app-insights-flag-calls-retention-notice--default--dark:- hash: v1.k794b7964.d9aefe5f9ce9d7a864d6bf0338965adf5c01284b0fa767b3db193cbf9102838b.F_x981isYjYR1oKf0BPU3Agkr_bpR7TqheKovVn432o+ hash: v1.k794b7964.20ccba3398f76ea2b88091e558b290bbadac2a2986aebb4fbf11aaed96dd7007.XfNlsSLFg2icPBsHW4S6cBHxBiUxCp6eJR_8O6sb60Escenes-app-insights-flag-calls-retention-notice--default--light:- hash: v1.k794b7964.7923e9cd78a4bd2e62c7f95ce8eb80df0bb9fab29de527b307048b8e5b5011ff.Mrf6YkRMfO82M2uM5Fc4LKBf3vjTEjIDdw4MZ1cPIrA+ hash: v1.k794b7964.c12813e57a6fae4cc18f454b742439c8fab67c25cd801f9f4f910d0f4cf68a49.AdEUCYBogjpl1gR_QBEajhMqLqSYE7BmAiGZ2yVsOd8+ scenes-app-insights-flag-calls-retention-notice--first-period--dark:+ hash: v1.k794b7964.19887b501b8f3644b8f533dd8d5890406c4dd06cc4030f4e00d5afe12db5cd74.DyMNZmR0PK6SE-kQVJNbvhQMaNTlh2XoaIhFC_WI4-A+ scenes-app-insights-flag-calls-retention-notice--first-period--light:+ hash: v1.k794b7964.25678808b05ea0f852ddcaab2d64d2d8c5a9643165935b6d84fed53bf8cd7473.Er2uhGCQiqBkVNJZRvhvK6k6iAeM2lB52PJ638tZld8scenes-app-insights-insight-quick-start--default--dark:hash: v1.k794b7964.f190c463ee799e93ea5d408200712776460a5a9a920977e2b7a85348350fa43b.dcN7n63RW9QEXstFsPgnAaKodbV6piSN7PMhBuHkaGcscenes-app-insights-insight-quick-start--default--light:diff --git a/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.stories.tsx b/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.stories.tsxindex 28a0056a6399..8cb40c5c0fd2 100644--- a/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.stories.tsx+++ b/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.stories.tsx@@ -5,6 +5,14 @@ import { FlagCallsRetentionNotice } from './FlagCallsRetentionNotice'const meta: Meta<typeof FlagCallsRetentionNotice> = {title: 'Scenes-App/Insights/Flag calls retention notice',component: FlagCallsRetentionNotice,+ decorators: [+ // LemonBanner is a size container, so a shrink-to-fit snapshot root collapses it to its padding.+ (Story) => (+ <div className="w-[32rem]">+ <Story />+ </div>+ ),+ ],parameters: {mockDate: '2026-10-07',},@@ -13,4 +21,6 @@ export default metatype Story = StoryObj<typeof FlagCallsRetentionNotice>-export const Default: Story = { args: { retentionStartDate: '2026-07-09' } }+export const Default: Story = { args: { gap: 'periods', retentionStartDate: '2026-07-09' } }++export const FirstPeriod: Story = { args: { gap: 'first-period', retentionStartDate: '2026-07-09' } }diff --git a/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.tsx b/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.tsxindex ee7c375f2e0b..c1900113c37d 100644--- a/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.tsx+++ b/frontend/src/queries/nodes/InsightViz/FlagCallsRetentionNotice.tsx@@ -1,13 +1,25 @@import { LemonBanner } from '@posthog/lemon-ui'import { dayjs } from 'lib/dayjs'-import { FLAG_EVALUATIONS_RETENTION_DAYS } from 'scenes/feature-flags/flagEvaluationsTable'+import { DATE_FORMAT } from 'lib/utils/datetime'+import { FLAG_EVALUATIONS_RETENTION_DAYS, FlagCallsRetentionGap } from 'scenes/feature-flags/flagEvaluationsTable'-export function FlagCallsRetentionNotice({ retentionStartDate }: { retentionStartDate: string }): JSX.Element {+export function FlagCallsRetentionNotice({+ gap,+ retentionStartDate,+}: {+ gap: FlagCallsRetentionGap+ retentionStartDate: string+}): JSX.Element {+ const date = <span translate="no">{dayjs.utc(retentionStartDate).format(DATE_FORMAT)}</span>return (<LemonBanner type="info" className="m-2">- This insight includes feature flag calls from the last {FLAG_EVALUATIONS_RETENTION_DAYS} days only. Periods- before <span translate="no">{dayjs.utc(retentionStartDate).format('MMMM D, YYYY')}</span> show no calls.+ This insight includes feature flag calls from the last {FLAG_EVALUATIONS_RETENTION_DAYS} days only.{' '}+ {gap === 'periods' ? (+ <>Periods before {date} show no calls.</>+ ) : (+ <>The first period depends on calls from before {date}, so its results may be inaccurate.</>+ )}</LemonBanner>)}diff --git a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsxindex 93a98f3a3c36..863cacd70212 100644--- a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx+++ b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx@@ -217,7 +217,7 @@ export function InsightVizDisplay({validationError,validationErrorCode,theme,- showsFlagCallsRetentionNotice,+ flagCallsRetentionGap,flagCallsRetentionStartDate,} = useValues(insightVizDataLogic(insightProps))const { loadData, updateQuerySource } = useActions(insightVizDataLogic(insightProps))@@ -604,8 +604,11 @@ export function InsightVizDisplay({</div>)}- {!embedded && showsFlagCallsRetentionNotice && (- <FlagCallsRetentionNotice retentionStartDate={flagCallsRetentionStartDate} />+ {!embedded && flagCallsRetentionGap && (+ <FlagCallsRetentionNotice+ gap={flagCallsRetentionGap}+ retentionStartDate={flagCallsRetentionStartDate}+ />)}<divclassName={clsx(diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex b8891c646b9e..ec5bc3c9ecb6 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -51670,6 +51670,11 @@"date_to": {"format": "date-time","type": "string"+ },+ "read_from": {+ "description": "The earliest timestamp the query reads, when only its first interval depends on rows from before date_from. Lifecycle sets it to the start of the interval before the range.",+ "format": "date-time",+ "type": "string"}},"required": ["date_from", "date_to"],diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex 97a4b3b534f4..80868767483a 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -7014,6 +7014,12 @@ export interface ResolvedDateRangeResponse {date_from: string/** @format date-time */date_to: string+ /**+ * The earliest timestamp the query reads, when only its first interval depends on rows from before date_from.+ * Lifecycle sets it to the start of the interval before the range.+ * @format date-time+ */+ read_from?: string}export type MultipleBreakdownType =diff --git a/frontend/src/scenes/feature-flags/flagEvaluationsTable.test.ts b/frontend/src/scenes/feature-flags/flagEvaluationsTable.test.tsindex 8d769361cf69..5eb61db17707 100644--- a/frontend/src/scenes/feature-flags/flagEvaluationsTable.test.ts+++ b/frontend/src/scenes/feature-flags/flagEvaluationsTable.test.ts@@ -1,6 +1,6 @@import { dayjs } from 'lib/dayjs'-import { FlagCallsInsightResponse, insightReachesPastFlagEvaluationsRetention } from './flagEvaluationsTable'+import { FlagCallsInsightResponse, flagCallsRetentionGap } from './flagEvaluationsTable'// The UTC date is a day ahead of the local date at UTC-12, and equal to it at UTC+14. Ninety days back is// November 2, 2025, when Havana repeats midnight.@@ -23,37 +23,37 @@ describe('flagEvaluationsTable', () => {})it.each([- ['a range inside the window', '-30d', resolved(daysAgo(30)), undefined, false],- ['a range past the window', '-180d', resolved(daysAgo(180)), undefined, true],- ['all time, which resolves inside the window', 'all', resolved(daysAgo(10)), undefined, true],- ['a query that has not run yet', '-180d', undefined, undefined, false],+ ['a range inside the window', '-30d', resolved(daysAgo(30)), undefined, null],+ ['a range past the window', '-180d', resolved(daysAgo(180)), undefined, 'periods'],+ ['all time, which resolves inside the window', 'all', resolved(daysAgo(10)), undefined, 'periods'],+ ['a query that has not run yet', '-180d', undefined, undefined, null],['the 90-day preset two hours ahead of UTC','-90d',resolved('2025-11-02T00:00:00+02:00', { timezone: 'Africa/Johannesburg' }),undefined,- false,+ null,],['the 90-day preset at UTC+14','-90d',resolved('2025-11-02T00:00:00+14:00', { timezone: 'Pacific/Kiritimati' }),undefined,- false,+ null,],['the 90-day preset at UTC-12','-90d',resolved('2025-11-01T00:00:00-12:00', { timezone: 'Etc/GMT+12' }),undefined,- false,+ null,],['the 90-day preset across a daylight saving change that repeats midnight','-90d',resolved('2025-11-02T00:00:00-04:00', { timezone: 'America/Havana' }),undefined,- false,+ null,],['the 90-day preset in a result cached before team-local midnight',@@ -63,43 +63,43 @@ describe('flagEvaluationsTable', () => {last_refresh: '2026-01-30T21:00:00Z',}),undefined,- false,+ null,],['a range that starts an hour before the team-local window','2025-11-01T23:00:00',resolved('2025-11-01T23:00:00+14:00', { timezone: 'Pacific/Kiritimati' }),undefined,- true,+ 'periods',],['a timezone the browser does not know','-30d',resolved(daysAgo(30), { timezone: 'Mars/Olympus_Mons' }),undefined,- false,+ null,],- ['a previous period inside the window', '-30d', resolved(daysAgo(30)), { compare: true }, false],+ ['a previous period inside the window', '-30d', resolved(daysAgo(30)), { compare: true }, null],['a previous period that doubles the range back past the window','-60d',resolved(daysAgo(60)),{ compare: true },- true,+ 'periods',],['a comparison shifted inside the window','-30d',resolved(daysAgo(30)),{ compare: true, compare_to: '-30d' },- false,+ null,],['a comparison shifted past the window','-30d',resolved(daysAgo(30)),{ compare: true, compare_to: '-1y' },- true,+ 'periods',],['a Metric whose change pill compares against the period before the 90-day preset',@@ -112,16 +112,37 @@ describe('flagEvaluationsTable', () => {},}),undefined,- true,+ 'periods',],['a comparison whose start the backend resolved inside the window','-30d',resolved(daysAgo(30), { resolved_compare_date_range: { date_from: daysAgo(60), date_to: daysAgo(30) } }),{ compare: true, compare_to: '-1y' },- false,+ null,],- ])('insightReachesPastFlagEvaluationsRetention: %s', (_name, dateFrom, response, compareFilter, expected) => {- expect(insightReachesPastFlagEvaluationsRetention({ dateFrom, response, compareFilter })).toBe(expected)+ [+ 'a lifecycle that reads the interval before its range from past the window',+ '-60d',+ { resolved_date_range: { date_from: daysAgo(60), date_to: now(), read_from: daysAgo(120) } },+ undefined,+ 'first-period',+ ],+ [+ 'a query that reads before its range from inside the window',+ '-30d',+ { resolved_date_range: { date_from: daysAgo(30), date_to: now(), read_from: daysAgo(60) } },+ undefined,+ null,+ ],+ [+ 'a range past the window that also reads before it',+ '-100d',+ { resolved_date_range: { date_from: daysAgo(100), date_to: now(), read_from: daysAgo(130) } },+ undefined,+ 'periods',+ ],+ ])('flagCallsRetentionGap: %s', (_name, dateFrom, response, compareFilter, expected) => {+ expect(flagCallsRetentionGap({ dateFrom, response, compareFilter })).toBe(expected)})})diff --git a/frontend/src/scenes/feature-flags/flagEvaluationsTable.ts b/frontend/src/scenes/feature-flags/flagEvaluationsTable.tsindex 548c4f2cfeb5..9cdd88305c98 100644--- a/frontend/src/scenes/feature-flags/flagEvaluationsTable.ts+++ b/frontend/src/scenes/feature-flags/flagEvaluationsTable.ts@@ -95,9 +95,9 @@ function comparedPeriodStart(response: FlagCallsInsightResponse | null | undefined,compareFilter: CompareFilter | null | undefined): dayjs.Dayjs {- const resolvedFrom = response?.resolved_compare_date_range?.date_from- if (resolvedFrom) {- return dayjs(resolvedFrom)+ const resolvedCompareDateRange = response?.resolved_compare_date_range+ if (resolvedCompareDateRange?.date_from) {+ return dayjs(resolvedCompareDateRange.date_from)}if (!compareFilter?.compare) {return start@@ -108,8 +108,15 @@ function comparedPeriodStart(: start.subtract(dayjs(response?.resolved_date_range?.date_to ?? undefined).diff(start), 'millisecond')}-/** Whether the range an insight ran over, or the period it compares against, starts before the table's oldest day. */-export function insightReachesPastFlagEvaluationsRetention({+/**+ * Which part of an insight reads days the table no longer holds.+ * `periods`: its range, or the period it compares against, starts before the table's oldest day.+ * `first-period`: only the rows the query reads before its range are gone. Lifecycle reads the interval before+ * its first one, so that first interval can count a returning person as resurrecting.+ */+export type FlagCallsRetentionGap = 'periods' | 'first-period'++export function flagCallsRetentionGap({dateFrom,response,compareFilter,@@ -118,18 +125,26 @@ export function insightReachesPastFlagEvaluationsRetention({dateFrom: string | null | undefinedresponse: FlagCallsInsightResponse | null | undefinedcompareFilter: CompareFilter | null | undefined-}): boolean {+}): FlagCallsRetentionGap | null {// All time resolves to the oldest row the table still holds, so the resolved range never shows the cutoff.if (dateFrom === 'all') {- return true+ return 'periods'}const resolvedDateRange = response?.resolved_date_rangeif (!resolvedDateRange?.date_from) {- return false+ return null}- const comparedStart = comparedPeriodStart(dayjs(resolvedDateRange.date_from), response, compareFilter)// The window covers whole days in the team timezone. This compares dates, not instants. A DST change can// repeat midnight. The backend starts the 90-day preset at the first midnight. An instant comparison against// the second midnight would show the notice for the preset.- return dateInTimezone(comparedStart, insightTimezone(response)) < flagEvaluationsRetentionStartDate(response)+ const retentionStartDate = flagEvaluationsRetentionStartDate(response)+ const isBeforeRetention = (instant: dayjs.Dayjs): boolean =>+ dateInTimezone(instant, insightTimezone(response)) < retentionStartDate+ if (isBeforeRetention(comparedPeriodStart(dayjs(resolvedDateRange.date_from), response, compareFilter))) {+ return 'periods'+ }+ if (resolvedDateRange.read_from && isBeforeRetention(dayjs(resolvedDateRange.read_from))) {+ return 'first-period'+ }+ return null}diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.tsindex cab0261d7cad..2f6b3d3146be 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts@@ -24,8 +24,9 @@ import { databaseTableListLogic } from 'scenes/data-management/database/databaseimport { dataThemeLogic } from 'scenes/dataThemeLogic'import {FLAG_EVALUATIONS_TABLE,+ FlagCallsRetentionGap,+ flagCallsRetentionGap,flagEvaluationsRetentionStartDate,- insightReachesPastFlagEvaluationsRetention,} from 'scenes/feature-flags/flagEvaluationsTable'import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/types'import { cleanSeriesNodes } from 'scenes/insights/filters/ActionFilter/cleanSeriesNodes'@@ -238,6 +239,7 @@ export interface insightVizDataLogicValues {display: ChartDisplayType | null | undefinedenabledIntervals: IntervalserroredQueryId: any+ flagCallsRetentionGap: FlagCallsRetentionGap | nullflagCallsRetentionStartDate: stringformula: string | null | undefinedformulaNodes: TrendsFormulaNode[]@@ -307,7 +309,6 @@ export interface insightVizDataLogicValues {showPercentStackView: boolean | null | undefinedshowPercentagesOnSeries: boolean | null | undefinedshowValuesOnSeries: boolean | null | undefined- showsFlagCallsRetentionNotice: booleanslowQueryPossibilities: SlowQueryPossibilities[]stickinessFilter: StickinessFilter | null | undefinedsupportsBarValueStacking: boolean@@ -1202,7 +1203,7 @@ export interface insightVizDataLogicMeta {isUsingSessionAnalysis: boolean | Breakdown,query: Node<Record<string, any>> | null) => boolean- showsFlagCallsRetentionNotice: (+ flagCallsRetentionGap: (querySource:| FunnelsQuery| LifecycleQuery@@ -1217,7 +1218,7 @@ export interface insightVizDataLogicMeta {dateRange: DateRange | null | undefined,compareFilter: CompareFilter | null | undefined,insightData: Record<string, any>- ) => boolean+ ) => FlagCallsRetentionGap | nullflagCallsRetentionStartDate: (insightData: Record<string, any>) => stringisNonTimeSeriesDisplay: (display: ChartDisplayType | null | undefined) => booleanisSingleSeriesOutput: (@@ -2316,21 +2317,17 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([query: Node | null) => isUsingSessionAnalysis && !(isInsightVizNode(query) && query.suppressSessionAnalysisWarning),],- showsFlagCallsRetentionNotice: [+ flagCallsRetentionGap: [(s) => [s.querySource, s.dateRange, s.compareFilter, s.insightData],(querySource: InsightQueryNode | null,dateRange: DateRange | null | undefined,compareFilter: CompareFilter | null | undefined,insightData: Record<string, any>- ): boolean =>- !!querySource &&- readsFlagCalls(querySource) &&- insightReachesPastFlagEvaluationsRetention({- dateFrom: dateRange?.date_from,- response: insightData,- compareFilter,- }),+ ): FlagCallsRetentionGap | null =>+ querySource && readsFlagCalls(querySource)+ ? flagCallsRetentionGap({ dateFrom: dateRange?.date_from, response: insightData, compareFilter })+ : null,],flagCallsRetentionStartDate: [(s) => [s.insightData],diff --git a/posthog/schema.py b/posthog/schema.pyindex bf1b2ab4aec5..d9d777eadc0c 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -3222,6 +3222,14 @@ class ResolvedDateRangeResponse(BaseModel):)date_from: AwareDatetimedate_to: AwareDatetime+ read_from: AwareDatetime | None = Field(+ default=None,+ description=(+ "The earliest timestamp the query reads, when only its first interval"+ " depends on rows from before date_from. Lifecycle sets it to the start of"+ " the interval before the range."+ ),+ )class ResultCustomizationBase(BaseModel):diff --git a/products/customer_analytics/frontend/generated/api.schemas.ts b/products/customer_analytics/frontend/generated/api.schemas.tsindex 272dc77a6ea6..15d178969612 100644--- a/products/customer_analytics/frontend/generated/api.schemas.ts+++ b/products/customer_analytics/frontend/generated/api.schemas.ts@@ -1951,6 +1951,8 @@ export interface AccountsTableRelationshipDefinitionApi {export interface ResolvedDateRangeResponseApi {date_from: stringdate_to: string+ /** The earliest timestamp the query reads, when only its first interval depends on rows from before date_from. Lifecycle sets it to the start of the interval before the range. */+ read_from?: string | null}export interface AccountsTableCustomPropertyHistoryPointApi {diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex 678e402c35c8..ebe46e78c18e 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -2629,6 +2629,8 @@ export interface QueryStatusApi {export interface ResolvedDateRangeResponseApi {date_from: stringdate_to: string+ /** The earliest timestamp the query reads, when only its first interval depends on rows from before date_from. Lifecycle sets it to the start of the interval before the range. */+ read_from?: string | null}export interface QueryTimingApi {diff --git a/products/desktop/packages/api-client/src/generated.ts b/products/desktop/packages/api-client/src/generated.tsindex 02447e3e8931..8bac3d95957f 100644--- a/products/desktop/packages/api-client/src/generated.ts+++ b/products/desktop/packages/api-client/src/generated.ts@@ -325,6 +325,7 @@ export namespace Schemas {export type ResolvedDateRangeResponse = {date_from: string;date_to: string;+ read_from?: (string | null) | undefined;};export type QueryTiming = {/**diff --git a/products/marketing_analytics/frontend/generated/api.schemas.ts b/products/marketing_analytics/frontend/generated/api.schemas.tsindex 5575a835bc35..e653ed80a7e4 100644--- a/products/marketing_analytics/frontend/generated/api.schemas.ts+++ b/products/marketing_analytics/frontend/generated/api.schemas.ts@@ -1871,6 +1871,8 @@ export interface QueryStatusApi {export interface ResolvedDateRangeResponseApi {date_from: stringdate_to: string+ /** The earliest timestamp the query reads, when only its first interval depends on rows from before date_from. Lifecycle sets it to the start of the interval before the range. */+ read_from?: string | null}export type WebAnalyticsItemKindApi = (typeof WebAnalyticsItemKindApi)[keyof typeof WebAnalyticsItemKindApi]diff --git a/products/persons/frontend/generated/api.schemas.ts b/products/persons/frontend/generated/api.schemas.tsindex 3dbce55d5f7b..4c2b436b81d0 100644--- a/products/persons/frontend/generated/api.schemas.ts+++ b/products/persons/frontend/generated/api.schemas.ts@@ -681,6 +681,8 @@ export interface QueryStatusApi {export interface ResolvedDateRangeResponseApi {date_from: stringdate_to: string+ /** The earliest timestamp the query reads, when only its first interval depends on rows from before date_from. Lifecycle sets it to the start of the interval before the range. */+ read_from?: string | null}export interface QueryTimingApi {diff --git a/products/product_analytics/backend/hogql_queries/lifecycle/lifecycle_query_runner.py b/products/product_analytics/backend/hogql_queries/lifecycle/lifecycle_query_runner.pyindex 54b2617ad283..a4b24561b9d2 100644--- a/products/product_analytics/backend/hogql_queries/lifecycle/lifecycle_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/lifecycle/lifecycle_query_runner.py@@ -195,9 +195,16 @@ class LifecycleQueryRunner(AnalyticsQueryRunner[LifecycleQueryResponse]):resolved_date_range=ResolvedDateRangeResponse(date_from=self.query_date_range.date_from(),date_to=self.query_date_range.date_to(),+ read_from=self.read_from,),)+ @property+ def read_from(self) -> datetime:+ # Keep equal to the lower bound in event_filter. Lifecycle reads the interval before the first one shown.+ date_range = self.query_date_range+ return date_range.align_with_interval(date_range.date_from()) - date_range.interval_relativedelta()+def format_results(self, response: HogQLQueryResponse) -> list[dict[str, Any]]:"""Format raw lifecycle HogQL response into status-grouped series.@@ -363,6 +370,7 @@ class LifecycleQueryRunner(AnalyticsQueryRunner[LifecycleQueryResponse]):))with self.timings.measure("date_range"):+ # read_from reports this lower bound. Keep the two equal.event_filters.append(parse_expr("{timestamp_field} >= {date_from_start_of_interval} - {one_interval_period}",diff --git a/products/product_analytics/backend/hogql_queries/lifecycle/test/test_lifecycle_query_runner.py b/products/product_analytics/backend/hogql_queries/lifecycle/test/test_lifecycle_query_runner.pyindex d266a4c8c1d6..abcdb2b1482e 100644--- a/products/product_analytics/backend/hogql_queries/lifecycle/test/test_lifecycle_query_runner.py+++ b/products/product_analytics/backend/hogql_queries/lifecycle/test/test_lifecycle_query_runner.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import UTC, datetimefrom types import SimpleNamespaceimport time_machine@@ -2327,21 +2327,26 @@ class TestLifecycleQueryRunner(ClickhouseTestMixin, APIBaseTest):IntervalType.WEEK,"2020-01-14","2020-01-19",+ datetime(2020, 1, 5, tzinfo=UTC),),("month_interval_mid_month",IntervalType.MONTH,"2020-01-14","2020-01-19",+ datetime(2019, 12, 1, tzinfo=UTC),),])@time_machine.travel("2020-01-20T00:00:00Z", tick=False)- def test_lifecycle_interval_boundary_filtering(self, _name, interval, date_from, date_to):+ def test_lifecycle_interval_boundary_filtering(self, _name, interval, date_from, date_to, expected_read_from):self._create_test_events()response = self._run_lifecycle_query(date_from, date_to, interval)+ assert response.resolved_date_range is not None+ assert response.resolved_date_range.read_from == expected_read_from+statuses = [r["status"] for r in response.results]assert statuses == ["new", "returning", "resurrecting", "dormant"]diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex a3acee43fc81..1313dc0861b6 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -1484,6 +1484,8 @@ export interface QueryStatusApi {export interface ResolvedDateRangeResponseApi {date_from: stringdate_to: string+ /** The earliest timestamp the query reads, when only its first interval depends on rows from before date_from. Lifecycle sets it to the start of the interval before the range. */+ read_from?: string | null}export interface QueryTimingApi {diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 8b87621e7a76..9c309a51aff1 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -2983,6 +2983,8 @@ export namespace Schemas {export interface ResolvedDateRangeResponse {date_from: string;date_to: string;+ /** The earliest timestamp the query reads, when only its first interval depends on rows from before date_from. Lifecycle sets it to the start of the interval before the range. */+ read_from?: string | null;}export interface QueryTiming {