@@ -217,11 +217,17 @@ public void processTurnEvent(ChatProgressValue value) {
217217 errMsg = Messages .chat_model_unsupported_message ;
218218 }
219219 if (StringUtils .isNotEmpty (errMsg )) {
220- // TODO: remove this error message replacement if statement when the CLS side warn message is aligned.
221- if (value .getCode () == 402 ) {
220+ // Check once whether we're already on the fallback model
221+ CopilotModel fallback = this .serviceManager .getModelService ().getFallbackModel ();
222+ CopilotModel current = this .serviceManager .getModelService ().getActiveModel ();
223+ boolean alreadyOnFallback = fallback != null && current != null
224+ && fallback .getModelName ().equals (current .getModelName ());
225+
226+ // Only replace the error message with "switched to fallback" when we're NOT already
227+ // on the fallback model. When already on fallback, show the original CLS message.
228+ if (value .getCode () == 402 && !alreadyOnFallback ) {
222229 CopilotPlan userPlan = this .serviceManager .getAuthStatusManager ().getQuotaStatus ().copilotPlan ();
223- CopilotModel fallbackModel = this .serviceManager .getModelService ().getFallbackModel ();
224- String fallbackModelName = fallbackModel != null ? fallbackModel .getModelName ()
230+ String fallbackModelName = fallback != null ? fallback .getModelName ()
225231 : Messages .chat_noQuotaView_fallbackModel ;
226232
227233 if (MenuUtils .isCfiPlan (userPlan )) {
@@ -235,15 +241,19 @@ public void processTurnEvent(ChatProgressValue value) {
235241
236242 renderWarnMessageWithUpgradePlanButton (errMsg , value .getCode ());
237243
238- if (value .getCode () == 402
244+ // Switch to fallback model and auto-retry, but only if not already on the fallback model
245+ // to avoid an infinite loop of 402 → switch → resend → 402 → ...
246+ if (value .getCode () == 402 && !alreadyOnFallback
239247 && this .serviceManager .getAuthStatusManager ().getQuotaStatus ().copilotPlan () != CopilotPlan .free ) {
240248 this .serviceManager .getModelService ().setFallBackModelAsActiveModel ();
241249 this .serviceManager .getAuthStatusManager ().checkQuota ();
242250
243- String previousInput = this .serviceManager .getUserPreferenceService ().getPreviousInput (StringUtils .EMPTY );
251+ String previousInput =
252+ this .serviceManager .getUserPreferenceService ().getPreviousInput (StringUtils .EMPTY );
244253 if (StringUtils .isNotEmpty (previousInput )) {
245254 IEventBroker eventBroker = PlatformUI .getWorkbench ().getService (IEventBroker .class );
246- Map <String , Object > properties = Map .of ("previousInput" , previousInput , "needCreateUserTurn" , false );
255+ Map <String , Object > properties =
256+ Map .of ("previousInput" , previousInput , "needCreateUserTurn" , false );
247257 eventBroker .post (CopilotEventConstants .TOPIC_CHAT_ON_SEND , properties );
248258 }
249259 }
0 commit comments