:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): show every signals run in the inbox Runs list (#92805)
posthog[bot]35cd0e95ffb0
diff --git a/products/desktop/packages/api-client/src/posthog-client.test.ts b/products/desktop/packages/api-client/src/posthog-client.test.tsindex 0093ab9bdb23..44a472003447 100644--- a/products/desktop/packages/api-client/src/posthog-client.test.ts+++ b/products/desktop/packages/api-client/src/posthog-client.test.ts@@ -2284,6 +2284,26 @@ describe("PostHogAPIClient", () => {// attribution survives the fallback pathexpect(results[0].task_id).toBe("t1");});++ it.each([+ [+ "asks for the full log when a caller reads every row",+ { limit: 1000 },+ "1000",+ ],+ ["leaves list callers on the server page size", undefined, null],+ ])("%s", async (_name, options, expected) => {+ const fetch = vi.fn().mockResolvedValue({+ ok: true,+ json: async () => ({ count: 0, results: [] }),+ });+ const client = makeClient(fetch);++ await client.getSignalReportArtefacts("r1", options);++ const { url } = fetch.mock.calls[0][0] as { url: URL };+ expect(url.searchParams.get("limit")).toBe(expected);+ });});describe("updateSignalReportArtefact", () => {diff --git a/products/desktop/packages/api-client/src/posthog-client.ts b/products/desktop/packages/api-client/src/posthog-client.tsindex c068e3e8c88e..89f60485346a 100644--- a/products/desktop/packages/api-client/src/posthog-client.ts+++ b/products/desktop/packages/api-client/src/posthog-client.ts@@ -5001,14 +5001,25 @@ export class PostHogAPIClient {}}+ /**+ * The list is newest-first and truncates to the server page size, which drops the oldest+ * rows — including the scout `task_run` written when the report was created. Pass `limit`+ * from callers that read the whole log. Callers that need only the newest row of a+ * latest-wins type should omit it: artefacts carry diffs and code excerpts, and list rows+ * fetch this once per card.+ */async getSignalReportArtefacts(reportId: string,+ options?: { limit?: number },): Promise<SignalReportArtefactsResponse> {const teamId = await this.getTeamId();const url = new URL(`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/${reportId}/artefacts/`,);const path = `/api/projects/${teamId}/signals/reports/${reportId}/artefacts/`;+ if (options?.limit !== undefined) {+ url.searchParams.set("limit", String(options.limit));+ }try {const response = await this.api.fetcher.fetch({diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsxindex 8c10de567ec7..b86ab16b7cdf 100644--- a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsx+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsx@@ -131,16 +131,18 @@ export function ReportTriageFocus({const clamped = Math.min(index, Math.max(0, reports.length - 1));const report = reports[clamped];const reportId = report?.id;- const { data: reportTasks, isLoading: reportTasksLoading } = useReportTasks(- reportId ?? "",- report?.status ?? "candidate",- );+ const {+ data: reportTasks,+ isLoading: reportTasksLoading,+ isError: reportTasksFailed,+ } = useReportTasks(reportId ?? "", report?.status ?? "candidate");const continuableTask = findContinuableImplementationTask(reportTasks);const canCreatePr =report?.status === "ready" &&canCreateImplementationPr(report, {hasLiveImplementationTask: continuableTask !== null,- isTaskLookupPending: reportTasksLoading,+ // A failed lookup leaves task state unknown, same as a pending one.+ isTaskLookupPending: reportTasksLoading || reportTasksFailed,});const livePrUrl = report?.implementation_pr_merged? nulldiff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.test.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.test.tsxindex 86343b5267ab..7852c6cd07b6 100644--- a/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.test.tsx+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.test.tsx@@ -245,6 +245,26 @@ describe("ReportVerdictBanner", () => {expect(createPrReport).not.toHaveBeenCalled();});+ it("withholds Create PR when the task lookup failed", () => {+ // An unresolved lookup cannot rule out live implementation work, so offering+ // Create PR here would bill a second agent PR on work that already has one.+ useReportTasks.mockReturnValue({+ data: undefined,+ isLoading: false,+ isError: true,+ });++ render(+ <ReportVerdictBanner+ report={{ ...report, actionability: "immediately_actionable" }}+ variant="triage-actions"+ surface="triage"+ />,+ );++ expect(screen.queryByText("Create PR")).not.toBeInTheDocument();+ });+it("keeps triage direction before creating the implementation task", async () => {const user = userEvent.setup();render(diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.tsxindex 4c2db220ea58..6324e3d55899 100644--- a/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.tsx+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportVerdictBanner.tsx@@ -99,14 +99,17 @@ export function ReportVerdictBanner({// that task rather than spin up a duplicate PR. `report.implementation_pr_url`// alone is unreliable here — it can be stale or not yet set — so we also look// at the linked implementation task's own state.- const { data: reportTasks, isLoading: reportTasksLoading } = useReportTasks(- report.id,- report.status,- );+ const {+ data: reportTasks,+ isLoading: reportTasksLoading,+ isError: reportTasksFailed,+ } = useReportTasks(report.id, report.status);const continuableTask = findContinuableImplementationTask(reportTasks);const canCreatePr = canCreateImplementationPr(report, {hasLiveImplementationTask: continuableTask !== null,- isTaskLookupPending: reportTasksLoading,+ // A failed lookup leaves task state unknown, same as a pending one. Reading it+ // as "no live task" would offer a second PR on work that already has one.+ isTaskLookupPending: reportTasksLoading || reportTasksFailed,});// A merged PR is history, not live work: the report only still exists// because evidence kept arriving after the fix, so it reads by its owndiff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.test.ts b/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.test.tsindex 0f73fd7ca5dd..efa43936a823 100644--- a/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.test.ts+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.test.ts@@ -1,6 +1,9 @@+import { ApiRequestError } from "@posthog/api-client/fetcher";import type { Task, TaskRun, TaskRunStatus } from "@posthog/shared/types";-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import {+ derivePurpose,+ fetchReportTasks,findContinuableImplementationTask,findLatestDiscussionTask,findPendingStartedTaskId,@@ -60,6 +63,91 @@ function entry(return { task, purpose, purposeLabel: purpose, startedAt: task.created_at };}+describe("fetchReportTasks", () => {+ function artefact(taskId: string, type: string) {+ return {+ id: `artefact-${taskId}`,+ type: "task_run",+ content: { task_id: taskId, product: "signals", type },+ created_at: "2026-06-24T10:00:00Z",+ };+ }++ const getArtefacts = vi.fn();++ function client(+ artefacts: ReturnType<typeof artefact>[],+ getTask: (taskId: string) => Promise<Task>,+ ) {+ getArtefacts.mockResolvedValue({+ results: artefacts,+ count: artefacts.length,+ });+ return {+ getSignalReportArtefacts: getArtefacts,+ getTask: (taskId: string) => getTask(taskId),+ } as unknown as Parameters<typeof fetchReportTasks>[0];+ }++ it("keeps the surviving runs when a task_run artefact points at a deleted task", async () => {+ const implementation = makeTask("impl", { prUrl: "https://gh/pr/1" });+ const tasks = await fetchReportTasks(+ client(+ [artefact("scout", "scout"), artefact("impl", "implementation")],+ async (taskId) => {+ if (taskId === "scout") {+ throw new ApiRequestError(404, '{"detail":"Not found."}');+ }+ return implementation;+ },+ ),+ "report-1",+ );++ expect(tasks.map((t) => t.task)).toEqual([implementation]);+ // Runs come from the whole log, so the oldest task_run is not truncated away.+ expect(getArtefacts).toHaveBeenCalledWith("report-1", { limit: 1000 });+ });++ it("fails the fetch when a task lookup errors for any other reason", async () => {+ await expect(+ fetchReportTasks(+ client([artefact("impl", "implementation")], async () => {+ throw new ApiRequestError(500, '{"detail":"Server error."}');+ }),+ "report-1",+ ),+ ).rejects.toThrow(ApiRequestError);+ });+});++describe("derivePurpose", () => {+ it.each([+ ["research", "Research"],+ ["implementation", "Implementation"],+ ["discussion", "Discussion"],+ ["scout", "Scout"],+ ["a_future_run_type", "A future run type"],+ ])("keeps the signals %s run in the list", (type, purposeLabel) => {+ expect(derivePurpose({ product: "signals", type })?.purposeLabel).toBe(+ purposeLabel,+ );+ });++ it("drops repo selection plumbing", () => {+ expect(+ derivePurpose({ product: "signals", type: "repo_selection" }),+ ).toBeNull();+ });++ it("labels a custom agent run with its product and type", () => {+ expect(derivePurpose({ product: "my_agent", type: "sweep" })).toEqual({+ purpose: "other",+ purposeLabel: "My agent — Sweep",+ });+ });+});+describe("findContinuableImplementationTask", () => {it("returns null when there are no report tasks", () => {expect(findContinuableImplementationTask(undefined)).toBeNull();diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.ts b/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.tsindex eecc21622f73..9999a9e0a97b 100644--- a/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.ts+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useReportTasks.ts@@ -1,3 +1,5 @@+import { requestErrorStatus } from "@posthog/api-client/fetcher";+import type { PostHogAPIClient } from "@posthog/api-client/posthog-client";import { humanizeIdentifier } from "@posthog/core/inbox/activityLog";import type {SignalReportStatus,@@ -24,7 +26,7 @@ export interface ReportTaskData {startedAt: string;}-function derivePurpose(taskRun: {+export function derivePurpose(taskRun: {product: string;type: string;}): { purpose: ReportTaskPurpose; purposeLabel: string } | null {@@ -38,9 +40,13 @@ function derivePurpose(taskRun: {if (taskRun.type === "discussion") {return { purpose: "discussion", purposeLabel: "Discussion" };}- // repo_selection runs are plumbing, not report work — never displayed (matches the- // pre-derivation behavior of only showing research/implementation).- return null;+ if (taskRun.type === "repo_selection") {+ // Pipeline plumbing, not report work — never displayed.+ return null;+ }+ // Every other run type (scout today, whatever ships next) is real work on the+ // report, so humanize it rather than drop it.+ return { purpose: "other", purposeLabel: humanizeIdentifier(taskRun.type) };}return {purpose: "other",@@ -55,6 +61,69 @@ const PURPOSE_ORDER: ReportTaskPurpose[] = ["other",];+/** Matches the web inbox's report-detail fetch, which reads the same full log. */+const FULL_ARTEFACT_LOG_LIMIT = 1000;++type ReportTaskClient = Pick<+ PostHogAPIClient,+ "getSignalReportArtefacts" | "getTask"+>;++export async function fetchReportTasks(+ client: ReportTaskClient,+ reportId: string,+): Promise<ReportTaskData[]> {+ // task_run artefacts ARE the task↔report association — one entry per associated task,+ // keyed by content.task_id (earliest artefact wins for startedAt). The runtime `type`+ // check is authoritative (the generic fallback artefact keeps `type: string` and+ // defeats static narrowing).+ const artefacts = await client.getSignalReportArtefacts(reportId, {+ // Runs are read from the whole log: the scout task_run is written when the report is+ // created, so it is the first row a default page drops.+ limit: FULL_ARTEFACT_LOG_LIMIT,+ });+ const taskRunByTaskId = new Map<+ string,+ { product: string; type: string; startedAt: string }+ >();+ for (const artefact of artefacts.results) {+ if (artefact.type !== "task_run") continue;+ const content = artefact.content as TaskRunArtefactContent;+ const existing = taskRunByTaskId.get(content.task_id);+ if (existing && existing.startedAt <= artefact.created_at) continue;+ taskRunByTaskId.set(content.task_id, {+ product: content.product,+ type: content.type,+ startedAt: artefact.created_at,+ });+ }++ const relevant = [...taskRunByTaskId.entries()].flatMap(([taskId, run]) => {+ const derived = derivePurpose(run);+ return derived ? [{ taskId, startedAt: run.startedAt, ...derived }] : [];+ });++ const tasks = await Promise.all(+ relevant.map(async ({ taskId, startedAt, purpose, purposeLabel }) => {+ // Nothing deletes the artefact when its task goes, so a deleted task leaves a+ // dangling pointer here. Drop that one row: failing the whole fetch would empty+ // the Runs list and read downstream as "no implementation task", which unlocks+ // the duplicate-PR action. Any other error still fails the query.+ const task = await client.getTask(taskId).catch((error: unknown) => {+ if (requestErrorStatus(error) === 404) return null;+ throw error;+ });+ return task ? { task, purpose, purposeLabel, startedAt } : null;+ }),+ );+ return tasks+ .filter((task) => task !== null)+ .sort(+ (a, b) =>+ PURPOSE_ORDER.indexOf(a.purpose) - PURPOSE_ORDER.indexOf(b.purpose),+ );+}+export function useReportTasks(reportId: string,reportStatus: SignalReportStatus,@@ -66,53 +135,7 @@ export function useReportTasks(return useAuthenticatedQuery<ReportTaskData[]>(["inbox", "report-tasks", reportId],- async (client) => {- // task_run artefacts ARE the task↔report association — one entry per associated task,- // keyed by content.task_id (earliest artefact wins for startedAt). The runtime `type`- // check is authoritative (the generic fallback artefact keeps `type: string` and- // defeats static narrowing).- const artefacts = await client.getSignalReportArtefacts(reportId);- const taskRunByTaskId = new Map<- string,- { product: string; type: string; startedAt: string }- >();- for (const artefact of artefacts.results) {- if (artefact.type !== "task_run") continue;- const content = artefact.content as TaskRunArtefactContent;- const existing = taskRunByTaskId.get(content.task_id);- if (existing && existing.startedAt <= artefact.created_at) continue;- taskRunByTaskId.set(content.task_id, {- product: content.product,- type: content.type,- startedAt: artefact.created_at,- });- }-- const relevant = [...taskRunByTaskId.entries()].flatMap(- ([taskId, run]) => {- const derived = derivePurpose(run);- return derived- ? [{ taskId, startedAt: run.startedAt, ...derived }]- : [];- },- );-- const tasks = await Promise.all(- relevant.map(async ({ taskId, startedAt, purpose, purposeLabel }) => {- const task = await client.getTask(taskId);- return {- task,- purpose,- purposeLabel,- startedAt,- };- }),- );- return tasks.sort(- (a, b) =>- PURPOSE_ORDER.indexOf(a.purpose) - PURPOSE_ORDER.indexOf(b.purpose),- );- },+ (client) => fetchReportTasks(client, reportId),{enabled: !!reportId,staleTime: isActive ? 5_000 : 10_000,