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(inbox): let the project default model win over the Ask AI pin (#105144)

Vojta Bartoš4ee75e296edb
diff --git a/products/posthog_ai/frontend/api/logics.ts b/products/posthog_ai/frontend/api/logics.ts
index 3dea851d5c6d..66d21cba0fba 100644
--- a/products/posthog_ai/frontend/api/logics.ts
+++ b/products/posthog_ai/frontend/api/logics.ts
@@ -23,6 +23,10 @@ export { getThinkingMessageFromResponse, getRandomThinkingMessage, THINKING_MESS
// --- Composer model/effort helpers (pure — no component imports) ---
export { resolveEffortForModel, DEFAULT_COMPOSER_MODEL, DEFAULT_COMPOSER_EFFORT } from '../utils/composerModels'
export { modelCatalogueLogic } from '../logics/modelCatalogueLogic'
+// The server-resolved default model/effort for this user in this project (their own preference over
+// the project default). A host that launches a run on the user's behalf reads it to tell whether a
+// stored default will apply, because a model sent with the run overrides one.
+export { taskRunDefaultsLogic } from '../logics/taskRunDefaultsLogic'
export { tasksLogic } from '../logics/tasksLogic'
diff --git a/products/posthog_ai/frontend/logics/taskRunDefaultsLogic.ts b/products/posthog_ai/frontend/logics/taskRunDefaultsLogic.ts
index 2b7e5a157a08..3cf8866054de 100644
--- a/products/posthog_ai/frontend/logics/taskRunDefaultsLogic.ts
+++ b/products/posthog_ai/frontend/logics/taskRunDefaultsLogic.ts
@@ -17,6 +17,7 @@ export interface taskRunDefaultsLogicValues {
defaultEffort: string | null
defaultModel: string | null
defaultRuntimeAdapter: string | null
+ defaultsResolved: boolean
myConfig: TasksUserConfigResponseApi | null
myConfigLoading: boolean
resolvedDefaults: TasksResolvedAIRunDefaultsApi | null
@@ -49,6 +50,7 @@ export interface taskRunDefaultsLogicMeta {
defaultModel: (acpDefaults: TasksResolvedAIRunDefaultsApi | null) => string | null
defaultEffort: (acpDefaults: TasksResolvedAIRunDefaultsApi | null) => string | null
defaultRuntimeAdapter: (acpDefaults: TasksResolvedAIRunDefaultsApi | null) => string | null
+ defaultsResolved: (myConfig: TasksUserConfigResponseApi | null) => boolean
}
}
@@ -119,6 +121,12 @@ export const taskRunDefaultsLogic = kea<taskRunDefaultsLogicType>([
(s) => [s.acpDefaults],
(defaults: TasksResolvedAIRunDefaultsApi | null): string | null => defaults?.runtime_adapter ?? null,
],
+ // The defaults are null both before the config lands and when nothing is stored. A caller that
+ // would override a stored default by acting on its absence has to tell the two apart.
+ defaultsResolved: [
+ (s) => [s.myConfig],
+ (myConfig: TasksUserConfigResponseApi | null): boolean => myConfig !== null,
+ ],
}),
afterMount(({ actions }) => {
diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
index 22c76cb3b59c..a30f7ea59b5c 100644
--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.test.ts
@@ -10,7 +10,12 @@ import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { SidePanelTab } from '~/types'
-import { attachedContextLogic, runnerPanelLogic, runStreamLogic } from 'products/posthog_ai/frontend/api/logics'
+import {
+ attachedContextLogic,
+ runnerPanelLogic,
+ runStreamLogic,
+ taskRunDefaultsLogic,
+} from 'products/posthog_ai/frontend/api/logics'
import { makeReport } from './__mocks__/inboxMocks'
import {
@@ -38,8 +43,26 @@ describe('inboxTaskKickoffLogic', () => {
let createStatus: number
// Runs while the kickoff awaits its run response, so a test can act as the reader does mid-flight.
let onRunRequest: (() => void) | null
+ // What `@me/config` resolves to for this user; null is a project that never picked a model.
+ let resolvedRunDefaults: Record<string, unknown> | null
+ // Holds the `@me/config` response until the test resolves it, so a test can act mid-flight.
+ let runDefaultsGate: Promise<void> | null
const report = makeReport({ id: 'report-sidebar', status: SignalReportStatus.READY })
+ // Names a model the fallback never picks, so a run that carries it came from the default.
+ const RESOLVED_TEAM_DEFAULT = {
+ runtime: 'acp',
+ runtime_adapter: 'claude',
+ model: 'claude-sonnet-5',
+ reasoning_effort: 'xhigh',
+ source: 'team',
+ }
+
+ async function applyRunDefaults(defaults: Record<string, unknown>): Promise<void> {
+ resolvedRunDefaults = defaults
+ await taskRunDefaultsLogic.asyncActions.loadMyConfig()
+ }
+
beforeEach(() => {
localStorage.clear()
createdTasks = []
@@ -52,9 +75,17 @@ describe('inboxTaskKickoffLogic', () => {
createResponse = { id: 'report-task' }
createStatus = 201
onRunRequest = null
+ resolvedRunDefaults = null
+ runDefaultsGate = null
useMocks({
get: {
'/api/projects/:team/signals/reports/:id/': report,
+ '/api/projects/:team/tasks/@me/config/': async () => {
+ if (runDefaultsGate) {
+ await runDefaultsGate
+ }
+ return [200, { ai_run_preferences: {}, resolved_ai_run_defaults: resolvedRunDefaults }]
+ },
},
post: {
'/api/projects/:team/tasks/': async ({ request }) => {
@@ -129,7 +160,7 @@ describe('inboxTaskKickoffLogic', () => {
description: expect.stringContaining('- insight insight-one ("Conversion rate")'),
signal_report_discussion_question: 'Explain the recommendation',
branch: null,
- model: 'claude-opus-5',
+ model: 'claude-opus-5-5',
})
expect(createdTasks[0].pending_user_message).toBe(createdTasks[0].description)
expect(startedRuns[0].pending_user_message).toBe(createdTasks[0].description)
@@ -173,7 +204,7 @@ describe('inboxTaskKickoffLogic', () => {
signal_report: report.id,
branch: null,
runtime_adapter: 'claude',
- model: 'claude-opus-5',
+ model: 'claude-opus-5-5',
})
expect(warmRequests[0]).not.toHaveProperty('repository')
expect(logic.values.reportWarmLease).toEqual({
@@ -184,6 +215,58 @@ describe('inboxTaskKickoffLogic', () => {
expect(cancelledRuns).toHaveLength(0)
})
+ it.each(['implementation', 'discussion'] as const)(
+ 'leaves the %s model to settings when the project set a default',
+ async (relationship) => {
+ await applyRunDefaults(RESOLVED_TEAM_DEFAULT)
+
+ await expectLogic(logic, () => {
+ if (relationship === 'implementation') {
+ logic.actions.createPrFromReport(report)
+ } else {
+ logic.actions.discussReport(report, 'https://example.com/report', 'Explain the recommendation')
+ }
+ }).toFinishAllListeners()
+
+ expect(createdTasks[0]).not.toHaveProperty('model')
+ expect(startedRuns[0]).not.toHaveProperty('model')
+ expect(startedRuns[0]).not.toHaveProperty('runtime_adapter')
+ expect(startedRuns[0]).not.toHaveProperty('reasoning_effort')
+ }
+ )
+
+ it('waits for the stored default before it falls back to a model of its own', async () => {
+ // Put `@me/config` back in flight, as it is for a reader who presses the button while the
+ // report is still opening.
+ taskRunDefaultsLogic.unmount()
+ let releaseRunDefaults = (): void => {}
+ runDefaultsGate = new Promise<void>((resolve) => {
+ releaseRunDefaults = resolve
+ })
+ resolvedRunDefaults = RESOLVED_TEAM_DEFAULT
+ taskRunDefaultsLogic.mount()
+
+ const kickoff = expectLogic(logic, () => logic.actions.createPrFromReport(report)).toFinishAllListeners()
+ releaseRunDefaults()
+ await kickoff
+
+ expect(createdTasks[0]).not.toHaveProperty('model')
+ expect(startedRuns[0]).not.toHaveProperty('model')
+ })
+
+ it('warms on the default model when the project set one', async () => {
+ warmResponse = { task_id: 'warm-task', run_id: 'warm-run' }
+ await applyRunDefaults(RESOLVED_TEAM_DEFAULT)
+
+ await expectLogic(logic, () =>
+ logic.actions.openReportDiscussion(report, 'https://example.com/report')
+ ).toFinishAllListeners()
+
+ // The warm sandbox boots its agent on this model; activation cannot change it.
+ expect(warmRequests[0]).not.toHaveProperty('model')
+ expect(warmRequests[0]).not.toHaveProperty('runtime_adapter')
+ })
+
it('does not warm when Create PR opens the panel', async () => {
await expectLogic(logic, () => logic.actions.createPrFromReport(report)).toFinishAllListeners()
diff --git a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts b/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
index 4fd6234d549e..e4d667edc39f 100644
--- a/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
+++ b/products/signals/frontend/inbox/inboxTaskKickoffLogic.ts
@@ -21,6 +21,7 @@ import {
attachedContextLogic,
runnerPanelLogic,
runStreamLogic,
+ taskRunDefaultsLogic,
wrapWithPosthogContext,
} from 'products/posthog_ai/frontend/api/logics'
import type { ActiveCreation } from 'products/posthog_ai/frontend/api/logics'
@@ -80,23 +81,27 @@ export const FREE_TRIAL_PR_DISABLED_REASON =
// The run endpoint rejects a model without its runtime adapter, so the two are always sent together.
type ClaudeRuntimeSelection = Pick<ClaudeTaskRunCreateSchemaApi, 'runtime_adapter' | 'model' | 'reasoning_effort'>
-// Discuss is a focused exchange about a report (a question to answer, or a suggested next step to
-// carry out) rather than a scheduled implementation run, so it pins the stronger model instead of
-// taking the server-side default of Sonnet: the answer quality is what the user is here for, and
-// the extra cost is bounded by the length of the conversation.
-const DISCUSS_RUNTIME: ClaudeRuntimeSelection = {
+/** The fallback selection, or nothing at all so the stored defaults decide. */
+type ReportRuntimeSelection = ClaudeRuntimeSelection | Record<string, never>
+
+// Both kickoffs are worth a stronger model than the agent server's Sonnet when nobody chose one:
+// Discuss because answer quality is what the user came for, and the extra cost is bounded by the
+// length of the conversation; Create PR because pressing it commits to a real implementation run.
+const REPORT_FALLBACK_RUNTIME: ClaudeRuntimeSelection = {
runtime_adapter: ClaudeRuntimeAdapterEnumApi.Claude,
- model: 'claude-opus-5',
+ model: 'claude-opus-5-5',
reasoning_effort: ReasoningEffortEnumApi.High,
}
-// Pressing "Create PR" is a strong engagement signal — the user is committing to a real
-// implementation run — so it pins the stronger model rather than taking the server-side default of
-// Sonnet, giving the change the best shot at landing.
-const CREATE_PR_RUNTIME: ClaudeRuntimeSelection = {
- runtime_adapter: ClaudeRuntimeAdapterEnumApi.Claude,
- model: 'claude-opus-5',
- reasoning_effort: ReasoningEffortEnumApi.High,
+// A model sent with the run is final server-side (`resolve_ai_run_selection`), so honoring the
+// project and personal defaults means sending none. `defaultModel` is the server's own resolution
+// for this user, but it also reads null while `@me/config` is still in flight, so wait for that
+// answer first: a fallback sent over a default nobody has looked up yet would silently win.
+async function launchSelection(values: inboxTaskKickoffLogicValues): Promise<ReportRuntimeSelection> {
+ if (!values.defaultsResolved) {
+ await taskRunDefaultsLogic.asyncActions.loadMyConfig()
+ }
+ return values.defaultModel ? {} : REPORT_FALLBACK_RUNTIME
}
// The report's state is part of what a run owes the reader, and only the two ends of the happy
@@ -242,7 +247,7 @@ async function createReportTask(
relationship: SignalReportTaskRelationship,
prompt: string,
fallbackTitle: string,
- runtimeSelection: ClaudeRuntimeSelection,
+ runtimeSelection: ReportRuntimeSelection,
discussionQuestion?: string,
warmLease: ReportWarmLease | null = null
): Promise<{ taskId: string; runId: string }> {
@@ -322,6 +327,8 @@ export interface inboxTaskKickoffLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
currentProjectId: number | null // projectLogic
activeCreation: ActiveCreation | null // runnerPanelLogic
+ defaultModel: string | null // taskRunDefaultsLogic
+ defaultsResolved: boolean // taskRunDefaultsLogic
aiConsentDisabledReason: string | null
createPrDisabledReason: string | null
freeTrialDisabledReason: string | null
@@ -461,6 +468,8 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
['contextItems'],
runnerPanelLogic({ panelId: REPORT_AI_PANEL_ID }),
['activeCreation'],
+ taskRunDefaultsLogic,
+ ['defaultModel', 'defaultsResolved'],
aiConsentLogic,
['dataProcessingAccepted', 'dataProcessingApprovalDisabledReason'],
featureFlagLogic,
@@ -583,7 +592,8 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
origin_product: TaskOriginProductEnumApi.SignalReport,
signal_report: report.id,
branch: null,
- ...DISCUSS_RUNTIME,
+ // The warm sandbox boots its agent on this model and activation cannot change it.
+ ...(await launchSelection(values)),
}
const warm = await tasksWarmCreate(projectId, request)
const newLease: ReportWarmLease | null =
@@ -713,7 +723,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
SIGNAL_REPORT_TASK_DISCUSSION_RELATIONSHIP,
prompt,
'Ask AI about report',
- DISCUSS_RUNTIME,
+ await launchSelection(values),
question,
warmLease
)
@@ -770,7 +780,7 @@ export const inboxTaskKickoffLogic = kea<inboxTaskKickoffLogicType>([
SIGNAL_REPORT_TASK_IMPLEMENTATION_RELATIONSHIP,
buildCreatePrReportPrompt(report, feedback),
'Implement report fix',
- CREATE_PR_RUNTIME
+ await launchSelection(values)
)
if (disposables.isDisposed) {
return