Skip to content

feat(task): task-local runtime thinking effort state with per-request override (DTE series 2/5) - #1523

Open
easonLiangWorldedtech wants to merge 17 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:feat/dte-v2-3-task-runtime-effort
Open

easonLiangWorldedtech wants to merge 17 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:feat/dte-v2-3-task-runtime-effort

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

≤400-line redo of #1338 — DTE series 2/5, unit 3/5

Task-local runtime thinking-effort state on Task: the in-memory override
channel, its per-request delivery at all four createMessage sites, and the
profile-switch re-capture in updateApiConfiguration. Transient state only — nothing is persisted; persistence is the next unit (U4).

Stack

GitHub's displayed diff vs main is cumulative over the unmerged lower units
(U1 #1521, U2 #1522); the standalone range below is the review target — the displayed number shrinks as they merge. Merge this PR only after its stack
base PR has merged.

Budget (plan §2: a+d ≤400 soft target; ≤1000 hard)

2 files changed, 417 insertions(+), 1 deletion(-) = 418 — soft target 400 exceeded by 18, CR-driven (see the amendments below); hard cap 1000 ✓

File a+d
src/core/task/Task.ts 102+/1−
src/core/task/__tests__/Task.runtime-thinking-effort.test.ts (new) 315+

Budget deviation note (plan §2.6). The plan estimated U3 at ~355
(Task +132/− + tests ~20); those numbers were stale. Measured against the
union, the U3 slice is Task +105/− + a 311-line test file = 417 > 400. Per
§2.6 (no budget bypass), the dispose boundary group is split into U4:
the task-end override reset (6 Task lines + 3 DTE JSDoc lines) and its
12-line describe("dispose") test block. This matches the plan's own U4 scope
line ("persistence + boundary cases"). U3 keeps the generic 4-line dispose()
JSDoc; U4 expands it with the DTE sentence alongside the reset code.

CR re-review amendment (2026-09-05, review 5120440807). The main-sync
head re-review requested the task-end override reset to live in
disposeOnce() of this unit (so a retained disposed task never serves a stale
override, and the dispose() JSDoc's "resets transient task-local state"
claim is accurate), plus the test afterEach teardown to call
await task.dispose() unconditionally (the !task.abort guard had skipped
disposal of aborted tasks). Both land here in commit 1edd728c4 (+5/−1 ⇒
standalone 398 → 403 — a 3-line overshoot of the soft target, within the 1000
hard cap). Under the split above, U4 loses the reset code it had carried; its
12-line dispose-boundary test block stays with U4 (it now exercises this
unit's reset on the stacked tree).

CR follow-up fix (2026-09-06, review thread comment 3942121231). The
re-review of head 1edd728c4 found that the unconditional field clears in
disposeOnce() left the override behind in apiConfiguration.reasoningEffort
and the built api handler — both are populated by
setRuntimeThinkingEffort, so a retained disposed task could still expose the
override through those copies. Commit 1087fcbd4 replaces the three
assignments with the standard clearing call this.setRuntimeThinkingEffort(undefined) —
which restores apiConfiguration/api from preOverrideReasoningEffort
(read before it is cleared) and then clears the runtime fields — and adds a
14-line describe("dispose") killing-test block asserting the clear and the
restore (Task.ts net +1; standalone 403 → 418 a+d — CR-driven, ≤1000 hard cap).

Provenance / fidelity

  • Task.ts: 3-way git merge-file — base 39bdfb188 (= 6ea45b36a^),
    ours = U2 head, theirs = 90b47b053 (the last U3 commit, before the U4
    persistence work). Zero conflicts. A whole-file extract was impossible:
    the union's Task.ts carries U14-orchestrator and U4/U5 content
    (215+/241− vs U1 head), and per-commit git apply --3way of the U3 patches
    fails on upstream base drift.
  • Test file: byte-exact 90b47b053 version (311 lines) minus the dispose
    describe (12 lines + separator), plus the 3 mutation-killing assertion
    lines below = 301 lines; the header comment is trimmed to the U3 scope
    ("the task-end reset in dispose()" clause moves with U4).
  • U4 content excluded: taskMetadata.ts / history.ts persistence changes,
    the describe("history persistence round-trip") and
    describe("abortTask final save") blocks, and the HistoryItem import
    (unused in the U3 slice).
  • src/eslint-suppressions.json: untouched. The union's +21 suppression-count
    deltas vs the stack base are all in files owned by other units
    (gemini-format.spec.ts 5→6, ask-queued-message-drain.spec.ts 18→32,
    newTaskTool.spec.ts 26→31, new extension.ts 1) — none U3-owned.

Out of scope (next units)

  • U4 (DTE-2c): persist task thinking effort to history items,
    taskMetadata merge propagation, and the task-end override reset split out
    above (dispose boundary + its test).
  • U5 (DTE-2d): the Anthropic output_config.effort adaptive envelope.

Mutation-diff fix (killing assertions, plan L42 — same PR)

The first CI mutation-diff run (head d0b1a3dcd) reported 2 Survived
ConditionalExpression mutants — both on the two ternaries this unit
introduces:

Location Surviving variant Fix (this PR)
setRuntimeThinkingEffort source capture: effort === undefined ? undefined : source replacement: false ⇒ always source: a label passed on a clearing call leaks into source the clearing call now carries a label (setRuntimeThinkingEffort(undefined, "stale-source")); the existing source: undefined assertion then kills the variant
getRuntimeThinkingEffortMetadata: effort !== undefined ? { reasoningEffort } : {} replacement: true ⇒ always { reasoningEffort: <maybe undefined> } key-absence assertion not.toHaveProperty("reasoningEffort") while unset — toEqual({}) cannot kill it (toEqual ignores keys whose value is undefined); asserted pre-set and post-clear

The complementary variants (L1683-true, L1721-false) were already killed by
the existing toBe("test-source") and toEqual({ reasoningEffort: "high" })
assertions.

Local dev-stage gate (skill §5.1) on the latest CR-fix head 1087fcbd4:
node scripts/stryker-diff.mjs ci --base 069c34b9a --head 1087fcbd4 — extension 36 changed lines, 26 valid mutants, 26 Killed, 0 Survived / 0 NoCoverage, exit 0 (previous CR-fix head 1edd728c4: 38 lines, 25/25 Killed).

Verification (local, head 1087fcbd4)

  • pnpm --dir src exec eslint --prune-suppressions --max-warnings=0 core/task/Task.ts core/task/__tests__/Task.runtime-thinking-effort.test.ts — exit 0 (re-run on 1087fcbd4; no suppression-count change)
  • pnpm check-types — 11/11 projects
  • pnpm --dir src exec vitest run core/task/__tests__/Task.runtime-thinking-effort.test.ts — 9/9 (re-run on 1087fcbd4, 4.16 s; includes the new dispose killing test)
  • git diff --shortstat 069c34b9a HEAD — 417+/1− = 418 (CR fixes +19/−4 vs 1edd728c4; soft overshoot documented above, ≤1000 hard)
  • mutation-diff gate (dev stage, skill §5.1) on 1087fcbd4 — exit 0, 26/26 Killed (see fix above)

… override (DTE series 2/5)

- Task: setRuntimeThinkingEffort/getRuntimeThinkingEffort with in-memory
  apiConfiguration merge/restore; per-request metadata at all four
  createMessage sites; profile-switch re-capture in updateApiConfiguration
- Transient state only: never persisted to settings or history
- Tests: 8 focused vitest cases (state machine, profile switch, metadata
  fragment, non-persistence)

Part of #35 (DTE-v2 ship plan, unit 3/5).
@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: baafb999-2cd1-4f28-9bdd-2275a89ca577

📥 Commits

Reviewing files that changed from the base of the PR and between 1edd728 and 1087fcb.

📒 Files selected for processing (2)
  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.runtime-thinking-effort.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (5)
Check persistence and lifecycle invariants: awaited atomic writes, rollback or explicit partial-failure behavior, cross-window state consistency, stale listeners/watchers, cancellation, idempotency, and safe restart/resume without lost or d...

⚙️ CodeRabbit configuration file

Files:

  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.runtime-thinking-effort.test.ts
Require regression coverage at the lowest valid harness with behavior-focused assertions, including relevant negative, error, false/unset, and boundary cases.

⚙️ CodeRabbit configuration file

Files:

  • src/core/task/__tests__/Task.runtime-thinking-effort.test.ts
Check strict typing and exhaustive behavior across normal, boundary, error, cancellation, retry, and compatibility paths.

⚙️ CodeRabbit configuration file

Files:

  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.runtime-thinking-effort.test.ts
Verify extension/webview contracts, cancellation and error propagation, VS Code lifecycle correctness, and behavior under retries and partial failure.

⚙️ CodeRabbit configuration file

Files:

  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.runtime-thinking-effort.test.ts
Act as an adversarial second-opinion reviewer.

⚙️ CodeRabbit configuration file

Files:

  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.runtime-thinking-effort.test.ts
🔇 Additional comments (2)
src/core/task/Task.ts (1)

25-25: LGTM!

Also applies to: 322-328, 1644-1726, 1843-1844, 2613-2616, 2709-2714, 4298-4299, 4526-4527, 4693-4694

src/core/task/__tests__/Task.runtime-thinking-effort.test.ts (1)

1-130: LGTM!

Also applies to: 132-221, 223-283, 285-300, 302-315


📝 Summary

Summary by CodeRabbit

  • New Features

    • Added an experimental Dynamic Thinking Effort setting, disabled by default.
    • Models can adjust thinking effort per step, while manual chat controls remain available.
    • Added temporary, per-request thinking-effort overrides that take precedence over configured defaults.
    • Active overrides persist when API profiles change and restore configured values when cleared.
  • Documentation

    • Added localized setting names and descriptions across supported languages.
  • Tests

    • Added coverage for configuration, persistence, runtime overrides, and visual settings displays.

Walkthrough

The PR adds the dynamicThinkingEffort experiment, transient task-level reasoning-effort overrides, effective-effort resolution, request propagation, settings UI coverage, localized labels, and Vitest-related Stryker test discovery.

Changes

Dynamic thinking effort

Layer / File(s) Summary
Experiment contracts and defaults
packages/types/src/experiment.ts, src/shared/experiments.ts, packages/types/src/__tests__/experiment.test.ts, src/shared/__tests__/experiments.spec.ts
Adds the optional experiment ID and schema field. Registers the experiment as disabled by default and tests valid, invalid, enabled, and disabled states.
Reasoning effort resolution
src/api/index.ts, src/api/transform/reasoning.ts, src/api/transform/__tests__/dte-effective-reasoning-effort.spec.ts
Adds transient request metadata, adaptive effort values, and precedence resolution from request override to settings value to model default.
Task-local runtime state and request propagation
src/core/task/Task.ts, src/core/task/__tests__/Task.runtime-thinking-effort.test.ts
Stores task-local overrides, preserves them across profile changes, restores profile values when cleared, clears them during disposal, and attaches active overrides to API requests.
Experiment settings and localization
src/core/webview/..., webview-ui/src/components/settings/..., webview-ui/playwright/gallery/stories.tsx, webview-ui/src/i18n/locales/*/settings.json
Adds settings persistence, webview state handling, UI interaction tests, visual coverage, gallery wiring, and localized setting labels.

Stryker Vitest discovery

Layer / File(s) Summary
Extension mutation-test discovery
scripts/stryker-diff.mjs, scripts/stryker-diff.test.mjs
Enables Vitest-related test discovery for the extension package and updates manifest assertions for the new flags.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Task
  participant resolveEffectiveReasoningEffort
  participant APIHandler
  User->>Task: setRuntimeThinkingEffort(effort)
  Task->>resolveEffectiveReasoningEffort: pass override, settings effort, and model default
  resolveEffectiveReasoningEffort-->>Task: return effective reasoning effort
  Task->>APIHandler: send request metadata with reasoningEffort
  APIHandler-->>Task: stream API response
Loading

Merge Risk: ⚪ Minimal · up to 1087f

Task-local thinking-effort overrides now reset during disposal, preventing disposed tasks from retaining stale effort state. No current merge-blocking risk remains.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore (reviewers only)

❌ Failed checks (1 error, 4 warnings)

Check name Status Explanation Resolution
Trust And Persistence Invariants ❌ Error The new Task.setRuntimeThinkingEffort path leaks provider lifecycle resources. It replaces this.api with buildApiHandler(...) at src/core/task/Task.ts:1705 without disposing the previous handl… Make API-handler replacement lifecycle-safe. Add an optional disposal contract to ApiHandler, dispose the old handler before replacing it in setRuntimeThinkingEffort and updateApiConfiguration, and dispose the final handler during `Ta…
Linked Issues check ⚠️ Warning The directly linked issue [#1527] focuses on async disposal, cleanup ordering, provider shutdown, failure isolation, and lifecycle model coverage. This PR primarily adds dynamic thinking-effort state … Link this PR to the appropriate DTE issue, or include the required #1527 cleanup implementation and deterministic coverage in this PR. Do not rely on stacked or base changes unless the linked issue explicitly accepts that structure.
Out of Scope Changes check ⚠️ Warning The changes include experiment schemas, reasoning-resolution APIs, Stryker configuration, webview settings, visual fixtures, and localization updates. These changes are unrelated to linked issue [#152… Remove unrelated DTE experiment, API, Stryker, webview, visual, and localization changes from this PR, or split them into focused PRs linked to the corresponding DTE issues. Update the description to match the actual standalone diff.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 18 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Regression Evidence ⚠️ Warning The new Task request-metadata behavior lacks focused boundary coverage. Task.ts adds the runtime-effort metadata spread at four request paths (lines 1844, 4299, 4527, and 4694), but `Task.runtime-th… Add focused Task-level tests at the request boundaries. Set a runtime override and assert metadata.reasoningEffort for attemptApiRequest, the normal context-management path, forced context truncation, and condenseContext; also assert …
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: task-local runtime thinking-effort state with per-request overrides.
Description check ✅ Passed The description gives detailed scope, implementation notes, exclusions, and reproducible verification results. It references related issues, but does not fill in the template’s explicit “Closes: #...”…
Full details: Linked Issues check

Explanation

The directly linked issue [#1527] focuses on async disposal, cleanup ordering, provider shutdown, failure isolation, and lifecycle model coverage. This PR primarily adds dynamic thinking-effort state and disposal reset behavior; it does not implement or demonstrate the issue's core cleanup requirements. The description states that the async disposal work comes from stacked or base changes.

Full details: Out of Scope Changes check

Explanation

The changes include experiment schemas, reasoning-resolution APIs, Stryker configuration, webview settings, visual fixtures, and localization updates. These changes are unrelated to linked issue [#1527] and exceed the stated two-file task-local scope.

Full details: Regression Evidence

Explanation

The new Task request-metadata behavior lacks focused boundary coverage. Task.ts adds the runtime-effort metadata spread at four request paths (lines 1844, 4299, 4527, and 4694), but Task.runtime-thinking-effort.test.ts only invokes the private getRuntimeThinkingEffortMetadata() helper through a cast (lines 286-299). It never invokes attemptApiRequest, condenseContext, manageContext, or createMessage. The existing Task.spec.ts request test checks only metadata.mode (lines 635-643), not reasoningEffort. Removing any new spread would therefore leave the new focused tests passing. The disposal test also checks apiConfiguration but not that the rebuilt api handler receives the restored effort, although the test mock records those rebuild arguments. The experimental settings change does have a Playwright component snapshot, so that requirement is covered.

Resolution

Add focused Task-level tests at the request boundaries. Set a runtime override and assert metadata.reasoningEffort for attemptApiRequest, the normal context-management path, forced context truncation, and condenseContext; also assert that the field is absent after clearing the override. Extend the disposal test to assert the final buildApiHandler call receives the restored settings-derived effort, confirming that the retained api handler does not keep the disposed override.

Full details: Trust And Persistence Invariants

Explanation

The new Task.setRuntimeThinkingEffort path leaks provider lifecycle resources. It replaces this.api with buildApiHandler(...) at src/core/task/Task.ts:1705 without disposing the previous handler. For providerIdentifiers.vscodeLm, the factory creates VsCodeLmHandler (src/api/index.ts:207-208). Each handler registers a vscode.workspace.onDidChangeConfiguration listener (src/api/providers/vscode-lm.ts:78-87) and exposes dispose() to remove it (:188-197), but ApiHandler has no disposal member and Task does not call it. A VS Code LM task that sets, changes, or clears the runtime effort abandons each prior handler and retains its configuration listener. Disposal can also rebuild a handler at Task.ts:2713 and leave that new handler undisposed.

Resolution

Make API-handler replacement lifecycle-safe. Add an optional disposal contract to ApiHandler, dispose the old handler before replacing it in setRuntimeThinkingEffort and updateApiConfiguration, and dispose the final handler during Task.dispose(); alternatively, avoid rebuilding handlers for runtime-only effort changes and pass the validated effort only through request metadata. Preserve the documented no-mid-stream behavior when selecting the replacement strategy.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Required CI passed. Waiting for automated review of the latest commit.

If automated review does not start, a maintainer must restart it.

Review-state labels are managed by this workflow; do not edit them manually. community-approved is managed the same way — do not add or remove it manually. It signals a fresh community code approval for the current head as an advisory priority only; maintainer review is still required.

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Sep 4, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 4, 2026
@github-actions github-actions Bot added awaiting-maintainer CodeRabbit approved; waiting for a human maintainer and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit labels Sep 4, 2026
@github-actions github-actions Bot added has-conflicts PR has merge conflicts with the base branch coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit and removed coderabbit-review-active Required CI passed; CodeRabbit review is active awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit has-conflicts PR has merge conflicts with the base branch labels Oct 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit coderabbit-review-active Required CI passed; CodeRabbit review is active

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants