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.

fix(signals): align side chat tasks with inbox reports (#124419)

Dylan Martin148f3d976161
diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
index c635f588fd47..cfa8ccb27ae9 100644
--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
@@ -432,6 +432,27 @@ describe('inboxTaskKickoffLogic', () => {
})
})
+ it('releases a warm still in flight when another report opens its task', async () => {
+ const otherReport = makeReport({ id: 'report-other', status: SignalReportStatus.READY })
+ let settleWarm!: () => void
+ warmGate = new Promise<void>((resolve) => {
+ settleWarm = resolve
+ })
+ warmResponse = { task_id: 'warm-task', run_id: 'warm-run' }
+
+ logic.actions.openReportDiscussion(report, 'https://example.com/report')
+ logic.actions.alignReportDiscussion(otherReport, 'https://example.com/other')
+ logic.actions.openReportTask(otherReport, 'other-task', 'other-run')
+ warmGate = null
+ settleWarm()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(cancelledRuns).toEqual([
+ { taskId: 'warm-task', runId: 'warm-run', body: { only_if_awaiting_first_message: true } },
+ ])
+ expect(logic.values.reportWarmLease).toBeNull()
+ })
+
it('keeps the warm when the same report reopens before its warm settles', async () => {
let settleWarm!: () => void
warmGate = new Promise<void>((resolve) => {
diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
index 9575d37cbece..03c32ed18494 100644
--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
@@ -486,6 +486,13 @@ export interface inboxTaskKickoffLogicActions {
setSidePanelOptions: (options: string | null) => {
options: string | null
} // sidePanelStateLogic
+ alignReportDiscussion: (
+ report: SignalReport,
+ reportUrl: string
+ ) => {
+ report: SignalReport
+ reportUrl: string
+ }
createPrFailure: () => {
value: true
}
@@ -611,6 +618,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
})),
actions({
+ alignReportDiscussion: (report: SignalReport, reportUrl: string) => ({ report, reportUrl }),
openReportDiscussion: (report: SignalReport, reportUrl: string) => ({ report, reportUrl }),
openReportTask: (report: SignalReport, taskId: string, runId: string, streamKey?: string) => ({
report,
@@ -653,7 +661,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
reportChatContext: [
null as ReportChatContext | null,
{
- openReportDiscussion: (_, { report, reportUrl }) => ({ report, reportUrl }),
+ alignReportDiscussion: (_, { report, reportUrl }) => ({ report, reportUrl }),
openReportTask: (_, { report }) => ({
report,
reportUrl: `${window.location.origin}${addProjectIdIfMissing(urls.inboxReport('reports', report.id))}`,
@@ -729,10 +737,17 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
}),
listeners(({ actions, cache, values }) => ({
- openReportDiscussion: ({ report }) => {
+ alignReportDiscussion: ({ report }) => {
cache.disposables.dispose(OPTIMISTIC_REPORT_STREAM)
actions.clearActiveCreation()
actions.setHistoryExpanded(false)
+ const warmReportIds = [values.reportWarmLease?.reportId, cache.warmingReportId, cache.pendingWarmReport?.id]
+ if (warmReportIds.some((id) => id && id !== report.id)) {
+ actions.releaseReportDiscussionWarm()
+ }
+ },
+ openReportDiscussion: ({ report, reportUrl }) => {
+ actions.alignReportDiscussion(report, reportUrl)
actions.openSidePanel(SidePanelTab.Max, REPORT_AI_PANEL)
if (!values.isCreatingPr) {
actions.warmReportDiscussion(report)
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
index bf96d780d427..defca29d6fe1 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.test.ts
@@ -9,16 +9,20 @@ import { lemonToast } from '@posthog/lemon-ui'
import { ApiConfig } from 'lib/api'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { useMocks } from '~/mocks/jest'
import type { MockResolverInfo } from '~/mocks/utils'
import { initKeaTests } from '~/test/init'
+import { SidePanelTab } from '~/types'
+import { runnerPanelLogic } from 'products/posthog_ai/frontend/api/logics'
import { TaskRunStatus } from 'products/posthog_ai/frontend/types/taskTypes'
import type { SignalReportCheckApi } from 'products/signals/frontend/generated/api.schemas'
import { ReportTaskPurpose } from '../components/detail/artefactTypes'
import { INBOX_EVENTS } from '../inboxAnalytics'
import { inboxSceneLogic } from '../inboxSceneLogic'
+import { REPORT_AI_PANEL, REPORT_AI_PANEL_ID, inboxTaskKickoffLogic } from '../inboxTaskKickoffLogic'
import { EnrichedReviewer, SignalReport, SignalReportStatus } from '../types'
import { inboxBulkActionsLogic } from './inboxBulkActionsLogic'
import { ReportTaskEntry, implementationSlotClaim, inboxReportDetailLogic } from './inboxReportDetailLogic'
@@ -1330,4 +1334,223 @@ describe('inboxReportDetailLogic', () => {
expect(logic.values.reportChecks).toEqual([approved])
})
})
+
+ describe('report sidebar alignment', () => {
+ const taskRunArtefact = (taskId: string, createdAt: string): Record<string, unknown> => ({
+ id: `artefact-${taskId}`,
+ type: 'task_run',
+ content: { task_id: taskId, product: 'signals', type: 'discussion' },
+ created_at: createdAt,
+ })
+
+ const useReportTaskMocks = (
+ artefactsByReport: Record<string, Record<string, unknown>[]>,
+ tasks: Record<string, any>
+ ): void => {
+ useMocks({
+ get: {
+ '/api/projects/:team_id/signals/reports/:id/feedback_state/': { sentiment: null, note: '' },
+ '/api/projects/:team_id/signals/reports/:id/artefacts/': (req) => {
+ const reportId = String(req.params.id)
+ return { results: artefactsByReport[reportId] ?? [] }
+ },
+ '/api/projects/:team_id/signals/reports/:id/signals/': { signals: [] },
+ '/api/projects/:team_id/signals/reports/:id/checks/': { results: [] },
+ '/api/projects/:team_id/signals/reports/available_reviewers/': [],
+ '/api/projects/:team_id/tasks/:id/': (req) => [200, tasks[String(req.params.id)]],
+ },
+ post: {
+ '/api/projects/:team/tasks/warm/': { task_id: 'warm-task', run_id: 'warm-run' },
+ },
+ })
+ }
+
+ it('follows the selected report to its active task, then clears it for a report without tasks', async () => {
+ const reportB = { ...REPORT, id: 'report-2', title: 'Second report' }
+ useReportTaskMocks(
+ {
+ [REPORT.id]: [
+ taskRunArtefact('active-task', '2026-01-01T00:00:00Z'),
+ taskRunArtefact('completed-task', '2026-01-02T00:00:00Z'),
+ taskRunArtefact('starting-task', '2026-01-03T00:00:00Z'),
+ ],
+ [reportB.id]: [],
+ },
+ {
+ 'active-task': {
+ id: 'active-task',
+ latest_run: { id: 'active-run', status: TaskRunStatus.IN_PROGRESS },
+ },
+ 'completed-task': {
+ id: 'completed-task',
+ latest_run: { id: 'completed-run', status: TaskRunStatus.COMPLETED },
+ },
+ 'starting-task': { id: 'starting-task', latest_run: null },
+ }
+ )
+ initKeaTests()
+ const kickoff = inboxTaskKickoffLogic()
+ const runner = runnerPanelLogic({ panelId: REPORT_AI_PANEL_ID })
+ const unmountKickoff = kickoff.mount()
+ const unmountRunner = runner.mount()
+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, REPORT_AI_PANEL)
+ const reportALogic = inboxReportDetailLogic({ reportId: REPORT.id, report: REPORT })
+ reportALogic.mount()
+ try {
+ await expectLogic(reportALogic).toFinishAllListeners()
+ expect(runner.values.activeCreation).toMatchObject({
+ taskId: 'active-task',
+ runId: 'active-run',
+ })
+
+ reportALogic.unmount()
+ const reportBLogic = inboxReportDetailLogic({ reportId: reportB.id, report: reportB })
+ reportBLogic.mount()
+ try {
+ expect(kickoff.values.reportChatContext?.report.id).toBe(reportB.id)
+ expect(runner.values.activeCreation).toBeNull()
+ await expectLogic(reportBLogic).toFinishAllListeners()
+ expect(runner.values.activeCreation).toBeNull()
+ } finally {
+ reportBLogic.unmount()
+ }
+ } finally {
+ reportALogic.unmount()
+ unmountRunner()
+ unmountKickoff()
+ }
+ })
+
+ it('leaves a generic PostHog AI sidebar unchanged', async () => {
+ useReportTaskMocks({ [REPORT.id]: [] }, {})
+ initKeaTests()
+ const kickoff = inboxTaskKickoffLogic()
+ const runner = runnerPanelLogic({ panelId: REPORT_AI_PANEL_ID })
+ const unmountKickoff = kickoff.mount()
+ const unmountRunner = runner.mount()
+ runner.actions.setActiveCreation({ streamKey: 'generic-run', taskId: 'generic-task', runId: 'generic-run' })
+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max)
+ const logic = inboxReportDetailLogic({ reportId: REPORT.id, report: REPORT })
+ logic.mount()
+ try {
+ await expectLogic(logic).toFinishAllListeners()
+ expect(runner.values.activeCreation).toMatchObject({ taskId: 'generic-task', runId: 'generic-run' })
+ expect(kickoff.values.reportChatContext).toBeNull()
+ } finally {
+ logic.unmount()
+ unmountRunner()
+ unmountKickoff()
+ }
+ })
+
+ it('does not reopen a linked task after the user goes back', async () => {
+ useReportTaskMocks(
+ { [REPORT.id]: [taskRunArtefact('linked-task', '2026-01-01T00:00:00Z')] },
+ {
+ 'linked-task': {
+ id: 'linked-task',
+ latest_run: { id: 'linked-run', status: TaskRunStatus.IN_PROGRESS },
+ },
+ }
+ )
+ initKeaTests()
+ const kickoff = inboxTaskKickoffLogic()
+ const runner = runnerPanelLogic({ panelId: REPORT_AI_PANEL_ID })
+ const unmountKickoff = kickoff.mount()
+ const unmountRunner = runner.mount()
+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, REPORT_AI_PANEL)
+ const logic = inboxReportDetailLogic({ reportId: REPORT.id, report: REPORT })
+ logic.mount()
+ try {
+ await expectLogic(logic).toFinishAllListeners()
+ expect(runner.values.activeCreation?.taskId).toBe('linked-task')
+
+ runner.actions.goBack()
+ logic.actions.loadReportTasksSuccess(logic.values.reportTasks ?? [])
+
+ expect(runner.values.activeCreation).toBeNull()
+ } finally {
+ logic.unmount()
+ unmountRunner()
+ unmountKickoff()
+ }
+ })
+
+ it('opens the linked task once a load after a transient task failure succeeds', async () => {
+ const linkedTask = {
+ id: 'linked-task',
+ latest_run: { id: 'linked-run', status: TaskRunStatus.IN_PROGRESS },
+ }
+ let taskFetchFails = true
+ useReportTaskMocks({ [REPORT.id]: [taskRunArtefact(linkedTask.id, '2026-01-01T00:00:00Z')] }, {})
+ useMocks({
+ get: {
+ '/api/projects/:team_id/tasks/:id/': () =>
+ taskFetchFails ? [500, { detail: 'Server error' }] : [200, linkedTask],
+ },
+ post: { '/api/projects/:team/tasks/:taskId/runs/:runId/cancel/': {} },
+ })
+ initKeaTests()
+ const kickoff = inboxTaskKickoffLogic()
+ const runner = runnerPanelLogic({ panelId: REPORT_AI_PANEL_ID })
+ const unmountKickoff = kickoff.mount()
+ const unmountRunner = runner.mount()
+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, REPORT_AI_PANEL)
+ const logic = inboxReportDetailLogic({ reportId: REPORT.id, report: REPORT })
+ logic.mount()
+ try {
+ await expectLogic(logic).toFinishAllListeners()
+ expect(runner.values.activeCreation).toBeNull()
+
+ taskFetchFails = false
+ await expectLogic(logic, () => logic.actions.loadReportTasks()).toFinishAllListeners()
+
+ expect(runner.values.activeCreation).toMatchObject({ taskId: 'linked-task', runId: 'linked-run' })
+ } finally {
+ logic.unmount()
+ unmountRunner()
+ unmountKickoff()
+ }
+ })
+
+ it('keeps a chat the user opens before the first task load finishes', async () => {
+ const linkedTask = {
+ id: 'linked-task',
+ latest_run: { id: 'linked-run', status: TaskRunStatus.IN_PROGRESS },
+ }
+ let releaseTask!: () => void
+ const taskGate = new Promise<void>((resolve) => {
+ releaseTask = resolve
+ })
+ useReportTaskMocks({ [REPORT.id]: [taskRunArtefact(linkedTask.id, '2026-01-01T00:00:00Z')] }, {})
+ useMocks({
+ get: {
+ '/api/projects/:team_id/tasks/:id/': async () => {
+ await taskGate
+ return [200, linkedTask]
+ },
+ },
+ })
+ initKeaTests()
+ const kickoff = inboxTaskKickoffLogic()
+ const runner = runnerPanelLogic({ panelId: REPORT_AI_PANEL_ID })
+ const unmountKickoff = kickoff.mount()
+ const unmountRunner = runner.mount()
+ sidePanelStateLogic.actions.openSidePanel(SidePanelTab.Max, REPORT_AI_PANEL)
+ const logic = inboxReportDetailLogic({ reportId: REPORT.id, report: REPORT })
+ logic.mount()
+ try {
+ kickoff.actions.openReportDiscussion(REPORT, 'https://example.com/report')
+ releaseTask()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.reportTasks?.map((entry) => entry.task.id)).toEqual(['linked-task'])
+ expect(runner.values.activeCreation).toBeNull()
+ } finally {
+ logic.unmount()
+ unmountRunner()
+ unmountKickoff()
+ }
+ })
+ })
})
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
index 3cdbe35034ac..31afdbd55d47 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
@@ -19,13 +19,18 @@ import { lemonToast } from '@posthog/lemon-ui'
import api, { ApiConfig } from 'lib/api'
import { ApiError } from 'lib/api-error'
import { dayjs } from 'lib/dayjs'
+import { addProjectIdIfMissing } from 'lib/utils/kea-router'
import { fullNameOrEmail } from 'lib/utils/strings'
import { SignalNode } from 'scenes/debug/signals/types'
import { personalIntegrationsLogic } from 'scenes/settings/user/personalIntegrationsLogic'
import type { PersonalGitHubIntegration } from 'scenes/settings/user/personalIntegrationsLogic'
import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
+import { SidePanelTab } from '~/types'
+
import { Task, TaskRunStatus } from 'products/posthog_ai/frontend/types/taskTypes'
import {
signalsReportArtefactsDiff,
@@ -80,7 +85,7 @@ import {
InboxReportFeedbackSentiment,
} from '../inboxAnalytics'
import { inboxSceneLogic } from '../inboxSceneLogic'
-import { inboxTaskKickoffLogic } from '../inboxTaskKickoffLogic'
+import { REPORT_AI_PANEL, ReportDiscussionIntent, inboxTaskKickoffLogic } from '../inboxTaskKickoffLogic'
import { EnrichedReviewer, ReviewerRemoval, SignalReport, SignalReportArtefact, SignalReportStatus } from '../types'
import { ChartPlacements, resolveChartPlacements } from '../utils/chartPlacement'
import { isReportClaimable, reportClaimant, requestReportClaim } from '../utils/reportClaim'
@@ -295,9 +300,24 @@ function latestJudgmentExplanation(
return typeof explanation === 'string' && explanation.trim() ? explanation : null
}
+function preferredReportTask(reportTasks: ReportTaskEntry[]): ReportTaskEntry | null {
+ return (
+ [...reportTasks].sort((a, b) => {
+ const aInMotion = !TERMINAL_RUN_STATUSES.includes(a.task.latest_run?.status ?? TaskRunStatus.NOT_STARTED)
+ const bInMotion = !TERMINAL_RUN_STATUSES.includes(b.task.latest_run?.status ?? TaskRunStatus.NOT_STARTED)
+ if (aInMotion !== bInMotion) {
+ return aInMotion ? -1 : 1
+ }
+ return new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
+ })[0] ?? null
+ )
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface inboxReportDetailLogicValues {
personalIntegrations: PersonalGitHubIntegration[] // personalIntegrationsLogic
+ selectedTab: SidePanelTab | null // sidePanelStateLogic
+ selectedTabOptions: string | null // sidePanelStateLogic
actionabilityExplanation: string | null
addReviewerOptions: AvailableReviewerOption[]
approvingCheckIds: string[]
@@ -384,12 +404,57 @@ export interface inboxReportDetailLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface inboxReportDetailLogicActions {
+ alignReportDiscussion: (
+ report: SignalReport,
+ reportUrl: string
+ ) => {
+ report: SignalReport
+ reportUrl: string
+ } // inboxTaskKickoffLogic
createPrSuccess: () => {
value: true
} // inboxTaskKickoffLogic
+ discussReport: (
+ report: SignalReport,
+ reportUrl: string,
+ question: string,
+ agentQuestion?: string | undefined,
+ intent?: ReportDiscussionIntent | undefined,
+ pullRequestUrl?: string | undefined,
+ background?: boolean | undefined
+ ) => {
+ agentQuestion: string | undefined
+ background: boolean | undefined
+ intent: ReportDiscussionIntent | undefined
+ pullRequestUrl: string | undefined
+ question: string
+ report: SignalReport
+ reportUrl: string
+ } // inboxTaskKickoffLogic
discussReportSuccess: () => {
value: true
} // inboxTaskKickoffLogic
+ openReportDiscussion: (
+ report: SignalReport,
+ reportUrl: string
+ ) => {
+ report: SignalReport
+ reportUrl: string
+ } // inboxTaskKickoffLogic
+ openReportTask: (
+ report: SignalReport,
+ taskId: string,
+ runId: string,
+ streamKey?: string | undefined
+ ) => {
+ report: SignalReport
+ runId: string
+ streamKey: string | undefined
+ taskId: string
+ } // inboxTaskKickoffLogic
+ warmReportDiscussion: (report: SignalReport) => {
+ report: SignalReport
+ } // inboxTaskKickoffLogic
approveReportCheck: (checkId: string) => {
checkId: string
}
@@ -780,9 +845,25 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
connect(() => ({
// Personal GitHub connection state gates the inline comment composer (comments post as the user).
- values: [personalIntegrationsLogic, ['integrations as personalIntegrations']],
+ values: [
+ personalIntegrationsLogic,
+ ['integrations as personalIntegrations'],
+ sidePanelStateLogic,
+ ['selectedTab', 'selectedTabOptions'],
+ ],
// Starting a PR task writes to the artefact log, which is where the Create PR gate reads from.
- actions: [inboxTaskKickoffLogic, ['createPrSuccess', 'discussReportSuccess']],
+ actions: [
+ inboxTaskKickoffLogic,
+ [
+ 'alignReportDiscussion',
+ 'createPrSuccess',
+ 'discussReport',
+ 'discussReportSuccess',
+ 'openReportDiscussion',
+ 'openReportTask',
+ 'warmReportDiscussion',
+ ],
+ ],
})),
actions({
@@ -868,7 +949,7 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
feedbackSaved: (feedback: SignalReportFeedbackStateApi) => ({ feedback }),
}),
- loaders(({ props, values }) => ({
+ loaders(({ props, values, cache }) => ({
savedFeedback: [
null as SignalReportFeedbackStateApi | null,
{
@@ -962,17 +1043,23 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
associations.set(content.task_id, { ...derived, startedAt: artefact.created_at })
}
}
+ let incomplete = false
const entries = await Promise.all(
[...associations.entries()].map(async ([taskId, meta]): Promise<ReportTaskEntry | null> => {
try {
const task = await api.tasks.get(taskId)
return { task, ...meta }
- } catch {
+ } catch (error) {
// A deleted/inaccessible task drops out of the list rather than failing the load.
+ if (!(error instanceof ApiError && (error.status === 403 || error.status === 404))) {
+ incomplete = true
+ }
return null
}
})
)
+ // Other failures can be transient. Sidebar alignment waits for a load that has every task.
+ cache.reportTasksIncomplete = incomplete
return entries
.filter((entry): entry is ReportTaskEntry => entry !== null)
.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime())
@@ -1528,23 +1615,7 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
// link. Mirrors desktop `AgentRunDetail`'s `pickPrimaryTask`.
primaryTask: [
(s) => [s.reportTasks],
- (reportTasks: ReportTaskEntry[] | null): ReportTaskEntry | null => {
- if (!reportTasks || reportTasks.length === 0) {
- return null
- }
- return [...reportTasks].sort((a, b) => {
- const aInMotion = !TERMINAL_RUN_STATUSES.includes(
- a.task.latest_run?.status ?? TaskRunStatus.NOT_STARTED
- )
- const bInMotion = !TERMINAL_RUN_STATUSES.includes(
- b.task.latest_run?.status ?? TaskRunStatus.NOT_STARTED
- )
- if (aInMotion !== bInMotion) {
- return aInMotion ? -1 : 1
- }
- return new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
- })[0]
- },
+ (reportTasks: ReportTaskEntry[] | null): ReportTaskEntry | null => preferredReportTask(reportTasks ?? []),
],
reportTaskToOpen: [
(s) => [s.reportTasks],
@@ -2060,7 +2131,38 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
actions.loadReportDiff({ artefactId: commit.id })
}
},
+ // A run or chat the user opens owns the sidebar, so a later task load must not replace it.
+ discussReport: ({ background }) => {
+ if (!background) {
+ cache.sidebarAlignmentPending = false
+ }
+ },
+ openReportDiscussion: () => {
+ cache.sidebarAlignmentPending = false
+ },
+ openReportTask: () => {
+ cache.sidebarAlignmentPending = false
+ },
loadReportTasksSuccess: (_, __, ___, previousState) => {
+ if (
+ cache.sidebarAlignmentPending &&
+ values.selectedTab === SidePanelTab.Max &&
+ values.selectedTabOptions === REPORT_AI_PANEL &&
+ values.report
+ ) {
+ // Task creation links a task before its run starts, so a runless task has nothing to open yet.
+ const task = cache.reportTasksIncomplete
+ ? null
+ : preferredReportTask((values.reportTasks ?? []).filter((entry) => entry.task.latest_run))
+ if (!cache.reportTasksIncomplete) {
+ cache.sidebarAlignmentPending = false
+ }
+ if (task?.task.latest_run) {
+ actions.openReportTask(values.report, task.task.id, task.task.latest_run.id)
+ } else {
+ actions.warmReportDiscussion(values.report)
+ }
+ }
const before = selectors.reportTasks(previousState) ?? []
const settled = (values.reportTasks ?? []).some((entry) => {
const run = entry.task.latest_run
@@ -2136,6 +2238,13 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
actions.loadReportChecks()
// Seed the report from props so polling is gated on its status from the first tick.
actions.setReport(props.report ?? null)
+ if (props.report && values.selectedTab === SidePanelTab.Max && values.selectedTabOptions === REPORT_AI_PANEL) {
+ cache.sidebarAlignmentPending = true
+ actions.alignReportDiscussion(
+ props.report,
+ `${window.location.origin}${addProjectIdIfMissing(urls.inboxReport('reports', props.report.id))}`
+ )
+ }
cache.disposables.add(() => {
const interval = setInterval(() => {
if (