Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): preserve timeline message chronology (#83430)

Shy Alter1232c9219a1e
diff --git a/products/desktop/packages/core/src/sessions/sessionService.ts b/products/desktop/packages/core/src/sessions/sessionService.ts
index 11e55dd4b6a8..8d694aff5f15 100644
--- a/products/desktop/packages/core/src/sessions/sessionService.ts
+++ b/products/desktop/packages/core/src/sessions/sessionService.ts
@@ -6462,7 +6462,7 @@ export class SessionService {
type: "user_message",
content: seedContent,
timestamp: Date.now(),
- ...(isResumeRun ? { pinToTop: false } : {}),
+ pinToTop: !isResumeRun,
});
}
if (hasCurrentRunUserPrompt || isTerminalRun) {
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.test.tsx
index 2d91471e2066..2194ec975520 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.test.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.test.tsx
@@ -9,6 +9,7 @@ vi.mock("@posthog/ui/features/git-interaction/usePrDetails", () => ({
}),
}));
+import type { ConversationItem } from "@posthog/ui/features/sessions/components/buildConversationItems";
import { useThreadNavigationStore } from "@posthog/ui/features/sessions/threadNavigationStore";
import { ActivityTimeline } from "./ActivityTimeline";
@@ -37,7 +38,10 @@ const conversationItems = [
},
];
-function renderTimeline(canOpenInPlace?: boolean, items = conversationItems) {
+function renderTimeline(
+ canOpenInPlace?: boolean,
+ items: ConversationItem[] = conversationItems,
+) {
return render(
<ActivityTimeline
task={task}
@@ -80,6 +84,31 @@ describe("ActivityTimeline", () => {
expect(screen.getByText(/and more detail/)).toBeInTheDocument();
});
+ it("places a delayed initial placeholder at task creation", () => {
+ renderTimeline(false, [
+ {
+ type: "user_message",
+ id: "initial-optimistic",
+ content: "initial request",
+ timestamp: Date.parse("2026-07-17T12:00:00Z"),
+ pinToTop: true,
+ },
+ {
+ type: "user_message",
+ id: "later-message",
+ content: "later follow-up",
+ timestamp: Date.parse("2026-07-17T10:00:00Z"),
+ },
+ ]);
+
+ expect(
+ screen.getAllByRole("button").map((button) => button.textContent),
+ ).toEqual([
+ expect.stringContaining("initial request"),
+ expect.stringContaining("later follow-up"),
+ ]);
+ });
+
it("renders structured references natively in conversation previews", () => {
renderTimeline(false, [
{
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx
index 237f47c2eac3..e3da827a9134 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityTimeline.tsx
@@ -181,49 +181,51 @@ export function ActivityTimeline({
return byId;
}, [timeline]);
- const rows = useMemo(
- () =>
- buildActivityTimeline({
- task: {
- id: task.id,
- createdAt: task.created_at,
- updatedAt: task.updated_at,
- latestRunId: task.latest_run?.id ?? null,
- latestRunStatus: task.latest_run?.status ?? null,
- latestRunPrUrl:
- typeof task.latest_run?.output?.pr_url === "string"
- ? task.latest_run.output.pr_url
- : null,
- },
- messages,
- commentThreads: commentThreads.map((thread) => ({
- id: thread.id,
- lastActivityAt: thread.last_activity_at,
- mentionedUserIds: thread.mentioned_user_ids ?? [],
- resolved: thread.resolved,
- stateEvent: thread.state_event
- ? {
- state: thread.state_event.state,
- createdAt: thread.state_event.created_at,
- }
+ const rows = useMemo(() => {
+ const taskCreatedTimestamp = Date.parse(task.created_at);
+ return buildActivityTimeline({
+ task: {
+ id: task.id,
+ createdAt: task.created_at,
+ updatedAt: task.updated_at,
+ latestRunId: task.latest_run?.id ?? null,
+ latestRunStatus: task.latest_run?.status ?? null,
+ latestRunPrUrl:
+ typeof task.latest_run?.output?.pr_url === "string"
+ ? task.latest_run.output.pr_url
: null,
- })),
- userMessages: conversationItems.reduce<UserMessageLike[]>(
- (items, item) => {
- if (item.type === "user_message") {
- items.push({
- id: item.id,
- content: item.content,
- timestamp: item.timestamp,
- });
+ },
+ messages,
+ commentThreads: commentThreads.map((thread) => ({
+ id: thread.id,
+ lastActivityAt: thread.last_activity_at,
+ mentionedUserIds: thread.mentioned_user_ids ?? [],
+ resolved: thread.resolved,
+ stateEvent: thread.state_event
+ ? {
+ state: thread.state_event.state,
+ createdAt: thread.state_event.created_at,
}
- return items;
- },
- [],
- ),
- }),
- [task, messages, commentThreads, conversationItems],
- );
+ : null,
+ })),
+ userMessages: conversationItems.reduce<UserMessageLike[]>(
+ (items, item) => {
+ if (item.type === "user_message") {
+ items.push({
+ id: item.id,
+ content: item.content,
+ timestamp:
+ item.pinToTop === true && Number.isFinite(taskCreatedTimestamp)
+ ? taskCreatedTimestamp
+ : item.timestamp,
+ });
+ }
+ return items;
+ },
+ [],
+ ),
+ });
+ }, [task, messages, commentThreads, conversationItems]);
// Numbering a run and deciding whether to number it at all have to come from the same
// population, or a task with three runs and one row labels that row "run 1".
diff --git a/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.test.ts b/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.test.ts
index 5ffaa89b376e..fe98b2d706b3 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.test.ts
@@ -24,8 +24,9 @@ function userMessage(
id: string,
content: string,
pinToTop?: boolean,
+ timestamp = 0,
): Extract<ConversationItem, { type: "user_message" }> {
- return { type: "user_message", id, content, timestamp: 0, pinToTop };
+ return { type: "user_message", id, content, timestamp, pinToTop };
}
describe("mergeConversationItems", () => {
@@ -56,16 +57,21 @@ describe("mergeConversationItems", () => {
expect(result.map((i) => i.id)).toEqual(["opt", "setup"]);
});
- it("cloud: filters echoed user_message that matches optimistic content", () => {
+ it("cloud: stitches an echoed user_message into its optimistic row", () => {
const result = mergeConversationItems({
conversationItems: [
- userMessage("echo", "hello"),
- userMessage("other", "different"),
+ userMessage("echo", "hello", undefined, 100),
+ userMessage("other", "different", undefined, 200),
],
- optimisticItems: [userMessage("opt", "hello")],
+ optimisticItems: [userMessage("opt", "hello", true, 300)],
isCloud: true,
});
expect(result.map((i) => i.id)).toEqual(["opt", "other"]);
+ expect(result[0]).toMatchObject({
+ id: "opt",
+ timestamp: 100,
+ pinToTop: undefined,
+ });
});
it("cloud: dedupes the echoed prompt even when it carries an appended channel CONTEXT.md", () => {
diff --git a/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.ts b/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.ts
index 64c0e2f011d7..820aa83e572d 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/mergeConversationItems.ts
@@ -74,9 +74,8 @@ export function mergeConversationItems({
}
// When the echoed prompt matches a pinned optimistic placeholder, drop the
- // echo but remember it: it may carry the channel CONTEXT.md block and the
- // attachment chips the placeholder lacks, so we surface the richer copy on
- // the pinned bubble below.
+ // echo but remember it. The server copy supplies the authoritative timestamp
+ // as well as context and attachments, while the optimistic id keeps the row stable.
const echoedItemByKey = new Map<string, UserMessageItem>();
const consumedPlainEchoByKey = new Set<string>();
const dedupedConversation =
@@ -111,14 +110,17 @@ export function mergeConversationItems({
: pinnedOptimisticItems.map((item) => {
if (item.type !== "user_message") return item;
const echoed = echoedItemByKey.get(strippedUserContent(item.content));
- if (
- !echoed ||
- (echoed.content === item.content && !echoed.attachments?.length)
- ) {
- return item;
+ if (!echoed) return item;
+ const resolvedItem = {
+ ...item,
+ timestamp: echoed.timestamp,
+ pinToTop: undefined,
+ };
+ if (echoed.content === item.content && !echoed.attachments?.length) {
+ return resolvedItem;
}
return {
- ...item,
+ ...resolvedItem,
content: echoed.content,
...(echoed.attachments?.length
? { attachments: echoed.attachments }
diff --git a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts
index 8f49ba8956ce..658ceb2faf19 100644
--- a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts
@@ -4056,6 +4056,7 @@ describe("SessionService", () => {
expect.objectContaining({
type: "user_message",
content: "build me a thing",
+ pinToTop: true,
}),
);
});