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 first message during cloud resume (#78827)

Jonathan Mieloofbc50e8da7e0
diff --git a/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.test.ts b/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.test.ts
index e79d0d2870b1..cb87ada33cf6 100644
--- a/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.test.ts
+++ b/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.test.ts
@@ -173,6 +173,37 @@ describe("CloudPiSessionClient", () => {
expect(cloud.client.sendCommand).toHaveBeenCalledOnce();
});
+ it("uses the readiness snapshot when opening an already-running session", async () => {
+ const cloud = createCloudTaskClient();
+ vi.mocked(cloud.client.sendCommand).mockResolvedValue({
+ success: true,
+ result: {
+ type: "response",
+ command: "get_state",
+ success: true,
+ data: { isStreaming: false },
+ },
+ });
+ const session = new CloudPiSessionClient(
+ cloud.client,
+ context("in_progress"),
+ );
+ session.onConversationEvent(vi.fn(), vi.fn());
+
+ const state = session.client.getState();
+ cloud.sendUpdate({
+ taskId: "task-1",
+ runId: "run-1",
+ kind: "snapshot",
+ status: "in_progress",
+ newEntries: [{ type: "pi_run_started" }],
+ totalEntryCount: 1,
+ });
+
+ await expect(state).resolves.toMatchObject({ isStreaming: false });
+ expect(cloud.client.sendCommand).toHaveBeenCalledOnce();
+ });
+
it("does not fail while a sandbox takes longer than 30 seconds to boot", async () => {
vi.useFakeTimers();
try {
@@ -229,11 +260,12 @@ describe("CloudPiSessionClient", () => {
taskId: "task-1",
runId: "run-1",
kind: "snapshot",
- status: "queued",
+ status: "in_progress",
newEntries: [{ type: "pi_run_started" }],
totalEntryCount: 1,
});
+ await new Promise<void>((resolve) => setTimeout(resolve, 0));
expect(cloud.client.sendCommand).not.toHaveBeenCalled();
cloud.sendUpdate({
diff --git a/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.ts b/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.ts
index 5cd8ed8063f8..00eba1a0b3e6 100644
--- a/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.ts
+++ b/products/desktop/packages/core/src/pi-runtime/cloudPiSessionClient.ts
@@ -337,7 +337,9 @@ export class CloudPiSessionClient implements PiSession {
onCloudStatus?: (status: TaskRunStatus) => void,
): void {
const snapshotCanProveReadiness =
- update.kind === "snapshot" && update.status === "in_progress";
+ update.kind === "snapshot" &&
+ this.context.runStatus === "in_progress" &&
+ update.status === "in_progress";
const hasCurrentReadinessEvent =
(update.kind === "logs" || snapshotCanProveReadiness) &&
update.newEntries.some((entry) => entry.type === "pi_run_started");