Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .agents/scripts/commands/pulse.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ This is idempotent — safe to run even when PATH is already correct. All subseq
# Max workers (dynamic, from available RAM)
MAX_WORKERS=$(cat ~/.aidevops/logs/pulse-max-workers 2>/dev/null || echo 4)

# Count running issue workers only (exclude supervisor /pulse processes whose
# command payload can contain '/full-loop' text from pre-fetched state)
WORKER_COUNT=$(ps axo command | grep '\.opencode run' | grep '/full-loop Implement issue #' | grep -v '/pulse' | grep -v grep | wc -l | tr -d ' ')
# Count all full-loop workers (issue + PR advancement), excluding supervisor /pulse noise
WORKER_COUNT=$(ps axo command | grep '\.opencode run' | grep '/full-loop' | grep -v '/pulse' | grep -v 'Supervisor Pulse' | grep -v grep | wc -l | tr -d ' ')

Choose a reason for hiding this comment

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

medium

This long chain of grep commands can be made more efficient and arguably more readable by using a single awk command. This avoids spawning multiple processes for filtering and counting.

Suggested change
WORKER_COUNT=$(ps axo command | grep '\.opencode run' | grep '/full-loop' | grep -v '/pulse' | grep -v 'Supervisor Pulse' | grep -v grep | wc -l | tr -d ' ')
WORKER_COUNT=$(ps axo command | awk '/\.opencode run/ && /\/full-loop/ && !/\/pulse/ && !/Supervisor Pulse/ {c++} END{print c+0}')
References
  1. Optimize shell script pipelines by consolidating multiple filtering commands (like grep chains) into a single, more efficient tool like awk to improve performance, similar to replacing grep | sed with a single sed command.

AVAILABLE=$((MAX_WORKERS - WORKER_COUNT))

# Priority-class allocations (t1423) — read from pre-fetched state
Expand Down
2 changes: 1 addition & 1 deletion .agents/scripts/pulse-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ prefetch_contribution_watch() {
#######################################
count_active_workers() {
local count
count=$(ps axo command | grep '\.opencode run' | grep '/full-loop Implement issue #' | grep -v '/pulse' | grep -c -v grep) || count=0
count=$(ps axo command | grep '\.opencode run' | grep '/full-loop' | grep -v '/pulse' | grep -v 'Supervisor Pulse' | grep -c -v grep) || count=0

Choose a reason for hiding this comment

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

medium

This chain of grep commands can be inefficient, especially in a script that might be called frequently as part of the pulse mechanism. Using a single awk command to perform the filtering and counting would be more performant as it avoids creating multiple processes.

Suggested change
count=$(ps axo command | grep '\.opencode run' | grep '/full-loop' | grep -v '/pulse' | grep -v 'Supervisor Pulse' | grep -c -v grep) || count=0
count=$(ps axo command | awk '/\.opencode run/ && /\/full-loop/ && !/\/pulse/ && !/Supervisor Pulse/ {c++} END{print c+0}') || count=0
References
  1. Optimize shell script pipelines by consolidating multiple filtering commands (like grep chains) into a single, more efficient tool like awk to improve performance, similar to replacing grep | sed with a single sed command.

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Make the supervisor exclusion more specific.

Line 1685 filters out any argv containing /pulse or Supervisor Pulse, but worker commands include free-form issue/PR text in their title/prompt. That means a real /full-loop worker on a pulse-related task can still be excluded here, so utilization remains undercounted for those jobs. Match the supervisor on its dedicated prompt/title shape instead of broad substring drops across the whole command line. As per coding guidelines, automation scripts should focus on reliability and robustness.

echo "$count"
return 0
}
Expand Down
Loading