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(tasks): report whether a Pi steer landed (#90908)

Alessandro Pogliaghied95861f082e
diff --git a/products/desktop/packages/agent/src/server/pi-agent-server.test.ts b/products/desktop/packages/agent/src/server/pi-agent-server.test.ts
index 3ec67a7166d7..970abf72d860 100644
--- a/products/desktop/packages/agent/src/server/pi-agent-server.test.ts
+++ b/products/desktop/packages/agent/src/server/pi-agent-server.test.ts
@@ -402,7 +402,7 @@ describe("PiAgentServer", () => {
await rm(repositoryPath, { recursive: true });
});
- it("aborts the streaming run and re-prompts when a steer arrives", async () => {
+ it("steers the streaming run in place instead of aborting it", async () => {
const sendCommand = vi.fn(async (_command: Record<string, unknown>) => ({
success: true,
}));
@@ -430,25 +430,27 @@ describe("PiAgentServer", () => {
},
};
- await server.executeCommand("user_message", {
+ const result = await server.executeCommand("user_message", {
content: "stop, do this instead",
messageId: "message-1",
steer: true,
});
- expect(order).toEqual(["abort", "sendCommand"]);
+ expect(result).toMatchObject({ steered: true });
+ expect(order).toEqual(["sendCommand"]);
+ expect(abort).not.toHaveBeenCalled();
expect(sendCommand).toHaveBeenCalledTimes(1);
expect(sendCommand).toHaveBeenCalledWith({
id: "message-1",
- type: "prompt",
+ type: "steer",
message: "stop, do this instead",
images: [],
});
});
- it("queues a steer that pi rejects because another run took the idle slot", async () => {
+ it("queues a steer that pi refuses while the run is still streaming", async () => {
const sendCommand = vi.fn(async (command: Record<string, unknown>) => {
- if (command.type === "prompt") {
+ if (command.type === "steer") {
return { success: false, error: "Agent is already processing." };
}
return { success: true };
@@ -483,11 +485,12 @@ describe("PiAgentServer", () => {
images: [],
});
expect(result).toMatchObject({ success: true });
+ expect(result).not.toHaveProperty("steered");
});
- it("declines a steer whose re-prompt fails while pi stays idle so the host redelivers", async () => {
+ it("declines a steer pi refuses while it stays idle so the host redelivers", async () => {
const sendCommand = vi.fn(async (command: Record<string, unknown>) => {
- if (command.type === "prompt") {
+ if (command.type === "steer") {
return {
success: false,
error: "Cannot submit a prompt while compaction is in progress.",
@@ -525,11 +528,53 @@ describe("PiAgentServer", () => {
expect(sendCommand).toHaveBeenCalledTimes(1);
expect(sendCommand).toHaveBeenCalledWith({
id: "message-4",
+ type: "steer",
+ message: "stop, do this instead",
+ images: [],
+ });
+ expect(result).toMatchObject({
+ success: false,
+ steered: false,
+ reason: "pi_delivery_failed",
+ });
+ });
+
+ it("sends a steer that arrives while pi is idle as a prompt, without asking for redelivery", async () => {
+ const sendCommand = vi.fn(async (_command: Record<string, unknown>) => ({
+ success: true,
+ }));
+ const abort = vi.fn(async () => {});
+ const server = new PiAgentServer(config()) as unknown as {
+ session: unknown;
+ executeCommand(
+ method: string,
+ params: Record<string, unknown>,
+ ): Promise<unknown>;
+ };
+ server.session = {
+ runtime: {
+ client: {
+ getState: vi.fn(async () => ({ isStreaming: false })),
+ abort,
+ },
+ sendCommand,
+ },
+ };
+
+ const result = await server.executeCommand("user_message", {
+ content: "stop, do this instead",
+ messageId: "message-5",
+ steer: true,
+ });
+
+ expect(abort).not.toHaveBeenCalled();
+ expect(sendCommand).toHaveBeenCalledWith({
+ id: "message-5",
type: "prompt",
message: "stop, do this instead",
images: [],
});
- expect(result).toMatchObject({ success: false });
+ expect(result).not.toHaveProperty("steered");
});
it("queues a mid-turn message that is not a steer instead of aborting", async () => {
@@ -554,11 +599,12 @@ describe("PiAgentServer", () => {
},
};
- await server.executeCommand("user_message", {
+ const result = await server.executeCommand("user_message", {
content: "when you are done, also update the docs",
messageId: "message-2",
});
+ expect(result).not.toHaveProperty("steered");
expect(abort).not.toHaveBeenCalled();
expect(sendCommand).toHaveBeenCalledWith({
id: "message-2",
diff --git a/products/desktop/packages/agent/src/server/pi-agent-server.ts b/products/desktop/packages/agent/src/server/pi-agent-server.ts
index 3e88b1288c19..500bddfecafa 100644
--- a/products/desktop/packages/agent/src/server/pi-agent-server.ts
+++ b/products/desktop/packages/agent/src/server/pi-agent-server.ts
@@ -846,7 +846,7 @@ export class PiAgentServer {
id: string,
steer: boolean,
): Promise<unknown> {
- const send = (type: "prompt" | "follow_up") =>
+ const send = (type: "prompt" | "follow_up" | "steer") =>
runtime.sendCommand({ id, type, message: content, images });
const state = await runtime.client.getState();
if (!state.isStreaming) {
@@ -855,13 +855,15 @@ export class PiAgentServer {
if (!steer) {
return send("follow_up");
}
- await runtime.client.abort();
- const prompted = await send("prompt");
- if (prompted.success) {
- return prompted;
+ const steered = await send("steer");
+ if (steered.success) {
+ return { ...steered, steered: true };
}
- const afterPrompt = await runtime.client.getState();
- return afterPrompt.isStreaming ? send("follow_up") : prompted;
+ const afterSteer = await runtime.client.getState();
+ if (afterSteer.isStreaming) {
+ return send("follow_up");
+ }
+ return { ...steered, steered: false, reason: "pi_delivery_failed" };
}
private installSseController(sseController: SseController | null): void {