fix(#3383): replace ps+grep with pgrep -af in dispatch-dedup-helper.sh#4559
fix(#3383): replace ps+grep with pgrep -af in dispatch-dedup-helper.sh#4559alex-solovyev merged 4 commits intomainfrom
Conversation
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).
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis change refactors Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
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.
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Sat Mar 14 03:15:10 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
.agents/scripts/dispatch-dedup-helper.sh
|
Pulse triage: CHANGES_REQUESTED from CodeRabbit. Fix needed in |
|
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 |
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Sat Mar 14 03:39:29 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
🧩 Analysis chain🏁 Script executed: Length of output: 11235
✅ Pattern 4 — portable fallback chain (Lines 88–95) ✅
The SC2009 suppression comment is fully removed, and all 🧠 Learnings used✅ Actions performedFull 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.
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Sat Mar 14 03:52:18 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|



Summary
ps -eo pid,args | grep ... | grep -v greppattern inlist_running_keys()withpgrep -af, which matches against the full command line and automatically excludes its own process from results.# shellcheck disable=SC2009suppression comment that was needed to silence the SC2009 warning about ps+grep usage.pgrep -afproduces the samePID argsoutput format, so the downstreamawk/sedparsing is unaffected.Testing
shellcheck .agents/scripts/dispatch-dedup-helper.shpasses clean (no warnings).References
Summary by CodeRabbit