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 to prompts, requests, context handling, and rate limits.
    • Mode and provider-profile changes now take effect immediately for subsequent requests.
    • Improved retry behavior for rate-limit and context-window errors.
    • Task behavior is no longer affected by unrelated provider settings.
  • Tests

    • Added coverage confirming task settings remain isolated across requests, prompts, context handling, and retries.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b0649c61-d5e2-4d16-b405-2a63be895ac2

📥 Commits

Reviewing files that changed from the base of the PR and between d0af4c0 and 625a490.

📒 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 (2)
  • src/core/task/tests/Task.spec.ts
  • src/core/task/Task.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 and provider profile changes update task state immediately. Tests cover configuration isolation.

Changes

Task configuration flow

Layer / File(s) Summary
Task configuration ownership and lifecycle
src/core/task/Task.ts
submitUserMessage stores the submitted mode and provider profile 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, provider profile, rate-limit, and context-window retry behavior.

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

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: navedmerchant

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes isolating task configuration from focused provider state.
Description check ✅ Passed The description covers the linked issue, implementation, testing, checklist, documentation, and non-applicable UI sections.
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 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch agent/task-config-isolation
📝 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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/core/task/Task.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/core/task/__tests__/Task.spec.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


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
navedmerchant
navedmerchant previously approved these changes Aug 4, 2026
@edelauna
edelauna added this pull request to the merge queue Aug 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 5, 2026
@edelauna
edelauna force-pushed the agent/task-config-isolation branch from aa07009 to 968b489 Compare August 5, 2026 10:40
@github-actions github-actions Bot removed the awaiting-review PR changes are ready and waiting for maintainer re-review label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions github-actions Bot added the has-conflicts PR has merge conflicts with the base branch label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has-conflicts PR has merge conflicts with the base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants