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): mobile preserve plan mode for warm cloud tasks (#105840)

Tom Owersd17013a1b997
diff --git a/products/desktop/apps/mobile/src/app/task/index.tsx b/products/desktop/apps/mobile/src/app/task/index.tsx
index bc4daa564ae0..1b77af83a1ab 100644
--- a/products/desktop/apps/mobile/src/app/task/index.tsx
+++ b/products/desktop/apps/mobile/src/app/task/index.tsx
@@ -465,6 +465,7 @@ export default function NewTaskScreen() {
runtimeAdapter: adapter,
model,
reasoningEffort: showReasoningPill ? reasoning : null,
+ permissionMode: mode,
contextWindow: supports1MContext(model) ? contextWindow : null,
fastMode: supportsFastMode(model) ? fastMode : null,
});
diff --git a/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.test.tsx b/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.test.tsx
index 83ffde108eb5..73d3b6ec9868 100644
--- a/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.test.tsx
+++ b/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.test.tsx
@@ -1,3 +1,4 @@
+import type { ExecutionMode } from "@posthog/shared";
import { createElement } from "react";
import { act, create, type ReactTestRenderer } from "react-test-renderer";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -34,6 +35,7 @@ interface Props {
runtimeAdapter?: string | null;
model?: string | null;
reasoningEffort?: string | null;
+ permissionMode?: ExecutionMode | null;
contextWindow?: "200k" | "1m" | null;
fastMode?: boolean | null;
sandboxEnvironmentId?: string | null;
@@ -51,6 +53,7 @@ const NULL_RUNTIME = {
runtime_adapter: null,
model: null,
reasoning_effort: null,
+ initial_permission_mode: null,
};
function render(initial: Props) {
@@ -186,6 +189,7 @@ describe("useWarmTask", () => {
runtime_adapter: "claude",
model: "claude-sonnet-4-6",
reasoning_effort: "high",
+ initial_permission_mode: null,
},
},
])(
@@ -222,6 +226,7 @@ describe("useWarmTask", () => {
runtime_adapter: "claude",
model: "claude-opus-4-8",
reasoning_effort: "high",
+ initial_permission_mode: null,
context_window: "200k",
fast_mode: true,
});
@@ -274,6 +279,42 @@ describe("useWarmTask", () => {
expect(mockWarmTask).toHaveBeenCalledTimes(2);
});
+ it("forwards the permission mode picked in the composer", async () => {
+ render({ ...composing, runtimeAdapter: "claude", permissionMode: "plan" });
+ await flushDebounce();
+
+ expect(mockWarmTask).toHaveBeenCalledWith({
+ repository: "acme/repo",
+ github_integration: 42,
+ branch: "main",
+ runtime_adapter: "claude",
+ model: null,
+ reasoning_effort: null,
+ initial_permission_mode: "plan",
+ });
+ });
+
+ it("re-warms when the permission mode changes", async () => {
+ const base = { ...composing, runtimeAdapter: "claude" };
+ const { rerender } = render({ ...base, permissionMode: "plan" });
+ await flushDebounce();
+ expect(mockWarmTask).toHaveBeenCalledOnce();
+
+ rerender({ ...base, permissionMode: "auto" });
+ await flushDebounce();
+
+ expect(mockWarmTask).toHaveBeenCalledTimes(2);
+ expect(mockWarmTask).toHaveBeenLastCalledWith({
+ repository: "acme/repo",
+ github_integration: 42,
+ branch: "main",
+ runtime_adapter: "claude",
+ model: null,
+ reasoning_effort: null,
+ initial_permission_mode: "auto",
+ });
+ });
+
it("swallows warm errors without throwing", async () => {
mockWarmTask.mockRejectedValue(new Error("boom"));
render(composing);
diff --git a/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.ts b/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.ts
index c9396ffb4632..a7b5fdc00695 100644
--- a/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.ts
+++ b/products/desktop/apps/mobile/src/features/tasks/hooks/useWarmTask.ts
@@ -1,4 +1,7 @@
-import { TASKS_PREWARM_SANDBOX_FLAG } from "@posthog/shared";
+import {
+ type ExecutionMode,
+ TASKS_PREWARM_SANDBOX_FLAG,
+} from "@posthog/shared";
import { useFeatureFlag } from "posthog-react-native";
import { useEffect, useRef } from "react";
import { logger } from "@/lib/logger";
@@ -16,6 +19,7 @@ interface UseWarmTaskOptions {
runtimeAdapter?: string | null;
model?: string | null;
reasoningEffort?: string | null;
+ permissionMode?: ExecutionMode | null;
contextWindow?: "200k" | "1m" | null;
fastMode?: boolean | null;
sandboxEnvironmentId?: string | null;
@@ -30,6 +34,7 @@ export function useWarmTask({
runtimeAdapter,
model,
reasoningEffort,
+ permissionMode,
contextWindow,
fastMode,
sandboxEnvironmentId,
@@ -44,6 +49,9 @@ export function useWarmTask({
const normalizedRuntimeAdapter = runtimeAdapter ?? null;
const normalizedModel = model ?? null;
const normalizedReasoningEffort = reasoningEffort ?? null;
+ const normalizedPermissionMode = runtimeAdapter
+ ? (permissionMode ?? null)
+ : null;
const normalizedContextWindow = contextWindow ?? null;
const normalizedFastMode = fastMode ?? null;
const normalizedSandboxEnvironmentId = sandboxEnvironmentId ?? null;
@@ -55,7 +63,7 @@ export function useWarmTask({
!composerIsEmpty;
const key =
repository && githubIntegrationId != null
- ? `${githubIntegrationId}:${repository}:${normalizedBranch ?? ""}:${normalizedRuntimeAdapter ?? ""}:${normalizedModel ?? ""}:${normalizedReasoningEffort ?? ""}:${normalizedContextWindow ?? ""}:${normalizedFastMode ?? ""}:${normalizedSandboxEnvironmentId ?? ""}:${normalizedCustomImageId ?? ""}`
+ ? `${githubIntegrationId}:${repository}:${normalizedBranch ?? ""}:${normalizedRuntimeAdapter ?? ""}:${normalizedModel ?? ""}:${normalizedReasoningEffort ?? ""}:${normalizedPermissionMode ?? ""}:${normalizedContextWindow ?? ""}:${normalizedFastMode ?? ""}:${normalizedSandboxEnvironmentId ?? ""}:${normalizedCustomImageId ?? ""}`
: null;
useEffect(() => {
@@ -80,6 +88,7 @@ export function useWarmTask({
const warmRuntimeAdapter = normalizedRuntimeAdapter;
const warmModel = normalizedModel;
const warmReasoningEffort = normalizedReasoningEffort;
+ const warmPermissionMode = normalizedPermissionMode;
const warmContextWindow = normalizedContextWindow;
const warmFastMode = normalizedFastMode;
const warmSandboxEnvironmentId = normalizedSandboxEnvironmentId;
@@ -95,6 +104,7 @@ export function useWarmTask({
runtime_adapter: warmRuntimeAdapter,
model: warmModel,
reasoning_effort: warmReasoningEffort,
+ initial_permission_mode: warmPermissionMode,
...(warmContextWindow ? { context_window: warmContextWindow } : {}),
...(warmFastMode != null ? { fast_mode: warmFastMode } : {}),
...(warmSandboxEnvironmentId
@@ -118,6 +128,7 @@ export function useWarmTask({
normalizedRuntimeAdapter,
normalizedModel,
normalizedReasoningEffort,
+ normalizedPermissionMode,
normalizedContextWindow,
normalizedFastMode,
normalizedSandboxEnvironmentId,