Skip to content

Commit d4a99d1

Browse files
fix(mobile): validate resumed agent controls
Generated-By: PostHog Code Task-Id: c1bbe3cf-742b-4b24-bf96-d11a18b4cf22
1 parent 1f98daa commit d4a99d1

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

apps/mobile/src/features/tasks/stores/taskSessionStore.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ describe("_resumeCloudRun", () => {
263263
mockGetTask.mockResolvedValue(
264264
previousTask({
265265
branch: "feature",
266+
runtime_adapter: "claude",
267+
model: "claude-opus-4-8",
266268
reasoning_effort: "low",
267269
state: { initial_permission_mode: "acceptEdits" },
268270
}),
@@ -275,6 +277,7 @@ describe("_resumeCloudRun", () => {
275277
expect(mockRunTaskInCloud).toHaveBeenCalledWith("t1", {
276278
branch: "feature",
277279
runtimeAdapter: "claude",
280+
model: "claude-opus-4-8",
278281
resumeFromRunId: "prev-run",
279282
pendingUserMessage: "hi",
280283
reasoningEffort: "low",
@@ -299,7 +302,14 @@ describe("_resumeCloudRun", () => {
299302

300303
it("prefers the composer's current selection over the previous run", async () => {
301304
useTaskStore.setState({
302-
composerConfigByTaskId: { t1: { mode: "plan", reasoning: "max" } },
305+
composerConfigByTaskId: {
306+
t1: {
307+
adapter: "codex",
308+
mode: "plan",
309+
model: "gpt-5.5",
310+
reasoning: "high",
311+
},
312+
},
303313
});
304314
mockGetTask.mockResolvedValue(
305315
previousTask({
@@ -316,11 +326,32 @@ describe("_resumeCloudRun", () => {
316326
expect(mockRunTaskInCloud).toHaveBeenCalledWith(
317327
"t1",
318328
expect.objectContaining({
319-
reasoningEffort: "max",
329+
runtimeAdapter: "codex",
330+
model: "gpt-5.5",
331+
reasoningEffort: "high",
320332
initialPermissionMode: "plan",
321333
}),
322334
);
323335
});
336+
337+
it("drops stored reasoning unsupported by the resumed model", async () => {
338+
mockGetTask.mockResolvedValue(
339+
previousTask({
340+
runtime_adapter: "claude",
341+
model: "claude-sonnet-4-6",
342+
reasoning_effort: "max",
343+
}),
344+
);
345+
346+
await useTaskSessionStore
347+
.getState()
348+
._resumeCloudRun("t1", "prev-run", "hi");
349+
350+
expect(mockRunTaskInCloud).toHaveBeenCalledWith(
351+
"t1",
352+
expect.objectContaining({ reasoningEffort: undefined }),
353+
);
354+
});
324355
});
325356

326357
describe("compaction tracking from the log stream", () => {

apps/mobile/src/features/tasks/stores/taskSessionStore.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { convertStoredEntriesToPortableSessionEvents } from "@posthog/core/sessions/portableSessionEvents";
22
import {
3+
type Adapter,
34
type CloudTaskUpdatePayload,
5+
isSupportedReasoningEffort,
46
isTerminalStatus,
57
type StoredLogEntry,
68
serializeCloudPrompt,
@@ -1187,9 +1189,18 @@ export const useTaskSessionStore = create<TaskSessionStore>((set, get) => ({
11871189

11881190
const composerConfig =
11891191
useTaskStore.getState().composerConfigByTaskId[taskId];
1192+
const adapter: Adapter =
1193+
composerConfig?.adapter ?? previousRun?.runtime_adapter ?? "claude";
1194+
const model = composerConfig?.model ?? previousRun?.model ?? undefined;
11901195
const previousPermissionMode = previousRun?.state?.initial_permission_mode;
1191-
const reasoningEffort =
1196+
const requestedReasoning =
11921197
composerConfig?.reasoning ?? previousRun?.reasoning_effort ?? undefined;
1198+
const reasoningEffort =
1199+
model &&
1200+
requestedReasoning &&
1201+
isSupportedReasoningEffort(adapter, model, requestedReasoning)
1202+
? requestedReasoning
1203+
: undefined;
11931204
const initialPermissionMode =
11941205
composerConfig?.mode ??
11951206
(typeof previousPermissionMode === "string"
@@ -1198,7 +1209,8 @@ export const useTaskSessionStore = create<TaskSessionStore>((set, get) => ({
11981209

11991210
const updatedTask = await runTaskInCloud(taskId, {
12001211
branch: previousBranch,
1201-
runtimeAdapter: "claude",
1212+
runtimeAdapter: adapter,
1213+
model,
12021214
resumeFromRunId: previousRunId,
12031215
pendingUserMessage: prompt,
12041216
reasoningEffort,

0 commit comments

Comments
 (0)