Skip to content

Comments

[BI] Resolve listener configuration change crashing BI issue#1541

Open
samithkavishke wants to merge 1 commit intowso2:release/bi-1.8.xfrom
samithkavishke:issue-2533
Open

[BI] Resolve listener configuration change crashing BI issue#1541
samithkavishke wants to merge 1 commit intowso2:release/bi-1.8.xfrom
samithkavishke:issue-2533

Conversation

@samithkavishke
Copy link
Contributor

@samithkavishke samithkavishke commented Feb 24, 2026

Purpose

Fixes: wso2/product-ballerina-integrator#2533

Goals

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

Approach

Refetch the listener position and data if only the listener changes.

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

BICrashingWhenListenerChange.mov

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 certification@wso2.com 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
    • Improved position tracking and synchronization in service configuration to ensure consistency after listener changes and configuration updates.
    • Enhanced handling of service identifiers during save operations to maintain data accuracy across modifications.

@samithkavishke samithkavishke changed the title Resolve listener configuration change crashing BI issue [BI] Resolve listener configuration change crashing BI issue Feb 24, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

The ServiceConfigureView component now manages position state locally instead of relying solely on props, synchronizing it across service fetch, listener detachment, save operations, and listener changes. A new refreshServicePosition helper was added to recompute position from the project structure based on the current service identifier.

Changes

Cohort / File(s) Summary
Position State Management
workspaces/ballerina/ballerina-visualizer/src/views/BI/ServiceDesigner/ServiceConfigureView.tsx
Introduced local NodePosition state initialized from props; updated position state after listener detachment and service save operations; added refreshServicePosition helper to recompute position from project structure; adjusted effect dependencies and save flow to keep position synchronized across service and listener updates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through position flows,
Where state and props now harmonize,
Position tracked from tip to toes,
Refreshed when listeners need reprise!
*bounce bounce* ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The pull request description is incomplete. While it includes the Purpose (linking to issue #2533) and a brief Approach, most required sections are either missing concrete details or left as empty templates. Complete the following sections: Goals (explain the solution), Release note, Documentation (specify doc impact or 'N/A' with explanation), and clarify if Security checks, Automation tests, and other sections apply to this change.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main bug fix of resolving a listener configuration change crash in the BI (Ballerina Integrator) component.
Linked Issues check ✅ Passed The code changes address the crash by adding position state management and listener change handling, which aligns with preventing crashes during variable addition [#2528].
Out of Scope Changes check ✅ Passed All changes are focused on fixing the listener configuration crash through position state management and refresh logic, with no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@LakshanWeerasinghe
Copy link
Contributor

Did you try adding an annotation to http service via the config panel?

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
workspaces/ballerina/ballerina-visualizer/src/views/BI/ServiceDesigner/ServiceConfigureView.tsx (1)

217-301: ⚠️ Potential issue | 🟠 Major

Sync position state with props and use it consistently

position now drives fetchService, but it never updates when props.position changes, and some consumers still read props.position (e.g., ServiceEditView). This can leave edits/saves targeting stale line ranges when the parent navigates to another service or after listener-only updates, which risks the same crash you’re trying to avoid.

🔧 Suggested fix
 const [position, setPosition] = useState<NodePosition>(props.position);
 
+useEffect(() => {
+    setPosition(props.position);
+}, [props.position]);
+
 useEffect(() => {
     fetchService(position);
 }, [position]);

Also switch remaining props.position usages that should track the refreshed state (e.g., ServiceEditView position={position} and the fallback position inside setServiceListeners).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/ServiceDesigner/ServiceConfigureView.tsx`
around lines 217 - 301, The component's local state position is not kept in sync
with props.position, causing fetchService (and consumers like ServiceEditView
and setServiceListeners) to operate on stale ranges; update the component to
sync state when props.position changes (e.g., useEffect watching props.position
to call setPosition), then replace remaining direct uses of props.position with
the synchronized position state (notably where fetchService, ServiceEditView
position={...}, and the fallback in setServiceListeners are used) so all readers
use the current position value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/ServiceDesigner/ServiceConfigureView.tsx`:
- Around line 700-723: In refreshServicePosition, guard against entryPoint being
undefined and against a missing optional position before calling setPosition to
avoid breaking fetchService: after locating entryPoint with .find(...) check if
entryPoint exists and if entryPoint.position is defined, otherwise log a clear
error (or return early) and do not call setPosition; update the function around
the entryPoint lookup (symbols: refreshServicePosition, entryPoint, setPosition,
ProjectStructureArtifactResponse.position, fetchService) to handle both cases
safely.

---

Outside diff comments:
In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/ServiceDesigner/ServiceConfigureView.tsx`:
- Around line 217-301: The component's local state position is not kept in sync
with props.position, causing fetchService (and consumers like ServiceEditView
and setServiceListeners) to operate on stale ranges; update the component to
sync state when props.position changes (e.g., useEffect watching props.position
to call setPosition), then replace remaining direct uses of props.position with
the synchronized position state (notably where fetchService, ServiceEditView
position={...}, and the fallback in setServiceListeners are used) so all readers
use the current position value.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebf8a66 and 6615d3d.

📒 Files selected for processing (1)
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/ServiceDesigner/ServiceConfigureView.tsx

Comment on lines +700 to +723
const refreshServicePosition = async () => {
if (!currentIdentifier) {
console.error("No current identifier available for refreshing service position");
return;
}

try {
const projectStructureResponse = await rpcClient.getBIDiagramRpcClient().getProjectStructure();
const project = projectStructureResponse.projects.find(p => p.projectPath === props.projectPath);

if (!project) {
console.error("Project not found in structure response");
return;
}

const entryPoint = project
.directoryMap[DIRECTORY_MAP.SERVICE]
.find((service: ProjectStructureArtifactResponse) => service.name === currentIdentifier);

setPosition(entryPoint.position);
} catch (error) {
console.error('Error refreshing service position:', error);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard against missing service entry/position in refreshServicePosition

ProjectStructureArtifactResponse.position is optional, and .find(...) can return undefined. As written, setPosition(entryPoint.position) can throw or set undefined, which will break fetchService.

🛡️ Suggested fix
-        const entryPoint = project
-            .directoryMap[DIRECTORY_MAP.SERVICE]
-            .find((service: ProjectStructureArtifactResponse) => service.name === currentIdentifier);
-        
-        setPosition(entryPoint.position);
+        const services = project.directoryMap?.[DIRECTORY_MAP.SERVICE] ?? [];
+        const entryPoint = services.find(
+            (service: ProjectStructureArtifactResponse) => service.name === currentIdentifier
+        );
+
+        if (!entryPoint?.position) {
+            console.error("Service position not found for", currentIdentifier);
+            return;
+        }
+        setPosition(entryPoint.position);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const refreshServicePosition = async () => {
if (!currentIdentifier) {
console.error("No current identifier available for refreshing service position");
return;
}
try {
const projectStructureResponse = await rpcClient.getBIDiagramRpcClient().getProjectStructure();
const project = projectStructureResponse.projects.find(p => p.projectPath === props.projectPath);
if (!project) {
console.error("Project not found in structure response");
return;
}
const entryPoint = project
.directoryMap[DIRECTORY_MAP.SERVICE]
.find((service: ProjectStructureArtifactResponse) => service.name === currentIdentifier);
setPosition(entryPoint.position);
} catch (error) {
console.error('Error refreshing service position:', error);
}
};
const refreshServicePosition = async () => {
if (!currentIdentifier) {
console.error("No current identifier available for refreshing service position");
return;
}
try {
const projectStructureResponse = await rpcClient.getBIDiagramRpcClient().getProjectStructure();
const project = projectStructureResponse.projects.find(p => p.projectPath === props.projectPath);
if (!project) {
console.error("Project not found in structure response");
return;
}
const services = project.directoryMap?.[DIRECTORY_MAP.SERVICE] ?? [];
const entryPoint = services.find(
(service: ProjectStructureArtifactResponse) => service.name === currentIdentifier
);
if (!entryPoint?.position) {
console.error("Service position not found for", currentIdentifier);
return;
}
setPosition(entryPoint.position);
} catch (error) {
console.error('Error refreshing service position:', error);
}
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/ServiceDesigner/ServiceConfigureView.tsx`
around lines 700 - 723, In refreshServicePosition, guard against entryPoint
being undefined and against a missing optional position before calling
setPosition to avoid breaking fetchService: after locating entryPoint with
.find(...) check if entryPoint exists and if entryPoint.position is defined,
otherwise log a clear error (or return early) and do not call setPosition;
update the function around the entryPoint lookup (symbols:
refreshServicePosition, entryPoint, setPosition,
ProjectStructureArtifactResponse.position, fetchService) to handle both cases
safely.

@samithkavishke
Copy link
Contributor Author

Did you try adding an annotation to http service via the config panel?

There are multiple related issues in the http service configuration which will be addressed here wso2/product-ballerina-integrator#2568

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.

2 participants