Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(signals): offer a get it merged action for approved report prs (#110927)

posthog[bot]aacf489fdced
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index db80feec3677..68987484f18a 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -357,6 +357,7 @@ export const FEATURE_FLAGS = {
HIDE_EVENTS_IN_QUERY_BUILDERS: 'hide-events-in-query-builders', // owner: #team-feature-flags, kill switch for hiding events marked hidden_in_query_builders from insight/cohort/destination pickers
HOGQL_WAREHOUSE_ACCESS_CONTROL: 'hogql-warehouse-access-control', // owner: @a-lider #team-platform-features, gates per-object access control for warehouse tables and views
IDENTITY_MATCHING: 'identity-matching', // owner: @fercgomes #team-growth, gates new identity matching scene on marketing analytics
+ INBOX_GET_IT_MERGED: 'inbox-get-it-merged', // owner: #team-self-driving, gates the Get it merged action in the report Ask AI menu
INBOX_MODEL_SORT: 'inbox-model-sort', // owner: #team-self-driving, gates the staff-only ranking model sort options and the probability tag on inbox cards
INBOX_REDESIGN: 'inbox-redesign', // owner: #team-self-driving, gates the inbox redesign: report sections, triage mode, the Settings tab, and scout cards
INBOX_SELF_DRIVING_EMPTY_STATE: 'inbox-self-driving-empty-state',
diff --git a/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsx b/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsx
index a58c8aff1ba7..e5a009f24faf 100644
--- a/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsx
+++ b/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsx
@@ -3,6 +3,9 @@ import '@testing-library/jest-dom'
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { initKeaTests } from '~/test/init'
import { SidePanelTab } from '~/types'
@@ -12,6 +15,7 @@ import { attachedContextLogic } from 'products/posthog_ai/frontend/api/logics'
import { captureInboxReportAction } from '../../inboxAnalytics'
import {
inboxTaskKickoffLogic,
+ MERGE_PR_REQUEST,
REPORT_AI_PANEL,
REPORT_DISCUSSION_QUESTION_MAX_LENGTH,
} from '../../inboxTaskKickoffLogic'
@@ -26,6 +30,30 @@ jest.mock('../../inboxAnalytics', () => ({
const SUGGESTION = 'Which teams are hitting this exception the most?'
+function withPullRequest(
+ report: SignalReport,
+ state: 'open' | 'merged',
+ reviewDecision: 'approved' | 'review_required'
+): SignalReport {
+ return {
+ ...report,
+ status: SignalReportStatus.IN_PROGRESS,
+ pull_requests: [
+ {
+ id: 'pr-1',
+ url: 'https://github.com/org/repo/pull/1',
+ state,
+ merged: state === 'merged',
+ review_decision: reviewDecision,
+ merged_at: null,
+ claim_id: null,
+ attached_at: null,
+ attached_by: null,
+ },
+ ],
+ }
+}
+
function makeReport(suggestedPrompts?: string[]): SignalReport {
return {
id: 'report-1',
@@ -237,6 +265,48 @@ describe('DiscussReportButton', () => {
expect(screen.queryByTestId('inbox-report-ask-ai-suggestion')).not.toBeInTheDocument()
})
+ it('sends Get it merged with the merge intent in one click from the Ask AI menu', async () => {
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_GET_IT_MERGED], {
+ [FEATURE_FLAGS.INBOX_GET_IT_MERGED]: true,
+ })
+ const user = userEvent.setup()
+ render(
+ <DiscussReportButton
+ report={withPullRequest(makeReport(), 'open', 'approved')}
+ reportUrl="https://app/report-1"
+ />
+ )
+
+ await user.click(screen.getByTestId('inbox-report-ask-ai-actions'))
+ await user.click(screen.getByText('Get it merged'))
+
+ expect(discussReport).toHaveBeenCalledWith(
+ expect.objectContaining({ id: 'report-1' }),
+ 'https://app/report-1',
+ MERGE_PR_REQUEST,
+ undefined,
+ 'merge_pr'
+ )
+ expect(jest.mocked(captureInboxReportAction).mock.calls[0][0].extra).toEqual({
+ question_source: 'suggested',
+ suggestion_count: 1,
+ question_intent: 'merge_pr',
+ })
+ })
+
+ it.each([
+ ['the PR needs review', true, withPullRequest(makeReport(), 'open', 'review_required')],
+ ['the PR is already merged', true, withPullRequest(makeReport(), 'merged', 'approved')],
+ ['the flag is off', false, withPullRequest(makeReport(), 'open', 'approved')],
+ ])('does not offer the Ask AI menu when %s', async (_name, flagEnabled, report) => {
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_GET_IT_MERGED], {
+ [FEATURE_FLAGS.INBOX_GET_IT_MERGED]: flagEnabled,
+ })
+ render(<DiscussReportButton report={report} reportUrl="https://app/report-1" />)
+
+ expect(screen.queryByTestId('inbox-report-ask-ai-actions')).not.toBeInTheDocument()
+ })
+
it('does not invite actions where the kickoff wrapper would only answer', async () => {
// The kickoff prompt pins the agent to answering on a resolved report, so a placeholder
// saying "tell AI what to do next" would promise an action the run won't carry out.
diff --git a/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsx b/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsx
index ee237b9d886c..55634891147d 100644
--- a/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsx
+++ b/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsx
@@ -1,14 +1,29 @@
import { useActions, useValues } from 'kea'
-import { IconSparkles } from '@posthog/icons'
-import { LemonButton } from '@posthog/lemon-ui'
+import { IconGitBranch, IconSparkles } from '@posthog/icons'
+import { LemonButton, LemonMenuOverlay } from '@posthog/lemon-ui'
-import { inboxTaskKickoffLogic } from '../../inboxTaskKickoffLogic'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+
+import { captureInboxReportAction, discussQuestionProperties } from '../../inboxAnalytics'
+import { inboxTaskKickoffLogic, MERGE_PR_REQUEST } from '../../inboxTaskKickoffLogic'
import { SignalReport } from '../../types'
+import { hasApprovedOpenReportPullRequest } from '../../utils/reportPullRequests'
export function DiscussReportButton({ report, reportUrl }: { report: SignalReport; reportUrl: string }): JSX.Element {
const { isDiscussing, isCreatingPr, aiConsentDisabledReason } = useValues(inboxTaskKickoffLogic)
- const { openReportDiscussion } = useActions(inboxTaskKickoffLogic)
+ const { openReportDiscussion, discussReport } = useActions(inboxTaskKickoffLogic)
+ const canMerge = useFeatureFlag('INBOX_GET_IT_MERGED') && hasApprovedOpenReportPullRequest(report)
+
+ const getItMerged = (): void => {
+ captureInboxReportAction({
+ report,
+ actionType: 'discuss',
+ surface: 'detail_pane',
+ extra: discussQuestionProperties({ source: 'suggested', suggestionCount: 1, intent: 'merge_pr' }),
+ })
+ discussReport(report, reportUrl, MERGE_PR_REQUEST, undefined, 'merge_pr')
+ }
return (
<LemonButton
@@ -19,6 +34,31 @@ export function DiscussReportButton({ report, reportUrl }: { report: SignalRepor
disabledReason={aiConsentDisabledReason ?? (isCreatingPr ? 'An implementation is starting.' : undefined)}
onClick={() => openReportDiscussion(report, reportUrl)}
tooltip="Ask PostHog AI about this report in the sidebar"
+ sideAction={
+ canMerge
+ ? {
+ tooltip: 'More AI actions',
+ 'aria-label': 'More AI actions',
+ 'data-attr': 'inbox-report-ask-ai-actions',
+ dropdown: {
+ placement: 'bottom-end',
+ overlay: (
+ <LemonMenuOverlay
+ items={[
+ {
+ label: 'Get it merged',
+ icon: <IconGitBranch />,
+ tooltip: 'Fix CI on the approved PR and merge it',
+ onClick: getItMerged,
+ 'data-attr': 'inbox-report-ask-ai-merge-pr',
+ },
+ ]}
+ />
+ ),
+ },
+ }
+ : undefined
+ }
>
Ask AI
</LemonButton>
diff --git a/products/signals/frontend/inbox/inboxAnalytics.ts b/products/signals/frontend/inbox/inboxAnalytics.ts
index 94d6cbc10251..354fc982755e 100644
--- a/products/signals/frontend/inbox/inboxAnalytics.ts
+++ b/products/signals/frontend/inbox/inboxAnalytics.ts
@@ -6,6 +6,7 @@ import { dayjs } from 'lib/dayjs'
import type { TaskRunStatus } from 'products/posthog_ai/frontend/types/taskTypes'
import type { ReportTaskPurpose } from './components/detail/artefactTypes'
+import type { ReportDiscussionIntent } from './inboxTaskKickoffLogic'
import {
InboxReportSectionKey,
SignalReport,
@@ -145,8 +146,13 @@ export type InboxQuestionSource = 'suggested' | 'edited_suggestion' | 'typed'
export function discussQuestionProperties(params: {
source: InboxQuestionSource
suggestionCount: number
+ intent?: ReportDiscussionIntent
}): Record<string, unknown> {
- return { question_source: params.source, suggestion_count: params.suggestionCount }
+ return {
+ question_source: params.source,
+ suggestion_count: params.suggestionCount,
+ ...(params.intent ? { question_intent: params.intent } : {}),
+ }
}
/**
diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
index 874185cb6dda..649763f6fa4e 100644
--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
@@ -20,6 +20,7 @@ import {
import { makeReport } from './__mocks__/inboxMocks'
import {
FREE_TRIAL_PR_DISABLED_REASON,
+ MERGE_PR_REQUEST,
REPORT_AI_PANEL,
REPORT_AI_PANEL_ID,
buildCreatePrReportPrompt,
@@ -553,6 +554,39 @@ describe('inboxTaskKickoffLogic', () => {
expect(prompt).not.toContain('inbox-reports-set-state')
})
+ it.each([
+ ['an approved, open PR', 'open', 'approved', true],
+ // The approval is what the person acted on, so a fresh state without it answers only.
+ ['an open PR that still needs review', 'open', 'review_required', false],
+ ['a PR that merged meanwhile', 'merged', 'approved', false],
+ ] as const)('frames a merge request on a report with %s', (_name, state, reviewDecision, merges) => {
+ const prompt = buildDiscussReportPrompt(
+ makeReport({
+ status: SignalReportStatus.IN_PROGRESS,
+ pull_requests: [
+ {
+ id: 'pr-1',
+ url: 'https://github.com/org/repo/pull/1',
+ state,
+ merged: state === 'merged',
+ review_decision: reviewDecision,
+ merged_at: null,
+ claim_id: null,
+ attached_at: null,
+ attached_by: null,
+ },
+ ],
+ }),
+ url,
+ MERGE_PR_REQUEST,
+ 'merge_pr'
+ )
+ expect(prompt).toContain(MERGE_PR_REQUEST)
+ expect(prompt.includes('merge queue')).toBe(merges)
+ expect(prompt.includes('Answer this question')).toBe(!merges)
+ expect(prompt).not.toContain('inbox-reports-set-state')
+ })
+
it.each([SignalReportStatus.READY, SignalReportStatus.PENDING_INPUT])(
'tells the agent to carry out actions for a %s report',
(status) => {
diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
index e48eda187678..493b0923bc6d 100644
--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
@@ -54,7 +54,7 @@ import {
SignalReportTaskRelationship,
} from './types'
import { aiConsentDisabledReason } from './utils/aiConsent'
-import { reportPullRequests } from './utils/reportPullRequests'
+import { hasApprovedOpenReportPullRequest, reportPullRequests } from './utils/reportPullRequests'
export const REPORT_AI_PANEL = 'inbox-report'
export const REPORT_AI_PANEL_ID = 'max-side-panel'
@@ -170,15 +170,27 @@ export function isActionCapableReport(report: SignalReport): boolean {
)
}
+/** Why Ask AI got the question: a dedicated surface that frames the run for one job. */
+export type ReportDiscussionIntent = 'measurement_plan' | 'merge_pr'
+
+/** What "Get it merged" in the Ask AI menu sends. The chat shows it as the person's own message. */
+export const MERGE_PR_REQUEST = `Get this approved PR merged. Fix failing CI, then use the repository's merge process. Ask me before you make a decision I did not make.`
+
export function buildDiscussReportPrompt(
report: SignalReport | null,
reportUrl: string,
question: string,
- intent?: 'measurement_plan'
+ intent?: ReportDiscussionIntent
): string {
if (intent === 'measurement_plan' && report !== null) {
return `A person asked you to revise the proposed measurement on the PostHog Inbox report at ${reportUrl}. Their description of success is:\n\n${question.trim()}\n\nRead the report and its impact_measurement_plan artefacts first. Investigate which data can test this outcome. Use inbox-report-artefacts-create to append one impact_measurement_plan per measurable outcome, with a stable metric_id, a bounded live Trends query, goal_value, goal_direction, goal_grain, and decision_window_days. Set minimum_data_points only if you also supply an eligibility_query counting qualifying opportunities (not failures). To revise a plan, append a new version with the same metric_id; keep other plans. Do not activate a plan: a person reviews it. If the requested outcome is not measurable, explain what is missing instead of inventing a query or threshold. Do not create a check, start monitoring, change the report state, or open a PR. You may use inbox-reports-update to clarify the Expected impact prose without changing other sections.\n\n${NO_CHECKOUT_INSTRUCTIONS}`
}
+ // Merging is an action on a report that already has a PR, which `isActionCapableReport` answers
+ // only. The fresh state must still show the approved, open PR: the approval is what the person
+ // acted on, and without it the run falls through to answering.
+ if (intent === 'merge_pr' && report !== null && hasApprovedOpenReportPullRequest(report)) {
+ return `A person approved the pull request on the PostHog Inbox report at ${reportUrl} and asked you to get it merged:\n\n${question.trim()}\n\nRead the report first and find its open, approved pull request with the inbox MCP tools. Work only on that pull request, on its own branch. Do not open a second PR. Fix failing CI checks and merge conflicts with the smallest change that keeps what the reviewer approved. Then merge it with the repository's own merge process: read its contribution guide and agent instructions first, and use its merge queue when it has one. This request approves the merge of this pull request only. Stop and ask the person before you continue when the work needs a decision they did not make: a fix that changes what the PR does, a new review that requests changes, a failure that this PR did not cause, or a merge rule that needs a person. Do not change the report state: the merge resolves the report.\n\n${NO_CHECKOUT_INSTRUCTIONS}`
+ }
// The task is already linked to the report, but including the URL lets the agent open and read
// the full report itself. The user's message follows after a blank line for clear separation.
// `null` means the caller could not confirm the report's current state (the kickoff refetch
@@ -399,10 +411,10 @@ export interface inboxTaskKickoffLogicActions {
reportUrl: string,
question: string,
agentQuestion?: string,
- intent?: 'measurement_plan'
+ intent?: ReportDiscussionIntent
) => {
agentQuestion: string | undefined
- intent: 'measurement_plan' | undefined
+ intent: ReportDiscussionIntent | undefined
question: string
report: SignalReport
reportUrl: string
@@ -508,7 +520,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
reportUrl: string,
question: string,
agentQuestion?: string,
- intent?: 'measurement_plan'
+ intent?: ReportDiscussionIntent
) => ({
report,
reportUrl,
@@ -729,6 +741,13 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
// changed: a failed refetch also answers only, but "report changed" would be a guess.
if (currentReport !== null && isActionCapableReport(report) && !isActionCapableReport(currentReport)) {
lemonToast.info('This report can no longer take actions, so AI will answer instead.')
+ } else if (
+ intent === 'merge_pr' &&
+ currentReport !== null &&
+ hasApprovedOpenReportPullRequest(report) &&
+ !hasApprovedOpenReportPullRequest(currentReport)
+ ) {
+ lemonToast.info('This PR is no longer open and approved, so AI will answer instead.')
}
if (values.currentProjectId == null) {
lemonToast.error("Couldn't ask AI about this report. Try again.")
diff --git a/products/signals/frontend/inbox/utils/reportPullRequests.ts b/products/signals/frontend/inbox/utils/reportPullRequests.ts
index ad9b5ffc769f..cff31b21a138 100644
--- a/products/signals/frontend/inbox/utils/reportPullRequests.ts
+++ b/products/signals/frontend/inbox/utils/reportPullRequests.ts
@@ -50,3 +50,9 @@ export function hasActiveReportPullRequest(report: ReportWithPullRequests | null
export function hasMergedReportPullRequest(report: ReportWithPullRequests | null | undefined): boolean {
return reportPullRequests(report).some((pr) => pr.merged || pr.state === 'merged')
}
+
+export function hasApprovedOpenReportPullRequest(report: ReportWithPullRequests | null | undefined): boolean {
+ return reportPullRequests(report).some(
+ (pr) => pr.state === 'open' && !pr.merged && pr.review_decision === 'approved'
+ )
+}