Skip to content

Claude/cpu guard review fixes dn d8u - #118

Merged
gamblecodezcom merged 5 commits into
mainfrom
claude/cpu-guard-review-fixes-DnD8u
Mar 1, 2026
Merged

Claude/cpu guard review fixes dn d8u#118
gamblecodezcom merged 5 commits into
mainfrom
claude/cpu-guard-review-fixes-DnD8u

Conversation

@gamblecodezcom

@gamblecodezcom gamblecodezcom commented Mar 1, 2026

Copy link
Copy Markdown
Owner

User description

Summary by Sourcery

Add CPU forensics mode to the rw_cpu_guard daemon and introduce a one-shot scripted redeploy flow for the Runewager bot.

New Features:

  • Introduce a passive CPU forensics mode in rw_cpu_guard that captures system metrics and summarizes findings without killing processes.
  • Add a runewager_redeploy script that automates stopping the bot, rebuilding dependencies, reinstalling the CPU guard, restarting the service, running health checks, and optionally launching background forensics.

Enhancements:

  • Adjust rw_cpu_guard strike handling so MAX_STRIKES is honored across the full throttling and kill ladder, including clearer logging and Telegram alerts.

CodeAnt-AI Description

Add a one-shot redeploy script and passive CPU forensics; fix guard strike logic

What Changed

  • Added scripts/runewager_redeploy.sh: a root-run script that stops the bot, clears port 3000, rebuilds npm deps, installs/restarts the CPU guard, starts the bot, waits up to 30s for /health, optionally launches a 5-minute background forensics trace, and prints a final status summary; supports --dry-run and --skip-forensics.
  • Extended rw_cpu_guard.sh with a passive forensics mode (default 5 minutes) that collects vmstat/iostat/1s process traces, process-count samples, and periodic top snapshots into a directory and prints a concise summary; safe to run alongside the daemon and configurable via FORENSICS_DIR and FORENSICS_DURATION; added --forensics and --forensics=N CLI options.
  • Fixed kill-ladder behavior so MAX_STRIKES is respected: STOP/CONT repeats for strikes 2..(MAX_STRIKES-1) and termination only occurs at strike >= MAX_STRIKES; log and Telegram messages now include strike X/Y context.

Impact

✅ Shorter redeploys with automated health checks
✅ Clearer forensic reports for transient CPU spikes
✅ Fewer unintended process terminations due to correct strike handling

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • New Features

    • Added automated redeploy capability for streamlined bot updates with built-in health monitoring and status verification.
    • Introduced system diagnostics and performance analysis tools for CPU usage monitoring and forensic data collection.
  • Chores

    • Enhanced deployment infrastructure with comprehensive logging and error handling for operational reliability.

claude added 3 commits March 1, 2026 11:34
The ladder previously hardcoded 3 tiers (strike==1 / strike==2 / else),
so MAX_STRIKES had no effect — termination always fired on the 3rd hit
regardless of configuration.

Fix: replace `strikes == 2` with `strikes < MAX_STRIKES` so the STOP/CONT
pause repeats for strikes 2..(MAX_STRIKES-1) and termination only triggers
at strike >= MAX_STRIKES.  All log and Telegram messages now include the
current strike / total (e.g. "STRIKE3/5") for clarity.

Reported by CodeAnt AI review of PR #116.

https://claude.ai/code/session_01WpEqAiDbpqnBywMjYXJHf4
rw_cpu_guard.sh — v3 upgrade:
- --forensics [N] / --forensics=N mode merged from CPU.sh:
  vmstat (steal time), iostat (disk wait), 1-second ps tracer
  (catches sub-8s spikes), proc-count fork-storm detector, 10s
  top snapshots — all collected in /root/rw_cpu_forensics/
- Prints a structured summary after collection: top offenders,
  peak proc count, steal-time samples, guard ACT log tail
- Safe to run alongside the daemon simultaneously (passive only)
- FORENSICS_DIR and FORENSICS_DURATION env overrides added
- Header updated to v3; all usage docs updated

runewager_redeploy.sh — new one-shot master deploy script:
  1. Stop runewager systemd service
  2. Kill anything holding port 3000 (SIGTERM → SIGKILL)
  3. npm ci at low priority (nice+ionice)
  4. Install/restart rw_cpu_guard via --install
  5. Start runewager systemd service
  6. Health-check bot at /health (waits up to 30 s)
  7. Launch 5-min background forensics trace (non-blocking)
  8. Final status summary (services, port, load, memory,
     guard ACT log, bot journal tail)
- --dry-run and --skip-forensics flags
- Colour output; VPS path fallback; no tooltips touched

https://claude.ai/code/session_01WpEqAiDbpqnBywMjYXJHf4
… checks

rw_cpu_guard.sh:
- Bug fix: proc_log sort/print was using field 2 (time HH:MM:SS) as
  the process count; changed to sort -k3 -rn and print $3 — correct
  since log format is "<date> <time> <count>"
- Writable-path guard in _run_forensics(): fail fast with a clear
  message if FORENSICS_DIR cannot be created or written; suggests
  setting the FORENSICS_DIR env var as the fix

runewager_redeploy.sh:
- _check_deps(): preflight check for lsof and curl with install hint;
  called from main() before any steps run
- _start_forensics(): writable-path check for the deploy log file;
  honours RW_FORENSICS_LOG env override; skips gracefully (with a
  suggestion) instead of silently redirecting to an unwritable path

https://claude.ai/code/session_01WpEqAiDbpqnBywMjYXJHf4
@codeant-ai

codeant-ai Bot commented Mar 1, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@sourcery-ai

sourcery-ai Bot commented Mar 1, 2026

Copy link
Copy Markdown

Reviewer's Guide

Extends rw_cpu_guard with a configurable strike ladder and a new passive CPU forensics mode, and adds a one-shot redeploy script that orchestrates bot restart, guard installation, health checks, and background forensics collection.

Sequence diagram for runewager_redeploy one-shot nuclear redeploy

sequenceDiagram
    actor Admin
    participant Redeploy as RunewagerRedeployScript
    participant Systemd
    participant Guard as RwCpuGuardScript
    participant Bot as RunewagerBotService
    participant Net as Port3000
    participant FxLog as ForensicsLog

    Admin->>Redeploy: Run runewager_redeploy.sh [--dry-run][--skip-forensics]

    Redeploy->>Redeploy: _check_root
    Redeploy->>Redeploy: _check_deps (lsof, curl)
    Redeploy->>Redeploy: _check_app_dir

    Redeploy->>Systemd: systemctl stop runewager
    Systemd-->>Redeploy: Service stopped (or was inactive)

    Redeploy->>Net: lsof -t -i :3000
    alt PIDs on port
        Redeploy->>Net: kill -TERM PIDs
        Redeploy->>Net: kill -KILL remaining PIDs
    else Port already free
        Net-->>Redeploy: no PIDs
    end

    Redeploy->>Redeploy: _npm_rebuild (cd app && nice+ionice npm ci)

    Redeploy->>Guard: rw_cpu_guard.sh --install
    Guard->>Systemd: Install/enable/start rw_cpu_guard service
    Systemd-->>Guard: Guard active

    alt systemd unit runewager.service exists
        Redeploy->>Systemd: systemctl start runewager
    else no systemd unit
        Redeploy->>Redeploy: fallback to prod-run.sh (if present)
    end

    loop until healthy or timeout (<=30s)
        Redeploy->>Bot: HTTP GET /health
        Bot-->>Redeploy: HTTP 200 JSON or error
    end

    opt Forensics not skipped and not dry-run
        Redeploy->>Guard: rw_cpu_guard.sh --forensics=300 &
        Guard->>FxLog: Append forensics output
    end

    Redeploy->>Systemd: Query is-active runewager, rw_cpu_guard
    Systemd-->>Redeploy: Active / inactive states

    Redeploy->>Net: lsof -t -i :3000
    Net-->>Redeploy: Current PIDs on port

    Redeploy->>Redeploy: Print load, memory, guard ACT log tail, bot log tail
    Redeploy-->>Admin: Final redeploy summary
Loading

Flow diagram for rw_cpu_guard forensics mode (_run_forensics)

flowchart TD
    Start([Start forensics])
    GetDuration["Set duration from arg or FORENSICS_DURATION"]
    SetDir["Set output dir to FORENSICS_DIR"]
    CheckDir{"Can create and write to FORENSICS_DIR?"}
    DirError[["Print error and return 1"]]

    InitFiles["Init paths: cpu_trace.csv, vmstat.log, iostat.log, proc_count.log, top_cpu.log, snapshot.txt"]
    Snapshot["Write system snapshot (uptime, loadavg, cpu, memory, cgroup) to snapshot.txt"]

    StartVmstat["Start vmstat 1s loop -> vmstat.log (background)"]
    CheckIostat{"iostat installed?"}
    StartIostat["Start iostat -xz 1 -> iostat.log (background)"]
    SkipIostat["Write 'iostat not installed' to iostat.log"]

    StartTrace["Start 1s CPU tracer (ps | awk cpu>15%) -> cpu_trace.csv (background)"]
    StartTop["Start 10s top-CPU ps snapshot -> top_cpu.log (background)"]
    StartProc["Start 5s /proc process-count sampler -> proc_count.log (background)"]

    ProgressLoop{{"elapsed < duration?"}}
    Sleep10["sleep 10"]
    PrintProgress["Print progress line with load and lines_traced"]

    StopCollectors["kill vmstat, trace, top, proc, iostat (if running); wait"]

    SummHeader["Print forensics summary header"]
    SummCPU["Summarize top CPU offenders from cpu_trace.csv"]
    SummProc["Summarize peak process counts from proc_count.log"]
    SummSteal["Summarize last 5 vmstat steal-time samples"]
    SummGuard["Show last ACT entries from rw_cpu_guard log"]
    SummFooter["Print paths for full data and guard log"]

    End([End forensics])

    Start --> GetDuration --> SetDir --> CheckDir
    CheckDir -- no --> DirError --> End
    CheckDir -- yes --> InitFiles --> Snapshot

    Snapshot --> StartVmstat --> CheckIostat
    CheckIostat -- yes --> StartIostat --> StartTrace
    CheckIostat -- no --> SkipIostat --> StartTrace

    StartTrace --> StartTop --> StartProc --> ProgressLoop

    ProgressLoop -- yes --> Sleep10 --> PrintProgress --> ProgressLoop
    ProgressLoop -- no --> StopCollectors --> SummHeader

    SummHeader --> SummCPU --> SummProc --> SummSteal --> SummGuard --> SummFooter --> End
Loading

File-Level Changes

Change Details Files
Honor MAX_STRIKES across the entire CPU hog handling ladder and improve strike-related logging/alerts.
  • Change the second-strike branch to apply for all strikes less than MAX_STRIKES, turning STOP/CONT into a repeated throttle until the configured strike limit is reached.
  • Update ACT log messages to include current and maximum strike count for throttles and kills.
  • Update Telegram alert messages to include strike counts and simplify command formatting in messages.
scripts/rw_cpu_guard.sh
Add a passive CPU forensics mode to the guard, with CLI integration and environment configuration.
  • Introduce FORENSICS_DIR and FORENSICS_DURATION env-configurable parameters and document them in the script header.
  • Implement _run_forensics to collect vmstat, iostat, high-CPU process traces, process counts, and snapshots into log files and emit a summary report.
  • Wire new --forensics and --forensics=N modes into argument parsing and main-mode dispatch, including help text expansion and environment loading.
scripts/rw_cpu_guard.sh
Add a nuclear redeploy script to safely restart the Runewager bot with guard installation and background forensics.
  • Implement runewager_redeploy.sh with structured, colorized logging helpers and dry-run support.
  • Add steps to stop the systemd bot service, free the application port, run npm ci in the app directory (with VPS path fallback), reinstall/restart the CPU guard, and restart the bot using systemd or a prod-run.sh fallback.
  • Include a health-check loop against the bot /health endpoint, an optional background forensics trace using the guard's --forensics mode, and a final summary of service states, port usage, load, memory, and recent guard/bot logs.
scripts/runewager_redeploy.sh

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

@coderabbitai

coderabbitai Bot commented Mar 1, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@gamblecodezcom has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 076752e and d0ec193.

📒 Files selected for processing (2)
  • scripts/runewager_redeploy.sh
  • scripts/rw_cpu_guard.sh
📝 Walkthrough

Walkthrough

A new deployment orchestration script for Runewager bot redeploys is introduced, alongside forensics functionality enhancements to the CPU guard monitoring script. The redeploy script automates service stopping, dependency installation, and health verification. The guard script adds background system forensics collection capabilities with configurable duration.

Changes

Cohort / File(s) Summary
Deployment Orchestration
scripts/runewager_redeploy.sh
New script orchestrating full bot redeploy: root/dependency checks, service stop, port cleanup, npm installation, guard setup, service restart with fallback, health polling loop (30s timeout), optional forensics, and comprehensive status reporting with colored output and logging.
CPU Monitoring & Forensics
scripts/rw_cpu_guard.sh
Added forensics mode with configurable duration via --forensics CLI flag. New _run_forensics() function collects vmstat, iostat, process traces, and snapshots to designated directory. Strike alerts now include count summaries (STRIKEX/MAX_STRIKES). Extended help documentation for new forensics parameters.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested labels

size:XL

Poem

🐰 A guard watches close, forensics in tow,
While deploys dance swift with a health-check flow,
Ports clear, services restart with care,
The bot awakens—fresh, debugged, and fair!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The pull request title is vague and uses cryptic notation ("dn d8u") that does not clearly convey the actual changes, which involve adding deployment and forensics scripts for the Runewager bot. Revise the title to be more descriptive, such as 'Add bot redeploy script and CPU guard forensics' or 'Implement Runewager deployment and CPU monitoring forensics', removing cryptic suffixes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/cpu-guard-review-fixes-DnD8u

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.

@codeant-ai codeant-ai Bot added the size:XL This PR changes 500-999 lines, ignoring generated files label Mar 1, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • In _summary, the echo -e " ${_bold}Memory:${_reset} $(free -m | awk 'NR==2{printf "used=%sMB free=%sMB\n",$3,$4}')" line has conflicting double quotes inside the command substitution, which will break the script; switch the inner printf string to single quotes or escape the inner double quotes.
  • The health check and JSON pretty-printing rely on curl and python3 -m json.tool, but only curl is validated in _check_deps; consider either checking for python3 as well or guarding the pretty-print block so it degrades gracefully when Python is not installed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_summary`, the `echo -e "  ${_bold}Memory:${_reset}    $(free -m | awk 'NR==2{printf "used=%sMB free=%sMB\n",$3,$4}')"` line has conflicting double quotes inside the command substitution, which will break the script; switch the inner `printf` string to single quotes or escape the inner double quotes.
- The health check and JSON pretty-printing rely on `curl` and `python3 -m json.tool`, but only `curl` is validated in `_check_deps`; consider either checking for `python3` as well or guarding the pretty-print block so it degrades gracefully when Python is not installed.

## Individual Comments

### Comment 1
<location path="scripts/rw_cpu_guard.sh" line_range="651-653" />
<code_context>
+    fi
+
+    # ── 1-second CPU tracer (catches sub-8s spikes the guard daemon may miss) ─
+    echo "timestamp,pid,ppid,cpu%,mem%,cmd" > "$trace"
+    (   while true; do
+            ps -eo pid,ppid,pcpu,pmem,cmd --sort=-pcpu --no-headers 2>/dev/null \
+                | awk -v ts="$(date '+%F %T')" '$3+0 > 15 {
+                    gsub(/,/, ";", $5);
</code_context>
<issue_to_address>
**issue (bug_risk):** The forensics CPU tracer is printing the wrong command column due to awk field indexing.

In this `ps` output, `$5` is the first token of `cmd` and `$6` is the second. Your change prints `$6` as the `cmd` column, so the first word of the command is dropped and the CSV no longer matches the header or later uses that assume it contains the full command (e.g., `substr($6,1,60)`). Instead, either print `$5` (after the `gsub`) or rebuild the full command field from `$5..$NF`, then apply `gsub(/,/, ";", cmd)` and print `cmd` in the last column.
</issue_to_address>

### Comment 2
<location path="scripts/rw_cpu_guard.sh" line_range="749-756" />
<code_context>
+            --status)        mode="status"  ;;
+            --once)          mode="once"    ;;
+            --dry-run)       DRY_RUN="1"   ;;
+            --forensics)     mode="forensics" ;;
+            --forensics=*)   mode="forensics"; FORENSICS_DURATION="${arg#*=}" ;;
             --help|-h)
-                grep '^#' "$SCRIPT_PATH" 2>/dev/null | head -30 | sed 's/^# *//'
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider validating FORENSICS_DURATION from --forensics=N to avoid non-numeric or pathological values.

`--forensics=*` currently just sets `FORENSICS_DURATION` and later uses it in arithmetic:

```bash
while (( elapsed < duration )); do
    elapsed=$(( elapsed + 10 ))
    ...
done
```

Non-numeric or very large values (e.g. `--forensics=foo`) could cause arithmetic errors or unexpectedly long runs. Adding a simple numeric guard here would harden the mode:

```bash
--forensics=*)
    mode="forensics"
    FORENSICS_DURATION="${arg#*=}"
    if ! [[ "$FORENSICS_DURATION" =~ ^[0-9]+$ ]]; then
        echo "Invalid --forensics duration: $FORENSICS_DURATION (must be seconds)" >&2
        exit 1
    fi
    ;;
```

```suggestion
        case "$arg" in
            --install)       mode="install" ;;
            --status)        mode="status"  ;;
            --once)          mode="once"    ;;
            --dry-run)       DRY_RUN="1"   ;;
            --forensics)     mode="forensics" ;;
            --forensics=*)
                mode="forensics"
                FORENSICS_DURATION="${arg#*=}"
                if ! [[ "$FORENSICS_DURATION" =~ ^[0-9]+$ ]]; then
                    echo "Invalid --forensics duration: $FORENSICS_DURATION (must be an integer number of seconds)" >&2
                    exit 1
                fi
                ;;
            --help|-h)
```
</issue_to_address>

### Comment 3
<location path="scripts/runewager_redeploy.sh" line_range="363-364" />
<code_context>
+        esac
+    done
+
+    hdr "Runewager Nuclear Redeploy — $(date)"
+    echo -e "  App dir  : $(_app)"
+    echo -e "  Guard    : $GUARD_SCRIPT"
+    echo -e "  Dry-run  : $( (( DRY_RUN )) && echo YES || echo no )"
</code_context>
<issue_to_address>
**nitpick:** Initial "App dir" banner can be inconsistent with the later APP_DIR_OVERRIDE fallback.

Since `_check_app_dir` can later detect `/var/www/html/Runewager` and set `APP_DIR_OVERRIDE`, the banner may show an outdated app dir when the fallback is used. To avoid confusion, consider calling `_check_app_dir` before printing the banner, or re-printing the resolved app dir afterward so the displayed path matches what the script actually uses.
</issue_to_address>

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 thread scripts/rw_cpu_guard.sh
Comment thread scripts/rw_cpu_guard.sh
Comment thread scripts/runewager_redeploy.sh
All conflicts were between our reviewed/fixed HEAD and the older
unpatched main version. Kept HEAD in all cases:

rw_cpu_guard.sh:
- Keep writable-path guard in _run_forensics() (vs bare mkdir -p)
- Keep sort -k3 / $3 proc-count fix (vs buggy sort -k2 / $2)

runewager_redeploy.sh:
- Keep _check_deps() function (lsof/curl preflight check)
- Keep _check_deps call in main()
- Keep RW_FORENSICS_LOG override + writability check in
  _start_forensics() (vs hardcoded /var/log path)

https://claude.ai/code/session_01WpEqAiDbpqnBywMjYXJHf4
@codeant-ai

codeant-ai Bot commented Mar 1, 2026

Copy link
Copy Markdown

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Alert Formatting
    Telegram alert messages include raw command snippets (${short_cmd}) inserted into the message body and the tg_alert call currently uses Markdown parse mode. Unescaped command text can break Markdown or include characters that change message rendering; it also increases the chance of exposing sensitive command arguments in alerts.

  • Logic Bug
    The one-second CPU tracer in the forensics routine uses awk and refers to $5 for the command column. Because awk splits on whitespace, $5 will not contain the full command (cmd may contain spaces), so traced command fields will be truncated and the resulting trace/csv will be inaccurate. This undermines the top-offender reporting and any forensic analysis.

  • Optional Dependency
    The health-check prints the JSON payload via python3 -m json.tool. If python3 or the json.tool module is not available on a target system, the formatted output step will silently be skipped (it is || true), but this dependency may lead to inconsistent output on systems without python3. Consider a fallback or avoid failing diagnostics when the tool is missing.

@codeant-ai

codeant-ai Bot commented Mar 1, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

rw_cpu_guard.sh:
- Bug fix: CPU tracer awk now rebuilds full cmd from $5..$NF before
  gsub so multi-word commands are not truncated to first token; the
  gsub and printf now use the `cmd` variable — fixes mismatched CSV
  header and later substr($6,…) reads
- Validate --forensics=N: rejects non-numeric and zero values with a
  clear error message before any execution begins

runewager_redeploy.sh:
- Bug fix: double-quote conflict in _summary Memory line resolved by
  extracting free|awk into a local variable (_mem) and interpolating
  it into the echo-e separately — no more nested quote ambiguity
- Guard python3 in _health_check: check command -v python3 before
  piping through json.tool; falls back to raw output when absent —
  curl alone suffices for the health check itself
- Nitpick: _check_root/_check_deps/_check_app_dir now run before the
  banner so the displayed "App dir" always shows the resolved path
  (including the VPS fallback) rather than the pre-check default
- Bug fix: npm ci exit code was silently swallowed by the tail|sed
  pipe; now captured via ${PIPESTATUS[0]} immediately after the pipe
  and propagated — a failed install aborts the redeploy with a clear
  message instead of proceeding silently

https://claude.ai/code/session_01WpEqAiDbpqnBywMjYXJHf4
@gamblecodezcom
gamblecodezcom merged commit 6969f89 into main Mar 1, 2026
6 checks passed
@gamblecodezcom
gamblecodezcom deleted the claude/cpu-guard-review-fixes-DnD8u branch March 1, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants