Skip to content

fix: use prefix increment to avoid set -e exit on zero#70

Merged
marcusquinn merged 1 commit intomainfrom
bugfix/fix-command-count-arithmetic
Jan 13, 2026
Merged

fix: use prefix increment to avoid set -e exit on zero#70
marcusquinn merged 1 commit intomainfrom
bugfix/fix-command-count-arithmetic

Conversation

@alex-solovyev
Copy link
Collaborator

@alex-solovyev alex-solovyev commented Jan 13, 2026

The script uses 'set -euo pipefail' for safety. When command_count=0, the postfix increment ((command_count++)) returns exit code 1 because the expression evaluates to 0 (falsy), causing immediate script exit.

Changed all ((command_count++)) to ((++command_count)) which returns the new value (always > 0), avoiding the false failure.

This fixes the issue where only the first command (agent-review) was created, with the remaining ~40 commands never generated.

Summary by CodeRabbit

  • Refactor
    • Internal code optimization to improve performance and maintainability.

Note: This release contains no user-facing changes or new features. It consists of internal improvements to existing functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

The script uses 'set -euo pipefail' for safety. When command_count=0,
the postfix increment ((command_count++)) returns exit code 1 because
the expression evaluates to 0 (falsy), causing immediate script exit.

Changed all ((command_count++)) to ((++command_count)) which returns
the new value (always > 0), avoiding the false failure.

This fixes the issue where only the first command (agent-review) was
created, with the remaining ~40 commands never generated.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

Walkthrough

The diff updates increment operator usage throughout .agent/scripts/generate-opencode-commands.sh, replacing post-increment expressions (command_count++) with pre-increment expressions (++command_count) across the script's command generation and auto-discovery logic, maintaining consistent coding style without altering behavioral semantics.

Changes

Cohort / File(s) Summary
Increment Operator Standardization
\.agent/scripts/generate-opencode-commands\.sh
Updated 41 occurrences of post-increment operators to pre-increment operators for consistent coding style and DevOps best practices across command counting and auto-discovery logic

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

Pre, not post—the increment stands tall, ⚡
Consistent style throughout the call,
DevOps excellence, zero debt in sight,
Every operator shines just right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the core fix: changing from post-increment to pre-increment to prevent set -e from exiting when command_count evaluates to 0, which directly addresses the root cause of commands not being generated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings

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 @alex-solovyev, 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 a critical bug in a shell script that prevented the full generation of commands. By switching from postfix to prefix increment for a counter variable, the script now correctly handles its execution flow under strict error handling, ensuring all commands are created as intended. This change improves the reliability and completeness of the command generation process.

Highlights

  • Fixing Script Execution Logic: The pull request addresses an issue in a shell script where the set -euo pipefail option caused premature exit. Specifically, the postfix increment operator ((command_count++)) would return an exit code of 1 when command_count was 0, leading the script to terminate unexpectedly.
  • Switch to Prefix Increment: To resolve this, all instances of ((command_count++)) have been replaced with ((++command_count)). The prefix increment operator always returns the new, incremented value (which is always greater than 0 in this context), thus preventing the script from exiting due to a 'falsy' return code.
  • Ensuring All Commands are Generated: This change ensures that all intended commands are generated by the script, fixing a bug where only the first command (e.g., /agent-review) was created, and subsequent commands were never processed.
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.

@sonarqubecloud
Copy link

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 addresses a critical bug in the shell script caused by the interaction of set -e and the postfix increment operator. When command_count was 0, ((command_count++)) would evaluate to 0, which has an exit code of 1 in bash arithmetic, causing the script to terminate prematurely. By changing all occurrences to the prefix increment ((++command_count)), the expression evaluates to the new, non-zero value, resulting in an exit code of 0 and allowing the script to continue. This is a solid and well-explained fix that resolves the reported issue of commands not being generated. The changes are applied consistently throughout the file. For future consideration, the script contains significant code duplication for command creation that could be refactored into a function to improve maintainability, but the focused scope of this PR is appropriate.

@augmentcode
Copy link

augmentcode bot commented Jan 13, 2026

🤖 Augment PR Summary

Summary: Prevents OpenCode command generation from exiting early under set -euo pipefail when the command counter is zero.

Changes:

  • Replaced postfix increments ((command_count++)) with prefix ((++command_count)) across all command creation steps.
  • Ensures the arithmetic expression evaluates to a non-zero value, avoiding a non-success exit status on the first increment.

Technical Notes: With command_count=0 initialized, prefix increment returns 1+ so the script continues generating the full command set.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@github-actions
Copy link

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Tue Jan 13 18:46:02 UTC 2026: Code review monitoring started
Tue Jan 13 18:46:02 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 256
Tue Jan 13 18:46:02 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Tue Jan 13 18:46:04 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 256
  • VULNERABILITIES: 0

Generated on: Tue Jan 13 18:46:43 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

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: 0

🧹 Nitpick comments (1)
.agent/scripts/generate-opencode-commands.sh (1)

16-16: Use pre-increment pattern ((++var)) consistently across all shell scripts with set -e.

This file correctly uses pre-increment throughout. However, codebase-wide scanning reveals post-increment patterns ((var++)) in 15+ other automation scripts (including beads-sync-helper.sh, dev-browser-helper.sh, quality-loop-helper.sh, todo-ready.sh, site-crawler-helper.sh, pre-commit-hook.sh, postflight-check.sh, linters-local.sh), many without the || true workaround. With set -e, post-increment returns the old value (0 on first increment = exit code 1 → script exits unexpectedly); pre-increment returns the new value (non-zero = exit code 0 → safe). Standardize on pre-increment across all .agent/scripts/*.sh files for consistency and robustness.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f889080 and 0124421.

📒 Files selected for processing (1)
  • .agent/scripts/generate-opencode-commands.sh
🧰 Additional context used
📓 Path-based instructions (1)
.agent/scripts/*.sh

⚙️ CodeRabbit configuration file

.agent/scripts/*.sh: Automation scripts - focus on:

  • Reliability and robustness
  • Clear logging and feedback
  • Proper exit codes
  • Error recovery mechanisms

Files:

  • .agent/scripts/generate-opencode-commands.sh
🧠 Learnings (2)
📚 Learning: 2025-12-22T01:24:53.937Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: templates/home/AGENTS.md:0-0
Timestamp: 2025-12-22T01:24:53.937Z
Learning: Follow all security protocols and working directory specifications defined in ~/Git/aidevops/AGENTS.md

Applied to files:

  • .agent/scripts/generate-opencode-commands.sh
📚 Learning: 2026-01-06T15:57:56.007Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.007Z
Learning: Applies to **/.agent/scripts/linters-local.sh : Run quality checks before committing using .agent/scripts/linters-local.sh

Applied to files:

  • .agent/scripts/generate-opencode-commands.sh
⏰ 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). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
.agent/scripts/generate-opencode-commands.sh (3)

82-1524: Consistent fix applied across all manual command generations.

All 40 manual command increments now use prefix increment ((++command_count)). While the bug primarily manifests on the first increment (when command_count=0), applying the fix uniformly maintains consistency and prevents issues if initialization logic changes in the future.


1534-1555: Auto-discovery section increment also corrected.

The auto-discovery loop that processes commands from scripts/commands/*.md now uses prefix increment as well. This maintains consistency and ensures robustness if the script structure changes.


30-57: Critical bug fix confirmed: pre-increment resolves set -e early exit.

Under set -euo pipefail, the original post-increment ((command_count++)) returns 0 when command_count is zero, triggering a fatal exit code and terminating the script after the first command. The corrected pre-increment ((++command_count)) returns 1 (truthy), allowing proper execution flow. This explains why only agent-review was generated previously.

All 41 increment operations throughout the script have been updated consistently. The fix is both necessary and correctly implemented.

@marcusquinn marcusquinn merged commit 47c54fd into main Jan 13, 2026
9 checks passed
@marcusquinn marcusquinn deleted the bugfix/fix-command-count-arithmetic branch January 13, 2026 21:29
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