: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(canvas): show the viewer's own run and drop the context scratch pad (#96531)
Peter Kirkham70ee44929652
diff --git a/products/desktop/packages/core/src/canvas/canvasListService.test.ts b/products/desktop/packages/core/src/canvas/canvasListService.test.tsindex bfdbcdd932bb..934c05d40af4 100644--- a/products/desktop/packages/core/src/canvas/canvasListService.test.ts+++ b/products/desktop/packages/core/src/canvas/canvasListService.test.ts@@ -25,7 +25,6 @@ function canvas(description: "",componentMeta: null,templateId: "freeform",- context: "",generationTaskId: null,createdAt: 1,updatedAt: 1,diff --git a/products/desktop/packages/core/src/canvas/channelItems.test.ts b/products/desktop/packages/core/src/canvas/channelItems.test.tsindex 65a0fbbacd1a..fc8376f1f7d5 100644--- a/products/desktop/packages/core/src/canvas/channelItems.test.ts+++ b/products/desktop/packages/core/src/canvas/channelItems.test.ts@@ -39,7 +39,6 @@ function canvas(over: Partial<DashboardRecord> = {}): DashboardRecord {kind: "freeform" as const,description: "",templateId: "freeform",- context: "",createdAt: 0,updatedAt: 1_000,...over,diff --git a/products/desktop/packages/core/src/canvas/dashboardSchemas.ts b/products/desktop/packages/core/src/canvas/dashboardSchemas.tsindex e46a6fca4280..43c6bf4b6641 100644--- a/products/desktop/packages/core/src/canvas/dashboardSchemas.ts+++ b/products/desktop/packages/core/src/canvas/dashboardSchemas.ts@@ -33,8 +33,6 @@ export const dashboardRecordSchema = z.object({// For components: the head version's placement contract (size, configSchema).componentMeta: componentMetaSchema.nullish(),templateId: z.string().default("freeform"),- // The live author-written context (markdown) passed to the agent.- context: z.string().default(""),// Id of the task currently generating this canvas (freeform gen runs as a// dedicated task, like CONTEXT.md). null/absent = no generation in flight.generationTaskId: z.string().nullish(),@@ -61,6 +59,7 @@ export const canvasVersionSchema = z.object({prompt: z.string().nullish(),taskId: z.string().nullish(),createdBy: z.string().optional(),+ createdByUuid: z.string().optional(),createdAt: z.number(),});export type CanvasVersion = z.infer<typeof canvasVersionSchema>;@@ -140,13 +139,6 @@ export const promoteCanvasInput = z.object({expectedCurrentVersionId: z.string().nullable(),});-// Persist the author-written context (markdown) shown in the Context tab and-// passed to generation tasks.-export const saveContextInput = z.object({- id: z.string().min(1),- context: z.string(),-});-// Rename a canvas (its display title).export const renameDashboardInput = z.object({id: z.string().min(1),diff --git a/products/desktop/packages/core/src/canvas/dashboardsService.test.ts b/products/desktop/packages/core/src/canvas/dashboardsService.test.tsindex 34dbee30bc63..78b821b0f1f2 100644--- a/products/desktop/packages/core/src/canvas/dashboardsService.test.ts+++ b/products/desktop/packages/core/src/canvas/dashboardsService.test.ts@@ -9,7 +9,6 @@ function apiCanvas(overrides: Record<string, unknown> = {}) {name: "Revenue board",channel: "chan-1",template_id: "freeform",- context: "",generation_task_id: null,pinned_at: null,current_version_id: "v1",diff --git a/products/desktop/packages/core/src/canvas/dashboardsService.ts b/products/desktop/packages/core/src/canvas/dashboardsService.tsindex 54eb05e82f72..2c33187e3dc4 100644--- a/products/desktop/packages/core/src/canvas/dashboardsService.ts+++ b/products/desktop/packages/core/src/canvas/dashboardsService.ts@@ -43,7 +43,6 @@ interface ApiCanvas {component_meta?: unknown;channel: string;template_id: string;- context: string;generation_task_id: string | null;pinned_at: string | null;current_version_id: string | null;@@ -98,7 +97,6 @@ function toRecord(api: ApiCanvas): DashboardRecord {description: api.description ?? "",componentMeta: meta.success ? meta.data : null,templateId: api.template_id || FREEFORM_TEMPLATE_ID,- context: api.context ?? "",generationTaskId: api.generation_task_id,createdBy: creatorLabel(api.created_by),createdByUuid: api.created_by?.uuid,@@ -307,18 +305,6 @@ export class DashboardsService {return toRecord(api);}- // Persist the author-written context (markdown) passed to generation tasks.- saveContext(input: {- id: string;- context: string;- }): Promise<DashboardRecord> {- return this.patch(- input.id,- { context: input.context },- "save canvas context",- );- }-// Record (or clear, when taskId is null) the task currently generating this// canvas.setGenerationTask(input: {@@ -502,6 +488,7 @@ export class DashboardsService {prompt: row.prompt,taskId: row.task_id,createdBy: creatorLabel(row.created_by),+ createdByUuid: row.created_by?.uuid,createdAt: toEpoch(row.created_at) ?? 0,}));}diff --git a/products/desktop/packages/core/src/canvas/services.ts b/products/desktop/packages/core/src/canvas/services.tsindex 344c2f361991..fcdb8e88fd30 100644--- a/products/desktop/packages/core/src/canvas/services.ts+++ b/products/desktop/packages/core/src/canvas/services.ts@@ -70,7 +70,6 @@ export interface IDashboardsService {prompt?: string;expectedCurrentVersionId: string | null;}): Promise<CanvasLayoutResult>;- saveContext(input: { id: string; context: string }): Promise<DashboardRecord>;setGenerationTask(input: {id: string;taskId: string | null;diff --git a/products/desktop/packages/host-router/src/routers/dashboards.router.ts b/products/desktop/packages/host-router/src/routers/dashboards.router.tsindex 89b14b77cb9f..208dd8b35b41 100644--- a/products/desktop/packages/host-router/src/routers/dashboards.router.ts+++ b/products/desktop/packages/host-router/src/routers/dashboards.router.ts@@ -26,7 +26,6 @@ import {reportCanvasErrorInput,requestCanvasAgentInput,revertCanvasInput,- saveContextInput,setGenerationTaskInput,setPinnedInput,} from "@posthog/core/canvas/dashboardSchemas";@@ -162,14 +161,6 @@ export const dashboardsRouter = router({.mutation(({ ctx, input }) =>ctx.container.get<IDashboardsService>(DASHBOARDS_SERVICE).create(input),),- saveContext: publicProcedure- .input(saveContextInput)- .output(dashboardRecordSchema)- .mutation(({ ctx, input }) =>- ctx.container- .get<IDashboardsService>(DASHBOARDS_SERVICE)- .saveContext(input),- ),setGenerationTask: publicProcedure.input(setGenerationTaskInput).output(dashboardRecordSchema)diff --git a/products/desktop/packages/ui/src/features/canvas/components/CanvasesPane.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/CanvasesPane.test.tsxindex 0bcf11164d65..4a436fe4754d 100644--- a/products/desktop/packages/ui/src/features/canvas/components/CanvasesPane.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/CanvasesPane.test.tsx@@ -64,7 +64,6 @@ function canvas(id: string, name: string, updatedAt: number): DashboardRecord {kind: "freeform",description: "",templateId: "freeform",- context: "",createdAt: updatedAt,updatedAt,};diff --git a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsxindex fac2b20a3575..c0d63112b229 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.test.tsx@@ -6,11 +6,6 @@ import { describe, expect, it, vi } from "vitest";vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({useChannelsLayout: () => false,}));-vi.mock("@posthog/host-router/react", () => ({- useHostTRPC: () => ({- dashboards: { saveContext: { mutationKey: () => ["save-context"] } },- }),-}));vi.mock("@posthog/ui/shell/analytics", () => ({ track: vi.fn() }));vi.mock("@posthog/ui/features/canvas/hooks/useSelectedCanvasId", () => ({useSelectedCanvasId: () => useSelectedCanvasId(),diff --git a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsx b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsxindex b4fd1dafeb0b..668e57d6be8a 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ShellLayout.tsx@@ -8,7 +8,6 @@ import {TrashIcon,XIcon,} from "@phosphor-icons/react";-import { useHostTRPC } from "@posthog/host-router/react";import {AlertDialog,AlertDialogClose,@@ -68,7 +67,7 @@ import { useTasks } from "@posthog/ui/features/tasks/useTasks";import { toast } from "@posthog/ui/primitives/toast";import { track } from "@posthog/ui/shell/analytics";import { Flex } from "@radix-ui/themes";-import { useIsMutating, useQueryClient } from "@tanstack/react-query";+import { useQueryClient } from "@tanstack/react-query";import {Outlet,useNavigate,@@ -77,9 +76,8 @@ import {} from "@tanstack/react-router";import { type CSSProperties, type ReactNode, useState } from "react";-// Edit toggle + autosave status for a canvas. Source is server-versioned now —-// version browsing and revert live in the canvas view's own toolbar — so the-// only autosave surfaced here is the author-context buffer's saveContext.+// Edit toggle and options menu for a canvas. Source is server-versioned;+// version browsing and revert live in the canvas view's own toolbar.function FreeformEditControls({channelId,dashboardId,@@ -148,14 +146,6 @@ function FreeformEditControls({});};- // Any in-flight saveContext mutation (the side panel's context editor- // commits through it) drives the toolbar's autosave spinner.- const trpc = useHostTRPC();- const isSavingContext =- useIsMutating({- mutationKey: trpc.dashboards.saveContext.mutationKey(),- }) > 0;-const queryClient = useQueryClient();const remountFrame = useCanvasFrameStore((s) => s.remount);// Fully remount the mounted canvas iframe: drop the host-side read cache so@@ -190,13 +180,6 @@ function FreeformEditControls({/><TooltipContent side="bottom">Copy link to canvas</TooltipContent></Tooltip>- {editing && (- // Autosave status — a non-interactive button showing a spinner while a- // context save is in flight, "Saved" otherwise.- <Button variant="outline" size="sm" disabled loading={isSavingContext}>- Saved- </Button>- )}<DropdownMenu><DropdownMenuTriggerrender={diff --git a/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsxindex 5e316d375c6b..3d69c97d0ae8 100644--- a/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/SpaceHeaderRow.test.tsx@@ -8,7 +8,6 @@ vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({}));vi.mock("@posthog/host-router/react", () => ({useHostTRPC: () => ({- dashboards: { saveContext: { mutationKey: () => ["save-context"] } },channelTasks: {list: {queryOptions: () => ({ queryKey: ["ct"], queryFn: async () => [] }),diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsxindex 5cac7a134327..c91bf3f60556 100644--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.test.tsx@@ -29,9 +29,6 @@ vi.mock("@posthog/ui/features/sessions/components/EmbeddedSessionView", () => ({vi.mock("@posthog/ui/features/canvas/freeform/FreeformGenerateBar", () => ({FreeformGenerateBar: () => <div data-testid="canvas-composer" />,}));-vi.mock("@posthog/ui/features/canvas/freeform/ContextEditor", () => ({- CanvasContextEditor: () => null,-}));describe("CanvasSidePanel", () => {beforeEach(() => {@@ -87,7 +84,7 @@ describe("CanvasSidePanel", () => {if (interactive) {expect(screen.getByTestId("canvas-composer")).toBeInTheDocument();} else {- expect(screen.getByText("No active run")).toBeInTheDocument();+ expect(screen.getByText("No run yet")).toBeInTheDocument();}});});diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsxindex 67fab146637d..e632c18be91b 100644--- a/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx+++ b/products/desktop/packages/ui/src/features/canvas/freeform/CanvasSidePanel.tsx@@ -13,14 +13,12 @@ import {Tabs,TabsList,TabsTrigger,- Text,Tooltip,TooltipContent,TooltipTrigger,} from "@posthog/quill";import type { Task } from "@posthog/shared/domain-types";import { TaskCommentsList } from "@posthog/ui/features/canvas/components/TaskCommentsList";-import { CanvasContextEditor } from "@posthog/ui/features/canvas/freeform/ContextEditor";import { FreeformGenerateBar } from "@posthog/ui/features/canvas/freeform/FreeformGenerateBar";import { useThreadConversation } from "@posthog/ui/features/canvas/hooks/useThreadConversation";import { useCanvasChatPanelStore } from "@posthog/ui/features/canvas/stores/canvasChatPanelStore";@@ -31,11 +29,10 @@ import { Spin } from "@posthog/ui/primitives/Spinner";import { useQuery } from "@tanstack/react-query";import { type Ref, useEffect, useRef } from "react";-// The canvas's right-hand dock. While a generation/edit run is in flight it-// shows that run's live chat (steering/queue included); otherwise it shows the-// edit composer, which starts a new run (and so a new session) for the next-// change. Header carries a minimize control that collapses the panel to a thin-// rail (handled by the parent).+// The canvas's right-hand dock. It shows the chat of this person's run on the+// canvas (steering/queue included) when they have one; otherwise it shows the+// edit composer, which starts their first run. Header carries a minimize+// control that collapses the panel to a thin rail (handled by the parent).export function CanvasSidePanel({chatTaskId,commentTaskId,@@ -53,14 +50,13 @@ export function CanvasSidePanel({editorRef,onStarted,}: {- /** The run whose live chat the panel shows: the one in flight right now, or- * null once it finished. A finished run's chat is not shown again, so every- * visit starts from the composer instead of the session that built the- * canvas. */+ /** The run whose chat the panel shows: the current person's own run on this+ * canvas, or null when they have none. Another person's run never shows+ * here, even while it is in flight. */chatTaskId: string | null;commentTaskId: string | null;/** Whether the canvas is being edited. The composer is an edit affordance, so- * view mode shows an empty chat when no run is in flight. */+ * view mode shows an empty chat when this person has no run. */interactive?: boolean;onMinimize: () => void;dashboardId: string;@@ -144,15 +140,15 @@ export function CanvasSidePanel({<EmptyMedia variant="icon"><ChatCircleIcon size={24} /></EmptyMedia>- <EmptyTitle>No active run</EmptyTitle>+ <EmptyTitle>No run yet</EmptyTitle><EmptyDescription>- Select Edit to start a new agent run on this canvas. Each run- publishes a new version.+ Select Edit to start an agent run on this canvas. Its chat shows+ here.</EmptyDescription></EmptyHeader></Empty>) : (- <div className="flex h-full min-h-0 flex-col gap-3 p-3">+ <div className="p-3"><FreeformGenerateBarref={editorRef}sessionId={`canvas:${dashboardId}`}@@ -164,17 +160,6 @@ export function CanvasSidePanel({isEdit={isEdit}onStarted={onStarted}/>- {/* The author context (markdown): background the agent reads on- every generation. Edits against the saved record, autosaving- on blur. */}- <div className="flex min-h-0 flex-1 flex-col gap-1">- <Text size="xs" variant="muted" className="shrink-0">- Context: notes the agent reads on every generation- </Text>- <div className="min-h-0 flex-1 overflow-hidden rounded-md border">- <CanvasContextEditor dashboardId={dashboardId} />- </div>- </div></div>)}</div>diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/ContextEditor.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/ContextEditor.tsxdeleted file mode 100644index 691824e2477f..000000000000--- a/products/desktop/packages/ui/src/features/canvas/freeform/ContextEditor.tsx+++ /dev/null@@ -1,125 +0,0 @@-import { EditorView } from "@codemirror/view";-import {- useDashboard,- useDashboardMutations,-} from "@posthog/ui/features/canvas/hooks/useDashboards";-import { useEditorExtensions } from "@posthog/ui/features/code-editor/hooks/useEditorExtensions";-import { toast } from "@posthog/ui/primitives/toast";-import { useEffect, useRef, useState } from "react";--// The canvas side panel's markdown editor for the author-written context (the-// canvas record's `context`, passed to generation tasks). A self-contained-// CodeMirror instance (the shared CodeMirrorEditor is wired to the host-// workspace/context-menu, which the canvas panel must not touch), reusing the-// app's editor extensions + theme via useEditorExtensions. `context.md` drives-// markdown syntax highlighting.-const CONTEXT_FILE = "context.md";--/**- * The author-context editor for a canvas, bound to the saved record: shows the- * record's `context`, buffers edits locally while typing, and commits on blur- * through the `saveContext` mutation (which invalidates the record so every- * viewer converges on the saved text).- */-export function CanvasContextEditor({ dashboardId }: { dashboardId: string }) {- const { dashboard } = useDashboard(dashboardId);- const { saveContext } = useDashboardMutations();- const saved = dashboard?.context ?? "";-- // Local editing buffer; null = untouched (mirror the saved record). A- // touched buffer stays authoritative — a record poll landing mid-edit must- // not clobber unsaved typing — and resets only once the record catches up- // with the committed text, so a commit can't flash the stale value while the- // invalidated record refetches.- const [draft, setDraft] = useState<string | null>(null);- if (draft !== null && draft === saved) setDraft(null);-- const commit = () => {- if (draft === null || draft === saved) return;- saveContext(dashboardId, draft).catch((error: unknown) => {- // The buffer stays authoritative, so the text isn't lost — the next- // blur retries the save.- toast.error("Couldn't save canvas context", {- description: error instanceof Error ? error.message : String(error),- });- });- };-- return (- <ContextEditor- key={dashboardId}- value={draft ?? saved}- onChange={setDraft}- onCommit={commit}- />- );-}--function ContextEditor({- value,- onChange,- onCommit,-}: {- value: string;- /** Fires on every keystroke (live state). */- onChange: (next: string) => void;- /** Fires on blur — the moment to snapshot a version + autosave. */- onCommit: () => void;-}) {- const baseExtensions = useEditorExtensions(CONTEXT_FILE, false, false);- const containerRef = useRef<HTMLDivElement>(null);- const viewRef = useRef<EditorView | null>(null);- // Latest callbacks, read through a ref so the create-effect needn't depend on- // them (which would tear down and rebuild the editor on every parent render).- const cbRef = useRef({ onChange, onCommit });- cbRef.current = { onChange, onCommit };- // Latest value, so the create-effect seeds the right doc without listing- // `value` as a dep (that would recreate the editor on every keystroke).- const valueRef = useRef(value);- valueRef.current = value;-- // (Re)create the editor when the extension set changes (e.g. theme toggle).- useEffect(() => {- if (!containerRef.current) return;- const view = new EditorView({- doc: valueRef.current,- parent: containerRef.current,- extensions: [- ...baseExtensions,- EditorView.updateListener.of((u) => {- if (u.docChanged) cbRef.current.onChange(u.state.doc.toString());- }),- EditorView.domEventHandlers({- blur: () => {- cbRef.current.onCommit();- return false;- },- }),- EditorView.theme({- "&": { height: "100%" },- ".cm-scroller": { overflow: "auto" },- }),- ],- });- viewRef.current = view;- return () => {- view.destroy();- viewRef.current = null;- };- }, [baseExtensions]);-- // Sync EXTERNAL value changes (undo/redo, version switch, initial seed) into the- // editor without clobbering the caret while the user is typing locally.- useEffect(() => {- const view = viewRef.current;- if (!view) return;- const current = view.state.doc.toString();- if (current !== value) {- view.dispatch({- changes: { from: 0, to: current.length, insert: value },- });- }- }, [value]);-- return <div ref={containerRef} className="h-full w-full overflow-hidden" />;-}diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsxindex 27d0ba3aefc9..9aef2281ebb8 100644--- a/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx+++ b/products/desktop/packages/ui/src/features/canvas/freeform/FreeformCanvasView.tsx@@ -54,6 +54,8 @@ import {} from "@posthog/quill";import { CANVAS_COMPONENT_PATH, formatRelativeAge } from "@posthog/shared";import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";+import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";+import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";import {isCanvasGenerating,isCanvasGenerationRunning,@@ -107,6 +109,7 @@ import { CanvasGenerateHero } from "./CanvasGenerateHero";import { CanvasPermissionDialog } from "./CanvasPermissionDialog";import { CanvasSelectionCommentAction } from "./CanvasSelectionCommentAction";import { CanvasSidePanel } from "./CanvasSidePanel";+import { canvasChatTaskId } from "./canvasChatTask";import { canvasCommentTaskId } from "./canvasCommentTask";import { canvasRuntimeErrorAnalytics } from "./canvasRuntimeError";import { canvasSidePanelVisibility } from "./canvasSidePanelVisibility";@@ -195,6 +198,7 @@ export function FreeformCanvasView({const trpc = useHostTRPC();const queryClient = useQueryClient();+ const authenticatedClient = useOptionalAuthenticatedClient();// The generation-task association lives in the canvas record's meta. Poll it// while a task is running so the fresh head version + the cleared association@@ -251,12 +255,6 @@ export function FreeformCanvasView({latestRun: genTask?.latest_run,session: genSession,});- // The run whose live chat the panel shows: only one that is still in flight.- // The record keeps a finished run's id (comments hang off it), but its chat- // is not reopened, so every visit starts a fresh run from the composer.- const chatTaskId =- startedTaskId ?? (isGenerating && !genTaskLoading ? genTaskId : null);-// Poll the record while the session is alive so a just-published head version// appears (the publish lands while the prompt is still pending).useQuery(@@ -335,6 +333,17 @@ export function FreeformCanvasView({interactive ? dashboardId : undefined,);const commentTaskId = canvasCommentTaskId(genTaskId, versions);+ // The run whose chat the panel shows: this person's own run on the canvas,+ // found through the record's task or the versions they published. Another+ // person's run never shows, so each editor keeps their own conversation.+ const { data: currentUser } = useCurrentUser({ client: authenticatedClient });+ const chatTaskId = canvasChatTaskId({+ startedTaskId,+ generationTaskId: genTaskId,+ generationTaskCreatorUuid: genTask?.created_by?.uuid,+ versions,+ currentUserUuid: currentUser?.uuid,+ });// The browsed version is a draft preview when it matches a staged draft// rather than a published version. Drives the Draft label and Promote action.const browsingDraft = drafts.some(@@ -784,12 +793,12 @@ export function FreeformCanvasView({const [generatingPanelDismissed, setGeneratingPanelDismissed] =useState(false);useEffect(() => {- if (effectiveTaskId) setGeneratingPanelDismissed(false);- }, [effectiveTaskId]);+ if (chatTaskId) setGeneratingPanelDismissed(false);+ }, [chatTaskId]);const generatingPanelOpen =!embedded &&isGenerating &&- !!effectiveTaskId &&+ !!chatTaskId &&!pinnedArtifact &&!headCode &&!generatingPanelDismissed;@@ -829,9 +838,9 @@ export function FreeformCanvasView({would have nowhere to go, so surface it as a modal. When the panel isopen, the chat handles it. */}{interactive &&- effectiveTaskId &&+ chatTaskId &&((collapsed && !generatingPanelOpen) || waitingForHeroExit) && (- <CanvasPermissionDialog taskId={effectiveTaskId} />+ <CanvasPermissionDialog taskId={chatTaskId} />)}<Flexdirection="column"diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/canvasChatTask.test.ts b/products/desktop/packages/ui/src/features/canvas/freeform/canvasChatTask.test.tsnew file mode 100644index 000000000000..80dd63dc4b73--- /dev/null+++ b/products/desktop/packages/ui/src/features/canvas/freeform/canvasChatTask.test.ts@@ -0,0 +1,50 @@+import { describe, expect, it } from "vitest";+import { canvasChatTaskId } from "./canvasChatTask";++describe("canvasChatTaskId", () => {+ const versions = [+ { taskId: "task-b", createdByUuid: "user-b" },+ { taskId: "task-a", createdByUuid: "user-a" },+ { taskId: "task-a-old", createdByUuid: "user-a" },+ ];++ it.each([+ {+ name: "shows this person's newest run instead of the other person's live run",+ generationTaskId: "task-b",+ generationTaskCreatorUuid: "user-b",+ currentUserUuid: "user-a",+ expected: "task-a",+ },+ {+ name: "shows the live run when this person started it",+ generationTaskId: "task-a-live",+ generationTaskCreatorUuid: "user-a",+ currentUserUuid: "user-a",+ expected: "task-a-live",+ },+ {+ name: "shows nothing to a person with no run on the canvas",+ generationTaskId: "task-b",+ generationTaskCreatorUuid: "user-b",+ currentUserUuid: "user-c",+ expected: null,+ },+ ])("$name", ({ expected, ...args }) => {+ expect(canvasChatTaskId({ startedTaskId: null, versions, ...args })).toBe(+ expected,+ );+ });++ it("prefers the run just started here while the record catches up", () => {+ expect(+ canvasChatTaskId({+ startedTaskId: "task-new",+ generationTaskId: "task-b",+ generationTaskCreatorUuid: "user-b",+ versions,+ currentUserUuid: "user-a",+ }),+ ).toBe("task-new");+ });+});diff --git a/products/desktop/packages/ui/src/features/canvas/freeform/canvasChatTask.ts b/products/desktop/packages/ui/src/features/canvas/freeform/canvasChatTask.tsnew file mode 100644index 000000000000..0987908a7eba--- /dev/null+++ b/products/desktop/packages/ui/src/features/canvas/freeform/canvasChatTask.ts@@ -0,0 +1,29 @@+import type { CanvasVersion } from "@posthog/core/canvas/dashboardSchemas";++// The run whose chat the canvas side panel shows: the current person's own run+// on this canvas. Another person's run never shows, even while it is in flight,+// so a shared canvas gives every editor their own conversation.+export function canvasChatTaskId(args: {+ /** The run this person just started here, before the record caught up. */+ startedTaskId: string | null;+ /** The record's generation task and its creator (undefined while loading). */+ generationTaskId: string | null;+ generationTaskCreatorUuid: string | null | undefined;+ /** Published versions, newest first. */+ versions: Pick<CanvasVersion, "taskId" | "createdByUuid">[];+ currentUserUuid: string | null | undefined;+}): string | null {+ if (args.startedTaskId) return args.startedTaskId;+ if (!args.currentUserUuid) return null;+ if (+ args.generationTaskId &&+ args.generationTaskCreatorUuid === args.currentUserUuid+ ) {+ return args.generationTaskId;+ }+ const ownVersion = args.versions.find(+ (version) =>+ !!version.taskId && version.createdByUuid === args.currentUserUuid,+ );+ return ownVersion?.taskId ?? null;+}diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.ts b/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.tsindex 6f5eadc408bd..5f640b205435 100644--- a/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.ts+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useDashboards.ts@@ -149,9 +149,6 @@ export function useDashboardMutations() {const remove = useMutation(trpc.dashboards.delete.mutationOptions({ onSuccess: invalidate }),);- const saveContext = useMutation(- trpc.dashboards.saveContext.mutationOptions({ onSuccess: invalidate }),- );const revertToVersion = useMutation(trpc.dashboards.revertToVersion.mutationOptions({// A revert moves the head and queues a rebuild; refresh the reverted@@ -194,9 +191,6 @@ export function useDashboardMutations() {createDashboard: (channelId: string, name: string, templateId?: string) =>create.mutateAsync({ channelId, name, templateId }),deleteDashboard: (id: string) => remove.mutateAsync({ id }),- // Persist the author-written context (markdown) passed to generation tasks.- saveContext: (id: string, context: string) =>- saveContext.mutateAsync({ id, context }),// Move the canvas's head back to an existing version (and rebuild it).revertToVersion: (id: string,@@ -226,7 +220,6 @@ export function useDashboardMutations() {file.mutateAsync({ id, channelId }),isCreating: create.isPending,isDeleting: remove.isPending,- isSavingContext: saveContext.isPending,isReverting: revertToVersion.isPending,isPromoting: promoteDraft.isPending,};diff --git a/products/desktop/packages/ui/src/features/canvas/stores/freeformChatStore.ts b/products/desktop/packages/ui/src/features/canvas/stores/freeformChatStore.tsindex 91438d042875..bcbe08276bfe 100644--- a/products/desktop/packages/ui/src/features/canvas/stores/freeformChatStore.ts+++ b/products/desktop/packages/ui/src/features/canvas/stores/freeformChatStore.ts@@ -1,9 +1,8 @@import { create } from "zustand";-// Per-canvas VIEW state for a freeform canvas. Source code, version history,-// and the author context are server-versioned (dashboards.get / source /-// versions) and the rendered output is the published build's artifact — none of-// that lives here. This store owns only what the client browses or observes+// Per-canvas VIEW state for a freeform canvas. Source code and version history+// are server-versioned (dashboards.get / source / versions) and the rendered+// output is the published build's artifact — none of that lives here. This store owns only what the client browses or observes// locally: the sandbox's runtime-error signal, and which historical version (if// any) the user is browsing. Threads are tiny (two nullable strings), so they// simply accumulate for the app's lifetime — no eviction.