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): keep the turn open when steered work outlasts the grace (#84195)

Alessandro Pogliaghi668e06999ee5
diff --git a/products/desktop/packages/agent/src/adapters/claude/claude-agent.streamed-text.test.ts b/products/desktop/packages/agent/src/adapters/claude/claude-agent.streamed-text.test.ts
index 920da7d459e3..0578f2051f7d 100644
--- a/products/desktop/packages/agent/src/adapters/claude/claude-agent.streamed-text.test.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/claude-agent.streamed-text.test.ts
@@ -401,6 +401,50 @@ describe("ClaudeAcpAgent.prompt — streamed assistant text wiring", () => {
]);
});
+ it("keeps the turn open when the steered work outlasts the delivery grace", async () => {
+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
+ try {
+ const { agent } = makeAgent();
+ const sessionId = "s-steer-slow-work";
+ const { query, input } = installFakeSession(agent, sessionId);
+
+ const promptPromise = agent.prompt({
+ sessionId,
+ prompt: [{ type: "text", text: "use orange" }],
+ });
+ let promptSettled = false;
+ void promptPromise.then(() => {
+ promptSettled = true;
+ });
+ await tick();
+ await echoUserMessage(query, input);
+
+ const steerPromise = agent.prompt({
+ sessionId,
+ prompt: [{ type: "text", text: "use green instead" }],
+ _meta: { steer: true },
+ });
+ await tick();
+
+ await send(query, resultSuccess(sessionId));
+ await echoUserMessage(query, input);
+ await send(query, assistantMessage(sessionId, "msg_green", "GREEN"));
+ await expect(steerPromise).resolves.toMatchObject({
+ _meta: { steer: true },
+ });
+
+ await vi.advanceTimersByTimeAsync(60_000);
+ expect(promptSettled).toBe(false);
+
+ await send(query, resultSuccess(sessionId));
+ await expect(promptPromise).resolves.toMatchObject({
+ stopReason: "end_turn",
+ });
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it("declines a steer the turn ends without acting on", async () => {
const { agent } = makeAgent();
const sessionId = "s-steer-unacted";
diff --git a/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts b/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts
index 187cd3289ddb..45b9b1296df6 100644
--- a/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts
@@ -223,6 +223,14 @@ function confirmConsumedSteers(turn: Turn): void {
turn.pendingSteers.delete(uuid);
}
}
+ if (turn.pendingSteers.size > 0) {
+ return;
+ }
+ if (turn.steerTimer) {
+ clearTimeout(turn.steerTimer);
+ turn.steerTimer = undefined;
+ }
+ turn.deferredResult = undefined;
}
/** Report every steer left on a finishing turn as undelivered so callers redeliver it. */
diff --git a/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx b/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx
index 8b01edef85b3..60b4ab0effc9 100644
--- a/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx
+++ b/products/desktop/packages/ui/src/features/pi-sessions/PiSessionView.tsx
@@ -329,13 +329,7 @@ function usePiSubmit(
);
void controller
.submit(taskId, message, isStreaming, messagingMode, pendingConfig)
- .then((result) => {
- if (result === "steer") {
- toast.info("Steering waits for a safe boundary", {
- description:
- "Pi will apply it at the next safe boundary. The run stays active until then.",
- });
- }
+ .then(() => {
onSuccess(action);
})
.catch((error) => {
diff --git a/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.test.tsx b/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.test.tsx
index f624bf62664a..1bb918f22469 100644
--- a/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.test.tsx
@@ -193,16 +193,18 @@ describe("useSessionCallbacks.handleSendPrompt", () => {
expect(toastError).toHaveBeenCalledWith("fetch failed");
});
- it("uses the post-send compaction state for the steering notice", async () => {
+ it("forwards the steer intent from the messaging mode", async () => {
messagingMode.value = "steer";
- sessionService.sendPrompt.mockImplementation(async () => {
- sessionState.isCompacting = true;
- });
+ sessionService.sendPrompt.mockResolvedValue({ stopReason: "steered" });
const { result } = renderCallbacks(sessionState as unknown as AgentSession);
await result.current.handleSendPrompt("change direction");
- expect(toastInfo).not.toHaveBeenCalled();
+ expect(sessionService.sendPrompt).toHaveBeenCalledWith(
+ TASK,
+ "change direction",
+ { steer: true },
+ );
});
});
diff --git a/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.ts b/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.ts
index 0fe0a0041c9b..f4b29a3e90ba 100644
--- a/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.ts
+++ b/products/desktop/packages/ui/src/features/sessions/hooks/useSessionCallbacks.ts
@@ -13,7 +13,6 @@ import {
} from "@posthog/core/sessions/sessionService";
import { useService } from "@posthog/di/react";
import { useHostTRPCClient } from "@posthog/host-router/react";
-import { sessionSupportsNativeSteer } from "@posthog/shared";
import type { Task } from "@posthog/shared/domain-types";
import {
resolveLocalSkillPrompt,
@@ -139,20 +138,6 @@ export function useSessionCallbacks({
steer: messagingMode === "steer",
});
- const sentSession = sessionStoreSetters.getSessionByTaskId(taskId);
- if (
- messagingMode === "steer" &&
- sentSession?.isPromptPending &&
- !sentSession.isCompacting &&
- sentSession.adapter === "claude" &&
- sessionSupportsNativeSteer(sentSession)
- ) {
- toast.info("Steering waits for a safe boundary", {
- description:
- "It will apply at the next safe boundary. The current command may keep running until then.",
- });
- }
-
const view = getAppViewSnapshot();
const isViewingTask =
view?.type === "task-detail" && view?.taskId === taskId;