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(tasks): always show the new chat composer (#127211)

Shy Alter7294ddf4cc1e
diff --git a/products/tasks/backend/tests/test_channels_api.py b/products/tasks/backend/tests/test_channels_api.py
index f5b0cc668519..8081039625b5 100644
--- a/products/tasks/backend/tests/test_channels_api.py
+++ b/products/tasks/backend/tests/test_channels_api.py
@@ -882,6 +882,19 @@ class ChannelsAPITestCase(TestCase):
listed = self.client.get(f"{self._tasks_url()}?archived=true").json()["results"]
self.assertEqual([task["id"] for task in listed], [task_id])
+ def test_task_without_a_channel_creates_and_lands_in_the_personal_channel(self):
+ self.assertFalse(Channel.objects.unscoped().filter(team=self.team).exists())
+
+ task_id = self.client.post(
+ self._tasks_url(),
+ {"title": "First chat", "description": "d", "origin_product": "posthog_ai"},
+ ).json()["id"]
+
+ channel = Task.objects.select_related("channel").get(id=task_id).channel
+ assert channel is not None
+ self.assertEqual(channel.channel_type, Channel.ChannelType.PERSONAL)
+ self.assertEqual(channel.created_by_id, self.user.id)
+
def test_cannot_file_task_into_someone_elses_personal_channel(self):
self._provision()
personal = Channel.objects.unscoped().get(team=self.team, channel_type=Channel.ChannelType.PERSONAL)
diff --git a/products/tasks/frontend/spaces/NewSessionScene.tsx b/products/tasks/frontend/spaces/NewSessionScene.tsx
index cafe18a0be64..a0202f311c4d 100644
--- a/products/tasks/frontend/spaces/NewSessionScene.tsx
+++ b/products/tasks/frontend/spaces/NewSessionScene.tsx
@@ -1,7 +1,5 @@
import { useActions, useValues } from 'kea'
-import { Button, Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle } from '@posthog/quill'
-
import { NotFound } from 'lib/components/NotFound'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { SceneExport } from 'scenes/sceneTypes'
@@ -22,8 +20,8 @@ export const scene: SceneExport = {
export function NewSessionScene(): JSX.Element {
const enabled = useFeatureFlag('TODAY_RAIL_NAV')
- const { space, spacesLoading, spacesUnavailable, composerRepositoryConfig } = useValues(newSessionSceneLogic)
- const { sessionStarted, loadSpaces } = useActions(newSessionSceneLogic)
+ const { space, spacesLoading, composerRepositoryConfig } = useValues(newSessionSceneLogic)
+ const { sessionStarted } = useActions(newSessionSceneLogic)
const { suggestions, prefillRequest } = useValues(newSessionSuggestionsLogic)
const { selectSuggestion } = useActions(newSessionSuggestionsLogic)
@@ -31,56 +29,30 @@ export function NewSessionScene(): JSX.Element {
return <NotFound object="page" />
}
- const resolving = !space && spacesLoading
- const failed = !space && spacesUnavailable
-
return (
<SceneContent className="flex-1">
{/* Like PostHog Desktop, the middle of the block sits 34% down the pane: the shrink weights take half the block's height from each spacer. */}
<div className="flex flex-1 flex-col" data-quill>
<div aria-hidden className="min-h-4 shrink-[66] basis-[34%]" />
<div className="mx-auto flex w-full max-w-150 shrink-0 flex-col">
- {failed ? (
- <Empty className="py-12">
- <EmptyHeader>
- <EmptyTitle>Your spaces didn’t load</EmptyTitle>
- <EmptyDescription>Check your connection and try again.</EmptyDescription>
- </EmptyHeader>
- <EmptyContent>
- <Button
- variant="outline"
- loading={spacesLoading}
- onClick={() => loadSpaces()}
- data-attr="today-new-session-retry"
- >
- Try again
- </Button>
- </EmptyContent>
- </Empty>
+ <h1 className="sr-only">Start a new session</h1>
+ {!space && spacesLoading ? (
+ <QuillTaskComposerSkeleton />
) : (
- <>
- <h1 className="sr-only">Start a new session</h1>
- {resolving ? (
- <QuillTaskComposerSkeleton />
- ) : (
- space && (
- // Each space gets its own composer, so it starts on that space's repository.
- <div data-attr="today-new-session-composer">
- <SpaceTaskComposer
- space={space}
- panelId={`new-session-${space.id}`}
- repositoryConfig={composerRepositoryConfig}
- onTaskCreated={sessionStarted}
- prefillRequest={prefillRequest}
- />
- </div>
- )
- )}
- </>
+ // Each space gets its own composer, so it starts on that space's repository.
+ <div data-attr="today-new-session-composer">
+ <SpaceTaskComposer
+ space={space}
+ panelId={`new-session-${space?.id ?? 'personal'}`}
+ repositoryConfig={composerRepositoryConfig}
+ onTaskCreated={sessionStarted}
+ prefillRequest={prefillRequest}
+ />
+ </div>
)}
</div>
<div className="mx-auto w-full max-w-150 shrink-[34] basis-[66%]">
- {space && suggestions.length > 0 && (
+ {suggestions.length > 0 && (
<div className="pt-6 pb-4">
<NewSessionSuggestions suggestions={suggestions} onSelect={selectSuggestion} />
</div>
diff --git a/products/tasks/frontend/spaces/SpaceTaskComposer.tsx b/products/tasks/frontend/spaces/SpaceTaskComposer.tsx
index 5d55b313f819..3fd2ebc22212 100644
--- a/products/tasks/frontend/spaces/SpaceTaskComposer.tsx
+++ b/products/tasks/frontend/spaces/SpaceTaskComposer.tsx
@@ -12,7 +12,7 @@ const SPACE_COMPOSER_OVERRIDE = {
}
export interface SpaceTaskComposerProps {
- space: ChannelDTOApi
+ space: ChannelDTOApi | null
panelId: string
repositoryConfig: SpaceComposerRepositoryConfig
onTaskCreated: (sessionId: string) => void
@@ -31,9 +31,9 @@ export function SpaceTaskComposer({
}: SpaceTaskComposerProps): JSX.Element {
return (
<EmbeddedTaskComposer
- key={space.id}
+ key={space?.id}
panelId={panelId}
- channelId={space.id}
+ channelId={space?.id}
initialRepositoryConfig={repositoryConfig}
composerOverride={SPACE_COMPOSER_OVERRIDE}
onTaskCreated={onTaskCreated}
diff --git a/products/tasks/frontend/spaces/newSessionSceneLogic.test.ts b/products/tasks/frontend/spaces/newSessionSceneLogic.test.ts
index d2b229200832..441db3c62836 100644
--- a/products/tasks/frontend/spaces/newSessionSceneLogic.test.ts
+++ b/products/tasks/frontend/spaces/newSessionSceneLogic.test.ts
@@ -1,20 +1,52 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
import { ChannelDTOApi } from '../generated/api.schemas'
-import { NewSessionSpaceSource, newSessionSpace } from './newSessionSceneLogic'
+import { NewSessionSpaceSource, newSessionSceneLogic, newSessionSpace } from './newSessionSceneLogic'
const space = (id: string, systemRole: ChannelDTOApi['system_role'] = null): ChannelDTOApi =>
({ id, name: id, system_role: systemRole }) as ChannelDTOApi
const SPACES = [space('general', 'general'), space('me', 'personal'), space('checkout')]
-describe('newSessionSpace', () => {
- it.each<[string, string | null, string | null, string, NewSessionSpaceSource]>([
- ['a space’s own New session wins over the last space', 'checkout', 'general', 'checkout', 'route'],
- ['a generic New session uses the last space', null, 'checkout', 'checkout', 'last_used'],
- ['a generic New session with no last space uses personal', null, null, 'me', 'personal'],
- ['a deleted last space falls back to personal', null, 'gone', 'me', 'personal'],
- ['a deleted route space falls back to the last space', 'gone', 'checkout', 'checkout', 'last_used'],
- ])('%s', (_, routeSpaceId, lastSpaceId, expectedId, expectedSource) => {
- const { space: chosen, source } = newSessionSpace(SPACES, routeSpaceId, lastSpaceId)
- expect({ id: chosen?.id, source }).toEqual({ id: expectedId, source: expectedSource })
+describe('newSessionSceneLogic', () => {
+ describe('newSessionSpace', () => {
+ it.each<[string, string | null, string | null, string, NewSessionSpaceSource]>([
+ ['a space’s own New session wins over the last space', 'checkout', 'general', 'checkout', 'route'],
+ ['a generic New session uses the last space', null, 'checkout', 'checkout', 'last_used'],
+ ['a generic New session with no last space uses personal', null, null, 'me', 'personal'],
+ ['a deleted last space falls back to personal', null, 'gone', 'me', 'personal'],
+ ['a deleted route space falls back to the last space', 'gone', 'checkout', 'checkout', 'last_used'],
+ ])('%s', (_, routeSpaceId, lastSpaceId, expectedId, expectedSource) => {
+ const { space: chosen, source } = newSessionSpace(SPACES, routeSpaceId, lastSpaceId)
+ expect({ id: chosen?.id, source }).toEqual({ id: expectedId, source: expectedSource })
+ })
+ })
+
+ describe('sessionStarted', () => {
+ it.each<[string, ChannelDTOApi[], boolean]>([
+ ['reloads spaces when the session had no space', [], true],
+ ['keeps the spaces when the session had one', [space('me', 'personal')], false],
+ ])('%s', async (_, spaces, reloads) => {
+ useMocks({
+ get: {
+ '/api/projects/:team_id/task_channels/': spaces,
+ '/api/projects/:team_id/task_activity/': { results: [] },
+ '/api/projects/:team_id/tasks/': { results: [], count: 0 },
+ },
+ })
+ initKeaTests()
+ const logic = newSessionSceneLogic()
+ logic.mount()
+ await expectLogic(todaySpacesLogic).toDispatchActions(['loadSpacesSuccess'])
+
+ const expectation = expectLogic(logic, () => logic.actions.sessionStarted('session-1'))
+ await (reloads
+ ? expectation.toDispatchActions(['loadSpaces'])
+ : expectation.toNotHaveDispatchedActions(['loadSpaces']))
+ })
})
})
diff --git a/products/tasks/frontend/spaces/newSessionSceneLogic.ts b/products/tasks/frontend/spaces/newSessionSceneLogic.ts
index 1f1d4d5f8ea9..8773de6775b9 100644
--- a/products/tasks/frontend/spaces/newSessionSceneLogic.ts
+++ b/products/tasks/frontend/spaces/newSessionSceneLogic.ts
@@ -143,7 +143,7 @@ export const newSessionSceneLogic = kea<newSessionSceneLogicType>([
],
],
}),
- listeners(({ values }) => ({
+ listeners(({ actions, values }) => ({
// Like PostHog Desktop, a pick moves to that space's own New session, so it becomes the last space too.
pickSpace: ({ spaceId }) => {
router.actions.push(urls.taskSpaceNewSession(spaceId))
@@ -154,6 +154,9 @@ export const newSessionSceneLogic = kea<newSessionSceneLogicType>([
space_role: values.space?.system_role ?? null,
space_source: values.spaceChoice.source,
})
+ if (!values.space) {
+ actions.loadSpaces()
+ }
router.actions.push(urls.aiTask(sessionId))
},
})),