Skip to content

Conversation

@zjgemi
Copy link
Contributor

@zjgemi zjgemi commented Oct 27, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Safer handling of missing job group IDs to avoid errors.
    • Only fetches job logs when output logs are available.
    • Improved job completion detection when exit codes are ignored.
  • Improvements

    • Uses job result URL reliably when downloading job output.
    • Includes user/session identifiers when available to improve job tracking.

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.83%. Comparing base (4816095) to head (4857458).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
dpdispatcher/machines/openapi.py 0.00% 8 Missing ⚠️
dpdispatcher/contexts/openapi_context.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #553      +/-   ##
==========================================
- Coverage   60.40%   54.83%   -5.58%     
==========================================
  Files          39       40       +1     
  Lines        3905     3921      +16     
==========================================
- Hits         2359     2150     -209     
- Misses       1546     1771     +225     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

📝 Walkthrough

Walkthrough

Safer jobGroupId retrieval in OpenAPI context; rename of image parameter and conditional inclusion of remote_profile fields in submit flow; gate log retrieval on output_log and switch download URL to resultUrl; treat status -1 as finished when ignore_exit_code is true.

Changes

Cohort / File(s) Summary
OpenAPI Context
dpdispatcher/contexts/openapi_context.py
Use data.get("jobGroupId", "") instead of direct data["jobGroupId"] to retrieve jobGroupId safely.
OpenAPI Machine / Job Handling
dpdispatcher/machines/openapi.py
Rename image_addressimage_name; include real_user_id and session_id from remote_profile only when present; always set job_id in openapi_params; in status finished branch, retrieve logs only when output_log is true; download job from data["resultUrl"] instead of data["jobFiles"]["outFiles"][0]["url"]; treat status -1 as finished if ignore_exit_code is true.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant OpenAPI_Machine
  participant OpenAPI_Service
  rect rgb(230, 245, 255)
    Client->>OpenAPI_Machine: do_submit(image_name, job data)
    Note right of OpenAPI_Machine: include real_user_id/session_id\nonly if remote_profile present
    OpenAPI_Machine->>OpenAPI_Service: submit job (openapi_params with job_id)
    OpenAPI_Service-->>OpenAPI_Machine: job accepted / job_id
  end

  rect rgb(245, 255, 230)
    Client->>OpenAPI_Machine: check_status(job_id)
    OpenAPI_Machine->>OpenAPI_Service: query status
    OpenAPI_Service-->>OpenAPI_Machine: status (e.g., -1 / finished / running)
    alt status finished
      Note right of OpenAPI_Machine: if output_log == true -> fetch logs
      OpenAPI_Machine->>OpenAPI_Service: request logs (conditional)
      OpenAPI_Service-->>OpenAPI_Machine: logs
      OpenAPI_Machine->>OpenAPI_Service: request result URL
      OpenAPI_Service-->>OpenAPI_Machine: `resultUrl`
      OpenAPI_Machine->>Client: download result from `resultUrl`
    else status -1 and ignore_exit_code == true
      OpenAPI_Machine->>Client: mark job finished
    else other statuses
      OpenAPI_Machine->>Client: report current status
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to data["resultUrl"] presence and error handling in _download_job.
  • Verify conditional inclusion of real_user_id / session_id doesn't alter authentication/authorization flows.
  • Check status -1 handling with ignore_exit_code for side effects on job lifecycle and downstream consumers.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Compatible for bohrium OpenAPI sandbox' clearly relates to the main changes, which involve modifications to handle OpenAPI sandbox compatibility across openapi_context.py and openapi.py.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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.

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

Caution

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

⚠️ Outside diff range comments (1)
dpdispatcher/machines/openapi.py (1)

232-251: Remove unused exit_code parameter.

The exit_code parameter is no longer used in the method body after removing the exit_code != 0 check on line 249. This makes the parameter misleading.

Apply this diff to remove the unused parameter:

     @staticmethod
-    def map_dp_job_state(status, exit_code, ignore_exit_code=True):
+    def map_dp_job_state(status, ignore_exit_code=True):
         if isinstance(status, JobStatus):
             return status
         map_dict = {

Then update the caller on line 182-186:

         job_state = self.map_dp_job_state(
             dp_job_status,
-            check_return.get("exitCode", 0),  # type: ignore
             self.ignore_exit_code,
         )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4816095 and 8d121ff.

📒 Files selected for processing (2)
  • dpdispatcher/contexts/openapi_context.py (2 hunks)
  • dpdispatcher/machines/openapi.py (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Always add type hints in all Python code
Ensure code remains compatible with Python 3.7+ (avoid syntax/features newer than 3.7)
Use Ruff (via pre-commit) for linting and formatting

Files:

  • dpdispatcher/contexts/openapi_context.py
  • dpdispatcher/machines/openapi.py
🧬 Code graph analysis (1)
dpdispatcher/machines/openapi.py (2)
dpdispatcher/contexts/ssh_context.py (1)
  • get (432-448)
dpdispatcher/utils/dpcloudserver/client.py (1)
  • get (47-48)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build (ssh_rsync)
  • GitHub Check: build (pbs)
  • GitHub Check: build (slurm)
🔇 Additional comments (3)
dpdispatcher/contexts/openapi_context.py (1)

168-174: Good defensive coding, but add type hints.

Using .get() with a default prevents KeyError if the key is missing. However, per the coding guidelines, type hints should be added throughout the codebase.

Consider adding type annotations to the jgid attributes where they are declared (e.g., in class definitions).

As per coding guidelines

dpdispatcher/machines/openapi.py (2)

188-190: LGTM!

Gating log retrieval behind the output_log flag avoids unnecessary API calls when logs are not needed, improving performance.


132-138: No action needed—the original review comment is incorrect.

The code at lines 132-138 is safe and intentional:

  1. Line 138 (job.job_id): The job.job_id attribute is initialized to "" (empty string) in Job.__init__ (line 752 of submission.py). It is always defined before do_submit is called, so there is no risk of uninitialized access. On first submission, it is ""; on resubmission, it holds the previous job ID—both are valid.

  2. Line 132 (image_addressimage_name): This mapping is intentional. The remote_profile uses the key "image_address" as configuration, while the OpenAPI backend expects the parameter key "image_name". This is confirmed by test cases (test_run_submission_bohrium.py) where different machine types use different key names, and the code correctly bridges them.

Likely an incorrect or invalid review comment.

@felix5572
Copy link
Collaborator

Is Ready for merge?

@njzjz njzjz enabled auto-merge (squash) November 11, 2025 01:13
@njzjz njzjz merged commit 0b5dfd1 into deepmodeling:master Nov 11, 2025
26 of 27 checks passed
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

🧹 Nitpick comments (1)
dpdispatcher/contexts/openapi_context.py (1)

139-178: Consider adding type hints to the method signature.

The coding guidelines require type hints in all Python code, but the upload_job method lacks them. Adding type annotations would improve maintainability and enable better static analysis.

Example type hints:

def upload_job(self, job, common_files: list[str] | None = None) -> None:

Note: For Python 3.7-3.9 compatibility, use Optional[List[str]] from typing instead of list[str] | None.

As per coding guidelines.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d121ff and 4857458.

📒 Files selected for processing (1)
  • dpdispatcher/contexts/openapi_context.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Always add type hints in all Python code
Ensure code remains compatible with Python 3.7+ (avoid syntax/features newer than 3.7)
Use Ruff (via pre-commit) for linting and formatting

Files:

  • dpdispatcher/contexts/openapi_context.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: pass
  • GitHub Check: build (pbs)
  • GitHub Check: build (ssh_rsync)
  • GitHub Check: build (slurm)
🔇 Additional comments (1)
dpdispatcher/contexts/openapi_context.py (1)

173-173: Safer jobGroupId retrieval approved.

Good change to use .get() with a default empty string, preventing potential KeyError if the API response omits this field.

Please verify that an empty string is the appropriate default for jgid. Consider whether downstream code expects a specific sentinel value (e.g., None) when no job group exists.

Comment on lines 170 to 172
object_key = os.path.join(data["storePath"], zip_filename) # type: ignore
job.upload_path = object_key
job.job_id = data["jobId"] # type: ignore
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

Inconsistent error handling for API response fields.

Lines 170 and 172 use direct indexing (data["storePath"], data["jobId"]) while lines 167, 168, and 173 use safe .get() access. If the API can omit jobGroupId, it may also omit storePath or jobId, leading to KeyError at runtime.

Apply this diff to use consistent safe access:

-        object_key = os.path.join(data["storePath"], zip_filename)  # type: ignore
+        object_key = os.path.join(data.get("storePath", ""), zip_filename)  # type: ignore
         job.upload_path = object_key
-        job.job_id = data["jobId"]  # type: ignore
+        job.job_id = data.get("jobId", "")  # type: ignore
📝 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
object_key = os.path.join(data["storePath"], zip_filename) # type: ignore
job.upload_path = object_key
job.job_id = data["jobId"] # type: ignore
object_key = os.path.join(data.get("storePath", ""), zip_filename) # type: ignore
job.upload_path = object_key
job.job_id = data.get("jobId", "") # type: ignore
🤖 Prompt for AI Agents
In dpdispatcher/contexts/openapi_context.py around lines 170 to 172, replace the
direct indexing data["storePath"] and data["jobId"] with safe .get() access
consistent with the surrounding code (e.g., data.get("storePath") and
data.get("jobId")); then handle the possibility of None by either raising a
clear ValueError or logging an error and providing a sensible default (or
aborting the operation) so a missing field does not cause an unhandled KeyError
at runtime.

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.

4 participants