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(today): show unread sessions and desktop-style pr chips (#109349)

Shy Alter935a7938dd8b
diff --git a/frontend/src/layout/today/TodaySessionRow.tsx b/frontend/src/layout/today/TodaySessionRow.tsx
index ee6a852c5476..28e847f2da52 100644
--- a/frontend/src/layout/today/TodaySessionRow.tsx
+++ b/frontend/src/layout/today/TodaySessionRow.tsx
@@ -10,6 +10,7 @@ import { TodaySessionMenu } from './TodaySessionMenu'
import { TodaySessionSurface, todaySessionMenuLogic } from './todaySessionMenuLogic'
import { TodaySessionRenameInput } from './TodaySessionRenameInput'
import { TodaySessionStatusIcon } from './TodaySessionStatusIcon'
+import { todaySpacesLogic } from './todaySpacesLogic'
import { TodaySpacesRow } from './TodaySpacesRow'
import { TodayWorkItem, activeCloudRunId, analysisRunId, canHandOff } from './todayWorkItems'
@@ -18,12 +19,14 @@ interface TodaySessionRowProps {
pinned: boolean
dataAttr: string
surface: TodaySessionSurface
+ unread: boolean
}
-export function TodaySessionRow({ item, pinned, dataAttr, surface }: TodaySessionRowProps): JSX.Element {
+export function TodaySessionRow({ item, pinned, dataAttr, surface, unread }: TodaySessionRowProps): JSX.Element {
const { renaming } = useValues(todaySessionMenuLogic)
const { location, searchParams } = useValues(router)
const { user } = useValues(userLogic)
+ const { pullRequestStates } = useValues(todaySpacesLogic)
const [pullRequest] = item.pullRequests
@@ -42,10 +45,13 @@ export function TodaySessionRow({ item, pinned, dataAttr, surface }: TodaySessio
<TaskPullRequestChip
pullRequest={pullRequest}
label={`#${pullRequest.number}`}
+ state={pullRequestStates[pullRequest.url]}
+ size="row"
dataAttr="today-pr-chip-sidebar"
/>
) : null
}
+ unread={unread}
action={
<TodaySessionMenu
sessionId={item.id}
diff --git a/frontend/src/layout/today/TodaySpacesRow.tsx b/frontend/src/layout/today/TodaySpacesRow.tsx
index 15df030dab52..cb208eba3f11 100644
--- a/frontend/src/layout/today/TodaySpacesRow.tsx
+++ b/frontend/src/layout/today/TodaySpacesRow.tsx
@@ -13,6 +13,7 @@ interface TodaySpacesRowProps {
badge?: JSX.Element | null
/** How many icon buttons `action` holds, so the label truncates before them. */
actionCount?: 1 | 2
+ unread?: boolean
}
export function TodaySpacesRow({
@@ -24,6 +25,7 @@ export function TodaySpacesRow({
action,
badge,
actionCount = 1,
+ unread = false,
}: TodaySpacesRowProps): JSX.Element {
return (
<div className="group/row relative flex min-w-0 items-center">
@@ -35,13 +37,22 @@ export function TodaySpacesRow({
data-attr={dataAttr}
className={cn(
'min-w-0 text-muted-foreground',
- active && 'bg-fill-selected text-foreground',
+ (active || unread) && 'text-foreground',
+ active && 'bg-fill-selected',
action && !badge && (actionCount === 2 ? 'pr-12' : 'pr-8'),
badge && 'pr-24'
)}
>
<span className="flex size-3.5 shrink-0 items-center justify-center">{icon}</span>
- <span className="min-w-0 flex-1 truncate">{label}</span>
+ <span className={cn('min-w-0 flex-1 truncate', unread && 'font-semibold')}>{label}</span>
+ {unread && !active && (
+ <span
+ role="img"
+ aria-label="Unread"
+ className="size-1.5 shrink-0 rounded-full bg-primary"
+ data-attr="today-unread-dot"
+ />
+ )}
</Button>
{(action || badge) && (
<div className="absolute right-1 flex min-w-0 items-center gap-0.5">
diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsx
index d68292bcd392..e9573793fdef 100644
--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx
+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx
@@ -33,6 +33,8 @@ export function TodaySpacesSidebar(): JSX.Element {
recentLoading,
recentTasksUnavailable,
collapsedSections,
+ unreadSessionIds,
+ unreadSpaceIds,
} = useValues(todaySpacesLogic)
const { loadSpaces, loadRecentTasks, toggleSection, setRecentSearchOpen, clearRecentSearchAndFilters } =
useActions(todaySpacesLogic)
@@ -49,6 +51,7 @@ export function TodaySpacesSidebar(): JSX.Element {
pinned={pinnedIds.has(item.id)}
dataAttr={dataAttr}
surface="sidebar"
+ unread={unreadSessionIds.has(item.id)}
/>
) : (
<TodaySpacesRow
@@ -276,6 +279,7 @@ export function TodaySpacesSidebar(): JSX.Element {
dataAttr="today-space-row"
action={<TodaySpaceActions space={space} />}
actionCount={2}
+ unread={unreadSpaceIds.has(space.id)}
/>
))}
{visibleSpaces.length <= 1 && (
diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.ts
index 33b714750bcd..ab635d65a3ec 100644
--- a/frontend/src/layout/today/todaySpacesLogic.ts
+++ b/frontend/src/layout/today/todaySpacesLogic.ts
@@ -1,6 +1,7 @@
import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { combineUrl } from 'kea-router'
+import { combineUrl, router } from 'kea-router'
+import type { LocationChangedPayload } from 'kea-router/lib/types'
import { toast } from '@posthog/quill'
@@ -12,8 +13,22 @@ import { userLogic } from 'scenes/userLogic'
import { ConversationDetail, UserType } from '~/types'
-import { taskChannelsList, taskChannelsStarCreate, tasksList } from 'products/tasks/frontend/generated/api'
-import { ChannelDTOApi, TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'
+import {
+ taskActivityList,
+ taskActivityMarkReadCreate,
+ taskChannelsList,
+ taskChannelsStarCreate,
+ tasksList,
+ tasksSummariesCreate,
+} from 'products/tasks/frontend/generated/api'
+import {
+ ChannelDTOApi,
+ PrStateEnumApi,
+ TaskActivityDTOApi,
+ TaskActivityReadMarkerApi,
+ TaskListItemApi,
+} from 'products/tasks/frontend/generated/api.schemas'
+import { pullRequestStates, sessionIdsWithPullRequests } from 'products/tasks/frontend/spaces/taskPullRequests'
import {
DEFAULT_RECENT_FILTERS,
@@ -31,11 +46,23 @@ import {
groupRecentItems,
sortRecentItems,
} from './todayRecentOrder'
-import { TodayWorkItem, buildRecentItems, sessionItem } from './todayWorkItems'
+import {
+ TodayWorkItem,
+ buildRecentItems,
+ sessionItem,
+ sessionReadRequest,
+ setActivityUnread,
+ unreadSessionIds,
+ unreadSpaceIds,
+} from './todayWorkItems'
const PINNED_SESSION_LIMIT = 20
const RECENT_SESSION_LIMIT = 30
const RECENT_ITEM_LIMIT = 30
+// One page of the requester's newest activity. Unread state older than this does not show on the rail.
+const UNREAD_ACTIVITY_LIMIT = 200
+// The sidebar and a space scene both refresh on mount, so collapse their requests into one.
+const UNREAD_ACTIVITY_DEBOUNCE_MS = 100
export type TodayWorkSectionId = 'pinned' | 'recent' | 'spaces'
@@ -97,6 +124,7 @@ export interface todaySpacesLogicValues {
pinnedItems: TodayWorkItem[]
pinnedTasks: TaskListItemApi[]
pinnedTasksLoading: boolean
+ pullRequestStates: Record<string, PrStateEnumApi>
recentFilters: TodayRecentFilters
recentFiltersActive: boolean
recentGrouping: TodayRecentGrouping
@@ -117,11 +145,36 @@ export interface todaySpacesLogicValues {
spaces: ChannelDTOApi[]
spacesLoading: boolean
spacesUnavailable: boolean
+ taskActivity: TaskActivityDTOApi[]
+ taskActivityLoading: boolean
+ unreadSessionIds: Set<string>
+ unreadSpaceIds: Set<string>
visibleSpaces: ChannelDTOApi[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface todaySpacesLogicActions {
+ locationChanged: ({
+ method,
+ pathname,
+ search,
+ searchParams,
+ hash,
+ hashParams,
+ initial,
+ url,
+ routerState,
+ }: LocationChangedPayload) => {
+ hash: string
+ hashParams: Record<string, any>
+ initial: boolean
+ method: 'POP' | 'PUSH' | 'REPLACE'
+ pathname: string
+ routerState: Record<string, any>
+ search: string
+ searchParams: Record<string, any>
+ url: string
+ } // router
clearRecentFilters: () => {
value: true
}
@@ -146,6 +199,9 @@ export interface todaySpacesLogicActions {
pinnedTasks: TaskListItemApi[]
payload?: any
}
+ loadPullRequestStates: (sessionIds: string[]) => {
+ sessionIds: string[]
+ }
loadRecentTasks: () => any
loadRecentTasksFailure: (
error: string,
@@ -176,6 +232,31 @@ export interface todaySpacesLogicActions {
spaces: ChannelDTOApi[]
payload?: any
}
+ loadTaskActivity: (_: void) => void
+ loadTaskActivityFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadTaskActivitySuccess: (
+ taskActivity: TaskActivityDTOApi[],
+ payload?: void
+ ) => {
+ taskActivity: TaskActivityDTOApi[]
+ payload?: void
+ }
+ markSessionRead: (
+ marker: TaskActivityReadMarkerApi,
+ activityIds: string[]
+ ) => {
+ activityIds: string[]
+ marker: TaskActivityReadMarkerApi
+ }
+ markSessionReadFailed: (activityIds: string[]) => {
+ activityIds: string[]
+ }
resetSectionPair: (
upper: TodayWorkSectionId,
lower: TodayWorkSectionId
@@ -183,6 +264,9 @@ export interface todaySpacesLogicActions {
lower: TodayWorkSectionId
upper: TodayWorkSectionId
}
+ setPullRequestStates: (states: Record<string, PrStateEnumApi>) => {
+ states: Record<string, PrStateEnumApi>
+ }
setRecentFilters: (filters: TodayRecentFilters) => {
filters: TodayRecentFilters
}
@@ -245,6 +329,8 @@ export interface todaySpacesLogicMeta {
spaceNames: Record<string, string>
) => TodayRecentSection[]
recentLoading: (recentTasksLoading: boolean, conversationHistoryLoading: boolean) => boolean
+ unreadSessionIds: (taskActivity: TaskActivityDTOApi[]) => Set<string>
+ unreadSpaceIds: (taskActivity: TaskActivityDTOApi[]) => Set<string>
}
}
@@ -266,6 +352,7 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
maxGlobalLogic,
['conversationHistory', 'conversationHistoryLoading'],
],
+ actions: [router, ['locationChanged']],
})),
actions({
toggleSection: (sectionId: TodayWorkSectionId) => ({ sectionId }),
@@ -281,6 +368,10 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
toggleStar: (spaceId: string, starred: boolean) => ({ spaceId, starred }),
starFailed: (spaceId: string) => ({ spaceId }),
copySpaceLink: (spaceId: string) => ({ spaceId }),
+ markSessionRead: (marker: TaskActivityReadMarkerApi, activityIds: string[]) => ({ marker, activityIds }),
+ markSessionReadFailed: (activityIds: string[]) => ({ activityIds }),
+ loadPullRequestStates: (sessionIds: string[]) => ({ sessionIds }),
+ setPullRequestStates: (states: Record<string, PrStateEnumApi>) => ({ states }),
}),
loaders(({ values }) => ({
spaces: [
@@ -329,8 +420,27 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
},
},
],
+ taskActivity: [
+ [] as TaskActivityDTOApi[],
+ {
+ loadTaskActivity: async (_: void, breakpoint) => {
+ await breakpoint(UNREAD_ACTIVITY_DEBOUNCE_MS)
+ if (!values.currentTeamId) {
+ return []
+ }
+ const response = await taskActivityList(String(values.currentTeamId), {
+ limit: UNREAD_ACTIVITY_LIMIT,
+ })
+ return response.results
+ },
+ },
+ ],
})),
reducers({
+ pullRequestStates: [
+ {} as Record<string, PrStateEnumApi>,
+ { setPullRequestStates: (state, { states }) => ({ ...state, ...states }) },
+ ],
collapsedSections: [
[] as TodayWorkSectionId[],
{ persist: true },
@@ -385,6 +495,10 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
],
spacesUnavailable: [false, { loadSpaces: () => false, loadSpacesFailure: () => true }],
recentTasksUnavailable: [false, { loadRecentTasks: () => false, loadRecentTasksFailure: () => true }],
+ taskActivity: {
+ markSessionRead: (state, { activityIds }) => setActivityUnread(state, activityIds, false),
+ markSessionReadFailed: (state, { activityIds }) => setActivityUnread(state, activityIds, true),
+ },
}),
selectors({
sortedSpaces: [(s) => [s.spaces], (spaces: ChannelDTOApi[]): ChannelDTOApi[] => sortSpaces(spaces)],
@@ -457,8 +571,56 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
(recentTasksLoading: boolean, conversationHistoryLoading: boolean): boolean =>
recentTasksLoading || conversationHistoryLoading,
],
+ unreadSessionIds: [
+ (s) => [s.taskActivity],
+ (taskActivity: TaskActivityDTOApi[]): Set<string> => unreadSessionIds(taskActivity),
+ ],
+ unreadSpaceIds: [
+ (s) => [s.taskActivity],
+ (taskActivity: TaskActivityDTOApi[]): Set<string> => unreadSpaceIds(taskActivity),
+ ],
+ }),
+ listeners(({ actions, values }) => {
+ // Reading a session anywhere in the app clears it, so the rail follows the open session rather than clicks.
+ const markOpenSessionRead = (): void => {
+ const { location, searchParams } = router.values
+ const sessionId = location.pathname.endsWith('/ai') ? searchParams.task : null
+ const request = typeof sessionId === 'string' ? sessionReadRequest(values.taskActivity, sessionId) : null
+ if (request) {
+ actions.markSessionRead(request.marker, request.activityIds)
+ }
+ }
+ return {
+ locationChanged: markOpenSessionRead,
+ loadTaskActivitySuccess: markOpenSessionRead,
+ loadRecentTasks: () => actions.loadTaskActivity(),
+ markSessionRead: async ({ marker, activityIds }) => {
+ try {
+ await taskActivityMarkReadCreate(String(values.currentTeamId), { activities: [marker] })
+ } catch {
+ actions.markSessionReadFailed(activityIds)
+ toast.error({ title: 'Couldn’t mark this session as read.' })
+ }
+ },
+ }
}),
listeners(({ actions, values }) => ({
+ loadPinnedTasksSuccess: ({ pinnedTasks }) =>
+ actions.loadPullRequestStates(sessionIdsWithPullRequests(pinnedTasks)),
+ loadRecentTasksSuccess: ({ recentTasks }) =>
+ actions.loadPullRequestStates(sessionIdsWithPullRequests(recentTasks)),
+ // One batched lookup per list.
+ loadPullRequestStates: async ({ sessionIds }) => {
+ if (!sessionIds.length || !values.currentTeamId) {
+ return
+ }
+ try {
+ const response = await tasksSummariesCreate(String(values.currentTeamId), { ids: sessionIds })
+ actions.setPullRequestStates(pullRequestStates(response.results))
+ } catch {
+ // A failed lookup only leaves the chips neutral, so it stays quiet.
+ }
+ },
toggleStar: async ({ spaceId, starred }) => {
try {
await taskChannelsStarCreate(String(values.currentTeamId), spaceId, { starred })
diff --git a/frontend/src/layout/today/todayWorkItems.ts b/frontend/src/layout/today/todayWorkItems.ts
index 8b2a2e70b0d9..e7199282098e 100644
--- a/frontend/src/layout/today/todayWorkItems.ts
+++ b/frontend/src/layout/today/todayWorkItems.ts
@@ -2,7 +2,11 @@ import { Dayjs, dayjs } from 'lib/dayjs'
import { ConversationDetail } from '~/types'
-import { TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'
+import {
+ TaskActivityDTOApi,
+ TaskActivityReadMarkerApi,
+ TaskListItemApi,
+} from 'products/tasks/frontend/generated/api.schemas'
import { TaskPullRequest, taskPullRequests } from 'products/tasks/frontend/spaces/taskPullRequests'
export type TodayWorkItemKind = 'session' | 'chat'
@@ -107,6 +111,58 @@ export function buildRecentItems(
.slice(0, limit)
}
+export interface TodaySessionReadRequest {
+ marker: TaskActivityReadMarkerApi
+ activityIds: string[]
+}
+
+// Comment notifications clear per comment, not per session, so only a session's own activity marks it unread.
+function unreadSessionActivity(activity: TaskActivityDTOApi[], sessionId?: string): TaskActivityDTOApi[] {
+ return activity.filter(
+ (row) => row.is_unread && !!row.task_id && !row.latest_comment_id && (!sessionId || row.task_id === sessionId)
+ )
+}
+
+export function unreadSessionIds(activity: TaskActivityDTOApi[]): Set<string> {
+ return new Set(unreadSessionActivity(activity).map((row) => row.task_id as string))
+}
+
+export function unreadSpaceIds(activity: TaskActivityDTOApi[]): Set<string> {
+ return new Set(unreadSessionActivity(activity).flatMap((row) => (row.channel_id ? [row.channel_id] : [])))
+}
+
+/**
+ * What to send to mark a session read, or null when it has nothing unread.
+ * `seen_before` is never earlier than the newest activity shown, so a client clock behind the server's still clears it.
+ */
+export function sessionReadRequest(
+ activity: TaskActivityDTOApi[],
+ sessionId: string,
+ now: Dayjs = dayjs()
+): TodaySessionReadRequest | null {
+ const rows = unreadSessionActivity(activity, sessionId)
+ if (!rows.length) {
+ return null
+ }
+ const seenBefore = rows.reduce(
+ (latest, row) => (dayjs(row.activity_at).isAfter(latest) ? dayjs(row.activity_at) : latest),
+ now
+ )
+ return {
+ marker: { task_id: sessionId, seen_before: seenBefore.toISOString() },
+ activityIds: rows.map((row) => row.id),
+ }
+}
+
+export function setActivityUnread(
+ activity: TaskActivityDTOApi[],
+ activityIds: string[],
+ isUnread: boolean
+): TaskActivityDTOApi[] {
+ const ids = new Set(activityIds)
+ return activity.map((row) => (ids.has(row.id) ? { ...row, is_unread: isUnread } : row))
+}
+
export function groupByDay(
items: TodayWorkItem[],
now: Dayjs = dayjs(),
diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
index 9f609d5eabb6..503034a7decf 100644
--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx
+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
@@ -206,6 +206,24 @@ const meta: Meta = {
: []
return [200, { results, count: results.length, next: null, previous: null }]
},
+ '/api/projects/:team_id/task_activity/': {
+ results: [
+ {
+ id: 'activity-task-2',
+ task_id: 'task-2',
+ task_title: 'Investigate the drop in trial starts',
+ channel_id: 'space-checkout',
+ channel_name: 'checkout',
+ activity_at: '2026-09-28T17:00:00Z',
+ activity_kind: 'completed',
+ snippet: '',
+ latest_comment_id: null,
+ is_unread: true,
+ },
+ ],
+ unread_count: 1,
+ next_before: null,
+ },
'/api/environments/:team_id/conversations/': { results: CONVERSATIONS, next: null },
'/api/environments/:team_id/file_system/': ({ request }) => {
const type = new URL(request.url).searchParams.get('type')
@@ -214,6 +232,22 @@ const meta: Meta = {
},
'/api/environments/:team_id/file_system/unfiled/': { results: [], count: 0 },
},
+ post: {
+ '/api/projects/:team_id/tasks/summaries/': {
+ count: 1,
+ next: null,
+ previous: null,
+ results: [
+ {
+ id: 'task-1',
+ latest_run: {
+ pr_url: 'https://github.com/example-org/webapp/pull/421',
+ pr_state: 'merged',
+ },
+ },
+ ],
+ },
+ },
}),
],
parameters: {
diff --git a/frontend/src/styles/quill-bridge.scss b/frontend/src/styles/quill-bridge.scss
index 3f8a66d437da..b08c088adc8a 100644
--- a/frontend/src/styles/quill-bridge.scss
+++ b/frontend/src/styles/quill-bridge.scss
@@ -184,6 +184,10 @@
color: var(--warning-foreground);
}
+[data-quill] .text-completed-foreground {
+ color: var(--completed-foreground);
+}
+
[data-quill] .text-accent-foreground {
color: var(--accent-foreground);
}
diff --git a/products/tasks/frontend/spaces/SpaceFeed.tsx b/products/tasks/frontend/spaces/SpaceFeed.tsx
index 9ea85dad4568..b2623555b016 100644
--- a/products/tasks/frontend/spaces/SpaceFeed.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeed.tsx
@@ -22,7 +22,7 @@ import { spaceSceneLogic } from './spaceSceneLogic'
export function SpaceFeed({ id }: { id: string }): JSX.Element {
const { feedGroups, sessionsById, sessionsLoading, sessionsUnavailable } = useValues(spaceSceneLogic({ id }))
const { loadSessions } = useActions(spaceSceneLogic({ id }))
- const { pinnedItems } = useValues(todaySpacesLogic)
+ const { pinnedItems, unreadSessionIds } = useValues(todaySpacesLogic)
const pinnedIds = new Set(pinnedItems.map((item) => item.id))
if (sessionsLoading && !feedGroups.length) {
@@ -77,7 +77,12 @@ export function SpaceFeed({ id }: { id: string }): JSX.Element {
</Text>
{group.items.map((item) =>
sessionsById[item.id] ? (
- <SpaceFeedCard key={item.id} task={sessionsById[item.id]} pinned={pinnedIds.has(item.id)} />
+ <SpaceFeedCard
+ key={item.id}
+ task={sessionsById[item.id]}
+ pinned={pinnedIds.has(item.id)}
+ unread={unreadSessionIds.has(item.id)}
+ />
) : null
)}
</Fragment>
diff --git a/products/tasks/frontend/spaces/SpaceFeedCard.tsx b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
index c27f3a52165d..1e268c667ee2 100644
--- a/products/tasks/frontend/spaces/SpaceFeedCard.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
@@ -14,6 +14,7 @@ import {
Tooltip,
TooltipContent,
TooltipTrigger,
+ cn,
} from '@posthog/quill'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
@@ -24,6 +25,7 @@ import { TodaySessionMenu } from '~/layout/today/TodaySessionMenu'
import { todaySessionMenuLogic } from '~/layout/today/todaySessionMenuLogic'
import { TodaySessionRenameInput } from '~/layout/today/TodaySessionRenameInput'
import { TodaySessionStatusIcon } from '~/layout/today/TodaySessionStatusIcon'
+import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
import { activeCloudRunId, analysisRunId, canHandOff, sessionItem, shortTimeAgo } from '~/layout/today/todayWorkItems'
import { TaskListItemApi } from '../generated/api.schemas'
@@ -35,13 +37,16 @@ import { pullRequestLabel, splitPullRequests } from './taskPullRequests'
interface SpaceFeedCardProps {
task: TaskListItemApi
pinned: boolean
+ unread: boolean
}
-export function SpaceFeedCard({ task, pinned }: SpaceFeedCardProps): JSX.Element {
+export function SpaceFeedCard({ task, pinned, unread }: SpaceFeedCardProps): JSX.Element {
const { renaming } = useValues(todaySessionMenuLogic)
const { user } = useValues(userLogic)
+ const { pullRequestStates } = useValues(todaySpacesLogic)
const item = sessionItem(task)
- const status = spaceFeedStatus(task.latest_run)
+ const [mainPullRequest] = item.pullRequests
+ const status = spaceFeedStatus(task.latest_run, mainPullRequest && pullRequestStates[mainPullRequest.url])
const pullRequests = splitPullRequests(item.pullRequests)
const preview = spaceFeedPreview('description_preview' in task ? task.description_preview : task.description)
const author = task.created_by
@@ -66,11 +71,22 @@ export function SpaceFeedCard({ task, pinned }: SpaceFeedCardProps): JSX.Element
<div className="flex min-w-0 flex-1 items-baseline gap-1.5">
<LinkPrimitive
to={urls.aiTask(task.id)}
- className="min-w-0 truncate font-medium text-foreground after:absolute after:inset-0 hover:underline"
+ className={cn(
+ 'min-w-0 truncate text-foreground after:absolute after:inset-0 hover:underline',
+ unread ? 'font-semibold' : 'font-medium'
+ )}
data-attr="today-space-feed-card"
>
{item.title || 'Untitled session'}
</LinkPrimitive>
+ {unread && (
+ <span
+ role="img"
+ aria-label="Unread"
+ className="size-1.5 shrink-0 self-center rounded-full bg-primary"
+ data-attr="today-unread-feed-dot"
+ />
+ )}
{item.timestamp && (
<Text render={<span />} size="xs" variant="muted" className="shrink-0" translate="no">
{`· ${shortTimeAgo(item.timestamp)}`}
@@ -115,6 +131,7 @@ export function SpaceFeedCard({ task, pinned }: SpaceFeedCardProps): JSX.Element
key={pullRequest.url}
pullRequest={pullRequest}
label={pullRequestLabel(pullRequest, task.repository)}
+ state={pullRequestStates[pullRequest.url]}
dataAttr="today-pr-chip-feed"
/>
))}
@@ -138,6 +155,7 @@ export function SpaceFeedCard({ task, pinned }: SpaceFeedCardProps): JSX.Element
key={pullRequest.url}
pullRequest={pullRequest}
label={pullRequestLabel(pullRequest, task.repository)}
+ state={pullRequestStates[pullRequest.url]}
dataAttr="today-pr-chip-feed"
/>
))}
diff --git a/products/tasks/frontend/spaces/TaskPullRequestChip.tsx b/products/tasks/frontend/spaces/TaskPullRequestChip.tsx
index 37756c21768c..23abef684108 100644
--- a/products/tasks/frontend/spaces/TaskPullRequestChip.tsx
+++ b/products/tasks/frontend/spaces/TaskPullRequestChip.tsx
@@ -1,36 +1,61 @@
import { IconPullRequest } from '@posthog/icons'
-import { Button, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
+import { Badge, Tooltip, TooltipContent, TooltipTrigger, cn } from '@posthog/quill'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
+import { PrStateEnumApi } from '../generated/api.schemas'
import { TaskPullRequest } from './taskPullRequests'
+// The icon carries the state, like PostHog Desktop: the chip itself stays neutral.
+const PR_STATES: Record<Exclude<PrStateEnumApi, 'unknown'>, { label: string; iconClassName: string }> = {
+ open: { label: 'Open', iconClassName: 'text-success-foreground' },
+ draft: { label: 'Draft', iconClassName: 'text-muted-foreground' },
+ merged: { label: 'Merged', iconClassName: 'text-completed-foreground' },
+ closed: { label: 'Closed', iconClassName: 'text-destructive-foreground' },
+}
+
interface TaskPullRequestChipProps {
pullRequest: TaskPullRequest
label: string
dataAttr: string
+ state?: PrStateEnumApi | null
+ /** `row` for the compact sidebar pill, `card` for the feed card chip. */
+ size?: 'row' | 'card'
}
-export function TaskPullRequestChip({ pullRequest, label, dataAttr }: TaskPullRequestChipProps): JSX.Element {
+export function TaskPullRequestChip({
+ pullRequest,
+ label,
+ dataAttr,
+ state,
+ size = 'card',
+}: TaskPullRequestChipProps): JSX.Element {
+ const known = state && state !== 'unknown' ? PR_STATES[state] : null
+ const name = `pull request ${pullRequest.repository}#${pullRequest.number}`
return (
<Tooltip>
<TooltipTrigger
render={
- <Button
- size="xs"
- variant="outline"
+ <Badge
render={<LinkPrimitive to={pullRequest.url} target="_blank" />}
- aria-label={`Open pull request ${pullRequest.repository}#${pullRequest.number} on GitHub`}
+ aria-label={
+ known ? `Open ${known.label.toLowerCase()} ${name} on GitHub` : `Open ${name} on GitHub`
+ }
data-attr={dataAttr}
- // Sits above the card's full-card link, so it stays clickable.
- className="relative max-w-full shrink-0 tabular-nums"
+ // `relative` lifts it above the feed card's full-card link, so it stays clickable.
+ className={cn(
+ 'relative max-w-full shrink-0 gap-1 border-border bg-fill-hover text-muted-foreground tabular-nums hover:bg-fill-selected hover:text-foreground',
+ size === 'row' ? 'rounded-sm px-1' : 'h-6 rounded-md px-2 text-xs'
+ )}
/>
}
>
- <IconPullRequest className="shrink-0" />
+ <IconPullRequest
+ className={cn('shrink-0', size === 'row' ? 'size-2.5' : 'size-3', known?.iconClassName)}
+ />
<span className="min-w-0 truncate">{label}</span>
</TooltipTrigger>
- <TooltipContent>{pullRequest.url}</TooltipContent>
+ <TooltipContent>{known ? `${known.label} · ${pullRequest.url}` : pullRequest.url}</TooltipContent>
</Tooltip>
)
}
diff --git a/products/tasks/frontend/spaces/spaceFeedStatus.test.ts b/products/tasks/frontend/spaces/spaceFeedStatus.test.ts
index 7bd28db7fa81..c2295297701b 100644
--- a/products/tasks/frontend/spaces/spaceFeedStatus.test.ts
+++ b/products/tasks/frontend/spaces/spaceFeedStatus.test.ts
@@ -28,4 +28,14 @@ describe('spaceFeedStatus', () => {
])('labels %s', (_, latestRun, label) => {
expect(spaceFeedStatus(latestRun)?.label ?? null).toEqual(label)
})
+
+ it.each([
+ ['merged', 'Merged'],
+ ['closed', 'Closed'],
+ ['draft', 'Draft PR'],
+ ['unknown', 'PR ready'],
+ ] as const)('labels a run whose pull request is %s', (prState, label) => {
+ const latestRun = run('completed', 'cloud', { pr_url: 'https://github.com/org/app/pull/1' })
+ expect(spaceFeedStatus(latestRun, prState)?.label).toEqual(label)
+ })
})
diff --git a/products/tasks/frontend/spaces/spaceFeedStatus.ts b/products/tasks/frontend/spaces/spaceFeedStatus.ts
index 0794f329dfe9..3c0494a8afdb 100644
--- a/products/tasks/frontend/spaces/spaceFeedStatus.ts
+++ b/products/tasks/frontend/spaces/spaceFeedStatus.ts
@@ -1,4 +1,4 @@
-import { TaskRunDetailDTOApi } from '../generated/api.schemas'
+import { PrStateEnumApi, TaskRunDetailDTOApi } from '../generated/api.schemas'
export type SpaceFeedStatusVariant = 'default' | 'info' | 'destructive' | 'success' | 'completed'
@@ -16,6 +16,14 @@ const RUN_STATUSES: Record<string, SpaceFeedStatus> = {
cancelled: { label: 'Cancelled', variant: 'default' },
}
+// Once a PR exists its GitHub state is the card's status, with PostHog Desktop's labels and colors.
+const PR_STATUSES: Record<Exclude<PrStateEnumApi, 'unknown'>, SpaceFeedStatus> = {
+ open: { label: 'PR ready', variant: 'info' },
+ draft: { label: 'Draft PR', variant: 'default' },
+ merged: { label: 'Merged', variant: 'default' },
+ closed: { label: 'Closed', variant: 'destructive' },
+}
+
const TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled'])
function hasPullRequest(output: TaskRunDetailDTOApi['output']): boolean {
@@ -26,13 +34,16 @@ function hasPullRequest(output: TaskRunDetailDTOApi['output']): boolean {
return typeof output.pr_url === 'string' || urls.some((url) => typeof url === 'string')
}
-export function spaceFeedStatus(run: TaskRunDetailDTOApi | null | undefined): SpaceFeedStatus | null {
+export function spaceFeedStatus(
+ run: TaskRunDetailDTOApi | null | undefined,
+ prState?: PrStateEnumApi | null
+): SpaceFeedStatus | null {
if (!run) {
return { label: 'Draft', variant: 'default' }
}
const stopped = run.status === 'failed' || run.status === 'cancelled'
if (!stopped && hasPullRequest(run.output)) {
- return { label: 'PR ready', variant: 'completed' }
+ return prState && prState !== 'unknown' ? PR_STATUSES[prState] : PR_STATUSES.open
}
if (run.environment !== 'cloud' && !TERMINAL_STATUSES.has(run.status)) {
return null
diff --git a/products/tasks/frontend/spaces/spaceSceneLogic.test.ts b/products/tasks/frontend/spaces/spaceSceneLogic.test.ts
index 1c3348da6765..fc23df3df43c 100644
--- a/products/tasks/frontend/spaces/spaceSceneLogic.test.ts
+++ b/products/tasks/frontend/spaces/spaceSceneLogic.test.ts
@@ -149,6 +149,92 @@ describe('spaceSceneLogic', () => {
expect(router.values.searchParams).toEqual({ task: 'task-new' })
})
+ it.each([
+ ['clears a session once it opens', 200, '2026-09-30T11:00:00.000Z', '2026-09-30T12:00:00.000Z', []],
+ [
+ 'clears activity stamped ahead of the local clock',
+ 200,
+ '2026-09-30T12:05:00.000Z',
+ '2026-09-30T12:05:00.000Z',
+ [],
+ ],
+ [
+ 'restores unread when marking read fails',
+ 500,
+ '2026-09-30T11:00:00.000Z',
+ '2026-09-30T12:00:00.000Z',
+ ['task-1'],
+ ],
+ ])('%s', async (_, status, activityAt, seenBefore, unreadAfter) => {
+ // Only the clock is faked, so kea listeners and the activity debounce still run on real timers.
+ jest.useFakeTimers({
+ now: new Date('2026-09-30T12:00:00.000Z'),
+ doNotFake: [
+ 'setTimeout',
+ 'clearTimeout',
+ 'setInterval',
+ 'clearInterval',
+ 'setImmediate',
+ 'queueMicrotask',
+ 'nextTick',
+ ],
+ })
+ const markReadBodies: unknown[] = []
+ useMocks({
+ get: {
+ '/api/projects/:team_id/task_activity/': {
+ unread_count: 2,
+ results: [
+ {
+ id: 'row-1',
+ task_id: 'task-1',
+ channel_id: 'space-a',
+ activity_at: activityAt,
+ is_unread: true,
+ },
+ {
+ id: 'row-2',
+ task_id: 'task-2',
+ channel_id: 'space-b',
+ activity_at: activityAt,
+ is_unread: false,
+ },
+ {
+ id: 'row-3',
+ task_id: 'task-3',
+ channel_id: 'space-c',
+ activity_at: activityAt,
+ latest_comment_id: 'comment-1',
+ is_unread: true,
+ },
+ ],
+ },
+ },
+ post: {
+ '/api/projects/:team_id/task_activity/mark_read/': async ({ request }) => {
+ markReadBodies.push(await request.json())
+ return [status, { marked_read: 1, unread_count: 1 }]
+ },
+ },
+ })
+ try {
+ const logic = spaceSceneLogic({ id: 'space-a' })
+ logic.mount()
+ await expectLogic(todaySpacesLogic).toDispatchActions(['loadTaskActivitySuccess'])
+ expect([...todaySpacesLogic.values.unreadSessionIds]).toEqual(['task-1'])
+ expect([...todaySpacesLogic.values.unreadSpaceIds]).toEqual(['space-a'])
+
+ router.actions.push(urls.aiTask('task-1'))
+ await expectLogic(todaySpacesLogic).toFinishAllListeners()
+
+ expect(markReadBodies).toEqual([{ activities: [{ task_id: 'task-1', seen_before: seenBefore }] }])
+ expect([...todaySpacesLogic.values.unreadSessionIds]).toEqual(unreadAfter)
+ expect([...todaySpacesLogic.values.unreadSpaceIds]).toEqual(unreadAfter.length ? ['space-a'] : [])
+ } finally {
+ jest.useRealTimers()
+ }
+ })
+
it('loads the members once the space turns private', async () => {
const logic = spaceSceneLogic({ id: 'space-a' })
logic.mount()
diff --git a/products/tasks/frontend/spaces/spaceSceneLogic.ts b/products/tasks/frontend/spaces/spaceSceneLogic.ts
index b65358506196..cbee363cde5c 100644
--- a/products/tasks/frontend/spaces/spaceSceneLogic.ts
+++ b/products/tasks/frontend/spaces/spaceSceneLogic.ts
@@ -26,6 +26,7 @@ import {
tasksList,
} from '../generated/api'
import { ChannelDTOApi, PatchedChannelUpdateApi, TaskListItemApi, TaskUserBasicInfoApi } from '../generated/api.schemas'
+import { sessionIdsWithPullRequests } from './taskPullRequests'
const SPACE_FEED_LIMIT = 50
@@ -88,6 +89,9 @@ export interface spaceSceneLogicActions {
sessionUpdated: (sessionId: string) => {
sessionId: string
} // todaySessionMenuLogic
+ loadPullRequestStates: (sessionIds: string[]) => {
+ sessionIds: string[]
+ } // todaySpacesLogic
loadSpaces: () => any // todaySpacesLogic
loadSpacesSuccess: (
spaces: ChannelDTOApi[],
@@ -96,6 +100,7 @@ export interface spaceSceneLogicActions {
payload?: any
spaces: ChannelDTOApi[]
} // todaySpacesLogic
+ loadTaskActivity: (_?: void | undefined) => void // todaySpacesLogic
deleteSpace: () => {
value: true
}
@@ -226,7 +231,12 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([
key((props) => props.id),
connect(() => ({
values: [teamLogic, ['currentTeam', 'currentTeamId']],
- actions: [todaySessionMenuLogic, ['sessionUpdated'], todaySpacesLogic, ['loadSpaces', 'loadSpacesSuccess']],
+ actions: [
+ todaySessionMenuLogic,
+ ['sessionUpdated'],
+ todaySpacesLogic,
+ ['loadSpaces', 'loadSpacesSuccess', 'loadTaskActivity', 'loadPullRequestStates'],
+ ],
})),
actions({
updateSpace: (patch: PatchedChannelUpdateApi) => ({ patch }),
@@ -393,6 +403,12 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([
],
}),
listeners(({ actions, props, values }) => ({
+ loadSessions: () => {
+ actions.loadTaskActivity()
+ },
+ loadSessionsSuccess: ({ sessions }) => {
+ actions.loadPullRequestStates(sessionIdsWithPullRequests(sessions))
+ },
sessionUpdated: () => {
actions.loadSessions()
},
diff --git a/products/tasks/frontend/spaces/taskPullRequests.test.ts b/products/tasks/frontend/spaces/taskPullRequests.test.ts
index 15277905687e..c3d1983f4345 100644
--- a/products/tasks/frontend/spaces/taskPullRequests.test.ts
+++ b/products/tasks/frontend/spaces/taskPullRequests.test.ts
@@ -1,5 +1,11 @@
-import { TaskRunDetailDTOApi } from '../generated/api.schemas'
-import { TaskPullRequest, pullRequestLabel, splitPullRequests, taskPullRequests } from './taskPullRequests'
+import { TaskRunDetailDTOApi, TaskSummaryDTOApi } from '../generated/api.schemas'
+import {
+ TaskPullRequest,
+ pullRequestLabel,
+ pullRequestStates,
+ splitPullRequests,
+ taskPullRequests,
+} from './taskPullRequests'
const pr = (repository: string, number: number): TaskPullRequest => ({
url: `https://github.com/${repository}/pull/${number}`,
@@ -50,4 +56,18 @@ describe('taskPullRequests', () => {
const split = splitPullRequests(prs(count))
expect([split.visible.length, split.overflow.length]).toEqual([visible, overflow])
})
+
+ // The chips look states up by URL, so a subpage URL from the run must land on the PR's own URL.
+ it('keys known states by the normalized PR URL and skips unknown ones', () => {
+ const summary = (id: string, pr_url: string | null, pr_state: string | null): TaskSummaryDTOApi =>
+ ({ id, latest_run: { pr_url, pr_state } }) as TaskSummaryDTOApi
+
+ expect(
+ pullRequestStates([
+ summary('a', 'https://github.com/org/app/pull/7/files', 'merged'),
+ summary('b', 'https://github.com/org/app/pull/8', 'unknown'),
+ summary('c', null, null),
+ ])
+ ).toEqual({ 'https://github.com/org/app/pull/7': 'merged' })
+ })
})
diff --git a/products/tasks/frontend/spaces/taskPullRequests.ts b/products/tasks/frontend/spaces/taskPullRequests.ts
index d6a4aed3ec72..6f5fa3c7faae 100644
--- a/products/tasks/frontend/spaces/taskPullRequests.ts
+++ b/products/tasks/frontend/spaces/taskPullRequests.ts
@@ -1,4 +1,4 @@
-import { TaskRunDetailDTOApi } from '../generated/api.schemas'
+import { PrStateEnumApi, TaskListItemApi, TaskRunDetailDTOApi, TaskSummaryDTOApi } from '../generated/api.schemas'
export interface TaskPullRequest {
url: string
@@ -64,3 +64,21 @@ export function pullRequestLabel(pullRequest: TaskPullRequest, taskRepository: s
const sameRepository = task === pullRequest.repository.toLowerCase() || task === repoName.toLowerCase()
return sameRepository ? `#${pullRequest.number}` : `${repoName}#${pullRequest.number}`
}
+
+/** Sessions whose latest run opened a pull request, the only ones the summaries endpoint can give a state for. */
+export function sessionIdsWithPullRequests(tasks: TaskListItemApi[]): string[] {
+ return tasks.filter((task) => taskPullRequests(task.latest_run?.output).length > 0).map((task) => task.id)
+}
+
+/** The known state of each run's main pull request, keyed by its normalized URL. */
+export function pullRequestStates(summaries: TaskSummaryDTOApi[]): Record<string, PrStateEnumApi> {
+ const states: Record<string, PrStateEnumApi> = {}
+ for (const summary of summaries) {
+ const run = summary.latest_run
+ const pullRequest = run?.pr_url ? parsePullRequestUrl(run.pr_url) : null
+ if (pullRequest && run?.pr_state && run.pr_state !== 'unknown') {
+ states[pullRequest.url] = run.pr_state
+ }
+ }
+ return states
+}