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(desktop): show ranking lift in inbox activity on desktop and mobile (#111053)

posthog[bot]e711224e3062
diff --git a/packages/agent/packages/agent-contracts/src/domain-types.ts b/packages/agent/packages/agent-contracts/src/domain-types.ts
index 064e6a5699f3..77600765c50d 100644
--- a/packages/agent/packages/agent-contracts/src/domain-types.ts
+++ b/packages/agent/packages/agent-contracts/src/domain-types.ts
@@ -1050,10 +1050,14 @@ export interface RankingScoreArtefact extends SignalReportArtefactBase {
content: RankingScoreContent;
}
-/** One outcome head. `readable` is false when the head has no holdout AUC yet. */
+/**
+ * One outcome head. `readable` is false when the head has no holdout AUC yet.
+ * `lift` is the probability over the head's base rate, or null when the model saved no base rate.
+ */
export interface RankingHead {
name: string;
probability: number;
+ lift: number | null;
readable: boolean;
}
@@ -1063,7 +1067,7 @@ export interface RankingModelResult {
roles: string[];
status: "scored" | "skipped";
skip_reason: string | null;
- /** Highest probability first. */
+ /** Highest lift first. Heads without a lift come last, highest probability first. */
heads: RankingHead[];
}
diff --git a/products/desktop/apps/mobile/src/features/inbox/activityLog.test.ts b/products/desktop/apps/mobile/src/features/inbox/activityLog.test.ts
index 4a6d16ce462b..84d202fcdd5f 100644
--- a/products/desktop/apps/mobile/src/features/inbox/activityLog.test.ts
+++ b/products/desktop/apps/mobile/src/features/inbox/activityLog.test.ts
@@ -34,7 +34,7 @@ function taskRun(id: string, createdAt: string): AnySignalReportArtefact {
}
describe("selectActivityArtefacts", () => {
- it("keeps only commit and task_run, sorted oldest-first", () => {
+ it("keeps only commit, task_run and parsed ranking_score, sorted oldest-first", () => {
const artefacts: AnySignalReportArtefact[] = [
taskRun("b", "2026-01-02T00:00:00Z"),
{
@@ -44,11 +44,36 @@ describe("selectActivityArtefacts", () => {
content: { note: "" },
},
commit("a", "2026-01-01T00:00:00Z"),
+ {
+ id: "r",
+ type: "ranking_score",
+ created_at: "2026-01-04T00:00:00Z",
+ content: {
+ scored_at: null,
+ manifest_version: null,
+ served: {
+ key: "m@1",
+ roles: ["served"],
+ status: "scored",
+ skip_reason: null,
+ heads: [],
+ },
+ challengers: [],
+ },
+ },
+ {
+ id: "degraded",
+ type: "ranking_score",
+ created_at: "2026-01-05T00:00:00Z",
+ content: { content: "{}" },
+ degraded: true,
+ } as AnySignalReportArtefact,
];
expect(selectActivityArtefacts(artefacts).map((a) => a.id)).toEqual([
"a",
"b",
+ "r",
]);
});
diff --git a/products/desktop/apps/mobile/src/features/inbox/activityLog.ts b/products/desktop/apps/mobile/src/features/inbox/activityLog.ts
index 7647862c9897..51a84707f15b 100644
--- a/products/desktop/apps/mobile/src/features/inbox/activityLog.ts
+++ b/products/desktop/apps/mobile/src/features/inbox/activityLog.ts
@@ -2,7 +2,7 @@ import type { AnySignalReportArtefact } from "@posthog/shared/domain-types";
export type ActivityArtefact = Extract<
AnySignalReportArtefact,
- { type: "commit" | "task_run" }
+ { type: "commit" | "task_run" | "ranking_score" }
>;
export function selectActivityArtefacts(
@@ -11,7 +11,10 @@ export function selectActivityArtefacts(
return artefacts
.filter(
(artefact): artefact is ActivityArtefact =>
- artefact.type === "commit" || artefact.type === "task_run",
+ artefact.type === "commit" ||
+ artefact.type === "task_run" ||
+ // A degraded score has no heads to show.
+ (artefact.type === "ranking_score" && !artefact.degraded),
)
.sort((left, right) => left.created_at.localeCompare(right.created_at));
}
diff --git a/products/desktop/apps/mobile/src/features/inbox/components/ArtefactRankingScore.tsx b/products/desktop/apps/mobile/src/features/inbox/components/ArtefactRankingScore.tsx
new file mode 100644
index 000000000000..f8edc5fc00c6
--- /dev/null
+++ b/products/desktop/apps/mobile/src/features/inbox/components/ArtefactRankingScore.tsx
@@ -0,0 +1,85 @@
+import { Text } from "@components/text";
+import { humanizeIdentifier } from "@posthog/core/inbox/activityLog";
+import {
+ formatRankingLift,
+ formatRankingProbability,
+ rankingLiftBarPercent,
+} from "@posthog/core/inbox/rankingFormat";
+import type {
+ RankingHead,
+ RankingScoreContent,
+} from "@posthog/shared/domain-types";
+import { View } from "react-native";
+
+function RankingHeadRow({ head }: { head: RankingHead }) {
+ const tone = head.readable ? "text-gray-12" : "text-gray-10";
+ const values = [
+ humanizeIdentifier(head.name),
+ head.lift !== null ? formatRankingLift(head.lift) : null,
+ formatRankingProbability(head.probability),
+ head.readable ? null : "no holdout read yet",
+ ];
+ return (
+ <View
+ className="flex-row items-center gap-2"
+ accessible
+ accessibilityLabel={values.filter(Boolean).join(", ")}
+ >
+ <Text className={`w-24 text-[12px] ${tone}`} numberOfLines={1}>
+ {humanizeIdentifier(head.name)}
+ </Text>
+ <View className="relative h-1.5 flex-1 overflow-hidden rounded-full bg-gray-4">
+ {head.lift !== null ? (
+ <View
+ className={`h-full rounded-full ${head.readable ? "bg-accent-9" : "bg-gray-8"}`}
+ style={{ width: `${rankingLiftBarPercent(head.lift)}%` }}
+ />
+ ) : null}
+ <View className="absolute top-0 bottom-0 left-1/2 w-px bg-gray-9" />
+ </View>
+ <Text
+ className={`min-w-10 text-right text-[12px] ${tone}`}
+ numberOfLines={1}
+ >
+ {head.lift !== null ? formatRankingLift(head.lift) : ""}
+ </Text>
+ <Text
+ className="min-w-11 text-right text-[12px] text-gray-10"
+ numberOfLines={1}
+ >
+ {formatRankingProbability(head.probability)}
+ </Text>
+ </View>
+ );
+}
+
+/** The served model's heads. Dimmed heads have no holdout read yet. */
+export function ArtefactRankingScore({
+ content,
+}: {
+ content: RankingScoreContent;
+}) {
+ const { served } = content;
+ const hasUnreadable = served.heads.some((head) => !head.readable);
+ return (
+ <View className="gap-1">
+ {served.status === "skipped" || served.heads.length === 0 ? (
+ <Text className="text-[12px] text-gray-10">
+ Skipped{served.skip_reason ? `: ${served.skip_reason}` : ""}
+ </Text>
+ ) : (
+ served.heads.map((head) => (
+ <RankingHeadRow key={head.name} head={head} />
+ ))
+ )}
+ {hasUnreadable ? (
+ <Text className="text-[11px] text-gray-9">
+ Dimmed heads have no holdout read yet.
+ </Text>
+ ) : null}
+ <Text className="font-mono text-[11px] text-gray-9" numberOfLines={1}>
+ {served.key}
+ </Text>
+ </View>
+ );
+}
diff --git a/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.test.tsx b/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.test.tsx
index 14bbc4b49375..5f2ba9f01ee1 100644
--- a/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.test.tsx
+++ b/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.test.tsx
@@ -64,6 +64,53 @@ describe("ReportActivity", () => {
expect(output).not.toContain("Corroborated");
});
+ it("shows each ranking head's lift beside its probability", () => {
+ const renderer = render({
+ artefacts: [
+ {
+ id: "r1",
+ type: "ranking_score",
+ created_at: "2026-01-01T00:00:00Z",
+ content: {
+ scored_at: null,
+ manifest_version: null,
+ served: {
+ key: "report_embeddings@1",
+ roles: ["served"],
+ status: "scored",
+ skip_reason: null,
+ heads: [
+ {
+ name: "pr_merged",
+ probability: 0.52,
+ lift: 2.6,
+ readable: true,
+ },
+ {
+ name: "refund",
+ probability: 0.04,
+ lift: null,
+ readable: false,
+ },
+ ],
+ },
+ challengers: [],
+ },
+ },
+ ],
+ });
+ const output = visibleText(renderer);
+ expect(output).toContain("Ranking scored");
+ expect(output).toContain("Pr merged2.6x52%");
+ expect(output).toContain("Refund4.0%");
+ expect(output).toContain("Dimmed heads have no holdout read yet.");
+ expect(
+ renderer.root
+ .findAll((node) => typeof node.props.accessibilityLabel === "string")
+ .map((node) => node.props.accessibilityLabel),
+ ).toContain("Refund, 4.0%, no holdout read yet");
+ });
+
it.each([
[1, "1 confirmation", "Corroborated 1 more time by a scout"],
[3, "3 confirmations", "Corroborated 3 more times by a scout"],
diff --git a/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.tsx b/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.tsx
index 30cf1f0888d2..057d0d0c6f77 100644
--- a/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.tsx
+++ b/products/desktop/apps/mobile/src/features/inbox/components/ReportActivity.tsx
@@ -8,8 +8,15 @@ import { formatRelativeTime } from "@/lib/format";
import { useThemeColors } from "@/lib/theme";
import { type ActivityArtefact, selectActivityArtefacts } from "../activityLog";
import { ArtefactCommit } from "./ArtefactCommit";
+import { ArtefactRankingScore } from "./ArtefactRankingScore";
import { ArtefactTaskRun } from "./ArtefactTaskRun";
+const ARTEFACT_LABELS: Record<ActivityArtefact["type"], string> = {
+ commit: "Commit pushed",
+ task_run: "Task run",
+ ranking_score: "Ranking scored",
+};
+
function ArtefactRow({
reportId,
artefact,
@@ -24,7 +31,7 @@ function ArtefactRow({
<View className="rounded-xl border border-gray-6 bg-gray-1 p-3">
<View className="mb-1.5 flex-row items-center gap-2">
<Text className="font-medium text-[12px] text-gray-12">
- {artefact.type === "commit" ? "Commit pushed" : "Task run"}
+ {ARTEFACT_LABELS[artefact.type]}
</Text>
<View className="flex-1" />
{attribution ? (
@@ -42,6 +49,8 @@ function ArtefactRow({
artefactId={artefact.id}
content={artefact.content}
/>
+ ) : artefact.type === "ranking_score" ? (
+ <ArtefactRankingScore content={artefact.content} />
) : (
<ArtefactTaskRun content={artefact.content} />
)}
diff --git a/products/desktop/packages/api-client/src/posthog-client.test.ts b/products/desktop/packages/api-client/src/posthog-client.test.ts
index 396950307214..272f9a0f323e 100644
--- a/products/desktop/packages/api-client/src/posthog-client.test.ts
+++ b/products/desktop/packages/api-client/src/posthog-client.test.ts
@@ -2699,11 +2699,24 @@ describe("PostHogAPIClient", () => {
status: "scored",
roles: ["served"],
scores: { pr_merged: 0.52, action: 0.78, refund: 0.04 },
+ lifts: { action: 1.3 },
metadata: {
heads: [
- { head: "action", readable: true },
- { head: "pr_merged", readable: true },
- { head: "refund", readable: false },
+ {
+ head: "action",
+ readable: true,
+ refit_classification_threshold: 0.6,
+ },
+ {
+ head: "pr_merged",
+ readable: true,
+ refit_classification_threshold: 0.2,
+ },
+ {
+ head: "refund",
+ readable: false,
+ refit_classification_threshold: 0,
+ },
],
},
},
@@ -2735,10 +2748,12 @@ describe("PostHogAPIClient", () => {
roles: ["served"],
status: "scored",
skip_reason: null,
+ // Stored lifts win, older rows derive lift from a positive base rate,
+ // and a head without one sorts last.
heads: [
- { name: "action", probability: 0.78, readable: true },
- { name: "pr_merged", probability: 0.52, readable: true },
- { name: "refund", probability: 0.04, readable: false },
+ { name: "pr_merged", probability: 0.52, lift: 2.6, readable: true },
+ { name: "action", probability: 0.78, lift: 1.3, readable: true },
+ { name: "refund", probability: 0.04, lift: null, readable: false },
],
},
challengers: [
diff --git a/products/desktop/packages/api-client/src/posthog-client.ts b/products/desktop/packages/api-client/src/posthog-client.ts
index a0d7b44712b2..0c50e36876f4 100644
--- a/products/desktop/packages/api-client/src/posthog-client.ts
+++ b/products/desktop/packages/api-client/src/posthog-client.ts
@@ -41,6 +41,7 @@ import type {
OrganizationMemberBasic,
PriorityJudgmentArtefact,
ProvisionedTaskChannels,
+ RankingHead,
RankingModelResult,
RankingScoreArtefact,
RepoSelectionArtefact,
@@ -1745,6 +1746,24 @@ function normalizeWorkReleaseArtefact(
};
}
+/** Reads the stored lift first. Otherwise mirrors `head_lifts` in `ranking/model_contract.py`. */
+function rankingHeadLift(
+ stored: unknown,
+ probability: number,
+ threshold: number | undefined,
+): number | null {
+ if (typeof stored === "number" && Number.isFinite(stored)) return stored;
+ return threshold !== undefined && threshold > 0
+ ? probability / threshold
+ : null;
+}
+
+function compareRankingHeads(a: RankingHead, b: RankingHead): number {
+ if (a.lift !== null && b.lift !== null) return b.lift - a.lift;
+ if (a.lift !== null || b.lift !== null) return a.lift === null ? 1 : -1;
+ return b.probability - a.probability;
+}
+
function normalizeRankingModelResult(
key: string,
value: unknown,
@@ -1762,6 +1781,17 @@ function normalizeRankingModelResult(
.filter((entry) => isObjectRecord(entry) && entry.readable === true)
.map((entry) => String((entry as Record<string, unknown>).head)),
);
+ // Mirrors `classification_thresholds` in `ranking/model_contract.py`.
+ const thresholds = new Map<string, number>();
+ for (const entry of metadataHeads) {
+ if (
+ isObjectRecord(entry) &&
+ typeof entry.refit_classification_threshold === "number"
+ ) {
+ thresholds.set(String(entry.head), entry.refit_classification_threshold);
+ }
+ }
+ const lifts = isObjectRecord(value.lifts) ? value.lifts : {};
const scores = isObjectRecord(value.scores) ? value.scores : {};
const heads = Object.entries(scores)
.filter(
@@ -1771,9 +1801,10 @@ function normalizeRankingModelResult(
.map(([name, probability]) => ({
name,
probability,
+ lift: rankingHeadLift(lifts[name], probability, thresholds.get(name)),
readable: readable.has(name),
}))
- .sort((a, b) => b.probability - a.probability);
+ .sort(compareRankingHeads);
return {
key,
roles: Array.isArray(value.roles)
diff --git a/products/desktop/packages/core/src/inbox/rankingFormat.test.ts b/products/desktop/packages/core/src/inbox/rankingFormat.test.ts
new file mode 100644
index 000000000000..561d296938f3
--- /dev/null
+++ b/products/desktop/packages/core/src/inbox/rankingFormat.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from "vitest";
+import {
+ formatRankingLift,
+ formatRankingProbability,
+ rankingLiftBarPercent,
+} from "./rankingFormat";
+
+describe("rankingFormat", () => {
+ it.each([
+ [0.04, "0.0x"],
+ [2.74, "2.7x"],
+ [9.96, "10x"],
+ [12.4, "12x"],
+ ])("formats a lift of %s as %s", (lift, expected) => {
+ expect(formatRankingLift(lift)).toBe(expected);
+ });
+
+ it.each([
+ [0.0123, "1.2%"],
+ [0.0996, "10%"],
+ [0.524, "52%"],
+ ])("formats a probability of %s as %s", (probability, expected) => {
+ expect(formatRankingProbability(probability)).toBe(expected);
+ });
+
+ it.each([
+ [0, 0],
+ [0.1, 0],
+ [1, 50],
+ [10, 100],
+ [40, 100],
+ ])("places a lift of %s at %s%% of the bar", (lift, expected) => {
+ expect(rankingLiftBarPercent(lift)).toBeCloseTo(expected);
+ });
+});
diff --git a/products/desktop/packages/core/src/inbox/rankingFormat.ts b/products/desktop/packages/core/src/inbox/rankingFormat.ts
new file mode 100644
index 000000000000..29c4a969e855
--- /dev/null
+++ b/products/desktop/packages/core/src/inbox/rankingFormat.ts
@@ -0,0 +1,26 @@
+/** No decimals at 10% and above. Heads such as `action` have low base rates, so one decimal below 10%. */
+export function formatRankingProbability(probability: number): string {
+ const percent = probability * 100;
+ const oneDecimal = Math.round(percent * 10) / 10;
+ return oneDecimal >= 10
+ ? `${Math.round(percent)}%`
+ : `${oneDecimal.toFixed(1)}%`;
+}
+
+/** One decimal below 10x, no decimals at 10x and above. */
+export function formatRankingLift(lift: number): string {
+ const oneDecimal = Math.round(lift * 10) / 10;
+ return oneDecimal >= 10
+ ? `${Math.round(lift)}x`
+ : `${oneDecimal.toFixed(1)}x`;
+}
+
+/**
+ * Bar width in percent for a lift on a log scale. 1x sits at 50%, and the bar clamps at 0.1x and 10x,
+ * so a lift and its inverse sit at equal distances from the center.
+ */
+export function rankingLiftBarPercent(lift: number): number {
+ if (!(lift > 0)) return 0;
+ const position = (Math.log10(lift) + 1) / 2;
+ return Math.min(1, Math.max(0, position)) * 100;
+}
diff --git a/products/desktop/packages/ui/src/features/inbox/components/detail/ArtefactLogList.tsx b/products/desktop/packages/ui/src/features/inbox/components/detail/ArtefactLogList.tsx
index 4cbdb7deec06..85bb52f54c6a 100644
--- a/products/desktop/packages/ui/src/features/inbox/components/detail/ArtefactLogList.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/components/detail/ArtefactLogList.tsx
@@ -5,6 +5,11 @@ import {
InfoIcon,
} from "@phosphor-icons/react";
import { attributionLabel } from "@posthog/core/inbox/activityLog";
+import {
+ formatRankingLift,
+ formatRankingProbability,
+ rankingLiftBarPercent,
+} from "@posthog/core/inbox/rankingFormat";
import type {
ActionabilityJudgmentContent,
AnySignalReportArtefact,
@@ -251,28 +256,37 @@ function ReviewersBody({ reviewers }: { reviewers: SuggestedReviewer[] }) {
);
}
+function RankingLiftBar({ head }: { head: RankingHead }) {
+ return (
+ <div className="relative h-1.5 overflow-hidden rounded-full bg-(--gray-4)">
+ {head.lift !== null ? (
+ <div
+ className={`h-full rounded-full ${head.readable ? "bg-(--accent-9)" : "bg-(--gray-8)"}`}
+ style={{ width: `${rankingLiftBarPercent(head.lift)}%` }}
+ />
+ ) : null}
+ <span
+ className="absolute inset-y-0 left-1/2 w-px bg-(--gray-9)"
+ aria-hidden
+ />
+ </div>
+ );
+}
+
function RankingHeadRows({ heads }: { heads: RankingHead[] }) {
return (
- <Box className="grid grid-cols-[minmax(0,max-content)_minmax(2rem,10rem)_auto] items-center justify-start gap-x-2 gap-y-1 text-[12px]">
+ <div className="grid grid-cols-[minmax(0,max-content)_minmax(2rem,10rem)_auto_auto] items-center justify-start gap-x-2 gap-y-1 text-[12px]">
{heads.map((head) => {
- const percent = Math.round(head.probability * 100);
const tone = head.readable ? "text-(--gray-12)" : "text-(--gray-10)";
return (
<Fragment key={head.name}>
- <Text className={`truncate ${tone}`}>{prettify(head.name)}</Text>
- <Box className="h-1.5 overflow-hidden rounded-full bg-(--gray-4)">
- <Box
- className={`h-full rounded-full ${head.readable ? "bg-(--accent-9)" : "bg-(--gray-8)"}`}
- style={{ width: `${percent}%` }}
- />
- </Box>
- <Flex
- align="center"
- justify="end"
- gap="1"
- className={`tabular-nums ${tone}`}
- >
- {percent}%
+ <span className={`truncate ${tone}`}>{prettify(head.name)}</span>
+ <RankingLiftBar head={head} />
+ <span className={`text-right tabular-nums ${tone}`}>
+ {head.lift !== null ? formatRankingLift(head.lift) : null}
+ </span>
+ <div className="flex items-center justify-end gap-1 text-(--gray-10) tabular-nums">
+ {formatRankingProbability(head.probability)}
{head.readable ? (
<span className="size-3" aria-hidden />
) : (
@@ -285,11 +299,11 @@ function RankingHeadRows({ heads }: { heads: RankingHead[] }) {
<InfoIcon size={12} />
</span>
)}
- </Flex>
+ </div>
</Fragment>
);
})}
- </Box>
+ </div>
);
}