fix(insights): validate localStorage model values and tighten fallback condition

- Guard against malformed localStorage values (e.g. "provider/") by
  validating both parts are non-empty before sending to the server
- Only wire settings fallback when both provider AND modelId are
  explicitly provided, preventing mismatched provider/modelId combos

Addresses ISSUE-002 and ISSUE-003 from code quality review.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Timothy Laurent
2026-05-06 08:01:05 -07:00
parent 4f674f2085
commit 41af820f1d
2 changed files with 9 additions and 4 deletions

View File

@@ -138,8 +138,12 @@ export function InsightsView({ projectId, addToast, onClose, onCreateTask, model
if (selectedModel) {
const slashIdx = selectedModel.indexOf("/");
if (slashIdx !== -1) {
modelProvider = selectedModel.slice(0, slashIdx);
modelId = selectedModel.slice(slashIdx + 1);
const provider = selectedModel.slice(0, slashIdx);
const id = selectedModel.slice(slashIdx + 1);
if (provider && id) {
modelProvider = provider;
modelId = id;
}
}
}

View File

@@ -130,8 +130,9 @@ async function executeInsightAttempt(params: {
const finalProvider = params.modelProvider ?? settingsProvider;
const finalModelId = params.modelId ?? settingsModelId;
const fallbackProvider = params.modelProvider ? settingsProvider : undefined;
const fallbackModelId = params.modelProvider ? settingsModelId : undefined;
const hasCustomModel = params.modelProvider && params.modelId;
const fallbackProvider = hasCustomModel ? settingsProvider : undefined;
const fallbackModelId = hasCustomModel ? settingsModelId : undefined;
const existingInsights = await readInsightsMemory(params.rootDir);
let responseText = "";