Skip to content

Conversation

@zjgemi
Copy link
Contributor

@zjgemi zjgemi commented Oct 27, 2025

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved reliability of job grouping by safely handling missing data fields with sensible defaults.
    • Fixed conditional log retrieval to only fetch logs when appropriate.
    • Enhanced exit code handling for better control over job completion status.
  • Improvements

    • Ensured automatic creation of required directories at initialization for smoother setup.

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.55%. Comparing base (4816095) to head (8d121ff).

Files with missing lines Patch % Lines
dpdispatcher/machines/openapi.py 0.00% 8 Missing ⚠️
dpdispatcher/contexts/openapi_context.py 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (4816095) and HEAD (8d121ff). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (4816095) HEAD (8d121ff)
15 13
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #553       +/-   ##
===========================================
- Coverage   60.40%   47.55%   -12.86%     
===========================================
  Files          39       39               
  Lines        3905     3909        +4     
===========================================
- Hits         2359     1859      -500     
- Misses       1546     2050      +504     

☔ 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

Updates to OpenAPI context and machine interaction logic. Changes include ensuring directory creation at OpenAPIContext initialization, relaxing job group ID retrieval with safe defaults, renaming an image address parameter, conditionally including remote profile fields, gating log retrieval based on output_log flag, changing job URL retrieval source, and adjusting exit code handling in status mapping.

Changes

Cohort / File(s) Summary
OpenAPI Context Initialization
dpdispatcher/contexts/openapi_context.py
Ensures DP_CLOUD_SERVER_HOME_DIR directory exists via os.makedirs() on initialization; relaxes jobGroupId retrieval using .get() with empty string default instead of direct indexing
OpenAPI Machine Job Handling
dpdispatcher/machines/openapi.py
Renames image_address parameter to image_name; conditionally includes real_user_id and session_id from remote_profile when present; always sets job_id in openapi_params; gates job log retrieval on output_log flag; changes job URL source from data["jobFiles"]["outFiles"][0]["url"] to data["resultUrl"]; treats status -1 as finished when ignore_exit_code is true

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify data["resultUrl"] availability and correctness as the new job URL source
  • Confirm that status -1 exit code handling with ignore_exit_code=true aligns with expected job lifecycle behavior
  • Validate that conditional inclusion of real_user_id and session_id does not break existing remote profile workflows

Possibly related PRs

Suggested reviewers

  • njzjz

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 PR title "Compatible for bohrium OpenAPI sandbox" is directly related to the changeset. The modifications across both files are specifically designed to support bohrium OpenAPI sandbox environments: ensuring directories exist at initialization, relaxing parameter retrieval with safer defaults, renaming parameters for sandbox compatibility, and adjusting job log retrieval and exit code handling based on sandbox requirements. The title meaningfully conveys the core purpose of these changes and is specific enough to distinguish this PR from generic updates, using concrete terms (bohrium, OpenAPI, sandbox) rather than vague placeholders like "misc updates."
✨ 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.

self.init_remote_root = remote_root
self.temp_local_root = os.path.abspath(local_root)
self.remote_profile = remote_profile
os.makedirs(DP_CLOUD_SERVER_HOME_DIR, exist_ok=True)
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 | 🟡 Minor

Remove duplicate directory creation.

The directory creation on line 75 duplicates the identical call on line 105 within the same __init__ method.

Apply this diff to remove the duplicate:

-        os.makedirs(DP_CLOUD_SERVER_HOME_DIR, exist_ok=True)
         access_key = (

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In dpdispatcher/contexts/openapi_context.py around line 75, there's a duplicate
call to os.makedirs(DP_CLOUD_SERVER_HOME_DIR, exist_ok=True) that is repeated
later at line 105 in the same __init__ method; remove the earlier call at line
75 so the directory is only created once (keep the existing call at line 105),
and run tests/lint to ensure no other side-effects.

def _download_job(self, job):
data = self.job.detail(job.job_id)
job_url = data["jobFiles"]["outFiles"][0]["url"] # type: ignore
job_url = data["resultUrl"] # 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.

🛠️ Refactor suggestion | 🟠 Major

Use .get() for safer dictionary access.

Direct indexing data["resultUrl"] will raise KeyError if the key is missing. For consistency with the changes in openapi_context.py (lines 168, 174), use .get() with a default value.

Apply this diff:

-        job_url = data["resultUrl"]  # type: ignore
+        job_url = data.get("resultUrl", "")  # type: ignore
🤖 Prompt for AI Agents
In dpdispatcher/machines/openapi.py around line 199, the code uses direct
indexing data["resultUrl"] which can raise KeyError if the key is missing;
change it to use data.get("resultUrl", None) (or "" if an empty string is
preferable) to match the safer pattern used in openapi_context.py (lines 168,
174), and preserve any existing type comments (e.g., keep "# type: ignore" if
needed).

@felix5572
Copy link
Collaborator

Is Ready for merge?

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