Skip to content

Conversation

@giuseppe
Copy link
Member

Closes: #1943

@gemini-code-assist
Copy link

Summary of Changes

Hello @giuseppe, 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 resolves an issue where crun would not correctly halt the container startup process if a poststart hook failed. The changes ensure that any non-zero exit status from a poststart hook is now properly detected and causes the container creation to terminate, preventing the container from entering an undefined or partially initialized state. This improves the robustness and reliability of container lifecycle management.

Highlights

  • Poststart Hook Error Handling: Modified the do_hooks function call for poststart hooks to correctly interpret non-zero return values as failures, ensuring that a failing hook immediately stops the container startup process.
  • New Test Cases: Introduced dedicated Python tests (test_fail_poststart and test_success_poststart) to validate the new error handling behavior for poststart hooks, confirming that container startup fails on hook error and succeeds on hook success.

🧠 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.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly modifies crun to exit immediately if a poststart hook fails, which is a good correctness improvement. The changes in src/libcrun/container.c properly implement this by adjusting the do_hooks call to stop on failure and ensuring the error is propagated. The new tests in tests/test_hooks.py effectively verify this behavior. I've added a couple of suggestions to improve the robustness of the new tests by using more specific exception handling and adhering to conventions for unused variables.

Comment on lines +74 to +77
try:
out, _ = run_and_get_output(conf, hide_stderr=True)
except:
return 0

Choose a reason for hiding this comment

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

medium

Using a bare except can catch unexpected exceptions like SystemExit or KeyboardInterrupt, making the test harder to debug and potentially masking other issues. It's better to catch a more specific exception, like Exception. Also, the out variable is not used and can be replaced with _ to indicate it's intentionally ignored.

Suggested change
try:
out, _ = run_and_get_output(conf, hide_stderr=True)
except:
return 0
try:
_, _ = run_and_get_output(conf, hide_stderr=True)
except Exception:
return 0

Comment on lines +85 to +88
try:
out, _ = run_and_get_output(conf, hide_stderr=True)
except:
return -1

Choose a reason for hiding this comment

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

medium

Similar to the previous comment, it's better to catch a more specific exception than a bare except to make the test more robust. Additionally, the out variable is unused and can be replaced with an underscore.

Suggested change
try:
out, _ = run_and_get_output(conf, hide_stderr=True)
except:
return -1
try:
_, _ = run_and_get_output(conf, hide_stderr=True)
except Exception:
return -1

@eriksjolund
Copy link
Contributor

typo in PR title poststark

Closes: containers#1943

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe changed the title hooks: exit immediately if poststark hooks fail hooks: exit immediately if poststart hooks fail Dec 28, 2025
@packit-as-a-service
Copy link

TMT tests failed. @containers/packit-build please check.

@giuseppe giuseppe force-pushed the fix-poststart-retcode branch from 6945363 to 8e8186b Compare December 28, 2025 13:21
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.

poststart hook with /bin/false gives different results for crun and runc

2 participants