: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(signals): use report's selected repo for inbox Create PR (#64992)
Andrew Maguiref16254680dba
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex ab8a13e2c713..c91a7c4b5219 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -5122,8 +5122,11 @@ const api = {async get(id: SignalReport['id']): Promise<SignalReport> {return await new ApiRequest().signalReport(id).get()},- async artefacts(id: SignalReport['id']): Promise<SignalReportArtefactResponse> {- return await new ApiRequest().signalReport(id).withAction('artefacts').get()+ async artefacts(+ id: SignalReport['id'],+ params: { limit?: number } = {}+ ): Promise<SignalReportArtefactResponse> {+ return await new ApiRequest().signalReport(id).withAction('artefacts').withQueryString(params).get()},async getReportSignals(reportId: string): Promise<{ report: SignalReport | null; signals: SignalNode[] }> {return await new ApiRequest().signalReport(reportId).withAction('signals').get()diff --git a/frontend/src/scenes/inbox/inboxTaskKickoffLogic.ts b/frontend/src/scenes/inbox/inboxTaskKickoffLogic.tsindex adffd5009cc7..dd12a29cdcbc 100644--- a/frontend/src/scenes/inbox/inboxTaskKickoffLogic.ts+++ b/frontend/src/scenes/inbox/inboxTaskKickoffLogic.ts@@ -16,6 +16,11 @@ import { SIGNAL_REPORT_TASK_IMPLEMENTATION_RELATIONSHIP, SignalReport, SignalRep// NOT a live chat surface. The created task carries the SignalReport linkage so the// backend's agent pipeline can pick it up.+// Report artefacts are paginated newest-first (default page size 100); `repo_selection` is+// written early in a research run, so a generous limit keeps it on the fetched page even for+// reports with many findings.+const REPO_SELECTION_ARTEFACT_FETCH_LIMIT = 1000+function buildCreatePrReportPrompt(report: SignalReport, feedback?: string): string {const base = `Act on PostHog Inbox report "${report.title ?? report.id}" (id ${report.id}). Investigate the root cause using the report's contributing findings, implement the fix, and open a PR.${report.summary ? `\n\nReport summary:\n${report.summary}` : ''@@ -42,17 +47,36 @@ async function createReportTask(report: SignalReport,relationship: SignalReportTaskRelationship,prompt: string,- fallbackTitle: string+ fallbackTitle: string,+ requireRepository = false): Promise<void> {- // Pick a default repository (mirrors desktop resolving lastUsedCloudRepository → first repo).+ // Use the repository the signals pipeline already selected for this report (its+ // `repo_selection` artefact), matching the desktop app and the auto-start flow. Never fall+ // back to an arbitrary project repo — `repositories[0]` previously leaked whichever repo+ // sorted first (e.g. a personal repo) and pinned the task to the wrong codebase.+ // Artefacts are paginated newest-first and `repo_selection` is written early in the run, so+ // fetch a high limit to keep it on the page even for reports with many findings.let repository: string | undefinedtry {- const { repositories } = await api.tasks.repositories()- repository = repositories[0]- } catch {+ const { results } = await api.signalReports.artefacts(report.id, { limit: REPO_SELECTION_ARTEFACT_FETCH_LIMIT })+ const selected = results.find((a) => a.type === 'repo_selection')?.content?.repository+ repository = typeof selected === 'string' && selected ? selected : undefined+ } catch (e) {+ // A genuine fetch failure must not masquerade as "no repository selected" — when a repo+ // is required, surface the real error so the user retries instead of waiting on analysis.+ if (requireRepository) {+ throw e+ }repository = undefined}+ // Opening a PR needs a concrete target repo. If selection hasn't resolved one (e.g. a+ // pending-input report), fail with a clear message instead of creating a task pinned to no+ // repository that can never open a PR. Discuss doesn't require a repo.+ if (requireRepository && !repository) {+ throw new Error('No repository has been selected for this report yet — try again once analysis finishes.')+ }+const task = await api.tasks.create({title: report.title?.trim() || fallbackTitle,description: prompt,@@ -113,7 +137,8 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([report,SIGNAL_REPORT_TASK_IMPLEMENTATION_RELATIONSHIP,buildCreatePrReportPrompt(report),- 'Implement report fix'+ 'Implement report fix',+ true)actions.createPrSuccess()} catch (error: any) {