Skip to content

Feat/162 service restart notify - #2125

Merged
giurgiur99 merged 4 commits into
next-release-v9from
feat/162-service-restart-notify
Jul 29, 2026
Merged

Feat/162 service restart notify#2125
giurgiur99 merged 4 commits into
next-release-v9from
feat/162-service-restart-notify

Conversation

@giurgiur99

@giurgiur99 giurgiur99 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes # .

Changes proposed in this PR:

  • Update model on restart

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced service restart handling to notify the incentive backend when restart metadata (image/tag/docker command) is available.
    • Added safeguards to only send restart notifications when required configuration and restart details are present.
    • Preserved existing restart behavior and outcomes when no restart command/metadata is provided.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@giurgiur99, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b97c919c-9dfc-4f60-ba76-ca8b8844ca90

📥 Commits

Reviewing files that changed from the base of the PR and between be9ce87 and 98b1330.

📒 Files selected for processing (1)
  • src/services/providers/BaseProvider.ts
📝 Walkthrough

Walkthrough

BaseProvider now preserves provider restart behavior while optionally notifying the incentive backend when restart parameters include image, tag, or dockerCmd.

Changes

Service restart notifications

Layer / File(s) Summary
Conditional restart notification
src/services/providers/BaseProvider.ts
Adds a guarded, error-logged POST to /services/{serviceId}/restarted and invokes it when image, tag, or dockerCmd is provided.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BaseProvider
  participant UnderlyingProvider
  participant IncentiveBackend
  BaseProvider->>UnderlyingProvider: serviceRestart(params)
  BaseProvider->>IncentiveBackend: POST restart metadata when image, tag, or dockerCmd exists
Loading

Possibly related PRs

Suggested reviewers: bogdanfazakas, mihaisc, andreip136

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: notifying the backend when a service restarts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/162-service-restart-notify

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.

@giurgiur99

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@giurgiur99

Copy link
Copy Markdown
Contributor Author

/run-security-scan

@alexcos20 alexcos20 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI automated code review (Gemini 3).

Overall risk: high

Summary:
This PR introduces a notification mechanism for service restarts. However, it contains a critical ReferenceError where dockerCmd is accessed without being declared in the local scope, which will fatally crash the serviceRestart method. Furthermore, there is an unused parameter in the new method and risky usage of process.env that may crash browser-based environments consuming this library.

Comments:
• [ERROR][bug] Critical: dockerCmd is not defined in the scope of serviceRestart. This will throw a ReferenceError and break the function. Assuming dockerCmd is a property of the optional params object, you should access it via params?.dockerCmd.

-    if (dockerCmd !== undefined) {
-      this.notifyIncentiveBackendServiceRestarted(nodeUri, serviceId, dockerCmd).catch(() => {})
+    if (params?.dockerCmd !== undefined) {
+      this.notifyIncentiveBackendServiceRestarted(nodeUri, serviceId, params.dockerCmd)

Note: The trailing .catch(() => {}) can also be safely removed because notifyIncentiveBackendServiceRestarted wraps its logic in a try/catch and never rejects.
• [WARNING][style] The parameter nodeUri is declared but never used inside the notifyIncentiveBackendServiceRestarted method. You can safely remove it to keep the method signature clean.

-  private async notifyIncentiveBackendServiceRestarted(
-    nodeUri: OceanNode,
-    serviceId: string,
-    dockerCmd: string[]
-  ): Promise<void> {
+  private async notifyIncentiveBackendServiceRestarted(
+    serviceId: string,
+    dockerCmd: string[]
+  ): Promise<void> {

(Be sure to update the call site at line 899 to match the removed argument)..
• [WARNING][bug] ocean.js is a library often consumed in both Node.js and browser environments. Accessing process.env directly can throw a fatal ReferenceError in browsers where the global process object is undefined (unless specifically polyfilled by the consumer's bundler). It is much safer to guard this check.

-      const incentiveBackendUrl = process.env.INCENTIVE_BACKEND_URL
+      const incentiveBackendUrl = typeof process !== 'undefined' ? process.env.INCENTIVE_BACKEND_URL : undefined

@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

🤖 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/services/providers/BaseProvider.ts`:
- Around line 897-900: Update serviceRestart to extract dockerCmd from its
params before the notification block, then use that optional restart parameter
value in the existing undefined check and notifyIncentiveBackendServiceRestarted
call.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 38588806-6f93-477f-a2dd-4630eafc7c76

📥 Commits

Reviewing files that changed from the base of the PR and between cedce7b and 1b6ddad.

📒 Files selected for processing (1)
  • src/services/providers/BaseProvider.ts

Comment thread src/services/providers/BaseProvider.ts Outdated
@giurgiur99

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@giurgiur99

Copy link
Copy Markdown
Contributor Author

/run-security-scan

@alexcos20 alexcos20 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI automated code review (Gemini 3).

Overall risk: low

Summary:
The PR introduces a helpful feature to notify the incentive backend when a service is restarted with new parameters. The changes are largely well-implemented, correctly preventing URL injection and gracefully handling missing configuration. However, there are a few architectural and performance improvements to consider. Reading from process.env directly in an SDK can cause issues in browser environments, the fetch call is unawaited and missing the AbortSignal, and there is a redundant .catch() statement.

Comments:
• [WARNING][architecture] Directly accessing process.env inside an SDK (which may be used in browsers or non-Node environments) can cause reference errors or require specific build-time polyfills. It's generally a better practice to accept such configuration values through the class constructor (e.g., via a Config object injected into BaseProvider) rather than hardcoding environment variable reads.
• [WARNING][performance] The fetch request does not use the signal provided to the parent serviceRestart method. This means if the user aborts the restart operation, this fetch will keep running. Additionally, without a timeout, a hanging endpoint could cause resource leaks. Consider passing the AbortSignal down to this method and adding it to the fetch options.

-  private async notifyIncentiveBackendServiceRestarted(
-    serviceId: string,
-    params: ServiceRestartParams
+  private async notifyIncentiveBackendServiceRestarted(
+    serviceId: string,
+    params: ServiceRestartParams,
+    signal?: AbortSignal
   ): Promise<void> {

And in the fetch:

       await fetch(`${baseUrl}/services/${encodeURIComponent(serviceId)}/restarted`, {
         method: 'POST',
+        signal,
         headers: { 'Content-Type': 'application/json' },

• [INFO][style] The .catch(() => {}) here is redundant because the notifyIncentiveBackendServiceRestarted method already wraps its entire body in a try/catch and gracefully handles any errors without re-throwing. If this was added to satisfy a linter rule like no-floating-promises, consider using void this.notifyIncentiveBackendServiceRestarted(...) instead.

Additionally, because this call is 'fire-and-forget' (not awaited), if this code runs in a short-lived serverless environment (like AWS Lambda), the Node process might exit before the background fetch completes, causing the notification to be lost. If reliable delivery is required, you should await it.

@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 (1)
src/services/providers/BaseProvider.ts (1)

482-499: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Destructure restart metadata in the helper.

Use parameter destructuring for image, tag, and dockerCmd instead of repeatedly accessing params.*.

Proposed refactor
   private async notifyIncentiveBackendServiceRestarted(
     serviceId: string,
-    params: ServiceRestartParams
+    { image, tag, dockerCmd }: ServiceRestartParams
   ): Promise<void> {
...
         body: JSON.stringify({
-          image: params.image,
-          tag: params.tag,
-          dockerCmd: params.dockerCmd
+          image,
+          tag,
+          dockerCmd
         })

As per coding guidelines: “Use destructuring for imports and function parameters.”

🤖 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/services/providers/BaseProvider.ts` around lines 482 - 499, Update
notifyIncentiveBackendServiceRestarted to destructure image, tag, and dockerCmd
from the params parameter, then use those local values in the request body
instead of accessing params.*.

Source: Coding guidelines

🤖 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/services/providers/BaseProvider.ts`:
- Around line 492-500: Update the restart notification fetch in BaseProvider to
store its response and validate response.ok; throw a status-only error for
non-2xx responses so the surrounding catch handles failed notifications and
prevents stale incentive state.

---

Nitpick comments:
In `@src/services/providers/BaseProvider.ts`:
- Around line 482-499: Update notifyIncentiveBackendServiceRestarted to
destructure image, tag, and dockerCmd from the params parameter, then use those
local values in the request body instead of accessing params.*.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b409f8e-bbbc-406f-9699-eec53dc7ae91

📥 Commits

Reviewing files that changed from the base of the PR and between 1b6ddad and be9ce87.

📒 Files selected for processing (1)
  • src/services/providers/BaseProvider.ts

Comment thread src/services/providers/BaseProvider.ts Outdated
@giurgiur99

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@giurgiur99

Copy link
Copy Markdown
Contributor Author

/run-security-scan

@alexcos20 alexcos20 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI automated code review (Gemini 3).

Overall risk: medium

Summary:
The PR adds a notification mechanism to the incentive backend when a service is restarted. The logic is generally sound and correctly executes as a fire-and-forget background task. However, the direct use of process.env in a library that supports browser environments poses a significant risk of runtime crashes. A fallback check for the process object is needed, or ideally, the configuration should be injected.

Comments:
• [ERROR][bug] Accessing process.env directly can cause ReferenceError: process is not defined in browser environments. If ocean.js is intended to be run in browsers without a bundler that polyfills process, you must verify that process exists before accessing its properties. Alternatively, consider passing the INCENTIVE_BACKEND_URL through the provider's configuration or constructor rather than relying on environment variables inside a core library class.

-      const incentiveBackendUrl = process.env.INCENTIVE_BACKEND_URL
+      const incentiveBackendUrl = typeof process !== 'undefined' && process.env ? process.env.INCENTIVE_BACKEND_URL : undefined;

• [INFO][security] Good use of encodeURIComponent on serviceId here. This prevents potential path injection vulnerabilities in the outgoing fetch URL.
• [INFO][style] The notifyIncentiveBackendServiceRestarted method has an internal try-catch block that catches and logs any errors without re-throwing them, which means its returned Promise will never reject. Because of this, the appended .catch(() => {}) here is redundant and can be safely removed.

-      this.notifyIncentiveBackendServiceRestarted(serviceId, params).catch(() => {})
+      this.notifyIncentiveBackendServiceRestarted(serviceId, params)

@giurgiur99
giurgiur99 merged commit ea4c3f7 into next-release-v9 Jul 29, 2026
13 checks passed
@giurgiur99
giurgiur99 deleted the feat/162-service-restart-notify branch July 29, 2026 06:18
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.

3 participants