Skip to content

add admin stopCompute#1392

Draft
alexcos20 wants to merge 3 commits into
mainfrom
admin/add_admin_stopJob
Draft

add admin stopCompute#1392
alexcos20 wants to merge 3 commits into
mainfrom
admin/add_admin_stopJob

Conversation

@alexcos20

@alexcos20 alexcos20 commented Jun 14, 2026

Copy link
Copy Markdown
Member

Changes proposed in this PR:

  • add admin stopCompute

Admins need a way to forcefully terminate a running compute job without being the job's consumer. The existing ComputeStopHandler requires a consumer signature proving job ownership. A new admin-only stopJob command bypasses that ownership requirement, allowing the node owner to stop any job by its ID.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added an admin “stop job” capability via a new command that validates the provided job identifier format.
  • Bug Fixes
    • Improved responses for invalid inputs and missing compute engine configurations with clear HTTP error codes/messages.
  • Tests
    • Added integration coverage for missing job identifiers, non-admin requests, invalid jobId formats, and no-engine scenarios.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c48530a1-445b-4727-bd14-89099d2f85c4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Adds a new admin-only stopJob protocol command. This includes the AdminStopJobCommand typed interface, the STOP_JOB constant in PROTOCOL_COMMANDS and SUPPORTED_PROTOCOL_COMMANDS, a StopJobHandler that parses a composite <clusterHash>-<jobId> string to locate a C2D engine and stop a compute job, registration in CoreHandlersRegistry, and a four-case integration test suite.

Changes

Admin StopJob Command

Layer / File(s) Summary
Command contract, handler, and registry wiring
src/@types/commands.ts, src/utils/constants.ts, src/components/core/admin/stopJob.ts, src/components/core/handler/coreHandlersRegistry.ts
AdminStopJobCommand interface and STOP_JOB constant are added; StopJobHandler implements jobId validation, composite format parsing, C2D engine lookup by hash, and stopComputeJob invocation with an empty owner; CoreHandlersRegistry imports and registers the handler under PROTOCOL_COMMANDS.STOP_JOB.
Integration tests
src/test/integration/stopJob.test.ts
Four test cases cover missing jobId (HTTP 400), non-admin signer rejection, invalid jobId format (HTTP 400 with "Invalid jobId format"), and no configured C2D engines (HTTP 500). Setup derives admin and non-admin signers, configures allowed admin overrides, and initializes OceanNode and Database.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A job runs astray in the compute sea,
So admin hops in with a signed decree.
Parse the hash, find the engine with care,
stopComputeJob — poof! — no job is there.
Four tests confirm every edge case is neat,
The bunny declares: this feature's complete! 🌊

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'add admin stopCompute' is partially related to the changeset but lacks precision. The actual implementation adds a 'STOP_JOB' admin command, not 'stopCompute'. While related to admin job control, the title uses different terminology than the actual implementation (stopCompute vs stopJob). Clarify the title to accurately reflect the implementation—consider 'add admin stopJob command' or 'add admin command to stop compute jobs' for better accuracy and consistency with the codebase terminology.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch admin/add_admin_stopJob

Comment @coderabbitai help to get the list of available commands and usage tips.

@alexcos20

Copy link
Copy Markdown
Member Author

/run-security-scan

@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/core/admin/stopJob.ts`:
- Around line 65-71: In the catch block of the stopJob function (lines 65-71),
the code directly accesses error.message without verifying that the caught value
is an Error instance. This can crash the handler if a non-Error value (string,
null, or plain object) is thrown. Use a type guard or utility function to safely
extract the error message: check if error is an instance of Error and access its
message property, otherwise convert the error to a string or use a fallback
message. Apply this safe extraction in both places where error.message is used:
in the CORE_LOGGER.error call and in the status object's error field.
🪄 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: 65b798a3-40c6-4dfe-92f0-df30a45db663

📥 Commits

Reviewing files that changed from the base of the PR and between cd3f609 and 50ef9e7.

📒 Files selected for processing (5)
  • src/@types/commands.ts
  • src/components/core/admin/stopJob.ts
  • src/components/core/handler/coreHandlersRegistry.ts
  • src/test/integration/stopJob.test.ts
  • src/utils/constants.ts

Comment thread src/components/core/admin/stopJob.ts Outdated

@alexcos20 alexcos20 left a comment

Copy link
Copy Markdown
Member Author

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 correctly introduces the stopJob admin command, integrating it properly with the existing admin handler framework and command registry. Validation and authorization checks are properly implemented, leveraging the AdminCommandHandler base class. A few minor improvements related to error handling and HTTP status semantics are suggested.

Comments:
• [WARNING][bug] Is it guaranteed that engines.getC2DByHash(hash) throws an error if the engine is not found? If it can return undefined or null, the subsequent call to engine.stopComputeJob(...) will throw a TypeError and crash the execution abruptly. Adding a truthiness check is safer.

       try {
         engine = await engines.getC2DByHash(hash)
+        if (!engine) {
+          throw new Error('C2D engine not found')
+        }
       } catch (e) {

• [INFO][style] When a client provides an invalid hash that cannot be mapped to a C2D environment, returning an HTTP 400 Bad Request or 404 Not Found is semantically more appropriate than a 500 Internal Server Error, as the failure is due to bad client input, not an internal server misconfiguration.

-          status: { httpStatus: 500, error: 'Invalid C2D Environment' }
+          status: { httpStatus: 400, error: 'Invalid C2D Environment' }

• [WARNING][bug] In TypeScript, caught errors are of type unknown or any. Directly accessing error.message could cause a runtime crash if a non-Error value is thrown, and will cause type errors if strict mode is enabled. It's safer to handle the error type explicitly.

-    } catch (error) {
-      CORE_LOGGER.error(error.message)
+    } catch (error: any) {
+      const errorMessage = error instanceof Error ? error.message : String(error)
+      CORE_LOGGER.error(errorMessage)
       return {
         stream: null,
-        status: { httpStatus: 500, error: error.message }
+        status: { httpStatus: 500, error: errorMessage }
       }
     }

• [INFO][style] The integration tests cover the negative edge cases thoroughly (missing jobId, non-admin, bad format, no engines). To ensure full coverage, consider using a mocking tool (like sinon or jest.mock) to mock the C2D engine and test the successful execution (happy path) where stopComputeJob is successfully called.

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.

1 participant