Skip to content

t2813: Fix security vulnerabilities in pulse-wrapper.sh#2823

Merged
alex-solovyev merged 4 commits intomainfrom
bugfix/t2813-pulse-wrapper-security
Mar 4, 2026
Merged

t2813: Fix security vulnerabilities in pulse-wrapper.sh#2823
alex-solovyev merged 4 commits intomainfrom
bugfix/t2813-pulse-wrapper-security

Conversation

@alex-solovyev
Copy link
Collaborator

@alex-solovyev alex-solovyev commented Mar 4, 2026

Summary

Addresses critical security vulnerabilities identified by Gemini Code Assist review on PR #2808.

Security fixes (CRITICAL)

  • Command injection via arithmetic expansion: Added _validate_int() helper that validates all values are ^[0-9]+$ before they enter $(( )) expansion. Bash arithmetic evaluates variable contents as expressions, so unsanitised strings like a[$(cmd)] execute arbitrary commands. Applied to:

    • All numeric env vars (PULSE_STALE_THRESHOLD, ORPHAN_MAX_AGE, RAM_PER_WORKER_MB, RAM_RESERVE_MB, MAX_WORKERS_CAP, QUALITY_SWEEP_INTERVAL)
    • File-sourced values (sweep timestamp from QUALITY_SWEEP_LAST_RUN)
    • Process data (ps etime components, RSS values)
    • System metrics (vm_stat page counts, sysctl page size)
    • API response data (SonarCloud issue counts, Codacy totals, scan findings)
    • Env vars used in _compute_struggle_ratio (STRUGGLE_RATIO_THRESHOLD, STRUGGLE_MIN_ELAPSED_MINUTES)
  • Markdown/mention injection: Added _sanitize_markdown() helper that strips @ mentions and backtick sequences from API response data before embedding in GitHub issue comments. Applied to SonarCloud gate_status and conditions.

  • Awk injection: Validate sys_load_1m and sys_cpu_cores are numeric before interpolating into awk expressions.

Efficiency improvements (MEDIUM)

  • Consolidated jq calls: Reduced from 3 separate jq invocations to 1 for:

    • sonar_status (gate status + conditions in single pass)
    • sonar_issues (total + severity + type breakdown in single pass)
    • scan_output (scanned + findings + issues_created in single pass)
  • Removed error-hiding 2>/dev/null: Removed stderr suppression on curl calls for SonarCloud API where it hid diagnostic information about network failures. Kept 2>/dev/null only where it's intentional (e.g., gopass show for optional credentials, kill for already-dead processes).

Verification

  • shellcheck — zero violations
  • bash -n — syntax valid

Closes #2813

Summary by CodeRabbit

  • Bug Fixes
    • Stronger numeric validation and sane defaults for configuration knobs and system metrics to prevent mis-parsing (e.g., octal issues) and arithmetic errors.
    • Safer handling of external API responses with fallbacks for missing or malformed numeric values.
    • Sanitized Markdown output in comments to remove unsafe characters and reduce injection risk.
    • More robust timestamp validation and logging to detect and recover from corrupt values.

…njection

- Add _validate_int() helper and validate all numeric env vars before
  arithmetic expansion — prevents RCE via crafted values like a[cmd]
- Validate integers from file reads (sweep timestamp), ps output (etime
  components, RSS), vm_stat (page counts), and API responses (issue
  counts) before arithmetic or -gt comparisons
- Add _sanitize_markdown() helper to strip @ mentions and backtick
  sequences from API data before embedding in GitHub issue comments
- Consolidate 3 separate jq calls on scan_output into single pass
- Consolidate 3 separate jq calls on sonar_issues into single pass
- Consolidate 2 separate jq calls on sonar_status into single pass
- Remove error-hiding 2>/dev/null on curl calls where it suppresses
  diagnostic information about network failures
- Validate sys_load_1m/sys_cpu_cores before passing to awk (prevents
  awk injection)

Closes #2813
@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 significantly enhances the security and efficiency of the pulse-wrapper.sh script. It introduces comprehensive input validation to guard against various injection attacks, particularly command injection in arithmetic operations and awk expressions, and markdown injection in generated comments. Additionally, it streamlines data processing by optimizing jq queries and improves the script's diagnostic capabilities by making curl errors visible.

Highlights

  • Security Enhancements: Implemented robust input validation to prevent command injection vulnerabilities in arithmetic expansions and awk commands, and introduced markdown sanitization for API response data to mitigate mention/markdown injection.
  • Code Efficiency: Optimized jq calls by consolidating multiple invocations into single passes for SonarCloud and scan output data, reducing overhead and improving parsing speed.
  • Improved Error Handling: Removed 2>/dev/null from curl commands interacting with the SonarCloud API, allowing diagnostic information to be visible for network failures and aiding debugging.
Changelog
  • .agents/scripts/pulse-wrapper.sh
    • Introduced _validate_int helper function to sanitize numeric environment variables and other integer inputs before arithmetic expansion, preventing command injection.
    • Implemented _sanitize_markdown helper function to strip @ mentions and backtick sequences from API response data, preventing markdown/mention injection in GitHub comments.
    • Added numeric validation for process age components (days, hours, minutes, seconds) derived from ps output.
    • Validated STRUGGLE_RATIO_THRESHOLD and STRUGGLE_MIN_ELAPSED_MINUTES to ensure they are numeric before use in arithmetic operations.
    • Ensured numeric validation for page_size, vm_free, and vm_inactive values obtained from sysctl and vm_stat.
    • Added explicit numeric validation for sys_load_1m and sys_cpu_cores before their use in awk expressions to prevent injection.
    • Validated the last_run timestamp read from QUALITY_SWEEP_LAST_RUN to prevent command injection if the file contains non-numeric data.
    • Removed 2>/dev/null from curl commands interacting with the SonarCloud API to expose potential network errors.
    • Refactored SonarCloud quality gate status and conditions extraction to use a single jq invocation, improving efficiency.
    • Refactored SonarCloud issues summary extraction (total, severity, type breakdown) to use a single jq invocation, improving efficiency, and added numeric validation for total_issues.
    • Added numeric validation for codacy_total extracted from Codacy API responses.
    • Refactored merged PR review scanner output extraction (scanned, findings, issues_created) to use a single jq invocation and added numeric validation for these values.
    • Added numeric validation for rss (Resident Set Size) values in cleanup_orphans before arithmetic calculations.
    • Added numeric validation for page_size, free_pages, inactive_pages, and free_mb in calculate_max_workers to prevent arithmetic expansion vulnerabilities.
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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 436301d4-bca7-4a9f-92d6-68bdc0304aaf

📥 Commits

Reviewing files that changed from the base of the PR and between 38ba009 and a3d2381.

📒 Files selected for processing (1)
  • .agents/scripts/pulse-wrapper.sh

Walkthrough

Introduces centralized integer validation and Markdown sanitization in .agents/scripts/pulse-wrapper.sh; replaces ad-hoc numeric checks, hardens external API/state handling, consolidates jq usage, and validates timestamps and system metrics to prevent octal interpretation and injection in Markdown/JSON outputs.

Changes

Cohort / File(s) Summary
Core helpers & sanitizers
.agents/scripts/pulse-wrapper.sh
Adds _validate_int(name, value, default, min) for canonical base‑10 integer coercion and _sanitize_markdown(input) to strip @ mentions and backticks.
Config knobs validation
.agents/scripts/pulse-wrapper.sh
Applies _validate_int to PULSE_STALE_THRESHOLD, ORPHAN_MAX_AGE, RAM_PER_WORKER_MB, RAM_RESERVE_MB, MAX_WORKERS_CAP, QUALITY_SWEEP_INTERVAL to enforce numeric defaults and avoid octal misinterpretation.
External API & output hardening
.agents/scripts/pulse-wrapper.sh
Guards SonarCloud, Codacy, CodeRabbit, GitHub API outputs with numeric validation/sanitization, URL-encodes project keys, and avoids direct arithmetic on untrusted values.
State file / jq usage
.agents/scripts/pulse-wrapper.sh
Consolidates jq reads/writes, switches to jq --arg/--argjson for safe JSON construction, validates last_run timestamps, and logs/resets corrupt state.
Arithmetic & system metrics
.agents/scripts/pulse-wrapper.sh
Validates system metrics (page_size, vm_free, vm_inactive, MemAvailable) and other counts with regex before arithmetic; replaces unsafe $((...)) usage with guarded numeric operations.
Markdown/embed outputs
.agents/scripts/pulse-wrapper.sh
Sanitizes gate_status and trigger-reason strings before creating PR comments/Markdown to prevent mention/Markdown injection.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #2789: Touches the same pulse-wrapper.sh scan invocation and error-handling for external scan outputs; closely related to API/output hardening.
  • #2808: Prior PR with review feedback on pulse-wrapper.sh (security and jq usage) that this change addresses.
  • #2745: Related hardening of arithmetic handling and counting logic in pulse-wrapper.sh, complementary to centralized validation.

Poem

🔧 Validators hum, the inputs tame,

Backticks muted, numbers named,
State restored, timestamps bright,
APIs checked before the write,
A steadier pulse through day and night.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 identifies the main security fix (vulnerabilities in pulse-wrapper.sh) with a concise, actionable description.
Linked Issues check ✅ Passed All five critical/medium security findings from issue #2813 are comprehensively addressed: command injection prevention via _validate_int(), JSON injection mitigation via jq --arg/--argjson, markdown sanitization via _sanitize_markdown(), consolidated jq calls, and simplified arithmetic validation.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing #2813 security review feedback; the PR maintains alignment with sweep state variables introduced in the concurrent t1390 CodeRabbit trigger feature without introducing unrelated modifications.
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 (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/t2813-pulse-wrapper-security

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.

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 significant security hardening for pulse-wrapper.sh. It successfully implements _validate_int() to prevent command injection via arithmetic expansion and _sanitize_markdown() for some API response data, applying these across various inputs. The consolidation of multiple jq calls also improves efficiency. However, critical command injection vulnerabilities persist in curl calls to the SonarCloud API due to unsanitized project_key interpolation; robust URL encoding, perhaps using python3, is recommended. Furthermore, some SonarCloud issue breakdown fields lack markdown sanitization, potentially causing notification spam or UI disruption. A minor suggestion is to remove a remaining stderr suppression to improve debuggability.

# SonarCloud public API — quality gate status
local sonar_status
sonar_status=$(curl -s "https://sonarcloud.io/api/qualitygates/project_status?projectKey=${project_key}" 2>/dev/null || echo "")
sonar_status=$(curl -s "https://sonarcloud.io/api/qualitygates/project_status?projectKey=${project_key}" || echo "")

Choose a reason for hiding this comment

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

security-critical critical

The project_key variable is interpolated directly into the curl URL string without sanitization. If an attacker can control the project_key (e.g., via a modified .aidevops.json in a pull request), they can inject double quotes to terminate the URL string and add arbitrary curl options, such as -o to write to arbitrary files, which can lead to Remote Code Execution (RCE). Consider using python3 for robust URL encoding.

References
  1. Prefer using 'python3' (e.g., 'urllib.parse.quote') for robust URL encoding in shell scripts to handle unicode correctly and avoid potential 'jq' version compatibility issues.

# Fetch open issues summary
local sonar_issues
sonar_issues=$(curl -s "https://sonarcloud.io/api/issues/search?componentKeys=${project_key}&statuses=OPEN,CONFIRMED,REOPENED&ps=1&facets=severities,types" 2>/dev/null || echo "")
sonar_issues=$(curl -s "https://sonarcloud.io/api/issues/search?componentKeys=${project_key}&statuses=OPEN,CONFIRMED,REOPENED&ps=1&facets=severities,types" || echo "")

Choose a reason for hiding this comment

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

security-critical critical

The project_key variable is interpolated directly into the curl URL string without sanitization. If an attacker can control the project_key (e.g., via a modified .aidevops.json in a pull request), they can inject double quotes to terminate the URL string and add arbitrary curl options, such as -o to write to arbitrary files, which can lead to Remote Code Execution (RCE). Consider using python3 for robust URL encoding.

References
  1. Prefer using 'python3' (e.g., 'urllib.parse.quote') for robust URL encoding in shell scripts to handle unicode correctly and avoid potential 'jq' version compatibility issues.

sys_load_ratio=$(awk "BEGIN {printf \"%d\", (${sys_load_1m} / ${sys_cpu_cores}) * 100}" 2>/dev/null || echo "?")
# Validate numeric before passing to awk (prevents awk injection)
if [[ "$sys_load_1m" =~ ^[0-9]+\.?[0-9]*$ ]] && [[ "$sys_cpu_cores" =~ ^[0-9]+$ ]]; then
sys_load_ratio=$(awk "BEGIN {printf \"%d\", (${sys_load_1m} / ${sys_cpu_cores}) * 100}" 2>/dev/null || echo "?")

Choose a reason for hiding this comment

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

medium

While the new validation on line 1093 prevents awk injection, this 2>/dev/null still suppresses stderr, which could hide other issues (e.g., if the awk command is not found or has other unexpected errors). The PR description mentions removing error-hiding 2>/dev/null, and several general rules for this repository advise against it for better debugging. Since you have a fallback with || echo "?", it's safe to let potential errors be printed to stderr.

Suggested change
sys_load_ratio=$(awk "BEGIN {printf \"%d\", (${sys_load_1m} / ${sys_cpu_cores}) * 100}" 2>/dev/null || echo "?")
sys_load_ratio=$(awk "BEGIN {printf \"%d\", (${sys_load_1m} / ${sys_cpu_cores}) * 100}" || echo "?")
References
  1. Avoid using '2>/dev/null' for blanket suppression of command errors in shell scripts to ensure that authentication, syntax, or system issues remain visible for debugging.

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

Caution

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

⚠️ Outside diff range comments (1)
.agents/scripts/pulse-wrapper.sh (1)

1569-1595: ⚠️ Potential issue | 🟠 Major

Add error handling and timeouts to SonarCloud curl calls

The current curl -s invocations at lines 1569 and 1594 suppress all error output and lack timeout protections, risking silent failures and unbounded waits in automation workflows. Use -S to show errors despite silent mode, --fail to exit on HTTP errors, and timeout flags to prevent hanging:

Fix
-			sonar_status=$(curl -s "https://sonarcloud.io/api/qualitygates/project_status?projectKey=${project_key}" || echo "")
+			sonar_status=$(curl -sS --fail --connect-timeout 5 --max-time 20 \
+				"https://sonarcloud.io/api/qualitygates/project_status?projectKey=${project_key}" || echo "")
@@
-			sonar_issues=$(curl -s "https://sonarcloud.io/api/issues/search?componentKeys=${project_key}&statuses=OPEN,CONFIRMED,REOPENED&ps=1&facets=severities,types" || echo "")
+			sonar_issues=$(curl -sS --fail --connect-timeout 5 --max-time 20 \
+				"https://sonarcloud.io/api/issues/search?componentKeys=${project_key}&statuses=OPEN,CONFIRMED,REOPENED&ps=1&facets=severities,types" || echo "")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/pulse-wrapper.sh around lines 1569 - 1595, The SonarCloud
curl calls (producing sonar_status and sonar_issues and feeding
gate_data/sonar_section) currently use silent curl which hides errors and have
no timeouts; update both invocations that set sonar_status and sonar_issues to
include error reporting and timeouts (e.g., add -S --fail and sensible
--connect-timeout/--max-time flags) so failures return non-empty error output or
fail fast, and ensure the existing gate_data parsing and
_sanitize_markdown/sonar_section logic still handles an empty or failed response
gracefully (e.g., fall back to "UNKNOWN" or an empty conditions string).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.agents/scripts/pulse-wrapper.sh:
- Around line 46-61: The _validate_int function currently returns the raw
numeric string (which may have leading zeros) causing bash to interpret values
as octal in subsequent arithmetic; update _validate_int to canonicalize
validated integers to base-10 before returning (e.g., convert to a decimal
integer using an explicit base-10 conversion or strip leading zeros) so any
input like "08" or "01024" becomes a safe decimal; ensure the function still
rejects non-digits, logs the same error message, and returns the normalized
decimal for the variables PULSE_STALE_THRESHOLD, ORPHAN_MAX_AGE,
RAM_PER_WORKER_MB, RAM_RESERVE_MB, MAX_WORKERS_CAP, and QUALITY_SWEEP_INTERVAL.

---

Outside diff comments:
In @.agents/scripts/pulse-wrapper.sh:
- Around line 1569-1595: The SonarCloud curl calls (producing sonar_status and
sonar_issues and feeding gate_data/sonar_section) currently use silent curl
which hides errors and have no timeouts; update both invocations that set
sonar_status and sonar_issues to include error reporting and timeouts (e.g., add
-S --fail and sensible --connect-timeout/--max-time flags) so failures return
non-empty error output or fail fast, and ensure the existing gate_data parsing
and _sanitize_markdown/sonar_section logic still handles an empty or failed
response gracefully (e.g., fall back to "UNKNOWN" or an empty conditions
string).

ℹ️ Review info
Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8e87d191-b86c-4950-b747-3b976bc41538

📥 Commits

Reviewing files that changed from the base of the PR and between b5173be and 64f34c0.

📒 Files selected for processing (1)
  • .agents/scripts/pulse-wrapper.sh

- _validate_int(): canonicalize to base-10 via printf '%d' "$((10#$value))"
  to prevent bash octal interpretation of leading-zero inputs (CodeRabbit)
- URL-encode project_key via python3 urllib.parse.quote before interpolation
  into SonarCloud curl URLs to prevent command injection (Gemini)
- Add -sS --fail --connect-timeout 5 --max-time 20 to SonarCloud curl calls
  with graceful fallback to empty string on failure (CodeRabbit)
- Sanitize severity_breakdown and type_breakdown API fields via
  _sanitize_markdown() before embedding in GitHub comments (Gemini)
- Remove 2>/dev/null from awk sys_load_ratio for better debuggability (Gemini)
…Rabbit trigger

Merge main into bugfix/t2813-pulse-wrapper-security, resolving conflicts in
pulse-wrapper.sh SonarCloud section:

- Keep consolidated single-jq-pass approach from security branch (efficiency)
- Extend issues jq query to also extract high/critical count in same pass
- Wire sweep_gate_status, sweep_total_issues, sweep_high_critical into the
  CodeRabbit conditional trigger logic added in main (t1390)
- Preserve all security hardening: URL-encoded project_key, curl timeouts,
  _sanitize_markdown on API data, numeric validation

Verification: shellcheck zero violations, bash -n syntax valid
@alex-solovyev
Copy link
Collaborator Author

Merge conflict resolution + review feedback

Merge conflicts resolved

Merged main into this branch. The conflicts were in the SonarCloud section of pulse-wrapper.sh where main added sweep_* variables for the CodeRabbit conditional trigger (t1390) while this branch had consolidated jq + sanitization.

Resolution strategy: Keep both — the security hardening from this branch AND the sweep state variables from main:

  1. Gate status section: Kept consolidated single-jq-pass + _sanitize_markdown(), added sweep_gate_status="$gate_status" assignment
  2. Issues section: Extended the consolidated jq query to also extract high/critical count (MAJOR/CRITICAL/BLOCKER) in the same pass, wired sweep_total_issues and sweep_high_critical for the CodeRabbit trigger logic

Review feedback status

All review feedback from the previous round was already addressed in commit 30fc755:

Reviewer Finding Status
CodeRabbit _validate_int octal canonicalization Fixed (30fc755)
CodeRabbit curl error handling + timeouts Fixed (30fc755)
Gemini URL-encode project_key Fixed (30fc755)
Gemini Remove 2>/dev/null from awk Fixed (30fc755)
Gemini Sanitize severity/type breakdowns Fixed (30fc755)

Verification

  • shellcheck — zero violations
  • bash -n — syntax valid
  • Sweep variables (sweep_gate_status, sweep_total_issues, sweep_high_critical) correctly flow into CodeRabbit conditional trigger (section 5) and _save_sweep_state()

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Wed Mar 4 13:36:27 UTC 2026: Code review monitoring started
Wed Mar 4 13:36:27 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 114

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 114
  • VULNERABILITIES: 0

Generated on: Wed Mar 4 13:36:30 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@github-actions github-actions bot added the bug Auto-created from TODO.md tag label Mar 4, 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.

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 @.agents/scripts/pulse-wrapper.sh:
- Around line 1831-1839: After calling _load_sweep_state() ensure the returned
prev_issues and prev_high_critical are normalized to numeric values before any
delta arithmetic: check each (prev_issues, prev_high_critical) with a numeric
regex (e.g. ^[0-9]+$) or arithmetic-safe test and set to 0 when invalid or empty
so downstream calculations that use prev_issues and prev_high_critical won't
fail; add this validation immediately after the _load_sweep_state() call and
before the code that computes deltas from sweep_total_issues and
sweep_high_critical.
- Around line 46-63: The _validate_int function currently allows zero which
makes RAM_PER_WORKER_MB=0 cause a divide-by-zero later; update validation so
divisor-backed settings cannot be zero by either (a) extending _validate_int to
accept an optional minimum parameter and return the default if value < min, or
(b) after calling _validate_int for RAM_PER_WORKER_MB check the returned value
and if it is less than 1 print an error and fall back to the default (1024);
specifically update the call that sets RAM_PER_WORKER_MB and the _validate_int
logic to enforce a minimum of 1 for that variable (reference symbols:
_validate_int and RAM_PER_WORKER_MB) so division operations using
RAM_PER_WORKER_MB never receive zero.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 150c3abb-f3e8-49cd-97d9-2d8e27256e86

📥 Commits

Reviewing files that changed from the base of the PR and between 64f34c0 and 38ba009.

📒 Files selected for processing (1)
  • .agents/scripts/pulse-wrapper.sh

- _validate_int: add optional min parameter; RAM_PER_WORKER_MB uses min=1
  to prevent divide-by-zero in calculate_max_workers
- Post _load_sweep_state: validate prev_issues and prev_high_critical are
  numeric before delta arithmetic; fall back to 0 on corrupt/missing values

Addresses CodeRabbit CHANGES_REQUESTED on PR #2823 (latest review 2026-03-04T13:42)
@alex-solovyev
Copy link
Collaborator Author

CodeRabbit CHANGES_REQUESTED addressed (2026-03-04T13:42 review)

Both actionable findings from the latest CodeRabbit review are now fixed in commit a3d2381:

1. _validate_int zero → divide-by-zero for RAM_PER_WORKER_MB
Added optional min parameter to _validate_int. RAM_PER_WORKER_MB now passes min=1 — any value < 1 (including 0) falls back to the default (1024). This prevents the divide-by-zero in calculate_max_workers.

2. _load_sweep_state return values not validated before delta arithmetic
Added numeric regex guards immediately after IFS='|' read for prev_issues and prev_high_critical. Corrupt or missing state file values fall back to 0 before the $(( )) delta calculations.

ShellCheck: zero violations. bash -n: syntax valid.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Wed Mar 4 14:10:01 UTC 2026: Code review monitoring started
Wed Mar 4 14:10:01 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 114

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 114
  • VULNERABILITIES: 0

Generated on: Wed Mar 4 14:10:04 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2026

@alex-solovyev
Copy link
Collaborator Author

Dispatching a worker to address CodeRabbit's CHANGES_REQUESTED review feedback. Issues flagged:

  1. Add error handling and timeouts to SonarCloud curl calls (lines 1569, 1594)
  2. Normalize prev_issues and prev_high_critical to numeric values before delta arithmetic (lines 1831-1839)

Resolves #2813

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.

quality-debt: .agents/scripts/pulse-wrapper.sh — PR #2808 review feedback (critical)

1 participant