Skip to content

fix(task): isolate task configuration from focused provider state - #1085

Open
edelauna wants to merge 4 commits into
mainfrom
agent/task-config-isolation
Open

fix(task): isolate task configuration from focused provider state#1085
edelauna wants to merge 4 commits into
mainfrom
agent/task-config-isolation

Conversation

@edelauna

@edelauna edelauna commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

References: #369 (PR 1 of 3)

Description

This is PR 1 of 3 for #369. It prevents a task's mode and API/profile configuration from leaking through shared focused-provider state, while preserving current single-concurrency behavior.

Task now reads mode from getTaskMode() and API configuration from its own apiConfiguration in system-prompt generation, manual and forced context condensing, request construction, and rate-limit/retry-backoff handling. Provider state remains the source for genuinely shared settings such as custom modes, experiments, and profile thresholds.

Profile-change notifications now update only the focused task, preventing a profile change from replacing another live task's API handler/configuration. This is a prerequisite for safe concurrent delegation work, without introducing fan-out scheduling, queues, e2e changes, persistence changes, or extension API changes.

Test Procedure

  • pnpm --dir src exec vitest core/task/__tests__/Task.spec.ts
  • pnpm --dir src exec eslint --prune-suppressions --max-warnings=0 core/task/Task.ts core/task/__tests__/Task.spec.ts
  • pnpm --dir src check-types
  • pnpm --dir src lint

The focused unit coverage verifies task-local mode/API configuration in prompt and request paths, task-local rate limits during retry backoff, and that profile changes update only the focused task.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Visual Snapshot (UI changes only): Not applicable; this PR has no UI changes.
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Visual Snapshots

Not applicable; this PR has no UI changes.

Videos (interaction / animation only)

Not applicable; this PR has no UI changes.

Documentation Updates

  • No documentation updates are required.

Additional Notes

No changeset included; changesets are managed separately.

Get in Touch

Summary by CodeRabbit

  • Bug Fixes
    • Task-specific mode and API settings are now consistently applied when generating prompts, managing context, sending requests, and handling rate limits.
    • Switching modes now takes effect immediately for subsequent requests.
    • Improved retry behavior when requests encounter rate limits or context-window limits.
  • Tests
    • Added coverage to verify task settings remain isolated from unrelated provider settings and are correctly used across requests and retries.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@edelauna, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 73f9c08a-4fbf-4dd1-a2d9-d8e7a931c1d9

📥 Commits

Reviewing files that changed from the base of the PR and between bf2cea1 and aa07009.

📒 Files selected for processing (2)
  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.spec.ts
📝 Walkthrough

Walkthrough

Task operations now use task-owned mode and API configuration for prompts, context handling, request setup, rate limiting, and retries. Provider profile-change listeners were removed. Submitted mode changes update task state immediately, with expanded isolation tests.

Changes

Task configuration flow

Layer / File(s) Summary
Task configuration ownership and lifecycle
src/core/task/Task.ts
submitUserMessage stores the submitted mode on the task. Provider profile-change listener setup, handling, and disposal were removed.
Request-path configuration usage
src/core/task/Task.ts
Context condensation, prompts, mentions, context-window recovery, request setup, rate-limit waits, and retry backoff use task-owned mode and API configuration.
Task-local configuration tests
src/core/task/__tests__/Task.spec.ts
Tests verify task-local prompt, request, condensation, mode submission, rate-limit, and context-window retry behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: jamesrobert20

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: isolating task configuration from focused provider state.
Description check ✅ Passed The description covers the issue, implementation, test procedure, scope, checklist, and documentation impact, with only a minor deviation from the requested issue-link format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/task-config-isolation

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.

@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/task/Task.ts 80.00% 0 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/task/Task.ts`:
- Line 3997: Update setupProviderProfileChangeListener and the
ProviderProfileChanged handling so only the task that explicitly selected the
changed profile updates its task-owned apiConfiguration; prevent focused-task
changes from overwriting unrelated tasks’ API handlers or rate limits. Add a
package-local unit test covering a ProviderProfileChanged event emitted while
this task is not focused and verify its API configuration remains unchanged.
- Around line 4036-4037: Update submitUserMessage to synchronize the task’s
_taskMode immediately after provider.setMode(mode) succeeds, so subsequent
getTaskMode() consumers use the selected mode. Add a package-local unit test
covering a mode switch through submitUserMessage followed by a request,
verifying the updated mode is used.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a7d3c65b-e2c6-4cca-9569-2fa63e26d78d

📥 Commits

Reviewing files that changed from the base of the PR and between 38d7e23 and 1e5ba45.

📒 Files selected for processing (2)
  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.spec.ts

Comment thread src/core/task/Task.ts
Comment thread src/core/task/Task.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/task/__tests__/Task.spec.ts`:
- Around line 530-571: Update the “only applies profile changes to the focused
task” test to dispose both Task instances after assertions, using their
dispose() methods before the test completes. Ensure the shared mockProvider no
longer retains the parent and child profile-change listeners for subsequent
tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e5779997-ce83-47d3-bd7e-71b8bbacbd0c

📥 Commits

Reviewing files that changed from the base of the PR and between 1e5ba45 and 59414bd.

📒 Files selected for processing (2)
  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/task/Task.ts

Comment thread src/core/task/__tests__/Task.spec.ts Outdated
@edelauna
edelauna marked this pull request as ready for review August 1, 2026 16:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/core/task/Task.ts (1)

1510-1518: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Persist the selected provider profile on the task.

After provider.setProviderProfile(providerProfile) succeeds, this code rebuilds api but does not update _taskApiConfigName. saveClineMessages() then persists the prior profile in task metadata. A resumed task can restore the wrong profile.

Set the task API config name from newState.currentApiConfigName, with providerProfile as a fallback. Add a regression test that switches profiles and verifies persisted task metadata.

Proposed fix
 const newState = await provider.getState()
+this.setTaskApiConfigName(newState?.currentApiConfigName ?? providerProfile)
 if (newState?.apiConfiguration) {
   this.updateApiConfiguration(newState.apiConfiguration)
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/task/Task.ts` around lines 1510 - 1518, Update the provider-profile
handling after setProviderProfile in the task flow to assign _taskApiConfigName
from newState.currentApiConfigName, falling back to providerProfile when
unavailable, before persisting task metadata. Add a regression test that
switches profiles and verifies saveClineMessages() persists the selected
profile.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/core/task/Task.ts`:
- Around line 1510-1518: Update the provider-profile handling after
setProviderProfile in the task flow to assign _taskApiConfigName from
newState.currentApiConfigName, falling back to providerProfile when unavailable,
before persisting task metadata. Add a regression test that switches profiles
and verifies saveClineMessages() persists the selected profile.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7808404d-5caa-4a5b-8337-45277dac09dc

📥 Commits

Reviewing files that changed from the base of the PR and between 59414bd and bf2cea1.

📒 Files selected for processing (2)
  • src/core/task/Task.ts
  • src/core/task/__tests__/Task.spec.ts

@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant