Skip to content

fix: guard ((var++)) with || true to prevent silent exit under set -e#548

Merged
alex-solovyev merged 1 commit intomainfrom
bugfix/t152-fix-cleaned-arithmetic
Feb 8, 2026
Merged

fix: guard ((var++)) with || true to prevent silent exit under set -e#548
alex-solovyev merged 1 commit intomainfrom
bugfix/t152-fix-cleaned-arithmetic

Conversation

@alex-solovyev
Copy link
Collaborator

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

Summary

  • Fix ((var++)) arithmetic expressions that silently abort scripts under set -e when the variable is 0
  • In bash, ((0)) returns exit code 1, and set -e (errexit) treats this as a fatal error
  • This caused setup.sh --non-interactive to abort at cleanup_deprecated_mcps() before reaching deploy_aidevops_agents(), leaving deployed agents at a stale version

Changes

  • setup.sh: Fixed 33 instances of ((var++))((var++)) || true
  • 10 helper scripts: Fixed the same pattern in scripts that use set -e:
    • anti-detect-helper.sh, codacy-cli-chunked.sh, crawl4ai-examples.sh
    • linter-manager.sh, localhost-helper.sh, markdown-formatter.sh
    • quality-cli-manager.sh, setup-linters-wizard.sh, setup-local-api-keys.sh
    • toon-helper.sh

Testing

  • bash -n syntax check passes on all 11 modified files
  • setup.sh --non-interactive now runs to completion (previously silently aborted)
  • Verified agents deploy correctly with VERSION file synced

Root Cause

set -euo pipefail
local cleaned=0
# ... inside a loop when first match found:
((cleaned++))  # cleaned is 0, post-increment returns 0, (( 0 )) = exit 1 → script dies

Closes t152

Summary by CodeRabbit

  • Chores
    • Enhanced error handling robustness across shell scripts to prevent unexpected termination during script execution.

In bash, ((var++)) when var=0 evaluates the post-increment expression
to 0, which (( )) treats as falsy (exit code 1). With set -e (errexit),
this silently aborts the script.

This caused setup.sh --non-interactive to abort at cleanup_deprecated_mcps()
before reaching deploy_aidevops_agents(), leaving deployed agents at a stale
version.

Fixed 33 instances in setup.sh and 10 additional helper scripts that use
set -e with the same pattern.

Closes #t152
@gemini-code-assist
Copy link

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

Walkthrough

Multiple shell scripts across the project's automation framework add || true guards to arithmetic increment expressions. This defensive pattern prevents set -e strict mode from causing premature script termination when arithmetic operations complete without error, improving script resilience without altering functional behavior.

Changes

Cohort / File(s) Summary
Arithmetic Increment Resilience — Minimal Scale
.agents/scripts/anti-detect-helper.sh, .agents/scripts/localhost-helper.sh, .agents/scripts/setup-linters-wizard.sh, .agents/scripts/setup-local-api-keys.sh
Single increment expression guarded with || true to prevent set -e termination on arithmetic evaluation; no functional behavior change.
Arithmetic Increment Resilience — Moderate Scale
.agents/scripts/crawl4ai-examples.sh, .agents/scripts/markdown-formatter.sh, .agents/scripts/toon-helper.sh
Two or more increment expressions (count, i, success_count, total_files, changed_files) appended with || true for error resilience.
Arithmetic Increment Resilience — Extended Scale
.agents/scripts/codacy-cli-chunked.sh, .agents/scripts/quality-cli-manager.sh
Multiple counter increments across different analysis sections guarded with || true; quality-cli-manager additionally adds status summary output after CLI installation sections.
Arithmetic Increment Resilience — Comprehensive Scale
.agents/scripts/linter-manager.sh, setup.sh
29–40 lines modified; all success/total counter increments throughout linter installation and setup orchestration logic now protected with || true guards.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • marcusquinn

Poem

🛡️ With falsy guards on arithmetic dreams,
No early exits disrupt our schemes.
Each ||\ true a safety net cast,
Shell resilience built to forever last.
Zero debt maintained, precise and bright! ✨

🚥 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 clearly and specifically describes the main change: guarding arithmetic increment expressions with || true to prevent script exit under set -e.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/t152-fix-cleaned-arithmetic

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.

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Feb 8 02:26:58 UTC 2026: Code review monitoring started
Sun Feb 8 02:26:58 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 33

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 33
  • VULNERABILITIES: 0

Generated on: Sun Feb 8 02:27:01 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 8, 2026

@alex-solovyev alex-solovyev merged commit c813053 into main Feb 8, 2026
10 of 11 checks passed
alex-solovyev added a commit that referenced this pull request Feb 8, 2026
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
.agents/scripts/linter-manager.sh (1)

374-402: ⚠️ Potential issue | 🟠 Major

Guard all unguarded arithmetic expressions in install_detected_linters() and install_all_linters() — fourteen instances of ((total_failures += $?)) lack protection and will silently abort when any linter installation succeeds (exit 0) while total_failures remains 0, triggering set -e.

🐛 Proposed fix — guard these the same way
-        ((total_failures += $?))
+        ((total_failures += $?)) || true

Apply to all instances at lines 378, 382, 386, 390, 394, 398, 402 (in install_detected_linters()) and 427, 431, 435, 439, 443, 447, 451 (in install_all_linters()).

.agents/scripts/codacy-cli-chunked.sh (1)

504-506: ⚠️ Potential issue | 🟡 Minor

Pre-existing: main dereferences $2 unconditionally under set -u.

local _arg2="$2" will abort when the script is invoked with fewer than 2 arguments (e.g., ./codacy-cli-chunked.sh help). This isn't introduced by this PR, but it's in the same function and will cause the exact class of silent-exit bug you're fixing.

Suggested fix
 main() {
-    local _arg2="$2"
+    local _arg2="${2:-}"
     local command="${1:-help}"
.agents/scripts/toon-helper.sh (1)

372-377: ⚠️ Potential issue | 🟡 Minor

Pre-existing: main dereferences positional params unconditionally under set -u.

Lines 374–377 assign $2 through $5 without defaults. Calling ./toon-helper.sh encode foo.json (3 args) will abort on local arg4="$4". Same class of bug this PR is addressing.

Suggested fix
 main() {
     local command="${1:-help}"
-    local arg2="$2"
-    local arg3="$3"
-    local arg4="$4"
-    local arg5="$5"
+    local arg2="${2:-}"
+    local arg3="${3:-}"
+    local arg4="${4:-}"
+    local arg5="${5:-}"
🧹 Nitpick comments (2)
.agents/scripts/anti-detect-helper.sh (1)

1099-1099: Redundant double || true — one is sufficient.

The line now reads:

[[ -d "$dir" ]] && [[ "$(basename "$dir")" != "default" ]] && ((profile_count++)) || true || true

The second || true is a no-op since the first already guarantees exit code 0. Looks like the PR appended || true without noticing one was already present.

🧹 Remove the redundant guard
-        [[ -d "$dir" ]] && [[ "$(basename "$dir")" != "default" ]] && ((profile_count++)) || true || true
+        [[ -d "$dir" ]] && [[ "$(basename "$dir")" != "default" ]] && ((profile_count++)) || true
.agents/scripts/quality-cli-manager.sh (1)

92-163: Consider extracting the repetitive install/count pattern.

Each CLI block in install_clis, init_clis, and analyze_with_clis follows the identical structure: conditional check → execute → increment success on success → always increment total. This is repeated ~18 times across three functions. A small helper (e.g., try_cli_command) could reduce ~6 lines per CLI to ~1 and eliminate the risk of missing a || true guard in the future.

Not blocking — the current code is correct and readable. Just flagging the duplication since maintaining zero tech debt is the goal.

@alex-solovyev
Copy link
Collaborator Author

Reopening: task was falsely marked complete in TODO.md, triggering auto-close via issue-sync. Reverted in PR #616.

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