Fix missing chatStorage config in AICommandExecutor during AI evals#1501
Fix missing chatStorage config in AICommandExecutor during AI evals#1501yasithrashan wants to merge 1 commit intowso2:mainfrom
Conversation
📝 WalkthroughWalkthroughThis change adds defensive guards to the AICommandExecutor class to handle cases where the optional chatStorage parameter may be absent, returning early or providing default values instead of accessing undefined storage. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
workspaces/ballerina/ballerina-extension/src/features/ai/executors/base/AICommandExecutor.ts (1)
42-46:enabledfield is declared but never evaluated — consider honoring it in the guards.The
chatStorageconfig exposes anenabled: booleanflag, but all three guards (and the fallback inrun()) only check forundefined. A caller supplyingchatStorage: { workspaceId, threadId, enabled: false }would bypass the early-return path and still invoke chat storage operations, which is likely unintentional.♻️ Suggested: unify the presence + enabled check into a single helper
+ /** Returns true when chat storage is present and enabled */ + private hasChatStorage(): boolean { + return !!this.config.chatStorage?.enabled; + }Then replace every guard:
- if (!this.config.chatStorage) { + if (!this.hasChatStorage()) {This keeps the three call-sites identical and makes the semantics explicit without changing behavior for callers that currently omit
chatStorageentirely.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@workspaces/ballerina/ballerina-extension/src/features/ai/executors/base/AICommandExecutor.ts` around lines 42 - 46, The guards and fallback in AICommandExecutor.ts currently only check chatStorage for undefined and ignore its enabled flag, so callers with chatStorage.enabled === false still trigger storage flows; add a helper (e.g., isChatStorageEnabled(chatStorage)) that returns false if chatStorage is undefined or chatStorage.enabled is false and replace the three existing undefined checks plus the run() fallback to call this helper (update references to chatStorage in AICommandExecutor methods to use the helper to short-circuit when disabled).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@workspaces/ballerina/ballerina-extension/src/features/ai/executors/base/AICommandExecutor.ts`:
- Around line 42-46: The guards and fallback in AICommandExecutor.ts currently
only check chatStorage for undefined and ignore its enabled flag, so callers
with chatStorage.enabled === false still trigger storage flows; add a helper
(e.g., isChatStorageEnabled(chatStorage)) that returns false if chatStorage is
undefined or chatStorage.enabled is false and replace the three existing
undefined checks plus the run() fallback to call this helper (update references
to chatStorage in AICommandExecutor methods to use the helper to short-circuit
when disabled).
Purpose
Resolves a crash when running the Ballerina Extension AI evals (
AI Testsuite).chatStorageis not configured in the eval environment, causingAICommandExecutorto throw aTypeErrorduring initialization and preventing all eval test cases from running.Error:
Goals
Make
chatStorageoptional inAICommandExecutorso AI evals can run successfully without requiring chat storage to be configured.Approach
Added null-guard checks in
initializeWorkspaceThread,getChatHistory, andaddGeneration. Each method now returns a safe default (void,[], ornull) ifthis.config.chatStorageis undefined, instead of attempting to destructure it.Summary by CodeRabbit
Bug Fixes