: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(inbox): restore quick ask dropdown on ask ai (#120203)
posthog[bot]c272adf0de0c
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex d7f06a3a45df..8dedcef554c1 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11590,6 +11590,14 @@ snapshots:hash: v1.k794b7964.416d6b37e787201bcf33ae67cd46ca701825ab022a8f278fb38b979083f049cb.wvD1Ef6zAy-zzV-D7Ledq6no5HqGkZZ1RE_FCxN1Djwscenes-app-inbox-detail-suggested-reviewers-mockup--wide-panel-long-reason--light:hash: v1.k794b7964.0d0dc8d3193487f704b100b9c43777833a1cb21babcc88a62639239b183fe0a2.y_RYeVFrA0n0HXB9_zh43BNv-i5IYfS8ziAccFPEoNY+ scenes-app-inbox-discussreportbutton--quick-ask-with-suggestions--dark:+ hash: v1.k794b7964.2ca3925161f5dd7eafaea33cfaea55666079827de58af90d43a2b67304d93fd1.X0vzBO7Z-JyaZ6DZRFSmZlVgcNwz2bRNJnfAeHxTgKo+ scenes-app-inbox-discussreportbutton--quick-ask-with-suggestions--light:+ hash: v1.k794b7964.e5c1ddc633b13a89fb89d53ce686573c9bb03c5ae8e452d14ba1f010bf5475b4.1RxpxoDWqe2GOOEzkACOlQimBwnP8STI0WLLbq9urYM+ scenes-app-inbox-discussreportbutton--quick-ask-without-suggestions--dark:+ hash: v1.k794b7964.9f892883605b743d1c518b4e8e4158e39501ad1e29137d06545a7bd2a43d778b.59xfUkYsv8EE54-_ztK7Ll-d9qFmxndwvpueRtvj_jU+ scenes-app-inbox-discussreportbutton--quick-ask-without-suggestions--light:+ hash: v1.k794b7964.42b46a63b373c3ca3793f66d58799840d685ec87224c9361b43723683a6d95de.dwbIFPC1zK2X8ivzo9rexSs1cz86s92hPGU91ja2I1Qscenes-app-inbox-discussreportbutton--sidebar--dark:hash: v1.k794b7964.5a357cca98a63ead6a78801c2fe9a6611e4e4fd7f5313db5949615633b8c2d1b.9DjLvoEQ9RglyBp_gJ0x7DpQIbSSeH0pBpu-vqGDP1Ascenes-app-inbox-discussreportbutton--sidebar--light:diff --git a/frontend/src/scenes/project-homepage/today/todayReportLogic.ts b/frontend/src/scenes/project-homepage/today/todayReportLogic.tsindex 6996ef9065c0..1c993b52e23a 100644--- a/frontend/src/scenes/project-homepage/today/todayReportLogic.ts+++ b/frontend/src/scenes/project-homepage/today/todayReportLogic.ts@@ -112,9 +112,11 @@ export interface todayReportLogicActions {question: string,agentQuestion?: string | undefined,intent?: import('products/signals/frontend/inbox/inboxTaskKickoffLogic').ReportDiscussionIntent | undefined,- pullRequestUrl?: string | undefined+ pullRequestUrl?: string | undefined,+ background?: boolean | undefined) => {agentQuestion: string | undefined+ background: boolean | undefinedintent: import('products/signals/frontend/inbox/inboxTaskKickoffLogic').ReportDiscussionIntent | undefinedpullRequestUrl: string | undefinedquestion: stringdiff --git a/products/signals/frontend/inbox/components/detail/DiscussReportButton.stories.tsx b/products/signals/frontend/inbox/components/detail/DiscussReportButton.stories.tsxindex 9d788f412b4f..1160c05a7a51 100644--- a/products/signals/frontend/inbox/components/detail/DiscussReportButton.stories.tsx+++ b/products/signals/frontend/inbox/components/detail/DiscussReportButton.stories.tsx@@ -1,4 +1,6 @@import type { Meta, StoryObj } from '@storybook/react'+import { waitFor, within } from '@testing-library/dom'+import userEvent from '@testing-library/user-event'import { useValues } from 'kea'import { Suspense } from 'react'@@ -69,3 +71,29 @@ export const Sidebar: Story = {)},}++async function openQuickAsk(canvasElement: HTMLElement): Promise<void> {+ await userEvent.click(await within(canvasElement).findByLabelText('Quick ask and more AI actions'))+ await waitFor(() => {+ if (!document.querySelector('.Popover')) {+ throw new Error('quick ask not open yet')+ }+ })+}++export const QuickAskWithSuggestions: Story = {+ parameters: { testOptions: { snapshotTargetSelector: '.Popover' } },+ render: () => <DiscussReportButton report={report} reportUrl="https://example.com/project/1/inbox/report-1" />,+ play: async ({ canvasElement }) => openQuickAsk(canvasElement),+}++export const QuickAskWithoutSuggestions: Story = {+ parameters: { testOptions: { snapshotTargetSelector: '.Popover' } },+ render: () => (+ <DiscussReportButton+ report={{ ...report, suggested_prompts: [] }}+ reportUrl="https://example.com/project/1/inbox/report-1"+ />+ ),+ play: async ({ canvasElement }) => openQuickAsk(canvasElement),+}diff --git a/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsx b/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsxindex 16fb95e753bc..58273f7bdbfe 100644--- a/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsx+++ b/products/signals/frontend/inbox/components/detail/DiscussReportButton.test.tsx@@ -320,13 +320,16 @@ describe('DiscussReportButton', () => {['the PR needs review', true, withPullRequest(makeReport(), 'open', 'review_required')],['the PR is already merged', true, withPullRequest(makeReport(), 'merged', 'approved')],['the flag is off', false, withPullRequest(makeReport(), 'open', 'approved')],- ])('does not offer the Ask AI menu when %s', async (_name, flagEnabled, report) => {+ ])('does not offer Get it merged when %s', async (_name, flagEnabled, report) => {featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_GET_IT_MERGED], {[FEATURE_FLAGS.INBOX_GET_IT_MERGED]: flagEnabled,})+ const user = userEvent.setup()render(<DiscussReportButton report={report} reportUrl="https://app/report-1" />)- expect(screen.queryByTestId('inbox-report-ask-ai-actions')).not.toBeInTheDocument()+ await user.click(screen.getByTestId('inbox-report-ask-ai-actions'))+ expect(screen.getByTestId('inbox-report-ask-ai-quick-submit')).toBeInTheDocument()+ expect(screen.queryByText('Get it merged')).not.toBeInTheDocument()})async function setChecks(report: SignalReport, conclusion: 'failure' | 'success'): Promise<void> {@@ -373,9 +376,39 @@ describe('DiscussReportButton', () => {})const report = withPullRequest(makeReport(), state, 'review_required')await setChecks(report, conclusion)+ const user = userEvent.setup()render(<DiscussReportButton report={report} reportUrl="https://app/report-1" />)- expect(screen.queryByTestId('inbox-report-ask-ai-actions')).not.toBeInTheDocument()+ await user.click(screen.getByTestId('inbox-report-ask-ai-actions'))+ expect(screen.queryByText('Make it green')).not.toBeInTheDocument()+ })++ it('fills the quick ask from a suggestion and sends it in the background on Enter', async () => {+ const user = userEvent.setup()+ render(<DiscussReportButton report={makeReport([SUGGESTION])} reportUrl="https://app/report-1" />)++ await user.click(screen.getByTestId('inbox-report-ask-ai-actions'))+ await user.click(screen.getByText(SUGGESTION))+ expect(discussReport).not.toHaveBeenCalled()+ await user.keyboard('{Enter}')+ await user.keyboard('{Enter}')++ expect(discussReport).toHaveBeenCalledTimes(1)+ expect(discussReport).toHaveBeenCalledWith(+ expect.objectContaining({ id: 'report-1' }),+ 'https://app/report-1',+ SUGGESTION,+ undefined,+ undefined,+ undefined,+ true+ )+ expect(jest.mocked(captureInboxReportAction).mock.calls[0][0].extra).toEqual({+ question_source: 'suggested',+ suggestion_count: 1,+ launch_mode: 'background',+ })+ expect(sidePanelStateLogic.values.sidePanelOpen).toBe(false)})it('does not invite actions where the kickoff wrapper would only answer', async () => {diff --git a/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsx b/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsxindex 36577c9d00fc..ac3f19224d8e 100644--- a/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsx+++ b/products/signals/frontend/inbox/components/detail/DiscussReportButton.tsx@@ -1,38 +1,130 @@import { useActions, useValues } from 'kea'+import { useEffect, useRef, useState } from 'react'import { IconCheckCircle, IconGitBranch, IconSparkles } from '@posthog/icons'-import { LemonButton, LemonMenuItems, LemonMenuOverlay } from '@posthog/lemon-ui'+import { LemonButton, LemonMenuItems, LemonMenuOverlay, lemonToast } from '@posthog/lemon-ui'import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'+import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea'-import { captureInboxReportAction, discussQuestionProperties } from '../../inboxAnalytics'+import { InboxQuestionSource, captureInboxReportAction, discussQuestionProperties } from '../../inboxAnalytics'import {FIX_CI_REQUEST,inboxTaskKickoffLogic,+ isActionCapableReport,MERGE_PR_REQUEST,+ REPORT_DISCUSSION_QUESTION_MAX_LENGTH,ReportDiscussionIntent,} from '../../inboxTaskKickoffLogic'import { inboxReportDetailLogic } from '../../logics/inboxReportDetailLogic'import { SignalReport } from '../../types'import { hasApprovedOpenReportPullRequest } from '../../utils/reportPullRequests'+// How much of a suggestion a draft has to keep, at one end or the other, to still count as an edit+// of it. Long enough that two suggestions opening on the same few words ("Which teams…", "Why did…")+// don't read as one, short enough that a heavy rewrite around a kept phrase still does.+const RECOGNIZABLE_RUN = 10++/** Whether a submitted draft is still the suggestion it was filled from, rather than a fresh question. */+function isEditOf(draft: string, suggestion: string): boolean {+ if (draft.length < RECOGNIZABLE_RUN || suggestion.length < RECOGNIZABLE_RUN) {+ return draft === suggestion+ }+ return (+ draft.slice(0, RECOGNIZABLE_RUN) === suggestion.slice(0, RECOGNIZABLE_RUN) ||+ draft.slice(-RECOGNIZABLE_RUN) === suggestion.slice(-RECOGNIZABLE_RUN)+ )+}+export function DiscussReportButton({ report, reportUrl }: { report: SignalReport; reportUrl: string }): JSX.Element {- const { isDiscussing, isCreatingPr, aiConsentDisabledReason, freeTrialDisabledReason } =+ const { isDiscussing, isCreatingPr, aiConsentDisabledReason, freeTrialDisabledReason, lastQuickAskFailure } =useValues(inboxTaskKickoffLogic)const { openReportDiscussion, discussReport } = useActions(inboxTaskKickoffLogic)const { prChecksFailing, selectedPullRequest } = useValues(inboxReportDetailLogic({ reportId: report.id, report }))const prActionsEnabled = useFeatureFlag('INBOX_GET_IT_MERGED')const canMerge = prActionsEnabled && hasApprovedOpenReportPullRequest(report)const canMakeGreen = prActionsEnabled && prChecksFailing+ const textAreaRef = useRef<HTMLTextAreaElement>(null)+ const [isQuickAskOpen, setIsQuickAskOpen] = useState(false)+ const [question, setQuestion] = useState('')+ // The suggestion the textarea was last filled from, so a submitted question can be reported as+ // sent as written, edited first, or written from scratch. Null until a row is clicked.+ const [filledFrom, setFilledFrom] = useState<string | null>(null)++ // A quick ask closes the dropdown before its run exists, so a failed ask puts the question back.+ useEffect(() => {+ if (lastQuickAskFailure?.reportId === report.id) {+ setQuestion(lastQuickAskFailure.question)+ }+ }, [lastQuickAskFailure, report.id])++ // Suggestions can be action requests, and the kickoff wrapper only carries actions out on+ // action-capable reports, so on any other report a stored suggestion would invite an action the+ // run then merely answers.+ const actionCapable = isActionCapableReport(report)+ const suggestions = actionCapable ? (report.suggested_prompts ?? []) : []+ const disabledReason = aiConsentDisabledReason ?? (isCreatingPr ? 'An implementation is starting.' : undefined)++ const questionSource = (trimmed: string): InboxQuestionSource => {+ if (filledFrom === null) {+ return 'typed'+ }+ if (trimmed === filledFrom) {+ return 'suggested'+ }+ // Selecting the filled box and typing over it leaves nothing of the suggestion, so the+ // question is the reader's own. Counting it as an edit would read as adoption.+ return isEditOf(trimmed, filledFrom) ? 'edited_suggestion' : 'typed'+ }++ const fillFromSuggestion = (suggestion: string): void => {+ setQuestion(suggestion)+ setFilledFrom(suggestion)+ // Fills the box and stops, so a mis-click costs nothing and a nearly right suggestion can be+ // edited before it spends a run.+ textAreaRef.current?.focus()+ }++ const submitQuickAsk = (): void => {+ const trimmed = question.trim()+ // Enter submits straight from the textarea, so it never sees the button's `loading` or+ // `disabledReason`. Each guard has to hold here too, or a second press starts another run.+ if (+ !trimmed ||+ isDiscussing ||+ isCreatingPr ||+ Array.from(trimmed).length > REPORT_DISCUSSION_QUESTION_MAX_LENGTH+ ) {+ return+ }+ if (aiConsentDisabledReason) {+ lemonToast.error(aiConsentDisabledReason)+ return+ }+ captureInboxReportAction({+ report,+ actionType: 'discuss',+ surface: 'detail_pane',+ extra: {+ ...discussQuestionProperties({ source: questionSource(trimmed), suggestionCount: suggestions.length }),+ launch_mode: 'background',+ },+ })+ discussReport(report, reportUrl, trimmed, undefined, undefined, undefined, true)+ setQuestion('')+ setFilledFrom(null)+ setIsQuickAskOpen(false)+ }- const startPrAction = (question: string, intent: ReportDiscussionIntent, pullRequestUrl?: string): void => {+ const startPrAction = (request: string, intent: ReportDiscussionIntent, pullRequestUrl?: string): void => {+ setIsQuickAskOpen(false)captureInboxReportAction({report,actionType: 'discuss',surface: 'detail_pane',extra: discussQuestionProperties({ source: 'suggested', suggestionCount: 1, intent }),})- discussReport(report, reportUrl, question, undefined, intent, pullRequestUrl)+ discussReport(report, reportUrl, request, undefined, intent, pullRequestUrl)}const items: LemonMenuItems = [@@ -60,22 +152,85 @@ export function DiscussReportButton({ report, reportUrl }: { report: SignalReporsize="small"icon={<IconSparkles />}loading={isDiscussing}- disabledReason={aiConsentDisabledReason ?? (isCreatingPr ? 'An implementation is starting.' : undefined)}+ disabledReason={disabledReason}onClick={() => openReportDiscussion(report, reportUrl)}tooltip="Ask PostHog AI about this report in the sidebar"- sideAction={- canMerge || canMakeGreen- ? {- tooltip: 'More AI actions',- 'aria-label': 'More AI actions',- 'data-attr': 'inbox-report-ask-ai-actions',- dropdown: {- placement: 'bottom-end',- overlay: <LemonMenuOverlay items={items} />,- },- }- : undefined- }+ sideAction={{+ tooltip: 'Quick ask and more AI actions',+ 'aria-label': 'Quick ask and more AI actions',+ 'data-attr': 'inbox-report-ask-ai-actions',+ dropdown: {+ placement: 'bottom-end',+ closeOnClickInside: false,+ visible: isQuickAskOpen,+ onVisibilityChange: setIsQuickAskOpen,+ overlay: (+ <div className="flex w-[22rem] max-w-full flex-col gap-2 p-2">+ {suggestions.length > 0 && (+ <div className="flex flex-col gap-1">+ <span className="text-xs font-semibold text-tertiary">Suggestions</span>+ {suggestions.map((suggestion) => (+ <LemonButton+ key={suggestion}+ // Secondary, not tertiary: above a textarea, rows with no+ // border read as a bulleted list, not as buttons.+ type="secondary"+ size="small"+ fullWidth+ onClick={() => fillFromSuggestion(suggestion)}+ data-attr="inbox-report-suggested-prompt"+ >+ {suggestion}+ </LemonButton>+ ))}+ </div>+ )}+ <LemonTextArea+ ref={textAreaRef}+ value={question}+ onChange={setQuestion}+ onPressEnter={submitQuickAsk}+ placeholder={+ actionCapable+ ? 'Ask a question, or tell AI what to do next'+ : 'Ask a question about this report'+ }+ maxLength={REPORT_DISCUSSION_QUESTION_MAX_LENGTH}+ rows={3}+ // Focus scrolls the textarea into view, which on a short viewport+ // hides the suggestions above it.+ autoFocus={suggestions.length === 0}+ actions={[+ <span key="shortcut" className="text-xs text-tertiary">+ Enter to ask, Shift + Enter for a new line+ </span>,+ ]}+ />+ <div className="flex justify-end">+ <LemonButton+ type="primary"+ size="small"+ icon={<IconSparkles />}+ onClick={submitQuickAsk}+ loading={isDiscussing}+ disabledReason={+ disabledReason ?? (question.trim() ? undefined : 'Enter a question first')+ }+ tooltip="AI works on it in the background. The sidebar stays as it is."+ data-attr="inbox-report-ask-ai-quick-submit"+ >+ Ask AI+ </LemonButton>+ </div>+ {(canMerge || canMakeGreen) && (+ <div className="border-t border-primary pt-1">+ <LemonMenuOverlay items={items} />+ </div>+ )}+ </div>+ ),+ },+ }}>Ask AI</LemonButton>diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.tsindex b82dea88778a..c635f588fd47 100644--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts@@ -2,6 +2,8 @@ import { waitFor } from '@testing-library/react'import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'+import { lemonToast } from '@posthog/lemon-ui'+import { FEATURE_FLAGS } from 'lib/constants'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'@@ -334,6 +336,41 @@ describe('inboxTaskKickoffLogic', () => {})})+ it('runs a background ask without the warm run or the panel, and its toast opens the run', async () => {+ const toastSuccess = jest.spyOn(lemonToast, 'success').mockImplementation(() => 'toast-id')+ warmResponse = { task_id: 'warm-task', run_id: 'warm-run' }+ await expectLogic(logic, () =>+ logic.actions.openReportDiscussion(report, 'https://example.com/report')+ ).toFinishAllListeners()++ await expectLogic(logic, () =>+ logic.actions.discussReport(+ report,+ 'https://example.com/report',+ 'Does this also affect EU?',+ undefined,+ undefined,+ undefined,+ true+ )+ ).toFinishAllListeners()++ expect(createdTasks).toHaveLength(1)+ expect(createdTasks[0]).not.toHaveProperty('branch')+ expect(startedRuns).toHaveLength(1)+ expect(logic.values.reportWarmLease).toMatchObject({ reportId: report.id })+ expect(logic.values.isDiscussing).toBe(false)+ expect(runnerPanelLogic({ panelId: REPORT_AI_PANEL_ID }).values.activeCreation).toBeNull()++ const toastOptions = toastSuccess.mock.calls[0][1] as { button: { action: () => void } }+ toastOptions.button.action()+ expect(logic.values.lastReportRun).toEqual({+ reportId: report.id,+ taskId: 'report-task',+ runId: 'report-run',+ })+ })+it.each([['the side panel closes', (): void => sidePanelStateLogic.actions.closeSidePanel()],[diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.tsindex 24a0fe25985c..0abf6d8f3f66 100644--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts@@ -357,7 +357,8 @@ async function createReportTask(fallbackTitle: string,runtimeSelection: ReportRuntimeSelection,discussionQuestion?: string,- warmLease: ReportWarmLease | null = null+ warmLease: ReportWarmLease | null = null,+ matchWarmRun: boolean = true): Promise<{ taskId: string; runId: string }> {const isDiscussion = relationship === SIGNAL_REPORT_TASK_DISCUSSION_RELATIONSHIP// `repository` is intentionally omitted: the backend resolves it for signal_report tasks.@@ -370,7 +371,8 @@ async function createReportTask(...(isDiscussion? {signal_report_discussion_question: discussionQuestion?.trim() ?? '',- branch: null,+ // The backend claims a matching warm run when `branch` is present.+ ...(matchWarmRun ? { branch: null } : {}),...runtimeSelection,pending_user_message: prompt,}@@ -443,6 +445,10 @@ export interface inboxTaskKickoffLogicValues {freeTrialDisabledReason: string | nullisCreatingPr: booleanisDiscussing: boolean+ lastQuickAskFailure: {+ question: string+ reportId: string+ } | nulllastReportRun: ReportRunRef | nullmetricCheckReplacementDisabledReason: string | nullreportChatContext: ReportChatContext | null@@ -499,9 +505,11 @@ export interface inboxTaskKickoffLogicActions {question: string,agentQuestion?: string,intent?: ReportDiscussionIntent,- pullRequestUrl?: string+ pullRequestUrl?: string,+ background?: boolean) => {agentQuestion: string | undefined+ background: boolean | undefinedintent: ReportDiscussionIntent | undefinedpullRequestUrl: string | undefinedquestion: string@@ -532,6 +540,13 @@ export interface inboxTaskKickoffLogicActions {streamKey: string | undefinedtaskId: string}+ quickAskFailed: (+ reportId: string,+ question: string+ ) => {+ question: string+ reportId: string+ }releaseReportDiscussionWarm: () => {value: true}@@ -612,7 +627,8 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([question: string,agentQuestion?: string,intent?: ReportDiscussionIntent,- pullRequestUrl?: string+ pullRequestUrl?: string,+ background?: boolean) => ({report,reportUrl,@@ -620,6 +636,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([agentQuestion,intent,pullRequestUrl,+ background,}),createPrFromReport: (report: SignalReport, feedback?: string) => ({ report, feedback }),warmReportDiscussion: (report: SignalReport) => ({ report }),@@ -627,6 +644,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([setReportWarmLease: (lease: ReportWarmLease | null) => ({ lease }),discussReportSuccess: true,discussReportFailure: true,+ quickAskFailed: (reportId: string, question: string) => ({ reportId, question }),createPrSuccess: true,createPrFailure: true,}),@@ -656,6 +674,13 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([setReportWarmLease: (_, { lease }) => lease,},],+ lastQuickAskFailure: [+ null as { reportId: string; question: string } | null,+ {+ quickAskFailed: (_, failure) => failure,+ discussReportSuccess: () => null,+ },+ ],isDiscussing: [false,{@@ -818,7 +843,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([actions.setActiveCreation({ streamKey: resolvedStreamKey ?? runId, taskId, runId })actions.openSidePanel(SidePanelTab.Max, REPORT_AI_PANEL)},- discussReport: async ({ report, reportUrl, question, agentQuestion, intent, pullRequestUrl }) => {+ discussReport: async ({ report, reportUrl, question, agentQuestion, intent, pullRequestUrl, background }) => {// The CTAs carry this as a `disabledReason`, but Discuss also submits on Enter, and the// run endpoint enforces no consent of its own.const disabledReason =@@ -834,9 +859,13 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([blockedReason: disabledReason,})actions.discussReportFailure()+ if (background) {+ actions.quickAskFailed(report.id, question)+ }return}- const contextItems = values.contextItems+ // The sidebar context can belong to another report, and the quick ask shows no attachments.+ const contextItems = background ? [] : values.contextItems// The composer renders from a snapshot that can go stale between load and submit (the// report resolves, fails, or gets suppressed meanwhile), so the action-vs-answer framing// is derived from the report's current server-side state. A failed refetch fails closed:@@ -871,6 +900,9 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([if (values.currentProjectId == null) {lemonToast.error("Couldn't ask AI about this report. Try again.")actions.discussReportFailure()+ if (background) {+ actions.quickAskFailed(report.id, question)+ }return}try {@@ -885,10 +917,12 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([...selectedPullRequest,...contextItems,])- const warmLease = values.reportWarmLease?.reportId === report.id ? values.reportWarmLease : null+ // A background ask leaves the warm sandbox to the sidebar composer it was started for.+ const warmLease =+ !background && values.reportWarmLease?.reportId === report.id ? values.reportWarmLease : nullif (warmLease) {actions.setReportWarmLease(null)- } else if (cache.warmingReportId === report.id) {+ } else if (!background && cache.warmingReportId === report.id) {cache.warmReleaseRequested = true}const { taskId, runId } = await createReportTask(@@ -900,13 +934,19 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>(['Ask AI about report',await launchSelection(values),question,- warmLease+ warmLease,+ !background)const sentContextKeys = contextItems.filter((item) => item.type !== 'text').map(attachedContextItemKey)if (sentContextKeys.length > 0) {actions.markContextSent(taskId, sentContextKeys)}- if (panelStillOnReport(values.reportChatContext, report.id)) {+ if (background) {+ lemonToast.success('Asked AI about this report', {+ toastId: `report-quick-ask-${runId}`,+ button: { label: 'View', action: () => actions.openReportTask(report, taskId, runId) },+ })+ } else if (panelStillOnReport(values.reportChatContext, report.id)) {const streamKey = `report-discussion-${uuid()}`const stream = runStreamLogic({ streamKey })cache.disposables.add(() => stream.mount(), OPTIMISTIC_REPORT_STREAM, {@@ -922,6 +962,9 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([} catch (error: any) {handleKickoffError(error, report, 'discuss', "Couldn't ask AI about this report. Try again.")actions.discussReportFailure()+ if (background) {+ actions.quickAskFailed(report.id, question)+ }}},createPrFromReport: async ({ report, feedback }) => {