Skip to content

Commit 4eb13a9

Browse files
committed
fix(task): new_task thinking_effort review fixes (boolean capability, post-mode-switch revalidation, ask prefill normalization)
1 parent f6410bb commit 4eb13a9

6 files changed

Lines changed: 209 additions & 20 deletions

File tree

‎src/__tests__/provider-delegation.spec.ts‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
396396
start: vi.fn(),
397397
run: childRun,
398398
setRuntimeThinkingEffort,
399+
// The child's resolved model (post mode switch) supports the requested level.
400+
api: {
401+
getModel: () => ({ id: "child-model", info: { supportsReasoningEffort: ["low", "medium", "high"] } }),
402+
},
399403
})
400404
const taskHistoryStore = makeStoreStub()
401405

@@ -463,4 +467,95 @@ describe("ClineProvider.delegateParentAndOpenChild()", () => {
463467

464468
expect(setRuntimeThinkingEffort).not.toHaveBeenCalled()
465469
})
470+
471+
it("falls back with an observable say when the child model (post mode switch) does not support the effort (DTE series 5/5)", async () => {
472+
const parentTask = makeParentTask()
473+
const setRuntimeThinkingEffort = vi.fn()
474+
const say = vi.fn().mockResolvedValue(undefined)
475+
const childRun = vi.fn().mockResolvedValue(undefined)
476+
// The mode switch resolved a DIFFERENT model than the parent's: it only
477+
// supports low/high, so the parent-validated "xhigh" must not be applied.
478+
const createTask = vi.fn().mockResolvedValue({
479+
taskId: "child-1",
480+
start: vi.fn(),
481+
run: childRun,
482+
setRuntimeThinkingEffort,
483+
say,
484+
api: { getModel: () => ({ id: "child-model", info: { supportsReasoningEffort: ["low", "high"] } }) },
485+
})
486+
const taskHistoryStore = makeStoreStub()
487+
488+
const provider = {
489+
taskScheduler: new TaskScheduler(),
490+
emit: vi.fn(),
491+
getCurrentTask: vi.fn(() => parentTask),
492+
removeClineFromStack: vi.fn().mockResolvedValue(undefined),
493+
createTask,
494+
handleModeSwitch: vi.fn().mockResolvedValue(undefined),
495+
log: vi.fn(),
496+
isViewLaunched: false,
497+
recentTasksCache: undefined,
498+
taskHistoryStore,
499+
} as unknown as ClineProvider
500+
501+
await ClineProvider.prototype.delegateParentAndOpenChild.call(provider, {
502+
parentTaskId: "parent-1",
503+
message: "Do something",
504+
initialTodos: [],
505+
mode: "code",
506+
thinkingEffort: "xhigh",
507+
})
508+
await Promise.resolve()
509+
510+
// No task-local override: the child runs with the settings-derived effort.
511+
expect(setRuntimeThinkingEffort).not.toHaveBeenCalled()
512+
// Observable on the child task: the fallback is announced, not silent.
513+
expect(say).toHaveBeenCalledTimes(1)
514+
const [sayType, sayText] = say.mock.calls[0]
515+
expect(sayType).toBe("error")
516+
expect(sayText).toContain("xhigh")
517+
expect(sayText).toContain("child-model")
518+
// Delegation itself still proceeds: the child runs.
519+
expect(childRun).toHaveBeenCalledTimes(1)
520+
})
521+
522+
it("applies the effort when the child model (post mode switch) has a boolean-true capability (DTE series 5/5)", async () => {
523+
const parentTask = makeParentTask()
524+
const setRuntimeThinkingEffort = vi.fn()
525+
const childRun = vi.fn().mockResolvedValue(undefined)
526+
// Boolean-true capability: the child model supports every level.
527+
const createTask = vi.fn().mockResolvedValue({
528+
taskId: "child-1",
529+
start: vi.fn(),
530+
run: childRun,
531+
setRuntimeThinkingEffort,
532+
api: { getModel: () => ({ id: "child-model", info: { supportsReasoningEffort: true } }) },
533+
})
534+
const taskHistoryStore = makeStoreStub()
535+
536+
const provider = {
537+
taskScheduler: new TaskScheduler(),
538+
emit: vi.fn(),
539+
getCurrentTask: vi.fn(() => parentTask),
540+
removeClineFromStack: vi.fn().mockResolvedValue(undefined),
541+
createTask,
542+
handleModeSwitch: vi.fn().mockResolvedValue(undefined),
543+
log: vi.fn(),
544+
isViewLaunched: false,
545+
recentTasksCache: undefined,
546+
taskHistoryStore,
547+
} as unknown as ClineProvider
548+
549+
await ClineProvider.prototype.delegateParentAndOpenChild.call(provider, {
550+
parentTaskId: "parent-1",
551+
message: "Do something",
552+
initialTodos: [],
553+
mode: "code",
554+
thinkingEffort: "xhigh",
555+
})
556+
await Promise.resolve()
557+
558+
expect(setRuntimeThinkingEffort).toHaveBeenCalledTimes(1)
559+
expect(setRuntimeThinkingEffort).toHaveBeenCalledWith("xhigh", "parent")
560+
})
466561
})

‎src/core/tools/NewTaskTool.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,24 @@ export class NewTaskTool extends BaseTool<"new_task"> {
6363

6464
// DTE series 5/5: the child task is created with the parent's API configuration,
6565
// so the child model is the parent's current model. Validate the optional start
66-
// effort against that model's capability array before asking for approval.
66+
// effort against that model's capability before asking for approval.
67+
//
68+
// ModelInfo.supportsReasoningEffort is `boolean | string[] | undefined`: the bare
69+
// `true` means the model supports reasoning effort without an explicit allow-list,
70+
// so normalize it to the full level set. `false`/`undefined` stay unsupported
71+
// (argument rejected below). The normalized array is the single source of truth
72+
// for the argument validation, the ask payload, and the ask-selection check.
6773
const modelCapabilities = task.api.getModel().info.supportsReasoningEffort
74+
// "disable" stays in the element type: capability arrays may carry it (it is a
75+
// settings off-switch, not a start level) and is filtered where levels are listed.
76+
const supportedLevels: readonly (ReasoningEffortExtended | "disable")[] =
77+
modelCapabilities === true
78+
? NEW_TASK_EFFORT_LEVELS
79+
: Array.isArray(modelCapabilities)
80+
? modelCapabilities
81+
: []
6882
let validatedEffort: ReasoningEffortExtended | undefined
6983
if (thinking_effort !== undefined && thinking_effort !== "") {
70-
const supportedLevels = Array.isArray(modelCapabilities) ? modelCapabilities : []
7184
if (!isNewTaskEffortLevel(thinking_effort) || !supportedLevels.includes(thinking_effort)) {
7285
const reason = !isNewTaskEffortLevel(thinking_effort)
7386
? `must be one of: ${NEW_TASK_EFFORT_LEVELS.join(", ")}`
@@ -146,9 +159,10 @@ export class NewTaskTool extends BaseTool<"new_task"> {
146159
content: message,
147160
todos: todoItems,
148161
thinkingEffort: validatedEffort ?? task.resolveNewTaskEffectiveEffort(),
149-
supportedThinkingEfforts: Array.isArray(modelCapabilities)
150-
? modelCapabilities.filter((level): level is ReasoningEffortExtended => level !== "disable")
151-
: undefined,
162+
supportedThinkingEfforts:
163+
supportedLevels.length > 0
164+
? supportedLevels.filter((level): level is ReasoningEffortExtended => level !== "disable")
165+
: undefined,
152166
})
153167

154168
const didApprove = await askApproval("tool", toolMessage)
@@ -162,8 +176,7 @@ export class NewTaskTool extends BaseTool<"new_task"> {
162176
// model-specified value, which wins over the parent's effective effort. An
163177
// ask selection the target model does not support falls back the same way.
164178
const askEffort = task.takeNewTaskAskThinkingEffort()
165-
const askEffortSupported =
166-
askEffort !== undefined && Array.isArray(modelCapabilities) && modelCapabilities.includes(askEffort)
179+
const askEffortSupported = askEffort !== undefined && supportedLevels.includes(askEffort)
167180
const childThinkingEffort = askEffortSupported
168181
? askEffort
169182
: (validatedEffort ?? task.resolveNewTaskEffectiveEffort())

‎src/core/tools/__tests__/newTaskThinkingEffort.spec.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import newTaskSchema from "../../prompts/tools/native-tools/new_task"
5151
import type { Task } from "../../task/Task"
5252

5353
interface RunOptions {
54-
/** Target model capability array (boolean/undefined = no known levels). */
54+
/** Target model capability: array = allow-list; true = full level set; false/undefined = unsupported. */
5555
supportsReasoningEffort?: boolean | string[]
5656
/** Effort the user chose in the ask block (carried by the ask response). */
5757
askEffort?: string
@@ -311,4 +311,36 @@ describe("new_task thinking_effort validation (DTE series 5/5)", () => {
311311

312312
expect(delegateParentAndOpenChild).toHaveBeenCalledWith(expect.objectContaining({ thinkingEffort: "low" }))
313313
})
314+
315+
it("accepts a valid level when the capability is boolean true (full level set)", async () => {
316+
const { task, delegateParentAndOpenChild } = makeTask({
317+
supportsReasoningEffort: true,
318+
})
319+
const callbacks = makeCallbacks()
320+
321+
// xhigh is a valid level but is not in any provider allow-list today: only the
322+
// boolean-true normalization (full level set) accepts it.
323+
await runNewTask(task, { thinking_effort: "xhigh" }, callbacks)
324+
325+
expect(delegateParentAndOpenChild).toHaveBeenCalledWith(expect.objectContaining({ thinkingEffort: "xhigh" }))
326+
327+
// The ask payload lists the full level set for a boolean-true capability.
328+
const [, toolMessage] = vi.mocked(callbacks.askApproval).mock.calls[0]
329+
const payload = JSON.parse(toolMessage as string) as { supportedThinkingEfforts?: string[] }
330+
expect(payload.supportedThinkingEfforts).toEqual(["none", "minimal", "low", "medium", "high", "xhigh", "max"])
331+
})
332+
333+
it("rejects an effort when the capability is boolean false", async () => {
334+
const { task, delegateParentAndOpenChild } = makeTask({
335+
supportsReasoningEffort: false,
336+
})
337+
const callbacks = makeCallbacks()
338+
339+
await runNewTask(task, { thinking_effort: "low" }, callbacks)
340+
341+
expect(callbacks.pushToolResult).toHaveBeenCalledWith(
342+
expect.stringContaining("does not support thinking_effort"),
343+
)
344+
expect(delegateParentAndOpenChild).not.toHaveBeenCalled()
345+
})
314346
})

‎src/core/webview/ClineProvider.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3867,11 +3867,29 @@ export class ClineProvider
38673867
startTask: false,
38683868
})
38693869

3870-
// DTE series 5/5: apply the subtask start effort as a task-local override before
3871-
// the child's first request so the child header shows it from the start.
3872-
// Source "parent" — set by the orchestrator, not the child's own settings.
3870+
// DTE series 5/5: the mode switch above can change the provider profile and
3871+
// therefore the model the child actually runs on (mode-specific provider
3872+
// profiles), so a level validated against the parent model can be invalid for
3873+
// the child's. Re-validate against the child's resolved model immediately before
3874+
// applying; when the child model does not support the level, fall back to no
3875+
// task-local override (the settings-derived effort applies) with an observable
3876+
// say on the child instead of failing the whole delegation.
38733877
if (thinkingEffort !== undefined) {
3874-
child.setRuntimeThinkingEffort(thinkingEffort, "parent")
3878+
const childModel = child.api.getModel()
3879+
const childCapability = childModel.info.supportsReasoningEffort
3880+
const childSupportsEffort =
3881+
childCapability === true || (Array.isArray(childCapability) && childCapability.includes(thinkingEffort))
3882+
if (childSupportsEffort) {
3883+
// Applied as a task-local override before the child's first request so the
3884+
// child header shows it from the start. Source "parent" — set by the
3885+
// orchestrator, not the child's own settings.
3886+
child.setRuntimeThinkingEffort(thinkingEffort, "parent")
3887+
} else {
3888+
await child.say(
3889+
"error",
3890+
`new_task thinking_effort '${thinkingEffort}' is not supported by the child model (${childModel.id}); the child starts without the effort override.`,
3891+
)
3892+
}
38753893
}
38763894

38773895
// 5) Persist parent delegation metadata BEFORE the child starts writing.

‎webview-ui/src/components/chat/ChatView.tsx‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,20 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
362362
const tool = JSON.parse(lastMessage.text || "{}") as ClineSayTool
363363
// DTE series 5/5: pre-fill the new_task ask effort selector (see NewTaskTool
364364
// for how the extension builds these fields); cleared for other tools.
365+
// The prefill also normalizes the SELECTION STATE to the supported levels, not
366+
// just the rendered value: the state is what gets posted on approval (see
367+
// handlePrimaryButtonClick), so an unsupported pre-filled effort falls back to
368+
// the first supported level — the level the select actually shows.
365369
if (tool.tool === "newTask") {
366-
setNewTaskAskEffort(tool.thinkingEffort)
367-
setNewTaskAskSupportedEfforts(tool.supportedThinkingEfforts)
370+
const supported = tool.supportedThinkingEfforts
371+
setNewTaskAskSupportedEfforts(supported)
372+
setNewTaskAskEffort(
373+
supported && supported.length > 0
374+
? tool.thinkingEffort && supported.includes(tool.thinkingEffort)
375+
? tool.thinkingEffort
376+
: supported[0]
377+
: tool.thinkingEffort,
378+
)
368379
}
369380
switch (tool.tool) {
370381
case "editedExistingFile":
@@ -1802,12 +1813,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
18021813
newTaskAskSupportedEfforts.length > 0 && (
18031814
<select
18041815
aria-label="Thinking effort"
1805-
value={
1806-
newTaskAskEffort &&
1807-
newTaskAskSupportedEfforts.includes(newTaskAskEffort)
1808-
? newTaskAskEffort
1809-
: newTaskAskSupportedEfforts[0]
1810-
}
1816+
// The prefill normalizes newTaskAskEffort to a supported level (see the
1817+
// newTask branch of the ask handler), so rendered and posted values agree.
1818+
value={newTaskAskEffort ?? newTaskAskSupportedEfforts[0]}
18111819
onChange={(event) =>
18121820
// The select only offers model-supported levels (rendered below), so the
18131821
// raw value is a ReasoningEffortExtended.

‎webview-ui/src/components/chat/__tests__/ChatView.spec.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,29 @@ describe("ChatView - new_task thinking effort selector (DTE series 5/5)", () =>
15771577
expect(select).toHaveValue("low")
15781578
})
15791579

1580+
it("posts the displayed level when approving an unsupported prefill without touching the select", async () => {
1581+
const { getByLabelText, getByRole } = renderChatView()
1582+
1583+
// The payload's effort ("xhigh") is not in the supported list (["low", "high"]):
1584+
// the select displays "low" (the first supported level). If the user approves
1585+
// without changing the selector, the posted effort must be the displayed level —
1586+
// not the raw payload value the user never saw.
1587+
await postToolAsk({ ...NEW_TASK_ASK, thinkingEffort: "xhigh", supportedThinkingEfforts: ["low", "high"] })
1588+
1589+
const select = await waitFor(() => getByLabelText("Thinking effort") as HTMLSelectElement)
1590+
expect(select).toHaveValue("low")
1591+
1592+
await act(async () => {
1593+
fireEvent.click(getByRole("button", { name: "chat:approve.title" }))
1594+
})
1595+
1596+
expect(vscode.postMessage).toHaveBeenCalledWith({
1597+
type: "askResponse",
1598+
askResponse: "yesButtonClicked",
1599+
thinkingEffort: "low",
1600+
})
1601+
})
1602+
15801603
it("hides the selector for non-newTask tool asks (the ask effect resets the state)", async () => {
15811604
const { getByLabelText, queryByLabelText } = renderChatView()
15821605

0 commit comments

Comments
 (0)