Skip to content

Add nodeActivity - #1016

Open
ayolab wants to merge 4 commits into
mainfrom
ayolab/add-node-activity
Open

Add nodeActivity#1016
ayolab wants to merge 4 commits into
mainfrom
ayolab/add-node-activity

Conversation

@ayolab

@ayolab ayolab commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR replaces blocked-node state with local and shared activity statuses persisted in the database. Activity guards now coordinate tree writes, builds, unbuilds, computations, notifications, REST endpoints, rebuild workflows, and asynchronous cleanup.

Changes

Node activity contracts and persistence

Layer / File(s) Summary
Activity contracts and database migration
src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/*, src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/*, src/main/java/org/gridsuite/study/server/dto/*, src/main/resources/db/changelog/*
Adds local/shared activity types and fields, removes blocked/building-state contracts, updates invalidation parameters, and migrates persisted columns.
Activity repositories and notifications
src/main/java/org/gridsuite/study/server/repository/*, src/main/java/org/gridsuite/study/server/notification/NotificationService.java, src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java
Adds conditional activity acquisition, release, cross-root activity lookup, and activity update notifications.
Scoped guard and tree resolution
src/main/java/org/gridsuite/study/server/service/NodeActivityGuardService.java, src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
Adds SELF, ANCESTORS, and BRANCH activity scopes, guarded execution and async release behavior, plus updated node traversal and DTO activity completion.
Study and rebuild workflows
src/main/java/org/gridsuite/study/server/service/StudyService.java, src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java, src/main/java/org/gridsuite/study/server/service/SupervisionService.java
Routes updates, builds, computations, modifications, and rebuilds through activity guards while removing direct block/unblock cleanup.
REST endpoints and asynchronous cleanup
src/main/java/org/gridsuite/study/server/controller/StudyController.java, src/main/java/org/gridsuite/study/server/service/ConsumerService.java
Guards tree writes and computation endpoints, applies idle/read-only checks, and clears activity after build, import, and computation events.

Suggested reviewers: meklo

Sequence Diagram(s)

sequenceDiagram
  participant StudyController
  participant NodeActivityGuardService
  participant StudyService
  participant ConsumerService
  StudyController->>NodeActivityGuardService: acquire activity for write or computation
  NodeActivityGuardService->>StudyService: execute guarded operation
  StudyService-->>ConsumerService: computation completion or failure
  ConsumerService->>NodeActivityGuardService: release local activity
  NodeActivityGuardService-->>StudyController: return operation result
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided, so its relevance can't be meaningfully assessed. Add a brief description of the node-activity changes and affected components.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: introducing node activity handling across services, DTOs, repositories, and migrations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch ayolab/add-node-activity

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
src/main/resources/db/changelog/db.changelog-master.yaml

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


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.

@ayolab ayolab added the WIP label Jul 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/java/org/gridsuite/study/server/service/StudyService.java (1)

1770-1782: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

getBuildInfos/setModificationReports run after BUILDING is set but outside the try.

If getBuildInfos or setModificationReports throws, clearNodeActivity is not invoked. DB state reverts via the caller's transaction, but the BUILDING activity-status notification emitted by setNodeActivity is not rolled back, so clients can be left seeing a stuck BUILDING state. Consider extending the try to cover these steps.

♻️ Suggested scope widening
         setNodeActivity(studyUuid, rootNetworkUuid, nodeUuid, NodeActivityStatus.BUILDING);
-        BuildInfos buildInfos = networkModificationTreeService.getBuildInfos(nodeUuid, rootNetworkUuid);
-
-        // Store all reports (inherited + new) for this node
-        networkModificationTreeService.setModificationReports(nodeUuid, rootNetworkUuid, buildInfos.getAllReportsAsMap());
         try {
+            BuildInfos buildInfos = networkModificationTreeService.getBuildInfos(nodeUuid, rootNetworkUuid);
+            // Store all reports (inherited + new) for this node
+            networkModificationTreeService.setModificationReports(nodeUuid, rootNetworkUuid, buildInfos.getAllReportsAsMap());
             networkModificationService.buildNode(nodeUuid, rootNetworkUuid, buildInfos, workflowInfos);
         } catch (Exception e) {
             clearNodeActivity(studyUuid, rootNetworkUuid, nodeUuid);
             throw e;
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java` around
lines 1770 - 1782, The node activity can get stuck in BUILDING because
getBuildInfos and setModificationReports run after setNodeActivity but outside
the guarded failure path. Move the build-info retrieval and modification-report
update into the same try/catch used around networkModificationService.buildNode
in StudyService so any exception triggers clearNodeActivity. Keep the existing
cleanup logic in the catch and make sure the BUILDING status is only emitted
once the whole build preparation and execution flow is safely covered.
src/main/java/org/gridsuite/study/server/dto/InvalidateNodeTreeParameters.java (1)

21-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Declare these shared presets as final.

These are public shared constant instances but are only static, so they can be accidentally reassigned by any caller, silently corrupting invalidation behavior everywhere. Mark them final.

♻️ Proposed change
-    public static InvalidateNodeTreeParameters ALL = new InvalidateNodeTreeParameters(InvalidationMode.ALL, ComputationsInvalidationMode.ALL);
+    public static final InvalidateNodeTreeParameters ALL = new InvalidateNodeTreeParameters(InvalidationMode.ALL, ComputationsInvalidationMode.ALL);
     `@SuppressWarnings`("checkstyle:AbbreviationAsWordInName")
-    public static InvalidateNodeTreeParameters ONLY_CHILDREN = new InvalidateNodeTreeParameters(InvalidationMode.ONLY_CHILDREN, ComputationsInvalidationMode.ALL);
+    public static final InvalidateNodeTreeParameters ONLY_CHILDREN = new InvalidateNodeTreeParameters(InvalidationMode.ONLY_CHILDREN, ComputationsInvalidationMode.ALL);
     `@SuppressWarnings`("checkstyle:AbbreviationAsWordInName")
-    public static InvalidateNodeTreeParameters ONLY_CHILDREN_BUILD_STATUS = new InvalidateNodeTreeParameters(InvalidationMode.ONLY_CHILDREN_BUILD_STATUS, ComputationsInvalidationMode.ALL);
+    public static final InvalidateNodeTreeParameters ONLY_CHILDREN_BUILD_STATUS = new InvalidateNodeTreeParameters(InvalidationMode.ONLY_CHILDREN_BUILD_STATUS, ComputationsInvalidationMode.ALL);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/org/gridsuite/study/server/dto/InvalidateNodeTreeParameters.java`
around lines 21 - 25, The shared preset instances in
InvalidateNodeTreeParameters are mutable static fields, so they can be
reassigned by callers; make ALL, ONLY_CHILDREN, and ONLY_CHILDREN_BUILD_STATUS
final to treat them as true constants. Update the field declarations in
InvalidateNodeTreeParameters so these public presets cannot be reassigned,
keeping the existing initialization with InvalidationMode and
ComputationsInvalidationMode unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 3244-3246: The modification notification flow in StudyService is
unbalanced because setNodeActivity(...) can throw after
emitStartModificationEquipmentNotification() but before the try/finally block
starts, leaving the UI stuck in MODIFICATIONS_UPDATING_IN_PROGRESS. Reorder the
logic in the same method so the UPDATING state is set before emitting the start
notification, then keep the existing try/finally cleanup with
emitEndModificationEquipmentNotification() and clearNodeActivity() to guarantee
the start/end pair always matches.

---

Nitpick comments:
In
`@src/main/java/org/gridsuite/study/server/dto/InvalidateNodeTreeParameters.java`:
- Around line 21-25: The shared preset instances in InvalidateNodeTreeParameters
are mutable static fields, so they can be reassigned by callers; make ALL,
ONLY_CHILDREN, and ONLY_CHILDREN_BUILD_STATUS final to treat them as true
constants. Update the field declarations in InvalidateNodeTreeParameters so
these public presets cannot be reassigned, keeping the existing initialization
with InvalidationMode and ComputationsInvalidationMode unchanged.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 1770-1782: The node activity can get stuck in BUILDING because
getBuildInfos and setModificationReports run after setNodeActivity but outside
the guarded failure path. Move the build-info retrieval and modification-report
update into the same try/catch used around networkModificationService.buildNode
in StudyService so any exception triggers clearNodeActivity. Keep the existing
cleanup logic in the catch and make sure the BUILDING status is only emitted
once the whole build preparation and execution flow is safely covered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e65c8fcc-dcc3-45b9-b0e4-0dbf2f83a195

📥 Commits

Reviewing files that changed from the base of the PR and between a76a79c and 525254e.

📒 Files selected for processing (18)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/dto/InvalidateNodeTreeParameters.java
  • src/main/java/org/gridsuite/study/server/dto/RootNetworkNodeInfo.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/BuildStatus.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/NetworkModificationNode.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/NodeActivityStatus.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/NodeBuildStatus.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java
  • src/main/java/org/gridsuite/study/server/notification/NotificationService.java
  • src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkNodeInfoRepository.java
  • src/main/java/org/gridsuite/study/server/service/ConsumerService.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
  • src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/main/java/org/gridsuite/study/server/service/SupervisionService.java
  • src/main/resources/db/changelog/changesets/changelog_20260703T120000Z.xml
  • src/main/resources/db/changelog/db.changelog-master.yaml
💤 Files with no reviewable changes (2)
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/NodeBuildStatus.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/BuildStatus.java

Comment thread src/main/java/org/gridsuite/study/server/service/StudyService.java Outdated
ayolab added 2 commits July 13, 2026 07:04
Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>
Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (2)
src/main/java/org/gridsuite/study/server/controller/StudyController.java (1)

1706-1715: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

TOCTOU between the build-status check and the guarded unbuild.

getNodeBuildStatus(...).isBuilt() is read outside the activity guard, and the guard is only acquired if that read was true. A concurrent build/unbuild between the check and the guard acquisition can make this decision stale — either skipping an unbuild that should now happen, or acquiring the guard for a node that's already been unbuilt.

🐛 Proposed fix: move the check inside the guarded action
-        if (networkModificationTreeService.getNodeBuildStatus(nodeUuid, rootNetworkUuid).isBuilt()) {
-            nodeActivityGuardService.runGuarded(studyUuid, List.of(rootNetworkUuid), List.of(nodeUuid), NodeActivityCheckScope.SELF, NodeActivityStatus.UPDATING,
-                () -> studyService.unbuildStudyNode(studyUuid, nodeUuid, rootNetworkUuid, userId));
-        }
+        nodeActivityGuardService.runGuarded(studyUuid, List.of(rootNetworkUuid), List.of(nodeUuid), NodeActivityCheckScope.SELF, NodeActivityStatus.UPDATING,
+            () -> {
+                if (networkModificationTreeService.getNodeBuildStatus(nodeUuid, rootNetworkUuid).isBuilt()) {
+                    studyService.unbuildStudyNode(studyUuid, nodeUuid, rootNetworkUuid, userId);
+                }
+                return null;
+            });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/study/server/controller/StudyController.java`
around lines 1706 - 1715, Move the getNodeBuildStatus(nodeUuid,
rootNetworkUuid).isBuilt() check into the action passed to
nodeActivityGuardService.runGuarded in unbuildNode, and invoke unbuildStudyNode
only when the status is built. Always acquire the guard before evaluating the
status, preserving the existing response behavior.
src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java (1)

186-203: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Keep UPDATING held through the rebuild trigger The runGuarded scope ends before the buildNode loop starts, so another request can slip in after UPDATING is cleared but before the rebuild call acquires its own BUILDING activity. Move the loop inside the guarded action or wrap it in a second guard.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java`
around lines 186 - 203, Keep the node rebuild trigger within the activity guard
in the method containing runGuarded: move the rootNetworkUuidsByNodeBuilt
buildNode loop into the action executed by nodeActivityGuardService.runGuarded,
or apply a second guard covering that loop. Ensure NodeActivityStatus.UPDATING
remains held until all studyService.buildNode calls have been initiated.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/org/gridsuite/study/server/service/NodeActivityGuardService.java`:
- Around line 40-56: Update acquireActivity to catch the broader unchecked
failures that can arise from setNodeActivity, while preserving the original
exception for propagation. During rollback over acquired root networks, handle
clearNodeActivity failures without replacing the original error, such as by
suppressing them on the caught exception.

---

Outside diff comments:
In `@src/main/java/org/gridsuite/study/server/controller/StudyController.java`:
- Around line 1706-1715: Move the getNodeBuildStatus(nodeUuid,
rootNetworkUuid).isBuilt() check into the action passed to
nodeActivityGuardService.runGuarded in unbuildNode, and invoke unbuildStudyNode
only when the status is built. Always acquire the guard before evaluating the
status, preserving the existing response behavior.

In `@src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java`:
- Around line 186-203: Keep the node rebuild trigger within the activity guard
in the method containing runGuarded: move the rootNetworkUuidsByNodeBuilt
buildNode loop into the action executed by nodeActivityGuardService.runGuarded,
or apply a second guard covering that loop. Ensure NodeActivityStatus.UPDATING
remains held until all studyService.buildNode calls have been initiated.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14f15bed-eda9-4c90-b28b-5a30a79693a4

📥 Commits

Reviewing files that changed from the base of the PR and between 525254e and b2fcdf6.

📒 Files selected for processing (7)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/NodeActivityCheckScope.java
  • src/main/java/org/gridsuite/study/server/service/ConsumerService.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
  • src/main/java/org/gridsuite/study/server/service/NodeActivityGuardService.java
  • src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java

Comment thread src/main/java/org/gridsuite/study/server/service/NodeActivityGuardService.java Outdated
Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (1)
src/main/java/org/gridsuite/study/server/service/ConsumerService.java (1)

495-506: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Clear calculation activity in a finally block.

handleClearNodeActivity(...) runs only after the result UUID update succeeds. If that database update or earlier result processing throws, the local activity remains set and can permanently block subsequent operations. Wrap the result handling in try/finally and release the activity for the parsed receiver.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/study/server/service/ConsumerService.java` around
lines 495 - 506, Update the result-processing flow around the computation/result
UUID updates so handleClearNodeActivity is invoked from a finally block,
ensuring cleanup even when result processing or database updates throw. Use the
parsed receiver object and resolve the study UUID needed for cleanup within the
protected flow, while preserving the existing LOAD_FLOW and other computation
update behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/main/java/org/gridsuite/study/server/service/ConsumerService.java`:
- Around line 495-506: Update the result-processing flow around the
computation/result UUID updates so handleClearNodeActivity is invoked from a
finally block, ensuring cleanup even when result processing or database updates
throw. Use the parsed receiver object and resolve the study UUID needed for
cleanup within the protected flow, while preserving the existing LOAD_FLOW and
other computation update behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 22e65c59-8540-478a-a614-1f16f6921361

📥 Commits

Reviewing files that changed from the base of the PR and between b2fcdf6 and 264293a.

📒 Files selected for processing (22)
  • src/main/java/org/gridsuite/study/server/controller/StudyController.java
  • src/main/java/org/gridsuite/study/server/dto/RootNetworkNodeInfo.java
  • src/main/java/org/gridsuite/study/server/error/StudyBusinessErrorCode.java
  • src/main/java/org/gridsuite/study/server/error/StudyExceptionHandler.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/LocalActivityStatus.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/NetworkModificationNode.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/NodeCheckScope.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/RootNetworkActivity.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/dto/SharedActivityStatus.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/NetworkModificationNodeInfoEntity.java
  • src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java
  • src/main/java/org/gridsuite/study/server/notification/NotificationService.java
  • src/main/java/org/gridsuite/study/server/repository/networkmodificationtree/NetworkModificationNodeInfoRepository.java
  • src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkNodeInfoRepository.java
  • src/main/java/org/gridsuite/study/server/service/ConsumerService.java
  • src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java
  • src/main/java/org/gridsuite/study/server/service/NodeActivityGuardService.java
  • src/main/java/org/gridsuite/study/server/service/RebuildNodeService.java
  • src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/main/resources/db/changelog/changesets/changelog_20260703T125842Z.xml
  • src/main/resources/db/changelog/db.changelog-master.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant