Skip to content

new arg "release" for stop service - #1434

Merged
alexcos20 merged 1 commit into
next-4from
release-resources-on-stop-arg
Jul 30, 2026
Merged

new arg "release" for stop service#1434
alexcos20 merged 1 commit into
next-4from
release-resources-on-stop-arg

Conversation

@giurgiur99

@giurgiur99 giurgiur99 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Fixes # .

Changes proposed in this PR:

Summary by CodeRabbit

  • New Features

    • Added an optional release option when stopping an on-demand service.
    • Services can now release reserved resources immediately, ending the paid window without a refund or restart capability.
    • By default, stopping preserves the reservation until its scheduled expiration.
  • Documentation

    • Updated API, lifecycle, and Postman documentation to describe the new stop behavior and request field.
  • Tests

    • Added coverage for releasing resources from running and already-stopped services.

@giurgiur99

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

serviceStop now accepts an optional release flag. Normal stops retain the paid reservation until expiresAt; released stops set expiry to the current time, with propagation through the HTTP API, handler, engine, documentation, and unit tests.

Changes

Service stop release

Layer / File(s) Summary
Release contract and request propagation
src/@types/commands.ts, src/components/httpRoutes/compute.ts, src/components/core/service/stopService.ts, docs/...
Adds the optional release request field, forwards it through the stop flow, and documents its behavior.
Early release engine behavior
src/components/c2d/compute_engine_base.ts, src/components/c2d/compute_engine_docker.ts
Propagates release through engine stop execution and sets expiresAt to Date.now() when the paid window is released.
Release behavior validation
src/test/unit/service/serviceNetworkCleanup.test.ts
Tests expiry updates for running and stopped services, unchanged expiry without release, and shared database stubbing.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: alexcos20, dnsi0, andreip136

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a new release argument to stop service.
✨ 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 release-resources-on-stop-arg

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.

@coderabbitai

coderabbitai Bot commented Jul 28, 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 implements a well-designed release argument for the serviceStop endpoint to support early-termination of paid reservations. The code is clean, introduces solid test coverage, and includes a nice refactoring to runExclusive for lifecycle lock management. LGTM!

Comments:
• [WARNING][bug] The refactoring to use this.runExclusive is much cleaner for lock management! However, the previous implementation manually tracked the operation in this.serviceOpPromises (with the comment explicitly mentioning engine stop() drains an in-flight stop too). Please verify if this.runExclusive internally tracks the operation in serviceOpPromises. If it does not, you might lose the graceful shutdown behavior for in-flight stops.
• [INFO][performance] Excellent handling of the early release edge case. Conditionally calling await this.db.updateServiceJob(job) only when the service is already Stopped efficiently avoids duplicate database writes for Running services (where the DB update naturally happens at the end of the teardown process).
• [INFO][style] Using strict equality task.release === true here is excellent for security and predictability, as it guarantees a boolean value and defends against prototype pollution or unexpected type coercions. Just keep in mind that if clients send stringified payloads (e.g., "true"), it will silently evaluate to false (though this is standard for JSON APIs).

@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/components/httpRoutes/compute.ts`:
- Line 426: Remove the trailing commas at both affected sites: after release:
req.body.release in src/components/httpRoutes/compute.ts lines 426-426 and after
task.release === true in src/components/core/service/stopService.ts lines 65-65,
preserving the surrounding TypeScript syntax.
🪄 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: 4e889c1a-1476-4c61-957e-d0168700b98d

📥 Commits

Reviewing files that changed from the base of the PR and between c483ea1 and 281c323.

📒 Files selected for processing (9)
  • docs/API.md
  • docs/Ocean Node.postman_collection.json
  • docs/services.md
  • src/@types/commands.ts
  • src/components/c2d/compute_engine_base.ts
  • src/components/c2d/compute_engine_docker.ts
  • src/components/core/service/stopService.ts
  • src/components/httpRoutes/compute.ts
  • src/test/unit/service/serviceNetworkCleanup.test.ts

nonce: (req.body.nonce as string) || null,
signature: (req.body.signature as string) || null,
serviceId: (req.body.serviceId as string) || null,
release: req.body.release,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the trailing commas from both changed TypeScript sites.

As per coding guidelines: TypeScript formatting requires no trailing commas.

  • src/components/httpRoutes/compute.ts#L426-L426: remove the comma after release: req.body.release.
  • src/components/core/service/stopService.ts#L65-L65: remove the comma after task.release === true.
📍 Affects 2 files
  • src/components/httpRoutes/compute.ts#L426-L426 (this comment)
  • src/components/core/service/stopService.ts#L65-L65
🤖 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/components/httpRoutes/compute.ts` at line 426, Remove the trailing commas
at both affected sites: after release: req.body.release in
src/components/httpRoutes/compute.ts lines 426-426 and after task.release ===
true in src/components/core/service/stopService.ts lines 65-65, preserving the
surrounding TypeScript syntax.

Source: Coding guidelines

@giurgiur99
giurgiur99 marked this pull request as ready for review July 28, 2026 13:14
@alexcos20
alexcos20 self-requested a review July 30, 2026 04:01
@alexcos20
alexcos20 merged commit 879f495 into next-4 Jul 30, 2026
15 of 16 checks passed
@alexcos20
alexcos20 deleted the release-resources-on-stop-arg branch July 30, 2026 04:01
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