Skip to content

fix(#3383): replace ps+grep with pgrep -af in dispatch-dedup-helper.sh#4559

Merged
alex-solovyev merged 4 commits intomainfrom
bugfix/issue-3383-quality-debt
Mar 14, 2026
Merged

fix(#3383): replace ps+grep with pgrep -af in dispatch-dedup-helper.sh#4559
alex-solovyev merged 4 commits intomainfrom
bugfix/issue-3383-quality-debt

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Mar 14, 2026

Summary

  • Replaces the fragile ps -eo pid,args | grep ... | grep -v grep pattern in list_running_keys() with pgrep -af, which matches against the full command line and automatically excludes its own process from results.
  • Removes the # shellcheck disable=SC2009 suppression comment that was needed to silence the SC2009 warning about ps+grep usage.
  • No functional change — pgrep -af produces the same PID args output format, so the downstream awk/sed parsing is unaffected.

Testing

  • shellcheck .agents/scripts/dispatch-dedup-helper.sh passes clean (no warnings).

References

Summary by CodeRabbit

  • Chores
    • Improved internal script behavior for more robust and portable process discovery and pattern matching.
    • Enhanced per-process key extraction and handling to reduce false positives when identifying running workers.
    • Added clearer in-script documentation and control flow refinements to make maintenance and troubleshooting easier.

Use pgrep -af instead of ps|grep|grep -v grep to find worker processes.
pgrep matches the full command line and automatically excludes itself,
making the process detection more robust and eliminating the grep-exclusion fragility.

Addresses review feedback from PR #2389 (gemini-code-assist finding).
@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 Mar 14, 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: e5805d57-c19f-4c7d-b232-e05791560a0d

📥 Commits

Reviewing files that changed from the base of the PR and between 43dc0f7 and ec87329.

📒 Files selected for processing (1)
  • .agents/scripts/dispatch-dedup-helper.sh

Walkthrough

This change refactors .agents/scripts/dispatch-dedup-helper.sh: adds a portable fallback for branch-style key extraction (rg → ggrep → grep), and replaces fragile ps | grep parsing with pgrep -f + per-PID ps -p <pid> -o args= and per-PID key extraction.

Changes

Cohort / File(s) Summary
Dispatch dedup helper script
.agents/scripts/dispatch-dedup-helper.sh
Rewrote key extraction to use a portable fallback chain (rgggrep -Pgrep) and replaced consolidated `ps

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🔧 A script trimmed, the processes align,
Keys plucked clean from command-line vine,
pgrep finds PIDs, each line now clear,
Fallbacks stand ready, no regex fear,
Shells sing tidy in CI cheer.

🚥 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 summarizes the primary change: replacing ps+grep pattern with pgrep -af for improved robustness in dispatch-dedup-helper.sh.
Linked Issues check ✅ Passed The pull request successfully addresses the medium-severity review finding from #3383 by replacing the fragile ps|grep|grep -v grep pattern with pgrep-based process discovery, implementing portable fallback chains for compatibility, and achieving zero shellcheck warnings.
Out of Scope Changes check ✅ Passed All changes in the pull request are directly scoped to addressing issue #3383: hardening process discovery logic and improving cross-platform compatibility; no extraneous modifications detected.
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/issue-3383-quality-debt
📝 Coding Plan
  • Generate coding plan for human review comments

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
Contributor

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Mar 14 01:23:09 UTC 2026: Code review monitoring started
Sat Mar 14 01:23:09 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 414

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 414
  • VULNERABILITIES: 0

Generated on: Sat Mar 14 01:23:12 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

…intainability rating

Replace the two-stage grep pipe (grep -oE 'issue-([0-9]+)' | grep -oE '[0-9]+')
with a single grep -oP 'issue-\K[0-9]+' using a PCRE lookbehind. This eliminates
the code smell flagged by SonarCloud (C Maintainability Rating on new code) while
preserving identical output semantics.
@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, 414 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Mar 14 03:15:08 UTC 2026: Code review monitoring started
Sat Mar 14 03:15:08 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 414

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 414
  • VULNERABILITIES: 0

Generated on: Sat Mar 14 03:15:10 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: 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/dispatch-dedup-helper.sh:
- Line 88: The branch_issue_nums extraction currently uses grep -P (PCRE) in the
assignment to branch_issue_nums; change it to a portable fallback sequence used
elsewhere: prefer rg if available, then ggrep -P, then grep -E with an
equivalent regex (e.g., 'issue-([0-9]+)') so macOS/BSD/Alpine won't silently
fail; update the variable assignment in the branch_issue_nums assignment to try
those in order. For process discovery, replace use of pgrep -af with portable
pgrep -f to get PIDs only, and then in the process parsing loop that currently
reads pgrep output (the block handling PIDs around the existing parsing loop),
retrieve the full command line per PID using ps -p "$pid" -o args= (instead of
extracting command text from pgrep output); update the parsing loop (the section
using the PID list and lines ~138–141) to call ps -p "$pid" -o args= for each
pid and use that output for further matching.
- Around line 129-130: The pgrep invocation storing worker_procs assumes
Linux-style "PID + full command" output; on macOS/BSD pgrep -a behaves
differently so the later awk/sed key extraction (used around the parsing for
keys) can fail. Change the logic that sets worker_procs: use pgrep -f to get
matching PIDs (e.g., pgrep -f '/full-loop|opencode run|claude.*run' || true'),
then for each PID call ps -p "$pid" -o command= (or ps -o command= -p "$pid") to
obtain the full command and assemble lines of "PID <space> FULL_COMMAND" into
the worker_procs variable; keep the later awk/sed key extraction unchanged so it
works cross-platform. Ensure the new code handles no-PID (empty) gracefully and
preserves the existing variable name worker_procs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b40a8b35-5197-4e1f-a518-64207582abec

📥 Commits

Reviewing files that changed from the base of the PR and between eccad3c and 43dc0f7.

📒 Files selected for processing (1)
  • .agents/scripts/dispatch-dedup-helper.sh

@alex-solovyev
Copy link
Collaborator

Pulse triage: CHANGES_REQUESTED from CodeRabbit. Fix needed in .agents/scripts/dispatch-dedup-helper.sh line 88: replace grep -P with portable fallback (rg → ggrep -P → grep -E). Also replace pgrep -af with pgrep -f for portability. Worker slots full this cycle — queued for next pulse.

@marcusquinn
Copy link
Owner Author

Addressed CHANGES_REQUESTED feedback in .agents/scripts/dispatch-dedup-helper.sh:\n\n- Replaced branch issue extraction with portable fallback order: rg, then ggrep -P, then grep -E\n- Switched worker discovery to pgrep -f PID collection and resolved command lines via ps -p -o args= for cross-platform compatibility\n- Re-ran shellcheck on the updated script\n\n@coderabbitai review

@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, 414 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Mar 14 03:39:26 UTC 2026: Code review monitoring started
Sat Mar 14 03:39:26 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 414

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 414
  • VULNERABILITIES: 0

Generated on: Sat Mar 14 03:39:29 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
fd -t f 'dispatch-dedup-helper.sh' --exec cat {}

Length of output: 11235


@marcusquinn — I've read the current state of .agents/scripts/dispatch-dedup-helper.sh. Here's what I verified against the portability feedback:

✅ Pattern 4 — portable fallback chain (Lines 88–95)
The three-tier order (rgggrep -Pgrep -E) is correctly structured with || true guards. The rg -o 'issue-([0-9]+)' | grep -oE '[0-9]+' pipeline is semantically correct — rg -o emits the full match (e.g. issue-2300), and the downstream grep -oE '[0-9]+' strips the prefix cleanly.

list_running_keyspgrep -f + ps -p
pgrep -f (without -a) is portable across Linux and macOS. Resolving command lines via ps -p "$pid" -o args= per PID is the correct POSIX-compatible approach and avoids the BSD/procps pgrep -a incompatibility.

⚠️ One minor observation to be aware of:
local worker_procs is declared without initialization before the += concatenation inside the while loop (Lines ~145–152). Bash treats an unset local as empty so it's functionally fine, but some ShellCheck versions may prefer local worker_procs="" for explicitness. Worth a quick check with shellcheck -S style.

The SC2009 suppression comment is fully removed, and all grep/pgrep calls are guarded with || true respecting set -euo pipefail. The changes look solid — triggering a full review now.


🧠 Learnings used
Learnt from: marcusquinn
Repo: marcusquinn/aidevops PR: 0
File: :0-0
Timestamp: 2026-03-03T16:33:18.313Z
Learning: For the marcusquinn/aidevops repository: The daily quality sweep system (pulse-wrapper.sh) should only mention coderabbitai for full codebase review when there are significant changes (Quality Gate failure, +10 issues in one day, etc.), not on every automated sweep with stable metrics.

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-08T12:35:20.083Z
Learning: Consult tools/build-agent/agent-review.md for guidance on reviewing and improving agents

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-08T12:35:20.083Z
Learning: Applies to .agents/scripts/*.sh : Run ShellCheck on all shell scripts in .agents/scripts/ before committing

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-08T12:35:20.083Z
Learning: Before adding instructions, run ripgrep search (rg "pattern" .agents/) to check for duplicates
✅ Actions performed

Full review triggered.

- Replace pgrep -af (GNU-only, -a not supported on macOS) with pgrep -f
  (portable, returns PIDs only) + ps -p <pid> -o args= per PID to get
  the full command line. ps -p ... -o args= is POSIX-compatible and works
  on Linux, macOS, and BSD without modification.
- Replace grep -oP 'issue-\K[0-9]+' (GNU PCRE-only) in Pattern 4 with a
  portable three-tier fallback: rg (ripgrep) → ggrep -P (GNU grep on
  macOS via Homebrew) → grep -E with equivalent two-pipe extraction.
- Rename local variable 'keys' to 'extracted_keys' in list_running_keys
  to avoid SC2178/SC2128 shellcheck warnings from name collision with the
  'keys' array in extract_keys.
- shellcheck passes with zero warnings/errors after these changes.

Addresses CodeRabbit CHANGES_REQUESTED on PR #4559.
@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, 414 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Mar 14 03:52:16 UTC 2026: Code review monitoring started
Sat Mar 14 03:52:16 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 414

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 414
  • VULNERABILITIES: 0

Generated on: Sat Mar 14 03:52:18 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@alex-solovyev alex-solovyev merged commit 98b03b9 into main Mar 14, 2026
20 checks passed
@alex-solovyev alex-solovyev deleted the bugfix/issue-3383-quality-debt branch March 14, 2026 04:04
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/archived/dispatch-dedup-helper.sh — PR #2389 review feedback (medium)

2 participants