Skip to content

fix: handle activateProviderProfile errors gracefully during mode switch#12099

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/mode-switch-error-handling-12098
Draft

fix: handle activateProviderProfile errors gracefully during mode switch#12099
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/mode-switch-error-handling-12098

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 bot commented Apr 12, 2026

Related GitHub Issue

Closes: #12098

Description

This PR attempts to address Issue #12098, where a user reported issues when switching modes (code to architect) with a proxy-based provider (agentrouter).

Root cause: In handleModeSwitch, if activateProviderProfile fails during a mode switch, the error propagates up unhandled. At that point the mode has already been updated in both memory (task._taskMode) and global state, but the API configuration has not been switched to the new mode's profile. This leaves the system in an inconsistent state where the UI shows the new mode but the API handler still uses the old configuration.

Fix: Wrap the activateProviderProfile call in handleModeSwitch with a try-catch. If profile activation fails (e.g. due to corrupted profile data, proxy provider configuration issues, or network errors), the mode switch completes gracefully and the task continues with the current API configuration. The error is logged for diagnostics.

Test Procedure

  • Added a new test case: "should complete mode switch gracefully when activateProviderProfile fails"
  • The test mocks activateProviderProfile to throw an error and verifies:
    • The mode switch completes without throwing
    • The task mode is updated to the new mode
    • The global state reflects the new mode
  • All 20 tests in the sticky-mode spec pass (19 existing + 1 new)
  • All existing API handler rebuild tests pass (10 tests)
  • Full lint and type-check pass across all packages

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.
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The user's original connection error was resolved by using a new API key. The mode-switching issue they reported was vague ("some other issue while changing mode from code to architect"), but this fix addresses the most likely root cause: unhandled errors during provider profile activation when switching modes. Feedback and guidance are welcome.

Interactively review PR in Roo Code Cloud

When switching modes, if activateProviderProfile fails (e.g. due to
corrupted profile data or proxy provider configuration issues), the
error would propagate up and leave the mode in an inconsistent state -
the mode was already updated in memory and global state, but the API
configuration was not switched.

This wraps the activateProviderProfile call in handleModeSwitch with
a try-catch so the mode switch completes gracefully, falling back to
the current API configuration. The error is logged for diagnostics.

Closes #12098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Proxy based provider

1 participant