Skip to content

Conversation

@VellummyilumVinoth
Copy link
Contributor

@VellummyilumVinoth VellummyilumVinoth commented Dec 1, 2025

Description

It resolves: wso2/product-ballerina-integrator#2031

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email [email protected] to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

UI Component Development

Specify the reason if following are not followed.

  • Added reusable UI components to the ui-toolkit. Follow the intructions when adding the componenent.
  • Use ui-toolkit components wherever possible. Run npm run storybook from the root directory to view current components.
  • Matches with the native VSCode look and feel.

Manage Icons

Specify the reason if following are not followed.

  • Added Icons to the font-wso2-vscode. Follow the instructions.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to [email protected] and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • Bug Fixes
    • Gracefully stop AI-driven mapping flows and show a clear user warning when no mappings are produced, preventing subsequent code generation or repair steps and avoiding downstream errors.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

Walkthrough

The PR adds three defensive guards in the AI datamapper to detect empty LLM-generated mappings, emit a user-facing warning, stop DataMap processing, and return early to prevent further repair or generation steps.

Changes

Cohort / File(s) Summary
AI Datamapper Empty Mapping Guards
workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts
Added a NO_MAPPINGS_GENERATED_WARNING constant and three early-return guards in generateMappingCodeCore and generateInlineMappingCodeCore to emit the warning, stop DataMap, and return when the LLM returns no mappings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Areas to check:
    • Correct placement of early returns so necessary cleanup/state transitions still occur.
    • Consistency and clarity of the warning content string.
    • No missing telemetry/logging for the new stop events.

Possibly related PRs

Suggested reviewers

  • hevayo
  • gigara

Poem

🐇 I hopped to map, but found no thread,
So I whispered a warning and rested my head.
No timeout tumble, no frantic race—
A gentle stop, with a rabbit's grace. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete. While it references the linked issue, critical sections like Goals, Approach, Release note, and test coverage contain only template placeholders without substantive content. Complete the Goals, Approach, Release note, automation tests, and test environment sections with specific implementation details and testing information.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing a crash when the LLM returns no mappings in AI Datamapper.
Linked Issues check ✅ Passed The code changes directly address the linked issue by adding null/empty-mapping checks with user-facing warnings, preventing crashes and timeouts as required.
Out of Scope Changes check ✅ Passed All changes are scoped to handling empty mappings in the datamapper service, which is directly aligned with the linked issue requirements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dfd8e1 and 2172e21.

📒 Files selected for processing (1)
  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts (1)

710-721: LGTM! Inline mapping path is now protected from the crash.

The guard correctly handles the empty mappings scenario for inline code generation, matching the pattern used in generateMappingCodeCore.

Consider extracting the warning message into a shared constant to eliminate duplication:

const NO_MAPPINGS_WARNING = `**No Relevant Mappings Generated**\n\n` +
    `The AI was unable to identify compatible field mappings between the input and output structures.\n\n` +
    `**Suggestions:**\n` +
    `- Check if input and output record structures are correct\n` +
    `- Try providing mapping hints or examples\n`;

Then use it at both lines 351 and 718:

-    const warningMessage = `**No Relevant Mappings Generated**\n\n` +
-        `The AI was unable to identify compatible field mappings between the input and output structures.\n\n` +
-        `**Suggestions:**\n` +
-        `- Check if input and output record structures are correct\n` +
-        `- Try providing mapping hints or examples\n`;
-
-    eventHandler({ type: "content_block", content: warningMessage });
+    eventHandler({ type: "content_block", content: NO_MAPPINGS_WARNING });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba5b5a7 and 3dfd8e1.

📒 Files selected for processing (1)
  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2025-11-26T06:37:07.886Z
Learnt from: KCSAbeywickrama
Repo: wso2/vscode-extensions PR: 653
File: workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/dm-data/array-inner/inline/map3.bal.txt:6-8
Timestamp: 2025-11-26T06:37:07.886Z
Learning: In workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/dm-data/ directories, BAL test data files (such as those in array-inner/inline/, array-root/inline/, basic/inline/, and their reusable counterparts) may intentionally contain type errors and other violations. These are comparison files used to test data mapper functionality and error handling, so such errors should not be flagged as issues.

Applied to files:

  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts
📚 Learning: 2025-11-26T06:35:19.217Z
Learnt from: KCSAbeywickrama
Repo: wso2/vscode-extensions PR: 653
File: workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts:173-178
Timestamp: 2025-11-26T06:35:19.217Z
Learning: In workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts, the commented-out debugging block in the verifyFileContent function (lines 172-177 containing console.log, page.pause, and updateDataFileSync) is intentionally kept as a developer utility for updating test data files when needed. It should not be removed.

Applied to files:

  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts
📚 Learning: 2025-11-26T06:34:09.752Z
Learnt from: KCSAbeywickrama
Repo: wso2/vscode-extensions PR: 653
File: workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts:128-134
Timestamp: 2025-11-26T06:34:09.752Z
Learning: In workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts, the goPrevViewBreadcrumb() method is only called when in a focused view, ensuring breadcrumbs are always present. No guard for empty breadcrumbs is needed.

Applied to files:

  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts
📚 Learning: 2025-11-26T07:49:56.428Z
Learnt from: KCSAbeywickrama
Repo: wso2/vscode-extensions PR: 653
File: workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts:136-141
Timestamp: 2025-11-26T07:49:56.428Z
Learning: In workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts, the goPrevViewBackButton() method is only called when in a focused view, ensuring breadcrumbs are always present. No guard for empty breadcrumbs is needed.

Applied to files:

  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts
📚 Learning: 2025-11-26T06:33:22.950Z
Learnt from: KCSAbeywickrama
Repo: wso2/vscode-extensions PR: 653
File: workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts:86-112
Timestamp: 2025-11-26T06:33:22.950Z
Learning: In workspaces/bi/bi-extension/src/test/e2e-playwright-tests/data-mapper/DataMapperUtils.ts, empty catch blocks around progress ring waitForSelector calls (state: 'attached' and 'detached') are intentional. The progress ring duration depends on machine performance and may appear very briefly, causing the wait to miss the event. The try-catch allows the test to proceed gracefully regardless of timing.

Applied to files:

  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts
🔇 Additional comments (1)
workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts (1)

343-354: LGTM! Crash prevention guard is correctly implemented.

The early-return guard successfully prevents the operation timeout crash by handling empty mapping results gracefully before attempting to update source code. The warning message is user-friendly and provides actionable suggestions.

One minor note: verify that the temporary directory created at line 323 is cleaned up appropriately when this early return path is taken. Confirm this is handled by a cleanup mechanism elsewhere (such as a try/finally block or resource cleanup handler) to avoid potential resource leaks.

@kanushka kanushka merged commit 86b7a53 into wso2:main Dec 1, 2025
6 checks passed
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.

[AI Datamapper] Crashes with *operation timeout* when LLM returns no mappings

3 participants