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.

feat(posthog-ai): rename a task from its title or the actions menu (#106543)

Vojta Bartoš51999adfa2a3
diff --git a/frontend/src/layout/panel-layout/navbar/tabs/NavTabChat.tsx b/frontend/src/layout/panel-layout/navbar/tabs/NavTabChat.tsx
index 29254a60999c..500606985071 100644
--- a/frontend/src/layout/panel-layout/navbar/tabs/NavTabChat.tsx
+++ b/frontend/src/layout/panel-layout/navbar/tabs/NavTabChat.tsx
@@ -253,7 +253,7 @@ const TaskRow = memo(function TaskRow({
/>
<TaskListItem.Trigger />
</TaskListItem.Group>
- <TaskListItem.Actions taskId={item.task.id} />
+ <TaskListItem.Actions task={item.task} />
</TaskListItem.Root>
)
})
diff --git a/frontend/src/layout/scenes/components/SceneTitleSection.test.tsx b/frontend/src/layout/scenes/components/SceneTitleSection.test.tsx
index 882e497bfd67..43429c26dfce 100644
--- a/frontend/src/layout/scenes/components/SceneTitleSection.test.tsx
+++ b/frontend/src/layout/scenes/components/SceneTitleSection.test.tsx
@@ -1,6 +1,6 @@
import '@testing-library/jest-dom'
-import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
import { SceneName } from './SceneTitleSection'
@@ -28,6 +28,42 @@ describe('SceneName', () => {
expect(onChange).toHaveBeenCalledWith('Paying users')
})
+ // Guards a duplicate rename request: Enter saves the value straight away, and the name prop
+ // only catches up once that save round-trips, so the blur right after it used to save again.
+ // The second half guards the over-correction — a rejected save must stay retryable, so the
+ // field may not treat the value as saved for good.
+ test('saves an Enter-then-blur rename once, and still saves it again on a later blur', () => {
+ jest.useFakeTimers()
+ try {
+ const onChange = jest.fn()
+ render(<SceneName name="Old name" onChange={onChange} canEdit saveOnBlur renameDebounceMs={0} />)
+
+ fireEvent.click(screen.getByRole('button'))
+
+ const textarea = screen.getByRole('textbox')
+ fireEvent.change(textarea, { target: { value: 'New name' } })
+ fireEvent.keyDown(textarea, { key: 'Enter' })
+ fireEvent.blur(textarea)
+ act(() => {
+ jest.advanceTimersByTime(1)
+ })
+
+ expect(onChange).toHaveBeenCalledTimes(1)
+ expect(onChange).toHaveBeenCalledWith('New name')
+
+ // The save was rejected, so the name prop still holds the old title.
+ fireEvent.click(screen.getByRole('button'))
+ fireEvent.blur(screen.getByRole('textbox'))
+ act(() => {
+ jest.advanceTimersByTime(1)
+ })
+
+ expect(onChange).toHaveBeenCalledTimes(2)
+ } finally {
+ jest.useRealTimers()
+ }
+ })
+
// Guards the reconciliation change: a genuine external update (loading a resource,
// an AI-generated name) must still replace the field's value.
test('adopts an external name change into the field', () => {
diff --git a/frontend/src/layout/scenes/components/SceneTitleSection.tsx b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
index a031de050188..84ea31f216c3 100644
--- a/frontend/src/layout/scenes/components/SceneTitleSection.tsx
+++ b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
@@ -349,7 +349,7 @@ export function SceneTitleSection({
data-editable={canEdit}
>
<div
- className={cn('flex gap-1 flex-1 min-w-0', {
+ className={cn('flex items-center gap-1 flex-1 min-w-0', {
'-ml-[var(--button-padding-x-base)]': willShowBreadcrumbs,
})}
>
@@ -477,6 +477,10 @@ export function SceneName({
// the user's own edit arriving back through the form, so the render-phase
// reconciliation below can't overwrite a keystroke that hasn't round-tripped yet.
const latestNameRef = useRef(initialName)
+ // What the last Enter press saved, held only until the next blur. `initialName` catches up
+ // when the save round-trips, so the blur straight after Enter still sees a changed field and
+ // would save the same value a second time.
+ const savedByEnterRef = useRef<string | null>(null)
if (initialName !== prevInitialName) {
setPrevInitialName(initialName)
if (initialName !== latestNameRef.current) {
@@ -519,7 +523,9 @@ export function SceneName({
if (relatedTarget && containerRef.current && containerRef.current.contains(relatedTarget)) {
return
}
- if (saveOnBlur && !isGeneratingMetadata && name !== initialName) {
+ const savedByEnter = savedByEnterRef.current
+ savedByEnterRef.current = null
+ if (saveOnBlur && !isGeneratingMetadata && name !== initialName && name !== savedByEnter) {
debouncedOnBlurSave(name || '')
} else if (!saveOnBlur) {
// Commit any pending debounced change synchronously so a submit or
@@ -570,6 +576,7 @@ export function SceneName({
if (e.key === 'Enter') {
e.preventDefault()
if (saveOnBlur && e.currentTarget.value !== initialName) {
+ savedByEnterRef.current = e.currentTarget.value || ''
onChange?.(e.currentTarget.value || '')
}
}
diff --git a/products/posthog_ai/frontend/components/navigation/TaskListItem.tsx b/products/posthog_ai/frontend/components/navigation/TaskListItem.tsx
index b61db98382b0..c099e44168eb 100644
--- a/products/posthog_ai/frontend/components/navigation/TaskListItem.tsx
+++ b/products/posthog_ai/frontend/components/navigation/TaskListItem.tsx
@@ -1,6 +1,6 @@
import { useActions } from 'kea'
-import { IconArchive } from '@posthog/icons'
+import { IconArchive, IconPencil } from '@posthog/icons'
import { Tooltip } from '@posthog/lemon-ui'
import { dayjs } from 'lib/dayjs'
@@ -16,6 +16,7 @@ import { TaskRunEnvironment } from '../../types/taskTypes'
import type { Task } from '../../types/taskTypes'
import { TaskEnvironmentIcon } from '../TaskEnvironmentIcon'
import { TaskRunLivenessDot } from '../TaskRunLivenessDot'
+import { openRenameTaskDialog } from './openRenameTaskDialog'
function compactTimeAgo(iso: string): string {
const seconds = dayjs().diff(dayjs(iso), 'second')
@@ -62,14 +63,28 @@ function Content({ task }: { task: Task }): JSX.Element {
)
}
-function Actions({ taskId }: { taskId: string }): JSX.Element {
- const { deleteTask } = useActions(tasksLogic)
+function Actions({ task }: { task: Task }): JSX.Element {
+ const { deleteTask, renameTask } = useActions(tasksLogic)
return (
<LinkListItem.Actions>
<DropdownMenuGroup>
<DropdownMenuItem asChild>
- <ButtonPrimitive menuItem variant="danger" onClick={() => deleteTask({ taskId })}>
+ <ButtonPrimitive
+ menuItem
+ onClick={() =>
+ openRenameTaskDialog(task.title || task.slug, (title) =>
+ renameTask({ taskId: task.id, title })
+ )
+ }
+ data-attr="task-rename"
+ >
+ <IconPencil className="size-4 text-tertiary" />
+ Rename
+ </ButtonPrimitive>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <ButtonPrimitive menuItem variant="danger" onClick={() => deleteTask({ taskId: task.id })}>
<IconArchive className="size-4 text-danger" />
<span className="text-danger">Archive task</span>
</ButtonPrimitive>
diff --git a/products/posthog_ai/frontend/components/navigation/openRenameTaskDialog.tsx b/products/posthog_ai/frontend/components/navigation/openRenameTaskDialog.tsx
new file mode 100644
index 000000000000..0604208b3416
--- /dev/null
+++ b/products/posthog_ai/frontend/components/navigation/openRenameTaskDialog.tsx
@@ -0,0 +1,32 @@
+import { LemonInput } from '@posthog/lemon-ui'
+
+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import { nextTaskTitle } from '../../lib/task-title'
+
+/** Matches `Task.title` on the server, which rejects anything longer. */
+const TASK_TITLE_MAX_LENGTH = 255
+
+export function openRenameTaskDialog(currentTitle: string, onRename: (title: string) => void): void {
+ LemonDialog.openForm({
+ title: 'Rename task',
+ initialValues: { title: currentTitle },
+ primaryButtonProps: { children: 'Rename' },
+ showErrorsOnTouch: true,
+ content: (
+ <LemonField name="title">
+ <LemonInput placeholder="Task name" maxLength={TASK_TITLE_MAX_LENGTH} autoFocus />
+ </LemonField>
+ ),
+ errors: {
+ title: (value) => (!value?.trim() ? 'Enter a name for the task' : undefined),
+ },
+ onSubmit: ({ title }) => {
+ const renamed = nextTaskTitle(title, currentTitle)
+ if (renamed) {
+ onRename(renamed)
+ }
+ },
+ })
+}
diff --git a/products/posthog_ai/frontend/e2e/run-surface.spec.ts b/products/posthog_ai/frontend/e2e/run-surface.spec.ts
index 99fcbd3cf3b9..edf2286c7346 100644
--- a/products/posthog_ai/frontend/e2e/run-surface.spec.ts
+++ b/products/posthog_ai/frontend/e2e/run-surface.spec.ts
@@ -173,7 +173,9 @@ async function openRunDeepLink(page: Page, teamId: string): Promise<void> {
const ph = (window as unknown as { posthog?: { reloadFeatureFlags?: () => void } }).posthog
ph?.reloadFeatureFlags?.()
})
- await expect(page.getByRole('heading', { name: 'Run surface e2e task', exact: true })).toBeVisible({
+ // An editable title renders as the rename button rather than a heading, so match the
+ // scene-name container instead of the element inside it.
+ await expect(page.locator('[data-attr="scene-name"]').first()).toContainText('Run surface e2e task', {
timeout: 40000,
})
}
diff --git a/products/posthog_ai/frontend/lib/task-title.test.ts b/products/posthog_ai/frontend/lib/task-title.test.ts
new file mode 100644
index 000000000000..d531e1555d98
--- /dev/null
+++ b/products/posthog_ai/frontend/lib/task-title.test.ts
@@ -0,0 +1,15 @@
+import { nextTaskTitle } from './task-title'
+
+describe('nextTaskTitle', () => {
+ test.each([
+ ['saves a new title', 'Fix the export', 'Old title', 'Fix the export'],
+ ['trims surrounding whitespace', ' Fix the export ', 'Old title', 'Fix the export'],
+ ['skips a blank title', '', 'Old title', null],
+ ['skips a whitespace-only title', ' ', 'Old title', null],
+ ['skips an unchanged title', 'Old title', 'Old title', null],
+ ['skips a title that only gained whitespace', ' Old title ', 'Old title', null],
+ ['saves over a task that has no title yet', 'Fix the export', undefined, 'Fix the export'],
+ ])('%s', (_name, input, currentTitle, expected) => {
+ expect(nextTaskTitle(input, currentTitle)).toBe(expected)
+ })
+})
diff --git a/products/posthog_ai/frontend/lib/task-title.ts b/products/posthog_ai/frontend/lib/task-title.ts
new file mode 100644
index 000000000000..9f87b00b4087
--- /dev/null
+++ b/products/posthog_ai/frontend/lib/task-title.ts
@@ -0,0 +1,11 @@
+/**
+ * The title a rename should save, or `null` when there is nothing to save. The title field fires on every
+ * blur whether or not the user typed, so most calls arrive with nothing to do.
+ */
+export function nextTaskTitle(input: string, currentTitle: string | undefined): string | null {
+ const trimmed = input.trim()
+ if (!trimmed || trimmed === currentTitle) {
+ return null
+ }
+ return trimmed
+}
diff --git a/products/posthog_ai/frontend/logics/taskLogic.test.ts b/products/posthog_ai/frontend/logics/taskLogic.test.ts
index 011d90fd2f5d..26c51dee9ba8 100644
--- a/products/posthog_ai/frontend/logics/taskLogic.test.ts
+++ b/products/posthog_ai/frontend/logics/taskLogic.test.ts
@@ -110,6 +110,18 @@ describe('taskLogic', () => {
})
})
+ describe('updateTaskFailure', () => {
+ it('surfaces the error so a rejected rename does not look saved', async () => {
+ logic = taskLogic({ taskId: 'task-123' })
+ logic.mount()
+
+ logic.actions.updateTaskFailure('Title is too long', new ApiError('Title is too long', 400))
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(lemonToast.error).toHaveBeenCalledWith('Title is too long')
+ })
+ })
+
describe('refreshing task lists after a mutation', () => {
afterEach(() => {
jest.restoreAllMocks()
diff --git a/products/posthog_ai/frontend/logics/taskLogic.ts b/products/posthog_ai/frontend/logics/taskLogic.ts
index ed7eb403947b..a447831ea9d7 100644
--- a/products/posthog_ai/frontend/logics/taskLogic.ts
+++ b/products/posthog_ai/frontend/logics/taskLogic.ts
@@ -185,12 +185,29 @@ export const taskLogic = kea<taskLogicType>([
},
],
}),
- listeners(({ props, values }) => ({
+ listeners(({ props, values, actions }) => ({
loadTaskSuccess: () => {
if (values.task) {
tasksLogic.findMounted()?.actions.updateTask(values.task)
}
},
+ // The sidebar rename writes through tasksLogic, so mirror the result onto this detail
+ // logic. Without it the header keeps the old title until the next full load.
+ [tasksLogic.actionTypes.renameTaskSuccess]: ({
+ tasks,
+ payload,
+ }: {
+ tasks: Task[]
+ payload?: { taskId: string; title: string }
+ }) => {
+ if (payload?.taskId !== props.taskId) {
+ return
+ }
+ const renamed = tasks.find((task) => task.id === props.taskId)
+ if (renamed) {
+ actions.loadTaskSuccess(renamed)
+ }
+ },
runTaskSuccess: () => {
if (values.task) {
tasksLogic.findMounted()?.actions.updateTask(values.task)
@@ -208,5 +225,9 @@ export const taskLogic = kea<taskLogicType>([
tasksLogic.findMounted()?.actions.updateTask(values.task)
}
},
+ // The title field keeps what the user typed, so without this a rejected rename reads as saved.
+ updateTaskFailure: ({ error, errorObject }) => {
+ lemonToast.error(loadErrorMessage(error, errorObject) || "Couldn't save the task. Try again.")
+ },
})),
])
diff --git a/products/posthog_ai/frontend/logics/tasksLogic.test.ts b/products/posthog_ai/frontend/logics/tasksLogic.test.ts
index 6e8b421a8c14..dc60c3efe4de 100644
--- a/products/posthog_ai/frontend/logics/tasksLogic.test.ts
+++ b/products/posthog_ai/frontend/logics/tasksLogic.test.ts
@@ -376,4 +376,20 @@ describe('tasksLogic', () => {
historyLogic.unmount()
})
})
+
+ describe('renameTask', () => {
+ // The loader next to this one archives by filtering the task out of the list. Renaming
+ // through the same shape would drop the row instead of relabelling it.
+ it('keeps the task in the list under its new title', async () => {
+ const renamed = { ...createMockTask('task-1'), title: 'Investigate slow dashboard load' }
+ useMocks({ patch: { '/api/projects/:team_id/tasks/:id/': () => [200, renamed] } })
+ logic.actions.loadTasksSuccess([createMockTask('task-1'), createMockTask('task-2')])
+
+ logic.actions.renameTask({ taskId: 'task-1', title: 'Investigate slow dashboard load' })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.tasks.map((t) => t.id)).toEqual(['task-1', 'task-2'])
+ expect(logic.values.tasks[0].title).toBe('Investigate slow dashboard load')
+ })
+ })
})
diff --git a/products/posthog_ai/frontend/logics/tasksLogic.ts b/products/posthog_ai/frontend/logics/tasksLogic.ts
index 8820f3f657da..6e102f6fdeda 100644
--- a/products/posthog_ai/frontend/logics/tasksLogic.ts
+++ b/products/posthog_ai/frontend/logics/tasksLogic.ts
@@ -157,6 +157,30 @@ export interface tasksLogicActions {
openTask: (taskId: Task['id']) => {
taskId: string
}
+ renameTask: ({ taskId, title }: { taskId: string; title: string }) => {
+ taskId: string
+ title: string
+ }
+ renameTaskFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ renameTaskSuccess: (
+ tasks: Task[],
+ payload?: {
+ taskId: string
+ title: string
+ }
+ ) => {
+ tasks: Task[]
+ payload?: {
+ taskId: string
+ title: string
+ }
+ }
setAssigneeFilter: (assigneeFilter: TaskAssigneeFilter) => {
assigneeFilter: TaskAssigneeFilter
}
@@ -272,6 +296,10 @@ export const tasksLogic = kea<tasksLogicType>([
await api.tasks.delete(taskId)
return values.tasks.filter((t) => t.id !== taskId)
},
+ renameTask: async ({ taskId, title }: { taskId: string; title: string }) => {
+ const renamed = await api.tasks.update(taskId, { title })
+ return values.tasks.map((t) => (t.id === taskId ? renamed : t))
+ },
},
],
repositories: [
@@ -457,6 +485,9 @@ export const tasksLogic = kea<tasksLogicType>([
taskHistoryLogic.findMounted()?.actions.taskArchived(payload.taskId)
}
},
+ renameTaskFailure: ({ error, errorObject }) => {
+ lemonToast.error(`Couldn't rename the task: ${loadErrorMessage(error, errorObject)}`)
+ },
setFeatureFlags: loadInitialTasks,
loadUserSuccess: () => {
if (cache.tasksLoadPending) {
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx
index ee30db22ae57..898327e21d50 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskDetailPage.tsx
@@ -6,6 +6,7 @@ import { LemonButton } from '@posthog/lemon-ui'
import { NotFound } from 'lib/components/NotFound'
import { urls } from 'scenes/urls'
+import { nextTaskTitle } from '../../../lib/task-title'
import { isPiTaskRuntime } from '../../../types/taskTypes'
import { taskDetailSceneLogic } from '../taskDetailSceneLogic'
import { taskTrackerSceneLogic } from '../taskTrackerSceneLogic'
@@ -23,7 +24,7 @@ export function TaskDetailPage({ taskId, isMobile, titleActions }: TaskDetailPag
const sceneLogic = taskDetailSceneLogic({ taskId })
const { task, taskNotFound, taskError, latestRun, selectedRun, isTaskPending, isHeaderLoading, runTaskInFlight } =
useValues(sceneLogic)
- const { runTask, deleteTask, loadTask } = useActions(sceneLogic)
+ const { runTask, deleteTask, loadTask, updateTask } = useActions(sceneLogic)
const { activeCreation, hasDesktopAccess } = useValues(taskTrackerSceneLogic)
const isActiveCreation = activeCreation?.taskId === taskId
@@ -40,6 +41,12 @@ export function TaskDetailPage({ taskId, isMobile, titleActions }: TaskDetailPag
const runButtonText = latestRun ? 'Retry task' : 'Run task'
const prUrl = selectedRun?.output?.pr_url as string | undefined
+ const renameTask = (title: string): void => {
+ const nextTitle = nextTaskTitle(title, task?.title)
+ if (nextTitle) {
+ updateTask({ data: { title: nextTitle } })
+ }
+ }
const taskActions =
isHeaderLoading || !task ? (
isActiveCreation ? undefined : (
@@ -101,6 +108,7 @@ export function TaskDetailPage({ taskId, isMobile, titleActions }: TaskDetailPag
{titleActions}
</div>
}
+ onRename={task ? renameTask : undefined}
onArchive={deleteTask}
taskError={taskError}
onRetry={loadTask}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsx
index 0e45c6bdfadf..c8190e1bff29 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunSceneShell.tsx
@@ -35,6 +35,8 @@ export interface TaskRunSceneShellProps {
isHeaderLoading?: boolean
/** Title-bar action buttons (or their skeleton). Supplied by the caller so the shell stays presentational. */
titleActions?: JSX.Element
+ /** Omitting this leaves the title read-only, which is what the create thread needs: it renders this shell before the task exists. */
+ onRename?: (title: string) => void
onArchive: () => void
taskError: string | null
onRetry: () => void
@@ -53,6 +55,7 @@ export function TaskRunSceneShell({
selectedRun,
isHeaderLoading = false,
titleActions,
+ onRename,
onArchive,
taskError,
onRetry,
@@ -133,7 +136,11 @@ export function TaskRunSceneShell({
forceIcon: <TaskEnvironmentIcon environment={task?.latest_run?.environment} />,
}}
isLoading={isHeaderLoading}
- canEdit={false}
+ canEdit={!!onRename}
+ onNameChange={onRename}
+ // One write when the field is left, rather than one per keystroke.
+ saveOnBlur
+ renameDebounceMs={0}
forceBackTo={
isMobile
? {