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): show restore sandbox conversation item in pi (#89250)

Jonathan Mieloo2ecd758f7323
diff --git a/products/desktop/packages/ui/src/features/sessions/components/buildAgentConversationItems.test.ts b/products/desktop/packages/ui/src/features/sessions/components/buildAgentConversationItems.test.ts
index 09796d9a8737..4d8984fa0d6c 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/buildAgentConversationItems.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/buildAgentConversationItems.test.ts
@@ -265,6 +265,86 @@ describe("buildAgentConversationItems", () => {
);
});
+ it("appends setup progress when Pi restarts a completed sandbox", () => {
+ const result = buildAgentConversationItems(
+ [
+ {
+ type: "progress",
+ timestamp: 1,
+ step: "agent",
+ status: "completed",
+ label: "Started agent",
+ group: "setup:run-1",
+ },
+ {
+ type: "user_message",
+ id: "user-1",
+ timestamp: 2,
+ content: [{ type: "text", text: "First message" }],
+ },
+ {
+ type: "assistant_message_chunk",
+ timestamp: 3,
+ content: { type: "text", text: "Done" },
+ },
+ { type: "turn_completed", timestamp: 4 },
+ {
+ type: "user_message",
+ id: "user-2",
+ timestamp: 5,
+ content: [{ type: "text", text: "Continue" }],
+ },
+ {
+ type: "progress",
+ timestamp: 6,
+ step: "sandbox",
+ status: "in_progress",
+ label: "Restoring sandbox",
+ group: "setup:run-1",
+ },
+ {
+ type: "progress",
+ timestamp: 7,
+ step: "sandbox",
+ status: "completed",
+ label: "Restored sandbox",
+ group: "setup:run-1",
+ },
+ {
+ type: "progress",
+ timestamp: 8,
+ step: "agent",
+ status: "completed",
+ label: "Started agent",
+ group: "setup:run-1",
+ },
+ ],
+ true,
+ );
+
+ const itemOrder = result.items.flatMap((item) => {
+ if (item.type === "user_message") {
+ return [`user:${item.content}`];
+ }
+ if (
+ item.type === "session_update" &&
+ item.update.sessionUpdate === "progress_group"
+ ) {
+ return [
+ `progress:${item.update.steps.map((step) => step.key).join(",")}`,
+ ];
+ }
+ return [];
+ });
+
+ expect(itemOrder).toEqual([
+ "user:First message",
+ "progress:agent",
+ "user:Continue",
+ "progress:sandbox,agent",
+ ]);
+ });
+
it("builds and completes a generic compaction status", () => {
const result = buildAgentConversationItems(
[
diff --git a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts
index fc0ef3a27ce7..ceade43d4b77 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts
+++ b/products/desktop/packages/ui/src/features/sessions/components/buildConversationItems.ts
@@ -465,7 +465,10 @@ export function processAgentConversationEvent(
}
if (event.type === "progress") {
- handleProgress(b, event, event.timestamp, false);
+ handleProgress(b, event, event.timestamp, {
+ waitForRunStarted: false,
+ appendOnSetupRestart: true,
+ });
return;
}
@@ -1010,7 +1013,10 @@ function handleProgress(
b: ItemBuilder,
rawParams: unknown,
ts: number,
- waitForRunStarted = true,
+ options?: {
+ waitForRunStarted?: boolean;
+ appendOnSetupRestart?: boolean;
+ },
) {
const params = rawParams as
| {
@@ -1024,6 +1030,18 @@ function handleProgress(
if (!params?.step || !params.label || !params.group) return;
const status = normalizeStepStatus(params.status);
+ const existingCard = b.progressCards.get(params.group);
+ const previousAgentStatus = existingCard?.steps.get("agent")?.status;
+ const startsNewSetup =
+ options?.appendOnSetupRestart === true &&
+ params.step === "sandbox" &&
+ status === "in_progress" &&
+ previousAgentStatus !== undefined &&
+ previousAgentStatus !== "in_progress";
+ if (startsNewSetup) {
+ b.progressCards.delete(params.group);
+ }
+
const card = ensureProgressCardForGroup(b, params.group, ts);
if (!card) return;
if (card.itemIndex < b.lowestTouchedProgressIndex) {
@@ -1035,7 +1053,7 @@ function handleProgress(
label: params.label,
detail: params.detail,
});
- syncProgressCard(card, b, waitForRunStarted);
+ syncProgressCard(card, b, options?.waitForRunStarted);
}
function normalizeStepStatus(raw: string | undefined): StepStatus {