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(tasks): surface PR merged state in the installation progress card (#69776)

Fernando Gomesbff7a1925167
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 7e7e4e36248b..4f6d96ecf926 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -7306,6 +7306,10 @@ snapshots:
hash: v1.k794b7964.36cf7228ba594332bed453ada313646e689878696d65f2e732ef4f20b9942b27.f5PtRTQsoB2LQF0JI-0_pmtiH7Lkd8HH3BnE6uSLoGU
scenes-other-onboarding-shared-installation-progress--completed-local-handoff--light:
hash: v1.k794b7964.0f40b7a983cb6f76ca10f79e72e7dfba4f974171a9e0ae670d6beae5ca6a5804.8x3ZMHjKx92IRRDfpRdipq0OEhUp0EmRlhjz9ZwrCsc
+ scenes-other-onboarding-shared-installation-progress--completed-merged--dark:
+ hash: v1.k794b7964.48c882f0b7d703503d0be6d629acdf785f7b7e2073b8ec0dfb99d8fb0baefee9.Ag4zdI8qORUkoAxyrbVQO0wja3mRQVhbKwMAyt6mr9k
+ scenes-other-onboarding-shared-installation-progress--completed-merged--light:
+ hash: v1.k794b7964.00d7ba883b7a9f23dec598f0e3beb5e708173d9637d37411969d52d8955151bb.a4WgCV7mt614PYHhNdoS9IM2OYiUGfYbVltyfeJrKiE
scenes-other-onboarding-shared-installation-progress--connecting--dark:
hash: v1.k794b7964.c979fc93fe8ea9d6a8d7ecfc667cba31879bfcafce56b1f09ae143d43e77efce.cHHBvXk9MnAaTdks6cwqJLv_--qKj8AwUXIv6FZRV3U
scenes-other-onboarding-shared-installation-progress--connecting--light:
@@ -7338,6 +7342,10 @@ snapshots:
hash: v1.k794b7964.73dd3b1ca302d1d915814fb1c93516188ee3a6c010a9deedc21aba892b0c4eaa.TED9G6l7yoWOiiXzoG27nGeTlcy4E02tWrI0-iEqOBM
scenes-other-onboarding-shared-installation-progress--playground--light:
hash: v1.k794b7964.136fe9ea63b8e3301642e87d677f6e9d46f1796683a666a3ab18ee23fbbf5539.4sb2JpWGGJR3UBjBelT0C_Y2JvuppqCQCzwvFT5RptI
+ scenes-other-onboarding-shared-installation-progress--pull-request-merged--dark:
+ hash: v1.k794b7964.ed63a038b7850e6fca64b61fddc7d786b95612b0cb313d1a8fec7e1e300cf7a7.KpidhTaObETHkR2JsrXbAl9Cgh7vqmF12CGN2DZYejI
+ scenes-other-onboarding-shared-installation-progress--pull-request-merged--light:
+ hash: v1.k794b7964.46a6ac2335f607534242f15615f19b9f75cb81c2d48099cfa9772f57df091d76.3Na2Ka58ITzwK3nfOXc8iuwudjObb8rH6LUoDAahiw0
scenes-other-onboarding-shared-installation-progress--pull-request-ready--dark:
hash: v1.k794b7964.c0dd7977c4b4e125098401eb4643e2896f600b116c04bf0ff56f09de25579835.x7qV5sJxPaxI27L4YuzDnvP5qLdsHcFQtGRM1cQE23c
scenes-other-onboarding-shared-installation-progress--pull-request-ready--light:
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.stories.tsx b/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.stories.tsx
index abf0f085bd89..1bf5fa064d4e 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.stories.tsx
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.stories.tsx
@@ -45,7 +45,7 @@ function steps(
}
function progress(overrides: Partial<InstallationProgress>): InstallationProgress {
- return { phase: 'running', steps: [], error: null, prUrl: null, isCurrent: true, ...overrides }
+ return { phase: 'running', steps: [], error: null, prUrl: null, prMerged: false, isCurrent: true, ...overrides }
}
export const Connecting: Story = {
@@ -129,6 +129,39 @@ export const PullRequestReady: Story = {
},
}
+export const PullRequestMerged: Story = {
+ args: {
+ progress: progress({
+ phase: 'running',
+ prUrl: 'https://github.com/acme-co/web/pull/42',
+ prMerged: true,
+ steps: [
+ { id: 'setup:sandbox', label: 'Set up sandbox', status: 'completed', detail: null },
+ { id: 'setup:clone', label: 'Cloned repository', status: 'completed', detail: null },
+ { id: 'setup:wizard', label: 'Ran PostHog setup wizard', status: 'completed', detail: null },
+ { id: 'setup:agent', label: 'Started agent', status: 'completed', detail: null },
+ { id: 'deliver:pr', label: 'Pull request merged', status: 'completed', detail: null },
+ ],
+ }),
+ },
+}
+
+export const CompletedMerged: Story = {
+ args: {
+ progress: progress({
+ phase: 'completed',
+ prUrl: 'https://github.com/acme-co/web/pull/42',
+ prMerged: true,
+ steps: [
+ { id: 'setup:sandbox', label: 'Set up sandbox', status: 'completed', detail: null },
+ { id: 'setup:clone', label: 'Cloned repository', status: 'completed', detail: null },
+ { id: 'setup:wizard', label: 'Ran PostHog setup wizard', status: 'completed', detail: null },
+ { id: 'deliver:pr', label: 'Pull request merged', status: 'completed', detail: null },
+ ],
+ }),
+ },
+}
+
export const FailedProvisioning: Story = {
args: {
progress: progress({
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.tsx b/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.tsx
index f558f1fa45ed..95a0095a8809 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.tsx
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/InstallationProgressView.tsx
@@ -1,5 +1,5 @@
import { useActions, useValues } from 'kea'
-import { useEffect } from 'react'
+import { useEffect, useRef } from 'react'
import * as wizardHogPng from '@posthog/brand/hoggies/png/wizard-hog'
import {
@@ -14,7 +14,9 @@ import {
import { LemonButton, Spinner } from '@posthog/lemon-ui'
import { pngHoggie } from 'lib/brand/hoggies'
+import { useHogfetti } from 'lib/components/Hogfetti/Hogfetti'
import { cn } from 'lib/utils/css-classes'
+import { inStorybookTestRunner } from 'lib/utils/dom'
import { urls } from 'scenes/urls'
import { onboardingEventUsageLogic } from '../../onboardingEventUsageLogic'
@@ -32,8 +34,15 @@ import { DetectedDashboard, wizardDashboardLogic } from './wizardDashboardLogic'
const HedgehogWizardHog = pngHoggie(wizardHogPng)
// Timeline dot for a single step.
-function StepIcon({ status }: { status: InstallationStepStatus }): JSX.Element {
+function StepIcon({ status, prState }: { status: InstallationStepStatus; prState?: 'open' | 'merged' }): JSX.Element {
if (status === 'completed') {
+ // GitHub's PR color language: green while open, purple once merged.
+ if (prState === 'merged') {
+ return <IconPullRequest className="text-purple text-base" />
+ }
+ if (prState === 'open') {
+ return <IconPullRequest className="text-success text-base" />
+ }
return <IconCheckCircle className="text-success text-base" />
}
if (status === 'failed') {
@@ -84,31 +93,59 @@ export function InstallationProgressContent({
* command). Omitted where no local fallback exists (e.g. the floating FAB), which shows only docs. */
onRetryLocally?: () => void
}): JSX.Element {
- const { phase, steps, error, prUrl } = progress
+ const { phase, steps, error, prUrl, prMerged } = progress
// The PR is opened mid-run: while the run keeps going (keeping CI green), surface it as ready rather
// than an indefinite "setting up". Terminal phases keep their own headline.
const prReady = !!prUrl && phase !== 'completed' && phase !== 'error'
+ // Celebrate a merge the user performs while watching, exactly once per mount. Gated on the
+ // false -> true transition so mounting an already-merged run (reloads, storybook snapshots)
+ // stays quiet; the test-runner guard keeps hogfetti out of visual regression captures.
+ const { trigger: triggerHogfetti, HogfettiComponent } = useHogfetti()
+ // Only a live false -> true transition celebrates. Start null so the first hydrated state (SSE
+ // replay / poll snapshot arrives async after mount) arms the detector instead of reading as a
+ // transition — otherwise every reload of a merged run re-fires. One-shot per mount on top.
+ const prevMergedRef = useRef<boolean | null>(null)
+ const mergeCelebratedRef = useRef(false)
+ useEffect(() => {
+ const prev = prevMergedRef.current
+ prevMergedRef.current = prMerged
+ if (prev === null || prev || !prMerged || mergeCelebratedRef.current) {
+ return
+ }
+ if (inStorybookTestRunner() || window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
+ return
+ }
+ mergeCelebratedRef.current = true
+ triggerHogfetti()
+ }, [prMerged, triggerHogfetti])
+
const headline =
phase === 'completed'
? 'PostHog is wired up'
: phase === 'error'
? (error?.title ?? "Setup didn't finish")
: prReady
- ? 'Pull request ready'
+ ? prMerged
+ ? 'Pull request merged'
+ : 'Pull request ready'
: 'Setting up PostHog'
const subtitle =
phase === 'completed'
? prUrl
- ? 'Review and merge the pull request, then deploy. Data starts flowing the moment it ships.'
+ ? prMerged
+ ? 'Your pull request is merged. Deploy the changes and data starts flowing.'
+ : 'Review and merge the pull request, then deploy. Data starts flowing the moment it ships.'
: mode === 'local'
? 'The wizard finished its work on your machine.'
: "You're all set."
: phase === 'error'
? "We couldn't finish the setup."
: prReady
- ? "Review it whenever you like; we'll keep CI green in the meantime."
+ ? prMerged
+ ? 'Deploy the changes and data starts flowing. The run will wrap up on its own.'
+ : "Review it whenever you like; we'll keep CI green in the meantime."
: phase === 'connecting'
? ((mode && CONNECTING_SUBTITLE[mode]) ?? 'Getting things ready…')
: phase === 'idle'
@@ -125,6 +162,7 @@ export function InstallationProgressContent({
className="rounded-lg border border-border bg-bg-light p-4 flex flex-col gap-3"
data-attr="installation-progress"
>
+ <HogfettiComponent />
<div className="flex items-start justify-between gap-2">
<div className="flex items-start gap-2.5 min-w-0">
{waitingForSteps && <Spinner className="text-xl shrink-0 mt-0.5 text-accent" textColored />}
@@ -158,21 +196,32 @@ export function InstallationProgressContent({
// One flat rail for pipeline and wizard-reported steps alike.
<li key={step.id} className="flex gap-3">
<div className="flex flex-col items-center pt-0.5">
- <StepIcon status={step.status} />
+ <StepIcon
+ status={step.status}
+ prState={
+ step.id.endsWith(':pr') && prUrl ? (prMerged ? 'merged' : 'open') : undefined
+ }
+ />
{i < steps.length - 1 && <div className="w-px flex-1 bg-border my-1 min-h-[0.75rem]" />}
</div>
<div className="flex-1 min-w-0 pb-3">
<div
className={cn(
- 'text-sm truncate',
+ 'text-sm truncate flex items-center gap-1.5',
step.status === 'pending' && 'text-muted',
step.status === 'failed' && 'text-danger font-medium',
step.status === 'in_progress' && 'font-medium'
)}
>
- {step.label}
+ <span className="truncate">
+ {step.id.endsWith(':pr') && prMerged
+ ? 'PR merged, congratulations!'
+ : step.label}
+ </span>
</div>
- {step.detail && <div className="text-xs text-muted truncate">{step.detail}</div>}
+ {step.detail && (
+ <div className="text-xs text-muted truncate ph-no-capture">{step.detail}</div>
+ )}
</div>
</li>
))}
@@ -246,7 +295,7 @@ export function InstallationProgressContent({
</div>
)}
- {prUrl && (
+ {prUrl && !prMerged && phase !== 'error' && (
// ph-no-capture: the label carries the customer's repo name and the href their PR
// url — neither may reach autocapture in the shared app analytics project.
<LemonButton
@@ -261,6 +310,30 @@ export function InstallationProgressContent({
</LemonButton>
)}
+ {prUrl && prMerged && phase !== 'error' && (
+ <div className="flex items-center gap-3 rounded-lg border border-[var(--color-purple-500)] p-3">
+ <span className="flex items-center justify-center rounded w-8 h-8 shrink-0 bg-[var(--color-purple-500)] text-white">
+ <IconPullRequest className="text-lg" />
+ </span>
+ <div className="flex-1 min-w-0">
+ <div className="text-sm font-semibold">Pull request successfully merged</div>
+ <div className="text-xs text-muted">
+ You're all set. Deploy the changes and your events start flowing.
+ </div>
+ </div>
+ {/* ph-no-capture: the href is the customer's PR url. */}
+ <LemonButton
+ type="secondary"
+ size="small"
+ to={prUrl}
+ targetBlank
+ className="ph-no-capture shrink-0"
+ >
+ View PR
+ </LemonButton>
+ </div>
+ )}
+
{phase === 'completed' && dashboard && (
<div className="flex flex-col gap-2">
<p className="text-sm text-muted m-0">
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.stories.tsx b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.stories.tsx
index 3691ed2f08e0..8ed43df02309 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.stories.tsx
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.stories.tsx
@@ -50,7 +50,7 @@ function cloudSteps(
}
function progress(overrides: Partial<InstallationProgress>): InstallationProgress {
- return { phase: 'running', steps: [], error: null, prUrl: null, isCurrent: true, ...overrides }
+ return { phase: 'running', steps: [], error: null, prUrl: null, prMerged: false, isCurrent: true, ...overrides }
}
export const Connecting: Story = {
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.tsx b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.tsx
index eb745e7cae72..0891027830dd 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.tsx
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncCard.tsx
@@ -36,6 +36,9 @@ export function StatusGlyph({ progress }: { progress: InstallationProgress }): J
if (progress.phase === 'error') {
return <IconWarning className="text-danger text-xl shrink-0" />
}
+ if (progress.prMerged) {
+ return <IconPullRequest className="text-purple text-xl shrink-0" />
+ }
return <Spinner className="text-xl shrink-0 text-accent" textColored />
}
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncFab.tsx b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncFab.tsx
index 2e31481fa982..56188d941396 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncFab.tsx
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/WizardSyncFab.tsx
@@ -220,10 +220,10 @@ function WizardSyncSurface({
openDialog()
}}
// Mid-run, the X only minimizes — hiding a live run for good would orphan
- // it. Once terminal there is nothing to orphan, so the X is the real
- // dismissal (the run never leaves on its own; the user decides when).
- onDismiss={isTerminal && handleClear ? handleClear : handleMinimize}
- dismissTooltip={isTerminal && handleClear ? 'Dismiss' : 'Minimize'}
+ // it. Once the run is terminal or the PR exists, the user's part is done,
+ // so the X becomes the real dismissal (the run never leaves on its own).
+ onDismiss={(isTerminal || prOpened) && handleClear ? handleClear : handleMinimize}
+ dismissTooltip={(isTerminal || prOpened) && handleClear ? 'Dismiss' : 'Minimize'}
/>
)}
</div>
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/helpers.ts b/frontend/src/scenes/onboarding/shared/wizard-sync/helpers.ts
index 1999624b6d63..91ca2807b3a5 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/helpers.ts
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/helpers.ts
@@ -21,6 +21,9 @@ export function syncHeadline(progress: InstallationProgress): string {
if (progress.phase === 'error') {
return progress.error?.title ?? 'Setup hit a snag'
}
+ if (progress.prMerged) {
+ return 'Pull request merged'
+ }
if (progress.prUrl) {
return 'Pull request ready'
}
@@ -40,12 +43,15 @@ export function activeStep(steps: InstallationStep[]): InstallationStep | null {
// The prominent line: the active step's live detail (the wizard's current sub-task) when present,
// otherwise the step label. This is what gives the wizard's own work top billing in the card.
export function currentTaskLabel(progress: InstallationProgress): string | null {
- if (progress.phase === 'completed') {
- return progress.prUrl ? 'Pull request is ready to review' : 'Everything is wired up'
- }
if (progress.phase === 'error') {
return progress.error?.detail ?? 'Something stopped the run'
}
+ if (progress.prMerged) {
+ return 'PR merged, congratulations!'
+ }
+ if (progress.phase === 'completed') {
+ return progress.prUrl ? 'Pull request is ready to review' : 'Everything is wired up'
+ }
const step = activeStep(progress.steps)
if (step) {
return step.detail ?? step.label
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.test.ts b/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.test.ts
index 623545f9d9f8..7871555408eb 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.test.ts
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.test.ts
@@ -334,6 +334,7 @@ describe('installationProgressLogic merge', () => {
],
error: null,
prUrl: null,
+ prMerged: false,
isCurrent: true,
})
})
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.ts b/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.ts
index 7b87dbace2e6..4bf896507439 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.ts
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/installationProgressLogic.ts
@@ -9,7 +9,13 @@ import { wizardSessionStreamLogic } from 'products/wizard/frontend/wizardSession
import { activeCloudRunLogic } from './activeCloudRunLogic'
import { finishedLocalRunLogic, FinishedLocalRunHandle } from './finishedLocalRunLogic'
import type { installationProgressLogicType } from './installationProgressLogicType'
-import { taskRunPrUrl, taskRunStreamLogic, TaskRunProgressStep, TaskRunStreamState } from './taskRunStreamLogic'
+import {
+ taskRunPrMerged,
+ taskRunPrUrl,
+ taskRunStreamLogic,
+ TaskRunProgressStep,
+ TaskRunStreamState,
+} from './taskRunStreamLogic'
import { isSessionActive, wizardActiveSessionDetectorLogic } from './wizardActiveSessionDetectorLogic'
import { wizardDashboardLogic } from './wizardDashboardLogic'
@@ -81,6 +87,8 @@ export interface InstallationProgress {
steps: InstallationStep[]
error: { title: string; detail: string | null } | null
prUrl: string | null
+ /** The bound PR was merged (webhook-recorded on the run's output). */
+ prMerged: boolean
isCurrent: boolean
}
@@ -216,6 +224,13 @@ export function cloudProgress(
}
const prUrl = taskRunPrUrl(taskRunState, progressSteps)
+ const prMerged = taskRunPrMerged(taskRunState)
+
+ // A merged PR ends the story: the CI-babysitting row would otherwise keep spinning forever
+ // (the workflow's follow-up loop skips closed PRs, so nothing will ever complete it).
+ if (prMerged) {
+ steps = steps.filter((s) => !s.id.endsWith(':ci'))
+ }
// The pipeline goes quiet between agent start and the PR opening: everything reads completed
// while the agent is still writing code, committing, and drafting the PR — which looks stalled.
@@ -248,6 +263,7 @@ export function cloudProgress(
steps,
error,
prUrl,
+ prMerged,
isCurrent: phase !== 'idle',
}
}
@@ -268,6 +284,7 @@ export function localProgress(
steps: [],
error: null,
prUrl: null,
+ prMerged: false,
isCurrent: false,
}
}
@@ -298,7 +315,7 @@ export function localProgress(
}
: null
- return { phase, steps, error, prUrl: null, isCurrent: sessionIsCurrent && !dismissed }
+ return { phase, steps, error, prUrl: null, prMerged: false, isCurrent: sessionIsCurrent && !dismissed }
}
// A finished local run rendered from its persisted snapshot, after the live session stream has
@@ -312,6 +329,7 @@ export function progressFromFinishedLocalRun(handle: FinishedLocalRunHandle): In
? { title: 'Wizard hit an error', detail: handle.error?.message ?? null }
: null,
prUrl: null,
+ prMerged: false,
isCurrent: true,
}
}
diff --git a/frontend/src/scenes/onboarding/shared/wizard-sync/taskRunStreamLogic.ts b/frontend/src/scenes/onboarding/shared/wizard-sync/taskRunStreamLogic.ts
index 7b31f93513cf..f8b2d09e136a 100644
--- a/frontend/src/scenes/onboarding/shared/wizard-sync/taskRunStreamLogic.ts
+++ b/frontend/src/scenes/onboarding/shared/wizard-sync/taskRunStreamLogic.ts
@@ -22,7 +22,7 @@ export function taskRunDetailToStreamState(dto: TaskRunDetailDTOApi): TaskRunStr
return {
status: dto.status,
stage: dto.stage ?? null,
- output: (dto.output as { pr_url?: string | null } | null) ?? null,
+ output: (dto.output as { pr_url?: string | null; pr_merged?: boolean | null } | null) ?? null,
branch: dto.branch ?? null,
error_message: dto.error_message ?? null,
updated_at: dto.updated_at ?? '',
@@ -37,7 +37,7 @@ export function taskRunDetailToStreamState(dto: TaskRunDetailDTOApi): TaskRunStr
export interface TaskRunStreamState {
status: string // queued | in_progress | completed | failed | cancelled
stage: string | null
- output: { pr_url?: string | null } | null
+ output: { pr_url?: string | null; pr_merged?: boolean | null } | null
branch: string | null
error_message: string | null
updated_at: string
@@ -131,6 +131,10 @@ export function taskRunPrUrl(state: TaskRunStreamState | null, steps: TaskRunPro
)
}
+export function taskRunPrMerged(state: TaskRunStreamState | null): boolean {
+ return state?.output?.pr_merged === true
+}
+
export interface CloudRunCompletionReport {
status: TerminalTaskRunStatus
durationSeconds: number | null
@@ -208,7 +212,26 @@ export const taskRunStreamLogic = kea<taskRunStreamLogicType>([
taskRunState: [
null as TaskRunStreamState | null,
{
- taskRunStateUpdated: (_, { state }) => state,
+ // Reconnects (tab-visibility resume) replay historical state events; PR facts only
+ // move forward, so a replayed pre-merge state must not regress them mid-replay.
+ taskRunStateUpdated: (prev, { state }) => {
+ if (!prev?.output) {
+ return state
+ }
+ const output = { ...state.output }
+ // A state event that replaces the PR (resumed run, new branch) carries its own
+ // url; don't drag the prior PR's merge onto it. Pin only while the url matches.
+ if (output.pr_url && prev.output.pr_url && output.pr_url !== prev.output.pr_url) {
+ return { ...state, output }
+ }
+ if (prev.output.pr_url && !output.pr_url) {
+ output.pr_url = prev.output.pr_url
+ }
+ if (prev.output.pr_merged && !output.pr_merged) {
+ output.pr_merged = prev.output.pr_merged
+ }
+ return { ...state, output }
+ },
},
],
// Last-write-wins per (group, step), kept in arrival order so the UI renders a stable timeline.
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index 3b1729b156c9..4ed5cbef745f 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -1848,7 +1848,14 @@ def set_task_run_output(
if run is None:
return None
task = run.task
- run.output = output
+ # Preserve PR facts a webhook may have written concurrently: this assignment is wholesale,
+ # so a bare `= output` would drop output.pr_url / output.pr_merged recorded out of band.
+ existing = run.output if isinstance(run.output, dict) else {}
+ merged = {**output}
+ for key in ("pr_url", "pr_merged"):
+ if not merged.get(key) and existing.get(key):
+ merged[key] = existing[key]
+ run.output = merged
run.save(update_fields=["output", "updated_at"])
if task.json_schema:
signal_workflow_completion(run.id, TaskRun.Status.COMPLETED, None)
diff --git a/products/tasks/backend/tests/test_webhooks.py b/products/tasks/backend/tests/test_webhooks.py
index b659e2288f24..ae4bef67072d 100644
--- a/products/tasks/backend/tests/test_webhooks.py
+++ b/products/tasks/backend/tests/test_webhooks.py
@@ -105,6 +105,29 @@ class TestGitHubPRWebhook(TestCase):
assert self.task_run.output is not None
self.assertIs(self.task_run.output.get("pr_merged"), True)
+ @patch("products.tasks.backend.facade.webhooks.get_github_webhook_secret")
+ @patch("products.tasks.backend.models.posthoganalytics.capture")
+ def test_pr_merged_publishes_stream_events(self, mock_capture, mock_get_secret):
+ # A live installation-progress view only learns about the merge through the stream;
+ # recording output.pr_merged without publishing leaves the UI stuck on "opened".
+ mock_get_secret.return_value = self.webhook_secret
+ payload = {
+ "action": "closed",
+ "pull_request": {
+ "html_url": "https://github.com/posthog/posthog/pull/123",
+ "merged": True,
+ },
+ }
+
+ with patch.object(TaskRun, "publish_stream_event") as mock_publish:
+ response = self._make_webhook_request(payload)
+
+ self.assertEqual(response.status_code, 200)
+ published = [c.args[0] for c in mock_publish.call_args_list if c.args]
+ progress = [e for e in published if e.get("notification", {}).get("method") == "_posthog/progress"]
+ self.assertEqual(len(progress), 1)
+ self.assertEqual(progress[0]["notification"]["params"]["label"], "Pull request merged")
+
@patch("products.tasks.backend.facade.webhooks.get_github_webhook_secret")
@patch("products.tasks.backend.models.posthoganalytics.capture")
def test_pr_merged_from_fork_does_not_record_pr_merged(self, mock_capture, mock_get_secret):
diff --git a/products/tasks/backend/webhooks.py b/products/tasks/backend/webhooks.py
index 08fa4b92b603..440682a9ecdb 100644
--- a/products/tasks/backend/webhooks.py
+++ b/products/tasks/backend/webhooks.py
@@ -207,7 +207,17 @@ def _record_run_pr_merged(task_run: TaskRun) -> None:
the wizard's setup PR) read it off the run's ``output``, which is the only PR state the task
APIs expose.
"""
- _record_run_output_field(task_run, "pr_merged", True, "github_pr_webhook_record_pr_merged_failed")
+ if not _record_run_output_field(task_run, "pr_merged", True, "github_pr_webhook_record_pr_merged_failed"):
+ return
+ # Publish-only (no append_log), same rationale and failure tolerance as _record_run_pr_url.
+ try:
+ pr_url = task_run.output.get("pr_url") if isinstance(task_run.output, dict) else None
+ task_run.publish_stream_event(
+ task_run.build_progress_event("pr", "completed", "Pull request merged", "setup", detail=pr_url)
+ )
+ task_run.publish_stream_state_event()
+ except Exception:
+ logger.warning("github_pr_webhook_pr_merged_events_failed", run_id=str(task_run.id), exc_info=True)
def _record_run_output_field(task_run: TaskRun, key: str, value: str | bool, failure_log_event: str) -> bool: