Add healthcheck on serve (fixes #2041)#2475
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a post-exec healthcheck to File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The repeated
getattr(args, ...)checks inside theifcondition make the logic a bit hard to scan; consider pulling these into clearly named local booleans (e.g.,is_container,is_detached,is_dry_run) before theiffor readability. - If
wait_for_healthy(args)can block for a noticeable time, you may want to surface some minimal user feedback or logging around this wait so thatramalama serve -ddoesn't appear to hang silently when starting the container.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The repeated `getattr(args, ...)` checks inside the `if` condition make the logic a bit hard to scan; consider pulling these into clearly named local booleans (e.g., `is_container`, `is_detached`, `is_dry_run`) before the `if` for readability.
- If `wait_for_healthy(args)` can block for a noticeable time, you may want to surface some minimal user feedback or logging around this wait so that `ramalama serve -d` doesn't appear to hang silently when starting the container.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request aims to add a health check when running ramalama serve in detached container mode. The intention is correct, but the current implementation has a critical flaw that makes the new health check code unreachable. I've provided a detailed comment and a code suggestion to fix this underlying issue and correctly implement the desired behavior.
| try: | ||
| self.execute_command(cmd, args) | ||
| if ( | ||
| getattr(args, "container", False) | ||
| and getattr(args, "detach", False) | ||
| and not getattr(args, "dryrun", False) | ||
| ): | ||
| self.wait_for_healthy(args) | ||
| except Exception as e: | ||
| self._cleanup_server_process(args.server_process) | ||
| raise e |
There was a problem hiding this comment.
The current implementation has a fundamental issue: the new health check logic is unreachable. The call to self.execute_command(cmd, args) on line 793 leads to sys.exit(), terminating the program before the health check can run for detached containers.
To fix this and correctly implement the health check, the logic for detached container runs needs to be handled differently to avoid exiting. I suggest refactoring this try...except block to handle detached container runs separately, using run_cmd which doesn't exit the process.
try:
# For detached container runs, we need to avoid `exec_cmd` which calls `sys.exit`.
if (
getattr(args, "container", False)
and getattr(args, "detach", False)
):
# This logic is similar to `exec_model_in_container` but uses `run_cmd`.
if len(cmd) > 0 and isinstance(cmd[0], ContainerEntryPoint):
cmd = cmd[1:]
self.setup_container(args)
self.setup_mounts(args)
self.engine.add([args.image] + cmd)
if not getattr(args, "dryrun", False):
run_cmd(self.engine.exec_args, stdout2null=args.noout)
self.wait_for_healthy(args)
else:
self.engine.dryrun()
else:
self.execute_command(cmd, args)
except Exception as e:
self._cleanup_server_process(args.server_process)
raise eThere was a problem hiding this comment.
This review looks correct to me. execute_command() calls exec_model_in_container() which calls engine.exec() which calls exec_cmd() which calls sys.exit() unconditionally. For this to work the call to engine.exec() would likely need to be replaced with engine.run() or engine.run_process().
When running ramalama serve with container and detach (-d), wait for the server to become healthy before returning, using the existing wait_for_healthy() and is_healthy() logic. The healthcheck is run from the inference plugin after execute_command() starts the container. Made-with: Cursor Signed-off-by: Daniel J Walsh <[email protected]>
|
@olliewalsh @mikebonnet @engelmi PTAL, this should be ready to go in. |
|
@sourcery-ai dismiss |
When running ramalama serve with container and detach (-d), wait for the server to become healthy before returning, using the existing wait_for_healthy() and is_healthy() logic.
Made-with: Cursor
Fixes: #2041
Summary by Sourcery
Bug Fixes:
ramalama servewith--containerand--detachwaits for the server to be healthy before exiting, avoiding races with dependent operations.