: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(tasks): show living documents in the artifacts tab (#110166)
Shy Alter198e9b0a9d59
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsxindex 5f5785cc5ee3..34b439c8a7ef 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx@@ -14,7 +14,10 @@ import { mswDecorator } from '~/mocks/browser'import TRENDS_LINE_INSIGHT from '~/mocks/fixtures/api/projects/team_id/insights/trendsLine.json'import type { MockSignature } from '~/mocks/utils'-import type { TaskRunArtifactResponseApi } from 'products/tasks/frontend/generated/api.schemas'+import type {+ TaskRunArtifactResponseApi,+ TaskRunLivingArtifactResponseApi,+} from 'products/tasks/frontend/generated/api.schemas'import { TaskRuntimeEnumApi } from 'products/tasks/frontend/generated/api.schemas'import { OriginProduct, Task, TaskRun, TaskRunEnvironment, TaskRunStatus } from '../../types/taskTypes'@@ -516,6 +519,75 @@ export const FlagOff: Story = {render: () => <StoryPage tab="conversation" />,}+function livingDocument(+ id: string,+ name: string,+ adapter: TaskRunLivingArtifactResponseApi['adapter'],+ versions: Record<string, unknown>[]+): TaskRunLivingArtifactResponseApi {+ return {+ id,+ task_id: TASK_ID,+ run_id: RUN_ID,+ team_id: 1,+ name,+ artifact_type: adapter === 'slack_file' ? 'spreadsheet' : 'document',+ adapter,+ status: 'active',+ location: { kind: adapter },+ metadata: {},+ current_version: versions.length,+ versions,+ created_at: '2026-09-28T17:58:00Z',+ updated_at: String(versions[versions.length - 1].created_at),+ }+}++const LIVING_DOCUMENTS = [+ livingDocument('doc-weekly-trials', 'Weekly trial report', 'slack_canvas', [+ {+ version: 1,+ content: REPORT_DRAFT_MARKDOWN,+ content_type: 'text/markdown',+ created_at: '2026-09-28T17:58:00Z',+ },+ {+ version: 2,+ content: REPORT_SECOND_DRAFT_MARKDOWN,+ content_type: 'text/markdown',+ created_at: '2026-09-28T18:05:00Z',+ },+ { version: 3, content: REPORT_MARKDOWN, content_type: 'text/markdown', created_at: '2026-09-28T18:21:00Z' },+ ]),+ livingDocument('doc-trial-sheet', 'trial-starts-by-week.xlsx', 'slack_file', [+ {+ version: 1,+ size: 9216,+ content_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',+ created_at: '2026-09-28T18:17:00Z',+ },+ ]),+]++function livingMocks(): ReturnType<typeof taskMocks> {+ const mocks = taskMocks([...ARTIFACTS, ...OBJECT_REFERENCES])+ return {+ get: {+ ...mocks.get,+ ...INSIGHT_MOCKS.get,+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/:run_id/living_artifacts/`]: {+ artifacts: LIVING_DOCUMENTS,+ },+ },+ post: { ...mocks.post, ...INSIGHT_MOCKS.post },+ }+}++export const LivingArtifact: Story = {+ parameters: { msw: { mocks: livingMocks() } },+ render: () => <StoryPage fileName="living-doc-weekly-trials" />,+}+export const ResumedTask: Story = {parameters: { msw: { mocks: taskMocks(ARTIFACTS, { resumed: true }) } },render: () => <StoryPage fileName={REPORT_FILE_NAME} />,diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsxindex 85b94eb4cd3a..3fddac40d616 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx@@ -97,6 +97,7 @@ import {isTextPreview,parseCsv,LIVE_OBJECT_KINDS,+ LIVING_ADAPTER_LABEL,postHogObjectRef,} from '../taskRunArtifacts'import { artifactDownloadUrl, taskRunArtifactsLogic } from '../taskRunArtifactsLogic'@@ -150,8 +151,11 @@ function ArtifactIcon({ artifact, className }: { artifact: RunArtifact; classNamreturn <KindIcon kind={artifactPreviewKind(artifact)} className={className} />}-/** Size for a file, the object kind for a cited PostHog object. */+/** Size for a file, the object kind for a cited PostHog object, where the agent sent a living document. */function artifactDetail(artifact: RunArtifact): string {+ if (artifact.living) {+ return LIVING_ADAPTER_LABEL[artifact.living.adapter] ?? 'Document'+ }const ref = postHogObjectRef(artifact)return ref ? objectKindLink(ref.objectKind, ref.objectId, '').kind.kindLabel : formatArtifactSize(artifact.size)}@@ -413,6 +417,20 @@ function ArtifactPreview({ taskId, mode }: { taskId: string; mode: PreviewMode }if (selectedKind === 'video') {return <VideoPreview taskId={taskId} name={selectedArtifact.name} />}+ if (selectedArtifact.living && selectedArtifact.living.text === null) {+ return (+ <Empty className="h-full">+ <EmptyHeader>+ <EmptyTitle>No preview for this document</EmptyTitle>+ <EmptyDescription>+ {selectedArtifact.living.adapter.startsWith('slack_')+ ? "PostHog can't show this version here. Open the Slack thread the agent replied in to see it."+ : "PostHog can't show this version here. Open it where the agent saved it."}+ </EmptyDescription>+ </EmptyHeader>+ </Empty>+ )+ }if (selectedKind === 'none') {return (<Empty className="h-full">@@ -485,6 +503,7 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {const { selectArtifact } = useActions(taskRunArtifactsLogic({ taskId }))// Cited PostHog objects sit under their own label, after the files.const objects = files.filter((file) => !!postHogObjectRef(file.latest))+ const livingDocuments = files.filter((file) => !!file.latest.living)const renderRow = (file: ArtifactFile): JSX.Element => {const selected = file.key === selectedFile?.keyreturn (@@ -519,7 +538,7 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {Files</Text><Text size="xs" variant="muted" render={<span />} className="tabular-nums">- {files.length - objects.length}+ {files.length - objects.length - livingDocuments.length}</Text></div><div@@ -527,7 +546,7 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {aria-label="Files"className="flex min-h-0 flex-1 flex-col gap-px overflow-y-auto p-1.5">- {files.filter((file) => !postHogObjectRef(file.latest)).map(renderRow)}+ {files.filter((file) => !postHogObjectRef(file.latest) && !file.latest.living).map(renderRow)}{objects.length > 0 && (<div role="group" aria-label="In PostHog" className="flex flex-col gap-px"><Text@@ -542,6 +561,20 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {{objects.map(renderRow)}</div>)}+ {livingDocuments.length > 0 && (+ <div role="group" aria-label="Living documents" className="flex flex-col gap-px">+ <Text+ size="xs"+ weight="medium"+ variant="muted"+ render={<span aria-hidden />}+ className="px-2 pt-3 pb-1"+ >+ Living documents+ </Text>+ {livingDocuments.map(renderRow)}+ </div>+ )}</div></aside>)@@ -567,7 +600,7 @@ function VersionSelect({ taskId, file }: { taskId: string; file: ArtifactFile })</SelectTrigger><SelectContent>{file.versions.map((version, index) => (- <SelectItem key={version.id} value={version.id ?? ''}>+ <SelectItem key={version.id} value={version.id ?? ''} className="pe-7"><span className="flex w-52 items-center gap-2"><span>{`Version ${total - index}`}</span>{index === 0 && <Badge variant="success">Latest</Badge>}@@ -776,7 +809,8 @@ function ArtifactToolbar({</IconAction></div><CopyLinkAction taskId={taskId} />- {kind !== 'reference' && (+ {/* No endpoint serves a living document's bytes, so it has no download. */}+ {kind !== 'reference' && !artifact.living && (<IconActionlabel={versioned ? 'Download this version' : 'Download'}href={downloadUrl ?? undefined}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.test.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.test.tsindex 95756a577257..53dab58f9b60 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.test.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.test.ts@@ -1,14 +1,41 @@-import type { TaskRunArtifactResponseApi } from 'products/tasks/frontend/generated/api.schemas'+import type {+ TaskRunArtifactResponseApi,+ TaskRunLivingArtifactResponseApi,+} from 'products/tasks/frontend/generated/api.schemas'import {RunArtifact,artifactPreviewKind,collectRunArtifacts,groupArtifactVersions,+ livingArtifactFiles,+ livingArtifactsFromResponse,parseCsv,visibleRunArtifacts,} from './taskRunArtifacts'+function livingArtifact(overrides: Partial<TaskRunLivingArtifactResponseApi>): TaskRunLivingArtifactResponseApi {+ return {+ id: 'doc-1',+ task_id: 'task-1',+ run_id: 'run-1',+ team_id: 1,+ name: 'report.md',+ artifact_type: 'document',+ adapter: 'slack_canvas',+ status: 'active',+ location: {},+ metadata: {},+ current_version: 2,+ versions: [+ { version: 1, run_id: 'run-1', content: '# Draft', created_at: '2026-09-30T17:00:00Z' },+ { version: 2, run_id: 'run-2', content: '# Final', created_at: '2026-09-30T18:00:00Z' },+ ],+ updated_at: '2026-09-30T18:00:00Z',+ ...overrides,+ }+}+function artifact(overrides: Partial<TaskRunArtifactResponseApi>): TaskRunArtifactResponseApi {return {id: 'a1',@@ -164,4 +191,38 @@ describe('taskRunArtifacts', () => {}))).toEqual(expected)})++ const slackFile = livingArtifact({+ id: 'doc-2',+ name: 'weeks.xlsx',+ adapter: 'slack_file',+ current_version: 1,+ versions: [{ version: 1, run_id: 'run-1', size: 2048, created_at: '2026-09-30T16:00:00Z' }],+ })+ test.each([+ ['the envelope the endpoint returns', { artifacts: [livingArtifact({}), slackFile] }],+ [+ 'the array of envelopes the generated client types, with a repeated id',+ [{ artifacts: [livingArtifact({})] }, { artifacts: [livingArtifact({}), slackFile] }],+ ],+ ])('living documents read from %s', (_, response) => {+ const files = livingArtifactFiles(livingArtifactsFromResponse(response))+ // An uploaded `report.md` keys by its name, so a living document with that name must not take the same key.+ expect(+ files.map((file) => ({+ key: file.key,+ versions: file.versions.map(({ id, living }) => ({ id, text: living?.text })),+ }))+ ).toEqual([+ {+ key: 'living-doc-1',+ versions: [+ { id: 'living-doc-1-v2', text: '# Final' },+ { id: 'living-doc-1-v1', text: '# Draft' },+ ],+ },+ { key: 'living-doc-2', versions: [{ id: 'living-doc-2-v1', text: null }] },+ ])+ expect(artifactPreviewKind(files[1].latest)).toBe('none')+ })})diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.tsindex 55c587e412f6..7fd59d19dd49 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts@@ -1,4 +1,8 @@-import type { TaskRunArtifactResponseApi } from 'products/tasks/frontend/generated/api.schemas'+import type {+ TaskRunArtifactResponseApi,+ TaskRunLivingArtifactResponseApi,+ TaskRunLivingArtifactsResponseApi,+} from 'products/tasks/frontend/generated/api.schemas'export type TaskRunTab = 'conversation' | 'artifacts'@@ -42,7 +46,12 @@ export function postHogObjectRef(artifact: TaskRunArtifactResponseApi): PostHogOreturn { objectKind: metadata.object_kind, objectId: metadata.object_id }}-export function artifactPreviewKind(artifact: TaskRunArtifactResponseApi): ArtifactPreviewKind {+export function artifactPreviewKind(+ artifact: TaskRunArtifactResponseApi & { living?: LivingVersion }+): ArtifactPreviewKind {+ if (artifact.living && artifact.living.text === null) {+ return 'none'+ }if (artifact.type === 'reference') {return 'reference'}@@ -143,6 +152,8 @@ export function parseCsv(text: string): string[][] {/** A file the agent wrote, with the run that holds it. Downloads must name that run, not the open one. */export interface RunArtifact extends TaskRunArtifactResponseApi {runId: string+ /** Set on a version of a living document. Absent for uploaded files and cited objects. */+ living?: LivingVersion}interface RunWithArtifacts {@@ -207,3 +218,86 @@ export function groupArtifactVersions(artifacts: readonly RunArtifact[]): Artifab.latest.uploaded_at.localeCompare(a.latest.uploaded_at))}++/** One version of a document the agent edits in place, such as a Slack canvas. */+export interface LivingVersion {+ /** The living artifact id. All versions of one document share it. */+ artifactId: string+ adapter: string+ /** `null` when PostHog keeps no text for the version, for example a file sent to Slack. */+ text: string | null+}++export const LIVING_ADAPTER_LABEL: Record<string, string> = {+ slack_message: 'Slack message',+ slack_canvas: 'Slack canvas',+ slack_file: 'Slack file',+ document_connector: 'Document',+ github_pr: 'Pull request',+}++/**+ * The generated client types the list response as an array of envelopes, but the endpoint returns one+ * envelope. Both shapes are read so the list keeps working after the schema is fixed.+ */+export function livingArtifactsFromResponse(+ response: TaskRunLivingArtifactsResponseApi | readonly TaskRunLivingArtifactsResponseApi[] | null | undefined+): TaskRunLivingArtifactResponseApi[] {+ const envelopes: readonly TaskRunLivingArtifactsResponseApi[] = Array.isArray(response)+ ? response+ : response+ ? [response as TaskRunLivingArtifactsResponseApi]+ : []+ const byId = new Map<string, TaskRunLivingArtifactResponseApi>()+ for (const artifact of envelopes.flatMap((envelope) => envelope.artifacts ?? [])) {+ if (artifact.id && !byId.has(artifact.id)) {+ byId.set(artifact.id, artifact)+ }+ }+ return [...byId.values()]+}++function stringField(record: Record<string, unknown>, field: string): string | undefined {+ const value = record[field]+ return typeof value === 'string' && value ? value : undefined+}++/** The registry types each version record as an open object, so every field is checked before use. */+function livingVersionArtifact(+ artifact: TaskRunLivingArtifactResponseApi,+ record: Record<string, unknown>,+ versionNumber: number+): RunArtifact {+ return {+ // The prefix keeps a document apart from an uploaded file or a cited object in `?artifact=`.+ id: `living-${artifact.id}-v${versionNumber}`,+ name: artifact.name,+ type: 'living',+ content_type: stringField(record, 'content_type'),+ size: typeof record.size === 'number' ? record.size : undefined,+ uploaded_at: stringField(record, 'created_at') ?? artifact.updated_at ?? artifact.created_at ?? '',+ runId: stringField(record, 'run_id') ?? artifact.run_id,+ living: {+ artifactId: artifact.id,+ adapter: artifact.adapter,+ text: typeof record.content === 'string' ? record.content : null,+ },+ }+}++/** One entry per living document, with its versions newest first. */+export function livingArtifactFiles(artifacts: readonly TaskRunLivingArtifactResponseApi[]): ArtifactFile[] {+ return artifacts+ .map((artifact) => {+ const records = artifact.versions.length > 0 ? artifact.versions : [{}]+ const versions = records+ .map((record, index) => ({+ record,+ number: typeof record.version === 'number' ? record.version : index + 1,+ }))+ .sort((a, b) => b.number - a.number)+ .map(({ record, number }) => livingVersionArtifact(artifact, record, number))+ return { key: `living-${artifact.id}`, name: artifact.name, versions, latest: versions[0] }+ })+ .sort((a, b) => b.latest.uploaded_at.localeCompare(a.latest.uploaded_at))+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.tsindex c06aafa2b7ea..1041c41fd2ad 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts@@ -23,9 +23,13 @@ import { urls } from 'scenes/urls'import {getTasksRunsArtifactsDownloadCreateUrl,getTasksRunsArtifactsDownloadRetrieveUrl,+ tasksRunsLivingArtifactsList,tasksRunsRetrieve,} from 'products/tasks/frontend/generated/api'-import type { TaskRunDetailDTOApi } from 'products/tasks/frontend/generated/api.schemas'+import type {+ TaskRunDetailDTOApi,+ TaskRunLivingArtifactResponseApi,+} from 'products/tasks/frontend/generated/api.schemas'import type { TaskRun } from '../../types/taskTypes'import { taskDetailSceneLogic } from './taskDetailSceneLogic'@@ -38,6 +42,8 @@ import {collectRunArtifacts,groupArtifactVersions,isTextPreview,+ livingArtifactFiles,+ livingArtifactsFromResponse,} from './taskRunArtifacts'export interface TaskRunArtifactsLogicProps {@@ -71,6 +77,9 @@ export interface taskRunArtifactsLogicValues {chainRuns: TaskRunDetailDTOApi[]chainRunsLoading: booleanfiles: ArtifactFile[]+ livingArtifacts: TaskRunLivingArtifactResponseApi[]+ livingArtifactsLoading: boolean+ livingFiles: ArtifactFile[]mediaById: Record<string, ArtifactMedia>selectedArtifact: RunArtifact | nullselectedFile: ArtifactFile | null@@ -146,6 +155,21 @@ export interface taskRunArtifactsLogicActions {chainRuns: TaskRunDetailDTOApi[]payload?: string[]}+ loadLivingArtifacts: (runId: string) => string+ loadLivingArtifactsFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadLivingArtifactsSuccess: (+ livingArtifacts: TaskRunLivingArtifactResponseApi[],+ payload?: string+ ) => {+ livingArtifacts: TaskRunLivingArtifactResponseApi[]+ payload?: string+ }openFromUrl: (fileKey: string,versionId: string | null@@ -178,7 +202,8 @@ export interface taskRunArtifactsLogicMeta {key: string__keaTypeGenInternalSelectorTypes: {artifacts: (selectedRun: TaskRunDetailDTOApi | null, chainRuns: TaskRunDetailDTOApi[]) => RunArtifact[]- files: (artifacts: RunArtifact[]) => ArtifactFile[]+ livingFiles: (livingArtifacts: TaskRunLivingArtifactResponseApi[]) => ArtifactFile[]+ files: (artifacts: RunArtifact[], livingFiles: ArtifactFile[]) => ArtifactFile[]selectedIndex: (files: ArtifactFile[], selectedFileKey: string | null) => numberselectedFile: (files: ArtifactFile[], selectedIndex: number) => ArtifactFile | nullselectedVersionIndex: (selectedFile: ArtifactFile | null, selectedVersionId: string | null) => number@@ -276,6 +301,24 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([},},],+ livingArtifacts: [+ [] as TaskRunLivingArtifactResponseApi[],+ {+ // The registry is task-scoped, so any run of the task lists the documents of the whole chain.+ loadLivingArtifacts: async (runId: string): Promise<TaskRunLivingArtifactResponseApi[]> => {+ if (values.currentProjectId === null) {+ return values.livingArtifacts+ }+ try {+ return livingArtifactsFromResponse(+ await tasksRunsLivingArtifactsList(String(values.currentProjectId), props.taskId, runId)+ )+ } catch {+ return values.livingArtifacts+ }+ },+ },+ ],artifactMedia: [null as ArtifactMedia | null,{@@ -380,7 +423,19 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([(selectedRun: TaskRunDetailDTOApi | null, chainRuns: TaskRunDetailDTOApi[]): RunArtifact[] =>collectRunArtifacts([selectedRun, ...chainRuns]),],- files: [(s) => [s.artifacts], (artifacts: RunArtifact[]): ArtifactFile[] => groupArtifactVersions(artifacts)],+ livingFiles: [+ (s) => [s.livingArtifacts],+ (livingArtifacts: TaskRunLivingArtifactResponseApi[]): ArtifactFile[] =>+ livingArtifactFiles(livingArtifacts),+ ],+ // Living documents come last, after the files and cited objects, so the list and the stepper share one order.+ files: [+ (s) => [s.artifacts, s.livingFiles],+ (artifacts: RunArtifact[], livingFiles: ArtifactFile[]): ArtifactFile[] => [+ ...groupArtifactVersions(artifacts),+ ...livingFiles,+ ],+ ],selectedIndex: [(s) => [s.files, s.selectedFileKey],(files: ArtifactFile[], selectedFileKey: string | null): number =>@@ -449,8 +504,13 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([],selectedText: [(s) => [s.selectedArtifact, s.textsById],- (selectedArtifact: RunArtifact | null, textsById: Record<string, ArtifactText>): ArtifactText | null =>- (selectedArtifact?.id && textsById[selectedArtifact.id]) || null,+ (selectedArtifact: RunArtifact | null, textsById: Record<string, ArtifactText>): ArtifactText | null => {+ // A living document version carries its text in the registry, so it needs no download.+ if (selectedArtifact?.id && typeof selectedArtifact.living?.text === 'string') {+ return { artifactId: selectedArtifact.id, text: selectedArtifact.living.text, error: null }+ }+ return (selectedArtifact?.id && textsById[selectedArtifact.id]) || null+ },],}),listeners(({ actions, values }) => {@@ -476,6 +536,7 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([kind: values.selectedKind,content_type: artifact.content_type ?? null,version_count: values.selectedFile?.versions.length ?? 1,+ living_adapter: artifact.living?.adapter ?? null,})}return {@@ -496,6 +557,11 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([})},ensureSelectedText: loadSelectedText,+ loadChainRuns: (runIds) => {+ if (runIds[0]) {+ actions.loadLivingArtifacts(runIds[0])+ }+ },loadTaskRunsSuccess: ({ runs }) => {actions.loadChainRuns(runs.map((run) => run.id))},