: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(engineering-analytics): show friction on the author and pull request pages (#106447)
Julian Bezce8662c70258
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex e5df01395b35..67fb6fc326aa 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -8385,25 +8385,25 @@ snapshots:scenes-app-discussions--threads--light:hash: v1.k794b7964.28ac830bf83be5cbb6d7a397d67c9b9c61711904a822de38402b82220b0f7a49.7wENY7hvo1-qAJwq5fcsvKGJsfRAF_vDkpnM8iqFZccscenes-app-engineering-analytics-author--author--dark:- hash: v1.k794b7964.f03c0a7743a7e114a6c38d13db3435b0daeaffe9052c7b186fc3a61fabaabd1f.IXoo6spuIAyp0C7qVPshL35bvPujoUDo113QyhQgLG4+ hash: v1.k794b7964.94843c0a69e5003d66026b75cc9c10c151375f639da48a64f7cf91247a3b8f14.Hgttx9kcZ3ObLfprwLMFS6TiLVsIJ22TfNpEnNjlnvoscenes-app-engineering-analytics-author--author--light:- hash: v1.k794b7964.b08b71cc389fe7f473a7e4ace18ac70fcce2c0b3aaf2cfba9eb00db4be907743.H3WFBL1JOGWrufOyEUanqaELXoRuBaTNfO-oh3ovRM8+ hash: v1.k794b7964.444a9ecb15101f5165d9b18aa01c66baf0f921d5201d471f28648efb6b4c532c.lTmfkqJuvx0jP2W2sbfFu04HuO_bzCL0NHi7How_M88scenes-app-engineering-analytics-author--author-narrow--dark:- hash: v1.k794b7964.c78c2a9ae0c90bc6af9dbff40dd59e3fe357e41cedb96a5f97702b53ab88df9b.ZrfYCZldiIyzV9l2-9uIb2r8pjri0EEVZyhH2sG_Kl8+ hash: v1.k794b7964.76aa3e24e92358988de45bda84c5ffafaaf65a49219fb19368419cf1d2694d52.3S2BhVPHN7CdplDfDVcq_uEwGFQHup3a3295mXiwavsscenes-app-engineering-analytics-author--author-narrow--light:- hash: v1.k794b7964.d55706ea4051519f0a0387f5cf13c85401fe7cab200f7fbbd2275bdb2dafa4a6.ePoCZCxRRpFvyiaWZzUCxTQOziqao-qfm3YzPTHjHYk+ hash: v1.k794b7964.3bd500e42cd2d5b4a866a8ac44476819ac19d424b1824d547803d03b41266eb7.e01uryY0yYNw3FxEch4-IgL-kFfBZlxYG2MW-KZq4VEscenes-app-engineering-analytics-author--author-without-reviews-or-deploys--dark:- hash: v1.k794b7964.2912a039cef968631e879d37ceb383cd890aa58a309fe994e54048d32c03fea0.ignhhu_rS-LmWB_l7JsirYO_2D5bsWCZSX5FJr_VMIs+ hash: v1.k794b7964.d866f278ac6f10ab1c02bfd118aebeba489beae23a3e924712539e80aab71622.AD_zrOifVoF3YyTFK7B9g5NKM6BUH7ipLTyETIxX75Escenes-app-engineering-analytics-author--author-without-reviews-or-deploys--light:- hash: v1.k794b7964.3cf36ae2af60fafbf05aa99aa8d21b91acfcec55cbc9e68eb880c28bbbb5428e.4LKTJhufJZrTUSXzWSLpd4drYCzho0V1sd5IwbPH52U+ hash: v1.k794b7964.ed20abf791a343c4746b96bf254ae2ade623baa3c8b77a55add4c68bb624a6c2.L-CzeVOPJhXcNU1HLeZ7MT-b-SouqwR1BVBTjKtBBQcscenes-app-engineering-analytics-authors--author-friction--dark:hash: v1.k794b7964.88728c06ce00b8f11db949d90b27a1b2093f0cb8673c28a3bacc0b5ff9a56b5e.OhfSy6zVs-UDsLgYDEhzFETfYob5SWTgB7RTbEuDb_cscenes-app-engineering-analytics-authors--author-friction--light:- hash: v1.k794b7964.eca39040c911e5915e0248649d8a301e9c9d279040f7ba8cb3b3c976d85d0c6b.HgkKTUfXLlpPr13D0Qvmewacq9avFmnPKohtIcUBT9s+ hash: v1.k794b7964.3bc0729aea98363b40832cf35ec30a99dba6d5e8a744e2ac8e74ff80d924d108.9Vhg9iYWBSHy87Mnmc2hZjQWgTLmBkO0zoh8uTIe-9wscenes-app-engineering-analytics-authors--author-friction-not-ready--dark:hash: v1.k794b7964.92889e0db2ca295765d91586d19fdd5183d8b6af425237baf4c5e6d0273b4949.q-FafIaHo1UO3RKISmWRKJWxEtw8-pgrKYWP4q9DoR8scenes-app-engineering-analytics-authors--author-friction-not-ready--light:- hash: v1.k794b7964.0f7bab03614efa0a14f40334900064ed8f915efd5193e19b6c7845dd7e79bd87.0Xgyj3Z2Vl3_EpcL0OvpPt1TXIPBlCVD8WCSPJcl79o+ hash: v1.k794b7964.bf18cf3f51dd0436b64f4d6cb533b6a36a7811c161122355a08d40a5136db8be.uGZadwMtx40uqMkqplCKQP9fzEMLnYReDvNvfVsG6EUscenes-app-engineering-analytics-delivery-pipeline--all-stages--dark:hash: v1.k794b7964.e6fc5778d62714ed6fd4174b65c767a850d116b902223aa6f2086ce967edcaed.HoZOw65AQI9tW_L6CG_9JN6y7lmyhzy_Q1PQL__zCskscenes-app-engineering-analytics-delivery-pipeline--all-stages--light:@@ -8445,17 +8445,17 @@ snapshots:scenes-app-engineering-analytics-lead-time-box-plot--horizontal-log-scale--light:hash: v1.k794b7964.bc3a9455717626ef2f9541e03740bd0027c89139cd54ba4eb57a883d0e222667.OlAdmRvrHHSpGH8a2jHqV60Z957X8hIrNlcY9Duvv9Ascenes-app-engineering-analytics-pull-request--merged--dark:- hash: v1.k794b7964.acc240273e3c622972e1653ba4f16f6040e76979ea082d6f66a0fa2f89ae29bc.zZBjgKQts14dqKAy3Yhh8MU3Y8lFcIiJ7QkYDoFDkzo+ hash: v1.k794b7964.47a2880202b02bb43d0ad1f19ba771d5a54d92ba1ae001bbf72b35371e19cc3c.k1yihnihPaTG_Uq01fK4XRb9Yl8npdf7eCww6SWlaSAscenes-app-engineering-analytics-pull-request--merged--light:- hash: v1.k794b7964.c925dfc7c1a140b4ac6bb86e227e730c5922402d9869b39721e2e3be3adb090f.ZzSuEdrpXj0QvyUsVJsZAgP5Oy3fgpSkPWdak_ppSSg+ hash: v1.k794b7964.3a01727ae63ec133f77361655eb8250e5ce24140289f455c3031aea2e4dbd014.8Zi95ISEKV_XYezI20q8cXuzgR88jg_NzbgBrLkquQ8scenes-app-engineering-analytics-pull-request--out-of-the-merge-queue--dark:hash: v1.k794b7964.35ee45735fdf0dcb12e2d67cb5b9b9cd1aaba455ce97738daf2dd916466c9e0b.uv8aAw7tKaVObN2jrVxLo2UK30qPTiqoRFVJ4P6pm24scenes-app-engineering-analytics-pull-request--out-of-the-merge-queue--light:hash: v1.k794b7964.07c8c7ca126fa2f0440103062315898d3bf6e34025e2f70ca6c912f9ceb0f4ad.6OoSv6aB1RglnwxoetlMdIC7cUkatAQB1qLExL5aK0Ascenes-app-engineering-analytics-pull-request--section-load-errors--dark:- hash: v1.k794b7964.76de14a4ffa422e5a5ea57a8f0453aa2047e8ac8f62d3bd2b2bbab71ed6034db.EYERMxdXe3SOe9gdm9yVBgfY7xXbZ_owZNWZ1LWtpQ0+ hash: v1.k794b7964.0afaedfa37c206f596d077bf9c3bf1c2e4796ae2766ac8bf3f731c1a9f8cd7d8.QTSqaIlk5JU2ILV3SdefnQb7uc3mXYy13jpItpyGg6Mscenes-app-engineering-analytics-pull-request--section-load-errors--light:- hash: v1.k794b7964.121cb409bd657c5e22b632034121b25d2b785dd5499955ebc59cd0271f4db7b6.ImnAMo179ievhgIRtD_9DG4DurcdVNczCHigsbbEVGo+ hash: v1.k794b7964.b9e2a9e84eb666481eb303f5f97dbe8284b89e9316e4c793bb1a189edbf3a98d.jlYwHaG_fAyElPt4Easkh-s3dEuLiYqW4HFCa2GNRGMscenes-app-engineering-analytics-repo-overview--repo-overview--dark:hash: v1.k794b7964.1a470083e7a94ff46652f4368277eae5d35c927d65b58685e43ce34881e1e728.SEm3E8XvqrTHtJNRhVGX-9aaaw6xdWyzTNb_mw6c380scenes-app-engineering-analytics-repo-overview--repo-overview--light:diff --git a/products/engineering_analytics/frontend/components/AuthorFrictionCard.tsx b/products/engineering_analytics/frontend/components/AuthorFrictionCard.tsxnew file mode 100644index 000000000000..84e37145c8f6--- /dev/null+++ b/products/engineering_analytics/frontend/components/AuthorFrictionCard.tsx@@ -0,0 +1,131 @@+import { LemonCard, LemonSkeleton, Link, Tooltip } from '@posthog/lemon-ui'++import { urls } from 'scenes/urls'++import type { AuthorFrictionDetailApi } from '../generated/api.schemas'+import { timesTypical } from '../lib/format'+import { withCurrentScope } from '../lib/scope'+import { ComparisonBarRow } from './ComparisonBarRow'+import { FrictionGroupBar } from './FrictionGroupBar'+import { FrictionGroupLegend } from './FrictionGroupLegend'+import { FrictionGroupSegments } from './FrictionGroupSegments'++/** One author's friction next to their teams and the typical author, and the pull requests behind it. */+export function AuthorFrictionCard({+ detail,+ loading,+ sourceId,+}: {+ detail: AuthorFrictionDetailApi | null+ loading: boolean+ sourceId: string | null+}): JSX.Element {+ if (loading && !detail) {+ return (+ <LemonCard hoverEffect={false} className="p-4">+ <LemonSkeleton className="h-24 w-full" />+ </LemonCard>+ )+ }+ if (!detail || !detail.available) {+ return (+ <LemonCard hoverEffect={false} className="p-4 text-sm text-secondary">+ Friction is not ready for this project yet. It needs a GitHub source with workflow runs, workflow jobs+ and pull requests synced, and it refreshes every 12 hours.+ </LemonCard>+ )+ }++ const author = detail.author+ const rows = [+ ...(author ? [{ label: 'This author', value: author.score, groups: author.groups, muted: false }] : []),+ ...detail.teams.map((team) => ({+ label: team.github_team,+ value: team.median_score,+ groups: null,+ muted: true,+ tooltip: `Median of ${team.scored_author_count} other scored members of ${team.github_team}.`,+ })),+ { label: 'Typical author', value: 1, groups: null, muted: true },+ ]+ const max = Math.max(...rows.map((row) => row.value))+ const topScore = Math.max(0, ...detail.pull_requests.map((pr) => pr.score))++ return (+ <LemonCard+ hoverEffect={false}+ className="flex flex-col gap-4 p-4"+ data-attr="engineering-analytics-author-friction"+ >+ {author ? (+ <div className="flex flex-wrap items-baseline gap-2">+ <span className="text-2xl font-semibold leading-none tabular-nums">+ {timesTypical(author.score)}+ </span>+ <Tooltip title="Where the author lands among everyone scored, with the range from resampling their pull requests.">+ <span className="cursor-default text-xs tabular-nums text-tertiary">+ rank {author.rank} of {detail.ranked_author_count}+ {author.rank_low !== author.rank_high && ` (${author.rank_low}–${author.rank_high})`}+ </span>+ </Tooltip>+ </div>+ ) : (+ <div className="text-sm text-secondary">+ A score needs 3 merged pull requests in the last {detail.window_days} days. This author has{' '}+ {detail.pr_count}.+ </div>+ )}+ <div className="flex flex-col gap-1.5">+ {rows.map((row, index) => (+ <ComparisonBarRow+ // A handle can equal a team slug, so the label alone is no unique key.+ key={`${index}:${row.label}`}+ label={row.label}+ labelTooltip={'tooltip' in row ? row.tooltip : undefined}+ value={row.value}+ max={max}+ formatValue={timesTypical}+ muted={row.muted}+ >+ {row.groups ? <FrictionGroupSegments groups={row.groups} /> : undefined}+ </ComparisonBarRow>+ ))}+ </div>+ {!detail.has_membership_data && (+ <div className="text-xs text-secondary">+ Team baselines need the team membership table synced for this source.+ </div>+ )}+ <div className="text-xs text-tertiary">+ <FrictionGroupLegend />+ </div>+ {detail.pull_requests.length > 0 && (+ <div className="flex flex-col gap-1.5">+ <h3 className="m-0 text-xs font-semibold text-secondary">Pull requests with the most friction</h3>+ {detail.pull_requests.map((pr) => (+ <div key={`${pr.repo_owner}/${pr.repo_name}#${pr.number}`} className="flex items-center gap-3">+ <Link+ to={withCurrentScope(+ urls.engineeringAnalyticsPullRequest(pr.repo_owner, pr.repo_name, pr.number),+ sourceId+ )}+ className="min-w-0 flex-1 truncate text-xs"+ data-attr="engineering-analytics-author-friction-pr-link"+ >+ <span className="tabular-nums text-tertiary">#{pr.number}</span> {pr.title}+ </Link>+ <div className="w-32 shrink-0">+ <FrictionGroupBar groups={pr.groups} max={topScore} />+ </div>+ <Tooltip title="This pull request's friction as a multiple of the typical pull request.">+ <span className="w-12 shrink-0 text-right text-xs font-medium tabular-nums">+ {timesTypical(pr.score)}+ </span>+ </Tooltip>+ </div>+ ))}+ </div>+ )}+ </LemonCard>+ )+}diff --git a/products/engineering_analytics/frontend/components/FrictionGroupLegend.tsx b/products/engineering_analytics/frontend/components/FrictionGroupLegend.tsxnew file mode 100644index 000000000000..5bada728c329--- /dev/null+++ b/products/engineering_analytics/frontend/components/FrictionGroupLegend.tsx@@ -0,0 +1,14 @@+import { FRICTION_GROUP_COLORS, FRICTION_GROUP_LABELS, FRICTION_GROUP_ORDER } from '../lib/friction'++export function FrictionGroupLegend(): JSX.Element {+ return (+ <span className="flex flex-wrap items-center gap-3">+ {FRICTION_GROUP_ORDER.map((group) => (+ <span key={group} className="flex items-center gap-1">+ <span className={`size-2 rounded-sm ${FRICTION_GROUP_COLORS[group]}`} />+ {FRICTION_GROUP_LABELS[group]}+ </span>+ ))}+ </span>+ )+}diff --git a/products/engineering_analytics/frontend/components/FrictionGroupSegments.tsx b/products/engineering_analytics/frontend/components/FrictionGroupSegments.tsxnew file mode 100644index 000000000000..6064fd384950--- /dev/null+++ b/products/engineering_analytics/frontend/components/FrictionGroupSegments.tsx@@ -0,0 +1,26 @@+import type { FrictionGroupShareApi } from '../generated/api.schemas'+import { timesTypical } from '../lib/format'+import { FRICTION_GROUP_COLORS, FRICTION_GROUP_LABELS, FRICTION_GROUP_ORDER } from '../lib/friction'++/** A friction score's groups as colored segments that fill a comparison bar. */+export function FrictionGroupSegments({ groups }: { groups: FrictionGroupShareApi[] }): JSX.Element {+ const total = groups.reduce((sum, share) => sum + share.score, 0)+ const label = FRICTION_GROUP_ORDER.map(+ (group) =>+ `${FRICTION_GROUP_LABELS[group]} ${timesTypical(groups.find((share) => share.group === group)?.score ?? 0)}`+ ).join(', ')+ return (+ <div className="flex h-full" role="img" aria-label={label}>+ {FRICTION_GROUP_ORDER.map((group) => {+ const score = groups.find((share) => share.group === group)?.score ?? 0+ return score > 0 && total > 0 ? (+ <div+ key={group}+ className={FRICTION_GROUP_COLORS[group]}+ style={{ width: `${(score / total) * 100}%` }}+ />+ ) : null+ })}+ </div>+ )+}diff --git a/products/engineering_analytics/frontend/components/PullRequestFrictionCard.tsx b/products/engineering_analytics/frontend/components/PullRequestFrictionCard.tsxnew file mode 100644index 000000000000..0c664c9424f0--- /dev/null+++ b/products/engineering_analytics/frontend/components/PullRequestFrictionCard.tsx@@ -0,0 +1,78 @@+import { LemonCard, LemonSkeleton } from '@posthog/lemon-ui'++import type { PullRequestFrictionDetailApi } from '../generated/api.schemas'+import { timesTypical } from '../lib/format'+import { FRICTION_GROUP_COLORS, pullRequestFrictionFacts } from '../lib/friction'+import { ComparisonBarRow } from './ComparisonBarRow'+import { FrictionGroupLegend } from './FrictionGroupLegend'+import { FrictionGroupSegments } from './FrictionGroupSegments'++/** One merged pull request's friction next to the typical pull request, and what added it. */+export function PullRequestFrictionCard({+ friction,+ loading,+}: {+ friction: PullRequestFrictionDetailApi | null+ loading: boolean+}): JSX.Element {+ if (loading && !friction) {+ return (+ <LemonCard hoverEffect={false} className="p-4">+ <LemonSkeleton className="h-16 w-full" />+ </LemonCard>+ )+ }+ if (!friction || !friction.available) {+ return (+ <LemonCard hoverEffect={false} className="p-4 text-sm text-secondary">+ Friction is not ready for this project yet. It needs a GitHub source with workflow runs, workflow jobs+ and pull requests synced, and it refreshes every 12 hours.+ </LemonCard>+ )+ }+ const pr = friction.pull_request+ if (!pr) {+ return (+ <LemonCard hoverEffect={false} className="p-4 text-sm text-secondary">+ Friction covers pull requests merged in the last {friction.window_days} days, not authored by a bot.+ </LemonCard>+ )+ }++ const facts = pullRequestFrictionFacts(pr)+ const max = Math.max(pr.score, 1)+ return (+ <LemonCard+ hoverEffect={false}+ className="flex flex-col gap-4 p-4"+ data-attr="engineering-analytics-pull-request-friction"+ >+ <div className="flex flex-wrap items-baseline gap-2">+ <span className="text-2xl font-semibold leading-none tabular-nums">{timesTypical(pr.score)}</span>+ <span className="text-xs text-tertiary">the typical pull request</span>+ </div>+ <div className="flex flex-col gap-1.5">+ <ComparisonBarRow label="This pull request" value={pr.score} max={max} formatValue={timesTypical}>+ <FrictionGroupSegments groups={pr.groups} />+ </ComparisonBarRow>+ <ComparisonBarRow label="Typical" value={1} max={max} formatValue={timesTypical} muted />+ </div>+ <div className="text-xs text-tertiary">+ <FrictionGroupLegend />+ </div>+ {facts.length > 0 ? (+ <div className="grid max-w-xl grid-cols-[auto_1fr_auto] items-center gap-x-2 gap-y-1 text-xs">+ {facts.map((fact) => (+ <div key={fact.label} className="contents">+ <span className={`size-2 rounded-sm ${FRICTION_GROUP_COLORS[fact.group]}`} />+ <span className="text-secondary">{fact.label}</span>+ <span className="text-right font-medium tabular-nums">{fact.value}</span>+ </div>+ ))}+ </div>+ ) : (+ <div className="text-xs text-secondary">Nothing added friction to this pull request.</div>+ )}+ </LemonCard>+ )+}diff --git a/products/engineering_analytics/frontend/lib/friction.test.ts b/products/engineering_analytics/frontend/lib/friction.test.tsnew file mode 100644index 000000000000..b9637d313ed6--- /dev/null+++ b/products/engineering_analytics/frontend/lib/friction.test.ts@@ -0,0 +1,38 @@+import type { PullRequestFrictionBreakdownApi } from '../generated/api.schemas'+import { pullRequestFrictionFacts } from './friction'++const QUIET: PullRequestFrictionBreakdownApi = {+ score: 0.2,+ groups: [],+ flake_red_count: 0,+ master_red_count: 0,+ unknown_red_count: 0,+ own_red_count: 0,+ futile_rerun_count: 0,+ push_count: 1,+ ci_wait_seconds: [],+ first_approval_wait_seconds: null,+ pushes_after_approval: null,+ queue_seconds: null,+ kickout_count: null,+}++describe('pullRequestFrictionFacts', () => {+ test.each([+ ['a pull request that met nothing lists nothing', QUIET, []],+ ['a pull request without CI pushes shows no negative extra pushes', { ...QUIET, push_count: 0 }, []],+ [+ 'only what happened shows, in group order',+ { ...QUIET, master_red_count: 2, kickout_count: 1, push_count: 3, ci_wait_seconds: [600, 1200] },+ // pluralize joins the count and the noun with a non-breaking space.+ [+ ['queue', 'Kicked out of the merge queue', '1'],+ ['ci', 'Red, the default branch was failing', '2'],+ ['ci', 'CI running', '30m over 3\u00a0pushes'],+ ['rework', 'Extra pushes that ran CI', '2'],+ ],+ ],+ ])('%s', (_name, pr, expected) => {+ expect(pullRequestFrictionFacts(pr).map((fact) => [fact.group, fact.label, fact.value])).toEqual(expected)+ })+})diff --git a/products/engineering_analytics/frontend/lib/friction.ts b/products/engineering_analytics/frontend/lib/friction.tsindex f152e3e398c8..d82da77630de 100644--- a/products/engineering_analytics/frontend/lib/friction.ts+++ b/products/engineering_analytics/frontend/lib/friction.ts@@ -1,4 +1,7 @@-import type { FrictionGroupEnumApi } from '../generated/api.schemas'+import { pluralize } from 'lib/utils/strings'++import type { FrictionGroupEnumApi, PullRequestFrictionBreakdownApi } from '../generated/api.schemas'+import { compactAgeLabel } from './format'/** Friction groups in the order the bars stack them: the heaviest group weight first. */export const FRICTION_GROUP_ORDER: FrictionGroupEnumApi[] = ['queue', 'review', 'ci', 'rework']@@ -23,3 +26,34 @@ export const FRICTION_GROUP_COLORS: Record<FrictionGroupEnumApi, string> = {ci: 'bg-[var(--data-color-3)]',rework: 'bg-[var(--data-color-4)]',}++export interface FrictionFact {+ group: FrictionGroupEnumApi+ label: string+ value: string+}++/** What added friction to one pull request, in group order. A zero or unobserved count is left out. */+export function pullRequestFrictionFacts(pr: PullRequestFrictionBreakdownApi): FrictionFact[] {+ const count = (value: number | null | undefined): string | null => (value ? `${value}` : null)+ const duration = (seconds: number | null | undefined): string | null => (seconds ? compactAgeLabel(seconds) : null)+ const ciSeconds = pr.ci_wait_seconds.reduce((sum, seconds) => sum + seconds, 0)+ const facts: [FrictionGroupEnumApi, string, string | null][] = [+ ['queue', 'Time in the merge queue', duration(pr.queue_seconds)],+ ['queue', 'Kicked out of the merge queue', count(pr.kickout_count)],+ ['review', 'Wait for the first approval', duration(pr.first_approval_wait_seconds)],+ ['ci', 'Red, passed on a re-run', count(pr.flake_red_count)],+ ['ci', 'Red, the default branch was failing', count(pr.master_red_count)],+ ['ci', 'Red, cause not provable', count(pr.unknown_red_count)],+ ['ci', 'Re-runs that failed again', count(pr.futile_rerun_count)],+ [+ 'ci',+ 'CI running',+ ciSeconds ? `${compactAgeLabel(ciSeconds)} over ${pluralize(pr.push_count, 'push', 'pushes')}` : null,+ ],+ ['rework', 'Red until the next push', count(pr.own_red_count)],+ ['rework', 'Extra pushes that ran CI', count(Math.max(0, pr.push_count - 1))],+ ['rework', 'Pushes after approval', count(pr.pushes_after_approval)],+ ]+ return facts.flatMap(([group, label, value]) => (value ? [{ group, label, value }] : []))+}diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsxindex d09e6a518aa7..6c4ed5779de0 100644--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsx+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.stories.tsx@@ -7,6 +7,7 @@ import { urls } from 'scenes/urls'import { mswDecorator } from '~/mocks/browser'import type {+ AuthorFrictionDetailApi,DeliveryComparisonApi,DeliverySummaryApi,DurationDistributionApi,@@ -247,6 +248,59 @@ const COMPARISON: DeliveryComparisonApi = {pull_request: null,}+const FRICTION_DETAIL: AuthorFrictionDetailApi = {+ available: true,+ window_days: 30,+ ranked_author_count: 42,+ has_membership_data: true,+ author: {+ author: 'jane-dev',+ avatar_url: '',+ score: 1.8,+ groups: [+ { group: 'queue', score: 0.9 },+ { group: 'review', score: 0.4 },+ { group: 'ci', score: 0.35 },+ { group: 'rework', score: 0.15 },+ ],+ pr_count: 14,+ rank: 6,+ rank_low: 3,+ rank_high: 14,+ teams: ['team-replay'],+ },+ pr_count: 14,+ teams: [{ github_team: 'team-replay', median_score: 1.1, scored_author_count: 5 }],+ pull_requests: [+ {+ number: 5101,+ repo_owner: 'PostHog',+ repo_name: 'posthog',+ title: 'fix(replay): keep the player in sync after a seek',+ score: 4.2,+ groups: [+ { group: 'queue', score: 2.6 },+ { group: 'review', score: 0.4 },+ { group: 'ci', score: 1.0 },+ { group: 'rework', score: 0.2 },+ ],+ },+ {+ number: 5088,+ repo_owner: 'PostHog',+ repo_name: 'posthog',+ title: 'feat(replay): add a speed control to the player',+ score: 2.1,+ groups: [+ { group: 'queue', score: 0.5 },+ { group: 'review', score: 1.2 },+ { group: 'ci', score: 0.2 },+ { group: 'rework', score: 0.2 },+ ],+ },+ ],+}+const meta: Meta = {component: App,title: 'Scenes-App/Engineering Analytics/Author',@@ -267,6 +321,7 @@ const meta: Meta = {'api/projects/:team_id/engineering_analytics/delivery_comparison/': COMPARISON,'api/projects/:team_id/engineering_analytics/pull_request_timelines/': TIMELINES,'api/projects/:team_id/engineering_analytics/author_workflow_costs/': WORKFLOW_COSTS,+ 'api/projects/:team_id/engineering_analytics/author_friction_detail/': FRICTION_DETAIL,},}),],diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsxindex 57d7bbd3b0a0..62e655e15767 100644--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsx+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthorScene.tsx@@ -12,6 +12,7 @@ import { urls } from 'scenes/urls'import { SceneContent } from '~/layout/scenes/components/SceneContent'import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'+import { AuthorFrictionCard } from '../components/AuthorFrictionCard'import { CIAnalyticsLoadError } from '../components/CIAnalyticsLoadError'import { EntityHeader, VerdictPill } from '../components/EntityHeader'import { PullRequestDayView } from '../components/PullRequestDayView'@@ -38,9 +39,18 @@ export const scene: SceneExport<AuthorLogicProps> = {}export function EngineeringAnalyticsAuthorScene(): JSX.Element {- const { handle, sourceId, deliveryScope, workflowCosts, workflowCostsLoading, workflowCostsFailed } =- useValues(authorLogic)- const { loadWorkflowCosts } = useActions(authorLogic)+ const {+ handle,+ sourceId,+ deliveryScope,+ workflowCosts,+ workflowCostsLoading,+ workflowCostsFailed,+ frictionDetail,+ frictionDetailLoading,+ frictionDetailFailed,+ } = useValues(authorLogic)+ const { loadWorkflowCosts, loadFrictionDetail } = useActions(authorLogic)const { summary, summaryLoading } = useValues(deliverySummaryLogic({ scope: deliveryScope, sourceId }))const { comparison, comparisonLoading, comparisonFailed } = useValues(deliveryComparisonLogic({ author: handle, sourceId })@@ -102,8 +112,16 @@ export function EngineeringAnalyticsAuthorScene(): JSX.Element {) : undefined}/>- {/* The page explains one author's own friction against the repository and the author's own team. It- never compares authors with each other (SPEC §2). */}+ {/* The page explains one author's own friction against the repository and the author's own team. The+ friction rank orders experiences, never delivery performance (SPEC §2). It reads a fixed window, so it+ sits outside the panel the date picker governs. */}+ <Section id="author-friction" title="Friction" note={`Last ${frictionDetail?.window_days ?? 30} days`}>+ {frictionDetailFailed ? (+ <CIAnalyticsLoadError onRetry={loadFrictionDetail} />+ ) : (+ <AuthorFrictionCard detail={frictionDetail} loading={frictionDetailLoading} sourceId={sourceId} />+ )}+ </Section><ScopePanelbusy={summaryLoading || comparisonLoading || timelinesLoading || workflowCostsLoading}controls={<ScopeDateFilter dateOptions={DELIVERY_DATE_OPTIONS} />}diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsxindex 45a25a0aedcd..b6acfa8810ba 100644--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsx+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsx@@ -9,17 +9,13 @@ import { CIAnalyticsLoadError } from '../components/CIAnalyticsLoadError'import { ConnectGitHubSource } from '../components/ConnectGitHubSource'import { CountCell } from '../components/CountCell'import { FrictionGroupBar } from '../components/FrictionGroupBar'+import { FrictionGroupLegend } from '../components/FrictionGroupLegend'import { SourceScopeChip } from '../components/ScopeBar'import { ScopePanel } from '../components/ScopePanel'import { Section } from '../components/Section'import type { AuthorFrictionApi } from '../generated/api.schemas'import { timesTypical } from '../lib/format'-import {- FRICTION_GROUP_COLORS,- FRICTION_GROUP_DESCRIPTIONS,- FRICTION_GROUP_LABELS,- FRICTION_GROUP_ORDER,-} from '../lib/friction'+import { FRICTION_GROUP_DESCRIPTIONS, FRICTION_GROUP_LABELS, FRICTION_GROUP_ORDER } from '../lib/friction'import { rowNavigationProps } from '../lib/rowNavigation'import { withCurrentScope } from '../lib/scope'import { authorFrictionLogic } from './authorFrictionLogic'@@ -140,21 +136,15 @@ export function EngineeringAnalyticsAuthors(): JSX.Element {/>)- const legend = (- <span className="flex flex-wrap items-center gap-3">- {FRICTION_GROUP_ORDER.map((group) => (- <span key={group} className="flex items-center gap-1">- <span className={`size-2 rounded-sm ${FRICTION_GROUP_COLORS[group]}`} />- {FRICTION_GROUP_LABELS[group]}- </span>- ))}- </span>- )-return (<div className="flex flex-col gap-4"><ScopePanel busy={frictionLoading && !!friction} controls={<SourceScopeChip pickerOnly />}>- <Section id="author-friction" title="Friction by author" note={legend} right={teamFilter}>+ <Section+ id="author-friction"+ title="Friction by author"+ note={<FrictionGroupLegend />}+ right={teamFilter}+ >{frictionFailed ? (<CIAnalyticsLoadError onRetry={loadFriction} loading={frictionLoading} />) : friction && !friction.available ? (diff --git a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsx b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsxindex 59a482233cf2..4dd28f502a9b 100644--- a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsx+++ b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.stories.tsx@@ -12,6 +12,7 @@ import type {PRCostSummaryApi,PRLifecycleApi,PRTimelineApi,+ PullRequestFrictionDetailApi,PullRequestTimelinesApi,ReadyToMergeMediansApi,WorkflowJobApi,@@ -258,6 +259,32 @@ const MERGED_COMPARISON = comparison({before_first_approval_share: 29 / 31.4,})+// One flaky red stretch, a first approval after more than a day, and a queue stay past its free half hour.+const MERGED_FRICTION: PullRequestFrictionDetailApi = {+ available: true,+ window_days: 30,+ pull_request: {+ score: 1.9,+ groups: [+ { group: 'queue', score: 0.4 },+ { group: 'review', score: 1.1 },+ { group: 'ci', score: 0.35 },+ { group: 'rework', score: 0.05 },+ ],+ flake_red_count: 1,+ master_red_count: 0,+ unknown_red_count: 0,+ own_red_count: 0,+ futile_rerun_count: 0,+ push_count: 2,+ ci_wait_seconds: [0.5 * HOUR_SECONDS, 1.9 * HOUR_SECONDS],+ first_approval_wait_seconds: 29 * HOUR_SECONDS,+ pushes_after_approval: 0,+ queue_seconds: 0.9 * HOUR_SECONDS,+ kickout_count: 0,+ },+}+const meta: Meta = {component: App,title: 'Scenes-App/Engineering Analytics/Pull Request',@@ -280,6 +307,7 @@ const meta: Meta = {'api/projects/:team_id/engineering_analytics/ci_failure_logs/': NO_FAILURE_LOGS,'api/projects/:team_id/engineering_analytics/pull_request_timelines/': timelines(MERGED),'api/projects/:team_id/engineering_analytics/delivery_comparison/': MERGED_COMPARISON,+ 'api/projects/:team_id/engineering_analytics/pull_request_friction/': MERGED_FRICTION,},}),],diff --git a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsx b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsxindex 6499771ff8e6..eaf3e5f23cd1 100644--- a/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsx+++ b/products/engineering_analytics/frontend/scenes/PullRequestDetailScene.tsx@@ -29,6 +29,7 @@ import { GroupedJobsTable } from '../components/GroupedJobsTable'import { MetricTile } from '../components/MetricTile'import { PullRequestComparisonCard } from '../components/PullRequestComparisonCard'import { PullRequestDeliveryTimeline } from '../components/PullRequestDeliveryTimeline'+import { PullRequestFrictionCard } from '../components/PullRequestFrictionCard'import { PullRequestStateTag } from '../components/PullRequestStateTag'import { RunConclusionTag } from '../components/runTables'import { RepoScopeChip, ScopeBar } from '../components/ScopeBar'@@ -417,9 +418,20 @@ export function PullRequestDetailScene(): JSX.Element {timelinesLoading,timelinesFailed,timeline,+ friction,+ frictionLoading,+ frictionFailed,} = useValues(pullRequestDetailLogic)- const { loadLifecycle, loadPrCost, loadPrRuns, loadTimelines, loadFailureLogs, setWorkflowFilter, setRunExpanded } =- useActions(pullRequestDetailLogic)+ const {+ loadLifecycle,+ loadPrCost,+ loadPrRuns,+ loadTimelines,+ loadFailureLogs,+ loadFriction,+ setWorkflowFilter,+ setRunExpanded,+ } = useActions(pullRequestDetailLogic)const pullRequest = lifecycle?.pull_requestconst githubUrl = pullRequest@@ -607,6 +619,18 @@ export function PullRequestDetailScene(): JSX.Element {<LemonSkeleton className="h-24 w-full" />)}+ {/* Friction exists only for merged pull requests. It reads a fixed window, like the author and team+ pages, and comes first there too. */}+ {pullRequest?.state === 'merged' && (+ <Section id="pr-friction" title="Friction" note={`Last ${friction?.window_days ?? 30} days`}>+ {frictionFailed ? (+ <CIAnalyticsLoadError onRetry={loadFriction} loading={frictionLoading} />+ ) : (+ <PullRequestFrictionCard friction={friction} loading={frictionLoading} />+ )}+ </Section>+ )}+<Section id="pr-timeline" title="Lifecycle">{timelinesFailed ? (<CIAnalyticsLoadErrordiff --git a/products/engineering_analytics/frontend/scenes/authorLogic.test.ts b/products/engineering_analytics/frontend/scenes/authorLogic.test.tsindex 348d7b09dddf..2d82f0851df9 100644--- a/products/engineering_analytics/frontend/scenes/authorLogic.test.ts+++ b/products/engineering_analytics/frontend/scenes/authorLogic.test.ts@@ -9,6 +9,7 @@ import { engineeringAnalyticsAuthorWorkflowCosts } from '../generated/api'import { authorLogic } from './authorLogic'jest.mock('../generated/api', () => ({+ engineeringAnalyticsAuthorFrictionDetail: jest.fn().mockResolvedValue(null),engineeringAnalyticsAuthorWorkflowCosts: jest.fn(),}))diff --git a/products/engineering_analytics/frontend/scenes/authorLogic.ts b/products/engineering_analytics/frontend/scenes/authorLogic.tsindex 5acd438c2d85..09c0285f1c99 100644--- a/products/engineering_analytics/frontend/scenes/authorLogic.ts+++ b/products/engineering_analytics/frontend/scenes/authorLogic.ts@@ -7,8 +7,8 @@ import { urls } from 'scenes/urls'import { Breadcrumb } from '~/types'-import { engineeringAnalyticsAuthorWorkflowCosts } from '../generated/api'-import type { WorkflowCostApi } from '../generated/api.schemas'+import { engineeringAnalyticsAuthorFrictionDetail, engineeringAnalyticsAuthorWorkflowCosts } from '../generated/api'+import type { AuthorFrictionDetailApi, WorkflowCostApi } from '../generated/api.schemas'import { DeliveryScope } from '../lib/deliveryScope'import { withScope } from '../lib/scope'import { engineeringAnalyticsFiltersLogic } from './engineeringAnalyticsFiltersLogic'@@ -25,6 +25,9 @@ export interface authorLogicValues {dateTo: string | null // engineeringAnalyticsFiltersLogicbreadcrumbs: Breadcrumb[]deliveryScope: DeliveryScope+ frictionDetail: AuthorFrictionDetailApi | null+ frictionDetailFailed: boolean+ frictionDetailLoading: booleanhandle: stringsourceId: string | nullworkflowCosts: WorkflowCostApi[]@@ -34,6 +37,12 @@ export interface authorLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface authorLogicActions {+ loadFrictionDetail: () => any+ loadFrictionDetailFailure: (error: string, errorObject?: any) => { error: string; errorObject?: any }+ loadFrictionDetailSuccess: (+ frictionDetail: AuthorFrictionDetailApi,+ payload?: any+ ) => { frictionDetail: AuthorFrictionDetailApi; payload?: any }loadWorkflowCosts: () => anyloadWorkflowCostsFailure: (error: string, errorObject?: any) => { error: string; errorObject?: any }loadWorkflowCostsSuccess: (@@ -79,10 +88,22 @@ export const authorLogic = kea<authorLogicType>([}),},],+ // A fixed 30-day window from the materialized friction view, so the date picker does not move it.+ frictionDetail: [+ null as AuthorFrictionDetailApi | null,+ {+ loadFrictionDetail: async () =>+ await engineeringAnalyticsAuthorFrictionDetail(String(ApiConfig.getCurrentProjectId()), {+ author: props.handle,+ source_id: props.sourceId ?? undefined,+ }),+ },+ ],})),reducers({workflowCostsFailed: [false, { loadWorkflowCosts: () => false, loadWorkflowCostsFailure: () => true }],+ frictionDetailFailed: [false, { loadFrictionDetail: () => false, loadFrictionDetailFailure: () => true }],}),listeners(({ actions }) => ({@@ -125,5 +146,6 @@ export const authorLogic = kea<authorLogicType>([afterMount(({ actions }) => {actions.loadWorkflowCosts()+ actions.loadFrictionDetail()}),])diff --git a/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.ts b/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.tsindex 27c1caad959e..e25424548654 100644--- a/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.ts+++ b/products/engineering_analytics/frontend/scenes/pullRequestDetailLogic.ts@@ -12,6 +12,7 @@ import {engineeringAnalyticsPrCost,engineeringAnalyticsPrLifecycle,engineeringAnalyticsPrRuns,+ engineeringAnalyticsPullRequestFriction,engineeringAnalyticsPullRequestTimelines,engineeringAnalyticsWorkflowJobs,} from '../generated/api'@@ -20,6 +21,7 @@ import type {PRCostSummaryApi,PRLifecycleApi,PRTimelineApi,+ PullRequestFrictionDetailApi,PullRequestTimelinesApi,WorkflowJobApi,WorkflowRunDetailApi,@@ -173,6 +175,9 @@ export interface pullRequestDetailLogicValues {filteredCommitGroups: PrCommitRuns[]filteredPrWorkflowRows: PrWorkflowRow[]filteredRuns: PrRunRow[]+ friction: PullRequestFrictionDetailApi | null+ frictionFailed: boolean+ frictionLoading: booleanlatestPushStats: LatestPushStats | nulllifecycle: PRLifecycleApi | nulllifecycleLoading: boolean@@ -223,6 +228,21 @@ export interface pullRequestDetailLogicActions {failureLogs: CIFailureLogsApi | 'unavailable'payload?: any}+ loadFriction: () => any+ loadFrictionFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadFrictionSuccess: (+ friction: PullRequestFrictionDetailApi,+ payload?: any+ ) => {+ friction: PullRequestFrictionDetailApi+ payload?: any+ }loadJobs: ({ runId, runAttempt }: { runAttempt: number | null; runId: number }) => {runId: numberrunAttempt: number | null@@ -431,6 +451,17 @@ export const pullRequestDetailLogic = kea<pullRequestDetailLogicType>([}),},],+ friction: [+ null as PullRequestFrictionDetailApi | null,+ {+ loadFriction: async (): Promise<PullRequestFrictionDetailApi> =>+ await engineeringAnalyticsPullRequestFriction(projectId(), {+ pr_number: props.number,+ repo: `${props.repoOwner}/${props.repoName}`,+ source_id: props.sourceId ?? undefined,+ }),+ },+ ],// Fetched only once a decisive failure is known; 'unavailable' = the fetch itself failed.failureLogs: [null as CIFailureLogsApi | 'unavailable' | null,@@ -499,6 +530,7 @@ export const pullRequestDetailLogic = kea<pullRequestDetailLogicType>([},],timelinesFailed: [false, { loadTimelines: () => false, loadTimelinesFailure: () => true }],+ frictionFailed: [false, { loadFriction: () => false, loadFrictionFailure: () => true }],expandedRunKeys: [[] as string[],{@@ -515,6 +547,12 @@ export const pullRequestDetailLogic = kea<pullRequestDetailLogicType>([actions.loadJobs({ runId, runAttempt })}},+ // Only a merged pull request has friction, so an open one skips the read.+ loadLifecycleSuccess: ({ lifecycle }) => {+ if (lifecycle?.pull_request?.state === 'merged') {+ actions.loadFriction()+ }+ },// Failure logs only exist once something failed — skip the Logs query otherwise.loadPrRunsSuccess: () => {if (values.prRuns.some((run) => isDecisiveFailure(run.conclusion))) {