Skip to content

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Jun 12, 2025

I have found that when running with nvidia the -t (--tty) option in podman is covering up certain errors. When we are not running ramalama interactively, we do not need this flag set, and this would make it easier to diagnose what is going on with users systems.

Summary by Sourcery

Disable the automatic inclusion of the TTY flag for non-interactive executions to prevent masking errors and update system tests to validate this behavior.

Bug Fixes:

  • Stop adding the '-t' (TTY) option when ramalama is run non-interactively to surface underlying errors.

Enhancements:

  • Refine add_tty_option logic to only include '-t' when no command-line arguments are present and stdin is a TTY.

Tests:

  • Add system tests to ensure the '-t' flag is only applied in interactive mode and omitted when commands are passed or input is piped.

Copy link
Contributor

sourcery-ai bot commented Jun 12, 2025

Reviewer's Guide

This PR updates the TTY allocation logic in the engine to skip the -t flag when not in interactive mode or when user arguments are provided, and extends the system tests to verify correct inclusion or exclusion of the -t flag under different run scenarios.

Sequence Diagram: Conditional TTY Flag for Podman Execution

sequenceDiagram
    actor User as CLI User
    participant RE as Ramalama Engine
    participant P as Podman

    CLI User->>RE: Executes command
    RE->>RE: Evaluates TTY conditions (add_tty_option)
    alt (NOT self.args.ARGS) AND sys.stdin.isatty()
        RE->>P: podman run ... -t ...
    else (self.args.ARGS) OR (NOT sys.stdin.isatty())
        RE->>P: podman run ... (no -t) ...
    end
Loading

Class Diagram: Update to RamalamaEngine

classDiagram
  class RamalamaEngine {
    +add_tty_option()
  }
Loading

File-Level Changes

Change Details Files
Refactor TTY flag allocation logic
  • Add guard to skip -t when args.ARGS is truthy or stdin is not a TTY
  • Remove stdout TTY check and early return on non-interactive contexts
  • Move exec_args append for -t into conditional else branch
ramalama/engine.py
Enhance system tests for TTY flag behavior
  • Assert -t flag appears only in default interactive dryrun runs
  • Add test to ensure no -t flag when passing arguments inline
  • Add test to ensure no -t flag when reading from piped stdin
test/system/030-run.bats

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@rhatdan
Copy link
Member Author

rhatdan commented Jun 12, 2025

This should help diagnose issues like:

#1487

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @rhatdan - I've reviewed your changes - here's some feedback:

  • In add_tty_option you dropped the stdout.isatty check—consider re-including it so you only request a TTY when both stdin and stdout are actual terminals to avoid forcing a TTY on redirected output.
  • The new tests for non‐interactive runs still assert that "-t" is present—but they should be asserting that the "-t" flag is absent when ARGS are provided or stdin isn’t a TTY.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 101 to 104
def add_tty_option(self):
if sys.stdout.isatty() or sys.stdin.isatty():
self.exec_args += ["-t"]
if self.args.ARGS or not sys.stdin.isatty():
return
self.exec_args += ["-t"]
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider adding -i for interactive input

The -t flag alone allocates a TTY, but to keep STDIN open for interactive use, you should also add -i (i.e., use -it).

Suggested change
def add_tty_option(self):
if sys.stdout.isatty() or sys.stdin.isatty():
self.exec_args += ["-t"]
if self.args.ARGS or not sys.stdin.isatty():
return
self.exec_args += ["-t"]
def add_tty_option(self):
if self.args.ARGS or not sys.stdin.isatty():
return
self.exec_args += ["-i", "-t"]

@rhatdan rhatdan force-pushed the tty branch 2 times, most recently from 69578c5 to 5315b2d Compare June 12, 2025 04:31
@ericcurtin
Copy link
Member

CI failing

I have found that when running with nvidia the -t (--tty) option
in podman is covering up certain errors.  When we are not running
ramalama interactively, we do not need this flag set, and this
would make it easier to diagnose what is going on with users
systems.

Don't add -i unless necessary

Server should not need to be run with --interactive or --tty.

Signed-off-by: Daniel J Walsh <[email protected]>
@rhatdan rhatdan merged commit 2f92ec5 into containers:main Jun 13, 2025
12 of 15 checks passed
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.

2 participants