Skip to content

t1350: fix: auto-detect non-interactive terminals in setup.sh#2468

Merged
alex-solovyev merged 2 commits intomainfrom
bugfix/setup-noninteractive
Feb 27, 2026
Merged

t1350: fix: auto-detect non-interactive terminals in setup.sh#2468
alex-solovyev merged 2 commits intomainfrom
bugfix/setup-noninteractive

Conversation

@alex-solovyev
Copy link
Collaborator

@alex-solovyev alex-solovyev commented Feb 27, 2026

Summary

  • Auto-detect non-interactive terminals in setup.sh — if stdin is not a tty and --interactive was not explicitly passed, set NON_INTERACTIVE=true automatically
  • Fix grep -c ERR trap noise in setup-modules/shell-env.sh by moving || true inside the subshell as || echo "0"

Why

When agents or CI/CD pipelines run setup.sh without --non-interactive, the read commands fail on non-tty stdin with set -Eeuo pipefail, killing the function before agent deployment runs. This means aidevops update in headless environments silently fails to deploy agents.

Changes

  • setup.sh: Added tty detection after parse_args[[ ! -t 0 ]] sets NON_INTERACTIVE=true unless --interactive was explicitly passed
  • setup-modules/shell-env.sh: Changed $(grep -cE ... 2>/dev/null) || true to $(grep -cE ... 2>/dev/null || echo "0") to handle no-match exit code inside the subshell, preventing ERR trap noise with inherit_errexit
  • todo/tasks/t1350-brief.md: Task brief

Closes #2464

Summary by CodeRabbit

  • New Features

    • Automatic detection of non-interactive terminals for seamless CI/CD and piped-input workflows.
  • Bug Fixes

    • Reduced spurious error/noise in certain shell environments by improving command output handling.
  • Documentation

    • Added a brief documenting the non-interactive behavior, acceptance criteria, and change rationale.

- Add tty detection after parse_args: if stdin is not a tty and
  --interactive was not explicitly passed, set NON_INTERACTIVE=true
- Fix grep -c ERR trap noise in shell-env.sh: move || true inside
  subshell as || echo "0" to prevent inherit_errexit from firing
  the ERR trap on no-match exit code

Fixes: setup.sh exits early in agent/CI shells where read fails
on non-tty stdin with set -Eeuo pipefail
@github-actions github-actions bot added the bug Auto-created from TODO.md tag label Feb 27, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1764a0 and 93c13d3.

📒 Files selected for processing (2)
  • setup-modules/shell-env.sh
  • todo/tasks/t1350-brief.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • todo/tasks/t1350-brief.md

Walkthrough

Auto-detect non-interactive terminals in setup.sh (sets NON_INTERACTIVE when stdin is not a TTY post-arg-parse) and harden grep -c calls in setup-modules/shell-env.sh to avoid ERR-trap noise by replacing trailing || true with a subshell/no-op fallback pattern.

Changes

Cohort / File(s) Summary
Non-interactive Terminal Detection
setup.sh
After parsing args, detect non-TTY stdin and set NON_INTERACTIVE=true when INTERACTIVE_MODE not explicitly enabled; preserves existing flag mutual-exclusion logic.
Bash grep robustness
setup-modules/shell-env.sh
Replace defensive `
Task documentation
todo/tasks/t1350-brief.md
Add task brief documenting the change plan, acceptance criteria, and context for the non-interactive detection and grep fixes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

Shells now sense the dark of pipes and streams,
No noisy grep, no unexpected screams,
Flags align post-parse, CI hums and beams,
Deploy flows onward—automated dreams. 🐚✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: auto-detection of non-interactive terminals in setup.sh, directly matching the primary objective of the PR.
Linked Issues check ✅ Passed All coding objectives from issue #2464 are met: auto-detect non-interactive terminals via tty check in setup.sh, handle grep -c exit codes inside subshells, and eliminate ERR trap noise.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #2464: setup.sh non-interactive detection, shell-env.sh grep -c fixes, and supporting documentation; no extraneous modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/setup-noninteractive

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.

@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 robustness of the setup.sh script, particularly for automated environments. It introduces automatic detection of non-interactive terminals to ensure the script runs smoothly in CI/CD pipelines or agent deployments without requiring explicit --non-interactive flags. Additionally, it refines error handling for grep commands within the shell environment setup, mitigating potential script interruptions due to ERR traps.

Highlights

  • Non-interactive terminal detection: The setup.sh script now automatically detects non-interactive terminals (e.g., in CI/CD or agent environments) and sets NON_INTERACTIVE=true unless the --interactive flag is explicitly passed. This prevents read command failures in headless environments.
  • grep -c error handling: Modified grep -c calls in setup-modules/shell-env.sh to handle no-match exit codes within the subshell using || echo "0", which prevents ERR trap noise when inherit_errexit is enabled.
Changelog
  • setup-modules/shell-env.sh
    • Modified grep -c calls for export, alias, and PATH detection to handle no-match exit codes inside the subshell using || echo "0" instead of || true outside the subshell.
    • Updated comments to clarify the change prevents ERR trap noise with inherit_errexit.
  • setup.sh
    • Added a conditional block in the main function to check if INTERACTIVE_MODE is not true and stdin is not a tty (! -t 0).
    • If both conditions are met, NON_INTERACTIVE is set to true to enable auto-detection for non-interactive environments.
    • The auto-detection logic is placed after parse_args to ensure explicit --interactive flags take precedence.
  • todo/tasks/t1350-brief.md
    • Added a new markdown file detailing the task brief for t1350, outlining the problem, solution, and acceptance criteria for fixing setup.sh non-interactive terminal issues.
Activity
  • No human activity has occurred on this pull request yet.
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.

@github-actions
Copy link
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 36 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Feb 27 14:31:25 UTC 2026: Code review monitoring started
Fri Feb 27 14:31:25 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 36

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 36
  • VULNERABILITIES: 0

Generated on: Fri Feb 27 14:31:28 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

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 introduces two main improvements. First, it enhances setup.sh to automatically detect non-interactive terminals (like in CI/CD environments) and set NON_INTERACTIVE=true, preventing the script from hanging on read prompts. This is a solid improvement for automation. Second, it refactors grep -c calls in setup-modules/shell-env.sh to handle 'no match' exit codes more robustly within subshells, which is a good fix to avoid issues with ERR traps. My review includes a suggestion to further improve the grep calls by removing stderr suppression, which would make potential file permission errors visible for easier debugging.

Comment on lines +207 to +211
n=$(grep -cE '^\s*export\s+[A-Z]' "$src_file" 2>/dev/null || echo "0")
total_exports=$((total_exports + ${n:-0}))
n=$(grep -cE '^\s*alias\s+' "$src_file" 2>/dev/null) || true
n=$(grep -cE '^\s*alias\s+' "$src_file" 2>/dev/null || echo "0")
total_aliases=$((total_aliases + ${n:-0}))
n=$(grep -cE 'PATH.*=' "$src_file" 2>/dev/null) || true
n=$(grep -cE 'PATH.*=' "$src_file" 2>/dev/null || echo "0")

Choose a reason for hiding this comment

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

medium

While the change to handle grep -c's exit code inside the subshell is a good improvement, the use of 2>/dev/null is problematic. The script already verifies that these shell configuration files exist before this loop. Suppressing stderr here can hide important errors like permission issues, causing the script to silently proceed with a count of 0. It's better to let such errors be visible for debugging.

This follows the general rule: 'Avoid using 2>/dev/null to suppress errors on file operations if the file's existence has already been verified by a preceding check... This practice is redundant for 'file not found' errors and can mask other important issues like permissions problems.'

Suggested change
n=$(grep -cE '^\s*export\s+[A-Z]' "$src_file" 2>/dev/null || echo "0")
total_exports=$((total_exports + ${n:-0}))
n=$(grep -cE '^\s*alias\s+' "$src_file" 2>/dev/null) || true
n=$(grep -cE '^\s*alias\s+' "$src_file" 2>/dev/null || echo "0")
total_aliases=$((total_aliases + ${n:-0}))
n=$(grep -cE 'PATH.*=' "$src_file" 2>/dev/null) || true
n=$(grep -cE 'PATH.*=' "$src_file" 2>/dev/null || echo "0")
n=$(grep -cE '^\s*export\s+[A-Z]' "$src_file" || echo "0")
total_exports=$((total_exports + ${n:-0}))
n=$(grep -cE '^\s*alias\s+' "$src_file" || echo "0")
total_aliases=$((total_aliases + ${n:-0}))
n=$(grep -cE 'PATH.*=' "$src_file" || echo "0")
References
  1. Avoid using 2>/dev/null to suppress errors on file operations if the file's existence has already been verified by a preceding check (e.g., [[ -f "$file" ]] or an early return). This practice is redundant for 'file not found' errors and can mask other important issues like permissions problems.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@setup-modules/shell-env.sh`:
- Around line 205-212: The arithmetic failures are caused by the fallback `||
echo "0"` producing multi-line output for the `n` variable; update the three
grep assignments that set `n` (the ones using `grep -cE '^\s*export\s+[A-Z]'`,
`grep -cE '^\s*alias\s+'`, and `grep -cE 'PATH.*='`) to use a no-op fallback
(`|| :`) instead of `|| echo "0"`, so `n` will only contain grep's single
numeric output and the existing `${n:-0}` arithmetic fallback remains effective.

In `@todo/tasks/t1350-brief.md`:
- Around line 25-31: The fenced code block containing the if-statement (if [[
"$INTERACTIVE_MODE" != "true" && ! -t 0 ]]; then ... fi) inside the numbered
list needs an empty blank line before the opening ```bash and an empty blank
line after the closing ``` so the list item is properly separated (fixing
markdownlint MD031); update the list item in todo/tasks/t1350-brief.md so there
is a blank line above the fenced block and a blank line after the closing fence
before the next list item.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2b978d and e1764a0.

📒 Files selected for processing (3)
  • setup-modules/shell-env.sh
  • setup.sh
  • todo/tasks/t1350-brief.md

Comment on lines +25 to +31
1. **setup.sh**: After `parse_args`, add:
```bash
if [[ "$INTERACTIVE_MODE" != "true" && ! -t 0 ]]; then
NON_INTERACTIVE=true
fi
```
2. **setup-modules/shell-env.sh**: Change `$(grep -cE ... 2>/dev/null) || true` to `$(grep -cE ... 2>/dev/null || echo "0")` to handle no-match inside the subshell, avoiding ERR trap noise with `inherit_errexit`.
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

Fix markdownlint MD031 around the fenced code block.

The fenced block in this list item needs surrounding blank lines to keep docs tooling at A-grade quality.

📝 Suggested markdown fix
 1. **setup.sh**: After `parse_args`, add:
+
    ```bash
    if [[ "$INTERACTIVE_MODE" != "true" && ! -t 0 ]]; then
      NON_INTERACTIVE=true
    fi
    ```
+
 2. **setup-modules/shell-env.sh**: Change `$(grep -cE ... 2>/dev/null) || true` to `$(grep -cE ... 2>/dev/null || echo "0")` to handle no-match inside the subshell, avoiding ERR trap noise with `inherit_errexit`.
📝 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
1. **setup.sh**: After `parse_args`, add:
```bash
if [[ "$INTERACTIVE_MODE" != "true" && ! -t 0 ]]; then
NON_INTERACTIVE=true
fi
```
2. **setup-modules/shell-env.sh**: Change `$(grep -cE ... 2>/dev/null) || true` to `$(grep -cE ... 2>/dev/null || echo "0")` to handle no-match inside the subshell, avoiding ERR trap noise with `inherit_errexit`.
1. **setup.sh**: After `parse_args`, add:
🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis

[notice] 26-26: todo/tasks/t1350-brief.md#L26
Fenced code blocks should be surrounded by blank lines


[notice] 30-30: todo/tasks/t1350-brief.md#L30
Fenced code blocks should be surrounded by blank lines

🪛 markdownlint-cli2 (0.21.0)

[warning] 26-26: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


[warning] 30-30: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@todo/tasks/t1350-brief.md` around lines 25 - 31, The fenced code block
containing the if-statement (if [[ "$INTERACTIVE_MODE" != "true" && ! -t 0 ]];
then ... fi) inside the numbered list needs an empty blank line before the
opening ```bash and an empty blank line after the closing ``` so the list item
is properly separated (fixing markdownlint MD031); update the list item in
todo/tasks/t1350-brief.md so there is a blank line above the fenced block and a
blank line after the closing fence before the next list item.

@github-actions
Copy link
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 36 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Feb 27 14:40:00 UTC 2026: Code review monitoring started
Fri Feb 27 14:40:01 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 36

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 36
  • VULNERABILITIES: 0

Generated on: Fri Feb 27 14:40:03 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@alex-solovyev
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@alex-solovyev alex-solovyev merged commit 38c268f into main Feb 27, 2026
16 checks passed
@marcusquinn marcusquinn deleted the bugfix/setup-noninteractive branch March 3, 2026 03:23
marcusquinn added a commit that referenced this pull request Mar 14, 2026
The markdownlint MD031 finding (fenced code blocks without surrounding blank
lines) was addressed in the original PR #2468 before merge. The
quality-feedback scanner flagged it as unactioned because it tracks review
comments by existence, not by fix status. Markdownlint confirms 0 errors.

Added a Resolution section to the brief documenting this finding.

Closes #3321
alex-solovyev pushed a commit that referenced this pull request Mar 14, 2026
#4597)

The markdownlint MD031 finding (fenced code blocks without surrounding blank
lines) was addressed in the original PR #2468 before merge. The
quality-feedback scanner flagged it as unactioned because it tracks review
comments by existence, not by fix status. Markdownlint confirms 0 errors.

Added a Resolution section to the brief documenting this finding.

Closes #3321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

t1350: fix: setup.sh exits early in non-interactive terminals

1 participant