Skip to content

Commit 79e1c24

Browse files
fix(task): address the #1523 review round on the effort override
api/index.ts: document the override where it is actually consumed (the handler options buildApiHandler passes to each provider) instead of naming a resolver that does not exist; drop the series-position tag. Task.ts: remove the two blank lines that split comments from their code, describe behaviour instead of the series position, and state in the setter JSDoc that child, handoff and resumed tasks do not inherit the override. Effort tests: assert the replaced handler is disposed on both the set and the clear path, compare the rebuilt configuration with toEqual, assert the clear path rebuilds from the projection object itself, and add one test that hands the configuration to the real buildApiHandler and checks a deepseek handler resolves the override and the restore. Condense spec: drop the series-position tag.
1 parent aa9d962 commit 79e1c24

4 files changed

Lines changed: 79 additions & 26 deletions

File tree

‎src/api/index.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ export interface ApiHandlerCreateMessageMetadata {
129129
*/
130130
abortSignal?: AbortSignal
131131
/**
132-
* Per-request thinking effort override (DTE series 2/5).
133-
* When defined, takes precedence over the settings-derived `reasoningEffort`
134-
* wherever the effective effort is resolved (see `resolveEffectiveReasoningEffort`).
135-
* Task-scoped and transient: it applies to this request only (the next request
136-
* after being set — no mid-stream effect) and is never persisted to settings.
132+
* Per-request thinking effort override applied by rebuilding the handler.
133+
* Providers resolve effort from the handler options (each provider reads
134+
* `options.reasoningEffort` through its own model-params step), so passing the
135+
* override in the configuration handed to `buildApiHandler` is what takes effect;
136+
* it outranks the settings-derived `reasoningEffort` for the handler built from
137+
* this object. Task-scoped and transient: it applies to the next request only
138+
* (no mid-stream effect) and is never persisted to settings.
137139
*/
138140
reasoningEffort?: ReasoningEffortExtended
139141
}

‎src/core/condense/__tests__/condense-effort-metadata.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// npx vitest run src/core/condense/__tests__/condense-effort-metadata.spec.ts
22
//
3-
// DTE series 2/5 — the summarizer boundary. Task hands the task-local thinking-effort override
3+
// The summarizer boundary: Task hands the task-local thinking effort override to
44
// to summarizeConversation inside request metadata. This checks the other half of that hand-off:
55
// the real summarizer forwards the metadata to the handler's createMessage instead of dropping
66
// the effort. The Task-side tests cover Task-to-summarizer propagation only.
@@ -52,7 +52,7 @@ function conversationHistory(): ApiMessage[] {
5252
]
5353
}
5454

55-
describe("summarizeConversation reasoning-effort forwarding (DTE series 2/5)", () => {
55+
describe("summarizeConversation reasoning-effort forwarding", () => {
5656
beforeEach(() => {
5757
if (!TelemetryService.hasInstance()) {
5858
TelemetryService.createInstance([])

‎src/core/task/Task.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
419419
// API
420420
apiConfiguration: ProviderSettings
421421
api: ApiHandler
422-
// DTE series 2/5: task-local thinking effort override. Transient per-task state —
422+
// Task-local thinking effort override. Transient per-task state —
423423
// never persisted to settings; cleared on dispose (see dispose()).
424424
private runtimeThinkingEffort?: ReasoningEffortExtended
425425
private runtimeThinkingEffortSource?: string
@@ -2494,7 +2494,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
24942494
* Updates the API configuration and rebuilds the API handler.
24952495
* There is no tool-protocol switching or tool parser swapping.
24962496
*
2497-
* DTE series 2/5: when a task-local thinking effort override is active
2497+
* When a task-local thinking effort override is active
24982498
* (`setRuntimeThinkingEffort`), the incoming configuration's `reasoningEffort`
24992499
* becomes the new restore value and the override is re-applied on top of the
25002500
* fresh in-memory copy — clearing the override later restores the NEW profile's
@@ -2507,7 +2507,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25072507
// VS Code LM / GitHub Copilot own host listeners, so the old one is
25082508
// released — immediately when idle, or when the last request, retry,
25092509
// background drain, or condense that leased it settles.
2510-
// DTE series 2/5: apiConfiguration stays the profile-derived projection;
2510+
// apiConfiguration stays the profile-derived projection;
25112511
// an active task-local override is applied to the rebuilt handler only, so
25122512
// a profile switch keeps the override live and clearing it later restores
25132513
// the NEW profile's value (it is the configuration itself now).
@@ -2544,7 +2544,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25442544
}
25452545

25462546
/**
2547-
* DTE series 2/5: sets — or clears with `undefined` — the task-local thinking
2547+
* Sets — or clears with `undefined` — the task-local thinking
25482548
* effort override.
25492549
*
25502550
* Resolution order for the affected requests (strongest first): this
@@ -2557,6 +2557,9 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25572557
* from it can never carry the task-local effort. `undefined` clears the
25582558
* override and rebuilds the handler from the projection.
25592559
*
2560+
* Not inherited: child, handoff, and resumed tasks construct their own Task and
2561+
* start with no override — it lives in this task's private fields and is never
2562+
* persisted.
25602563
* @param effort - The task-local effort, or `undefined` to clear.
25612564
* @param source - Optional provenance label (UI wiring lands in a later PR).
25622565
*/
@@ -2592,7 +2595,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25922595
}
25932596

25942597
/**
2595-
* DTE series 2/5: reads the current task-local thinking effort override.
2598+
* Reads the current task-local thinking effort override.
25962599
*/
25972600
public getRuntimeThinkingEffort(): { effort?: ReasoningEffortExtended; source?: string } {
25982601
return {
@@ -2602,7 +2605,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
26022605
}
26032606

26042607
/**
2605-
* DTE series 2/5: metadata fragment carrying the active task-local effort
2608+
* Metadata fragment carrying the active task-local effort
26062609
* override on a single request. Empty when no override is active, so the
26072610
* existing settings resolution applies unchanged.
26082611
*/
@@ -2789,7 +2792,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
27892792
parallelToolCalls: true,
27902793
}
27912794
: {}),
2792-
// DTE series 2/5: carry the active task-local effort override.
2795+
// Carry the active task-local effort override.
27932796
...this.getRuntimeThinkingEffortMetadata(),
27942797
}
27952798
// Generate environment details to include in the condensed summary
@@ -4891,7 +4894,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
48914894
if (event.type === "tool_call_end") {
48924895
// Create compound key for deduplication (same pattern as streaming handler).
48934896
// End events carry the tool name; fall back to the id for events that don't.
4894-
48954897
let eventName = event.name ?? event.id
48964898
let dedupKey = NativeToolCallParser.makeStreamingKey(event.id, eventName)
48974899

@@ -4908,7 +4910,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
49084910
// name (provider quirk), the compound-key lookup above misses and both the
49094911
// parser entry and the dedup tracking would stay stale. Resolve the tracked
49104912
// entry by id and target the real compound key for finalization and cleanup.
4911-
49124913
if (finalToolUse === null && toolUseIndex === undefined) {
49134914
const resolved = NativeToolCallParser.getStreamingToolCallById(
49144915
event.id,
@@ -5607,7 +5608,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
56075608
parallelToolCalls: true,
56085609
}
56095610
: {}),
5610-
// DTE series 2/5: carry the active task-local effort override.
5611+
// Carry the active task-local effort override.
56115612
...this.getRuntimeThinkingEffortMetadata(),
56125613
}
56135614

@@ -5887,7 +5888,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
58875888
parallelToolCalls: true,
58885889
}
58895890
: {}),
5890-
// DTE series 2/5: carry the active task-local effort override.
5891+
// Carry the active task-local effort override.
58915892
...this.getRuntimeThinkingEffortMetadata(),
58925893
}
58935894

@@ -6058,7 +6059,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
60586059
taskId: this.taskId,
60596060
suppressPreviousResponseId: this.skipPrevResponseIdOnce,
60606061
abortSignal,
6061-
// DTE series 2/5: carry the active task-local effort override for this request.
6062+
// Carry the active task-local effort override for this request.
60626063
...this.getRuntimeThinkingEffortMetadata(),
60636064
// Include tools whenever they are present.
60646065
...(shouldIncludeTools

‎src/core/task/__tests__/Task.runtime-thinking-effort.test.ts‎

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// npx vitest run src/core/task/__tests__/Task.runtime-thinking-effort.test.ts
22
//
3-
// DTE series 2/5 — task-local thinking effort state on Task:
3+
// Task-local thinking effort state on Task:
44
// setRuntimeThinkingEffort / getRuntimeThinkingEffort, the in-memory
55
// effective-effort handler rebuild (the profile-derived apiConfiguration
66
// projection never carries the override).
@@ -11,6 +11,7 @@ import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
1111
import { Task } from "../Task"
1212
import { ClineProvider } from "../../webview/ClineProvider"
1313
import { buildApiHandler } from "../../../api"
14+
import { DeepSeekHandler } from "../../../api/providers/deepseek"
1415
import { disposeApiHandler } from "../../../api/dispose-api-handler"
1516
import { summarizeConversation } from "../../condense"
1617
import { ApiStreamChunk } from "../../../api/transform/stream"
@@ -120,7 +121,7 @@ function getPrivateAccess(task: Task): RuntimeThinkingEffortAccess {
120121

121122
const SETTINGS_EFFORT: ReasoningEffortExtended = "low"
122123

123-
describe("Task runtime thinking effort (DTE series 2/5)", () => {
124+
describe("Task runtime thinking effort override", () => {
124125
let mockProvider: Record<string, unknown>
125126
let mockApiConfiguration: ProviderSettings
126127
let task: Task
@@ -194,6 +195,10 @@ describe("Task runtime thinking effort (DTE series 2/5)", () => {
194195

195196
describe("setRuntimeThinkingEffort", () => {
196197
it("stores effort + source and rebuilds the handler with the override applied", () => {
198+
// The handler this task owned before the swap must be disposed by the swap:
199+
// handlers that hold host listeners (VS Code LM, GitHub Copilot) leak otherwise.
200+
const handlerBefore = task.api
201+
vi.mocked(disposeApiHandler).mockClear()
197202
task.setRuntimeThinkingEffort("xhigh", "test-source")
198203

199204
expect(task.getRuntimeThinkingEffort()).toEqual({ effort: "xhigh", source: "test-source" })
@@ -207,10 +212,47 @@ describe("Task runtime thinking effort (DTE series 2/5)", () => {
207212
}),
208213
)
209214
// The handler is rebuilt with the override applied (last build call)...
215+
// Exact configuration, not a shape subset: dropping any other profile field
216+
// from the rebuild would fail here.
210217
const lastCall = vi.mocked(buildApiHandler).mock.calls.at(-1)
211-
expect(lastCall?.[0]).toEqual(expect.objectContaining({ reasoningEffort: "xhigh" }))
218+
expect(lastCall?.[0]).toEqual({ ...mockApiConfiguration, reasoningEffort: "xhigh" })
212219
// ...from a fresh copy, not the settings object itself.
213220
expect(lastCall?.[0]).not.toBe(mockApiConfiguration)
221+
const disposedHandlers = vi.mocked(disposeApiHandler).mock.calls.map(([api]) => api)
222+
expect(disposedHandlers.filter((api) => api === handlerBefore)).toHaveLength(1)
223+
})
224+
225+
it("hands buildApiHandler a configuration a real provider handler honours", async () => {
226+
// The mocked builder proves the override reaches buildApiHandler; this feeds
227+
// the configuration it handed over to the REAL builder and checks that an
228+
// actual provider resolves it. deepseek's model-params step reads
229+
// `options.reasoningEffort` and outranks the model's own default ("high"),
230+
// while the profile asks for SETTINGS_EFFORT, so all three values differ.
231+
const { buildApiHandler: buildRealHandler } =
232+
await vi.importActual<typeof import("../../../api")>("../../../api")
233+
// The real builder routes this configuration to deepseek's handler, whose
234+
// model-params step is what reads the effort.
235+
const deepSeekEffortOf = (configuration: ProviderSettings): ReasoningEffortExtended | undefined => {
236+
const handler = buildRealHandler({
237+
...configuration,
238+
apiProvider: providerIdentifiers.deepseek,
239+
apiModelId: "deepseek-v4-flash",
240+
})
241+
if (!(handler instanceof DeepSeekHandler)) {
242+
throw new Error("the real builder must route this configuration to deepseek's handler")
243+
}
244+
return handler.getModel().reasoningEffort
245+
}
246+
247+
expect(deepSeekEffortOf(mockApiConfiguration)).toBe(SETTINGS_EFFORT)
248+
249+
task.setRuntimeThinkingEffort("max", "real-builder")
250+
const handedConfiguration = vi.mocked(buildApiHandler).mock.calls.at(-1)?.[0] as ProviderSettings
251+
expect(deepSeekEffortOf(handedConfiguration)).toBe("max")
252+
253+
task.setRuntimeThinkingEffort(undefined)
254+
const clearedConfiguration = vi.mocked(buildApiHandler).mock.calls.at(-1)?.[0] as ProviderSettings
255+
expect(deepSeekEffortOf(clearedConfiguration)).toBe(SETTINGS_EFFORT)
214256
})
215257

216258
it("replaces effort + source when re-set while active and restores on clear", () => {
@@ -221,17 +263,22 @@ describe("Task runtime thinking effort (DTE series 2/5)", () => {
221263
const lastSet = vi.mocked(buildApiHandler).mock.calls.at(-1)
222264
expect(lastSet?.[0]).toEqual(expect.objectContaining({ reasoningEffort: "medium" }))
223265

224-
// Clearing rebuilds from the profile projection, not the intermediate effort.
266+
// Clearing rebuilds from the profile projection itself — the same object, not
267+
// a copy carrying the intermediate effort.
225268
task.setRuntimeThinkingEffort(undefined)
226269
const lastClear = vi.mocked(buildApiHandler).mock.calls.at(-1)
227-
expect(lastClear?.[0]).toEqual(expect.objectContaining({ reasoningEffort: SETTINGS_EFFORT }))
270+
expect(lastClear?.[0]).toBe(task.apiConfiguration)
271+
expect(task.apiConfiguration.reasoningEffort).toBe(SETTINGS_EFFORT)
228272
})
229273

230274
it("restores the settings-derived effort when cleared with undefined", () => {
231275
task.setRuntimeThinkingEffort("max")
232276
const lastSet = vi.mocked(buildApiHandler).mock.calls.at(-1)
233277
expect(lastSet?.[0]).toEqual(expect.objectContaining({ reasoningEffort: "max" }))
234278

279+
// The handler that served the override must be disposed by the clearing swap.
280+
const handlerUnderOverride = task.api
281+
vi.mocked(disposeApiHandler).mockClear()
235282
// A label passed on the clearing call must not survive into source.
236283
task.setRuntimeThinkingEffort(undefined, "stale-source")
237284

@@ -246,9 +293,12 @@ describe("Task runtime thinking effort (DTE series 2/5)", () => {
246293
reasoningEffort: SETTINGS_EFFORT,
247294
}),
248295
)
249-
// The handler is rebuilt from the projection.
296+
// The handler is rebuilt from the projection object itself, and the handler
297+
// that served the override is gone.
250298
const lastCall = vi.mocked(buildApiHandler).mock.calls.at(-1)
251-
expect(lastCall?.[0]).toEqual(expect.objectContaining({ reasoningEffort: SETTINGS_EFFORT }))
299+
expect(lastCall?.[0]).toBe(task.apiConfiguration)
300+
const disposedHandlers = vi.mocked(disposeApiHandler).mock.calls.map(([api]) => api)
301+
expect(disposedHandlers.filter((api) => api === handlerUnderOverride)).toHaveLength(1)
252302
})
253303

254304
it("never lets the override enter apiConfiguration (webview projection + profile save contract)", () => {

0 commit comments

Comments
 (0)