Skip to content

GH-4282: resolve pulse-wrapper worker count review feedback#4357

Merged
alex-solovyev merged 3 commits intomainfrom
bugfix/4282-pulse-wrapper-quality-debt
Mar 13, 2026
Merged

GH-4282: resolve pulse-wrapper worker count review feedback#4357
alex-solovyev merged 3 commits intomainfrom
bugfix/4282-pulse-wrapper-quality-debt

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Mar 13, 2026

Summary

  • Replace the multi-grep active worker count pipeline with a single awk pass for lower process overhead.
  • Narrow supervisor exclusion to the dedicated --role pulse + --session-key supervisor-pulse signature so /full-loop workers mentioning /pulse are still counted.
  • Add a focused regression test script covering worker counting, supervisor exclusion, and zero-worker behavior.

Verification

  • shellcheck .agents/scripts/pulse-wrapper.sh
  • shellcheck .agents/scripts/tests/test-pulse-wrapper-worker-count.sh
  • bash .agents/scripts/tests/test-pulse-wrapper-worker-count.sh

Closes #4282

Summary by CodeRabbit

  • Refactor

    • Enhanced worker detection logic with more precise filtering to accurately identify active processes.
  • Tests

    • Introduced comprehensive test coverage for worker counting, including edge cases and non-supervisor configurations.

@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 13, 2026

Warning

Rate limit exceeded

@alex-solovyev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 56 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a4e6ab5c-23b4-4546-b45d-2cfa2a991a95

📥 Commits

Reviewing files that changed from the base of the PR and between 17eaa70 and f4f1088.

📒 Files selected for processing (2)
  • .agents/scripts/pulse-wrapper.sh
  • .agents/scripts/tests/test-pulse-wrapper-worker-count.sh

Walkthrough

The PR refines the count_active_workers() function in pulse-wrapper.sh by replacing a chain of grep filters with a single awk command for improved performance, and tightens supervisor process exclusion logic to be more precise. Comprehensive test coverage validates the new behavior across multiple scenarios.

Changes

Cohort / File(s) Summary
Worker Count Optimization
.agents/scripts/pulse-wrapper.sh
Refactored count_active_workers() from multiple grep filters to a single awk-based filter for performance. Updated exclusion logic to require both --role pulse AND --session-key supervisor-pulse instead of OR-based filtering on /pulse or Supervisor Pulse, enabling accurate counting of legitimate workers processing pulse-related tasks.
Test Coverage
.agents/scripts/tests/test-pulse-wrapper-worker-count.sh
Added comprehensive test suite with test framework, setup/teardown infrastructure, mocked ps function, and three test cases validating: supervisor session exclusion, zero-count scenarios for non-full-loop commands, and non-supervisor pulse command inclusion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #4234 — The original PR containing unactioned review feedback on grep performance and supervisor exclusion specificity that this PR directly addresses.
  • #4218 — Modifies pulse-wrapper's worker-counting logic to tighten detection of real .opencode run / /full-loop workers while excluding supervisor/pulse noise.
  • #4200 — Tightens the pulse worker-counting filter with similar .opencode run and /full-loop pattern matching and supervisor/pulse process exclusions.

Suggested labels

bug

Poem

🔍 A counting bug caught in the net,
Pulse workers lost we won't forget,
With awk's sharp blade and logic tight,
Supervisor shadows fade from sight,
Now tests stand guard—our zero debt! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly references the issue number (GH-4282) and accurately describes the main change: addressing review feedback for the pulse-wrapper worker count optimization.
Linked Issues check ✅ Passed The pull request successfully implements both objectives from #4282: replacing grep chains with a single awk command for efficiency, and narrowing supervisor exclusion to match dedicated supervisor signature (--role pulse + --session-key supervisor-pulse) rather than broadly excluding /pulse mentions.
Out of Scope Changes check ✅ Passed All changes are directly scoped to addressing #4282 feedback: the pulse-wrapper.sh optimization and the new regression test script for verifying correct worker counting behavior.

✏️ 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 bugfix/4282-pulse-wrapper-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, 412 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Mar 13 06:01:00 UTC 2026: Code review monitoring started
Fri Mar 13 06:01:00 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 412

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 412
  • VULNERABILITIES: 0

Generated on: Fri Mar 13 06:01:03 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: 1

🧹 Nitpick comments (1)
.agents/scripts/pulse-wrapper.sh (1)

1920-1923: Harden supervisor exclusion to argument boundaries.

The current index() checks are substring-based, so a worker line containing both tokens in free-form text can be excluded accidentally. Prefer token-boundary matching for --role pulse and --session-key supervisor-pulse.

♻️ Proposed refinement
 count=$(ps axo command | awk '
-		index($0, ".opencode run") > 0 &&
-		index($0, "/full-loop") > 0 &&
-		!(index($0, "--role pulse") > 0 && index($0, "--session-key supervisor-pulse") > 0) {
+		index($0, ".opencode run") > 0 &&
+		index($0, "/full-loop") > 0 &&
+		!(
+			$0 ~ /(^|[[:space:]])--role([=[:space:]])pulse([[:space:]]|$)/ &&
+			$0 ~ /(^|[[:space:]])--session-key([=[:space:]])supervisor-pulse([[:space:]]|$)/
+		) {
 			count++
 		}
 		END {
 			print count + 0
 		}
 	') || count=0
🤖 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 1920 - 1923, The substring
checks in the conditional using index($0, "--role pulse") and index($0,
"--session-key supervisor-pulse") can falsely match inside other text; update
the condition that currently checks index($0, ".opencode run"), "/full-loop",
and the two index(...) checks to use token-boundary regex matches instead (e.g.
replace the index(...) checks with match($0,
/(^|[[:space:]])--role[[:space:]]*pulse($|[[:space:]])/) and match($0,
/(^|[[:space:]])--session-key[[:space:]]*supervisor-pulse($|[[:space:]])/)) so
only exact argument tokens for "--role pulse" and "--session-key
supervisor-pulse" trigger the exclusion; keep the rest of the condition (the
.opencode run and /full-loop checks and the count++ action) unchanged.
🤖 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/tests/test-pulse-wrapper-worker-count.sh:
- Around line 109-112: The trap for cleanup is registered after calling
setup_test_env which can leave temp artifacts if setup_test_env fails; move the
trap registration so trap teardown_test_env EXIT is executed before calling
setup_test_env in main(), ensuring teardown_test_env is always registered (with
the same trap command and EXIT signal) prior to invoking setup_test_env.

---

Nitpick comments:
In @.agents/scripts/pulse-wrapper.sh:
- Around line 1920-1923: The substring checks in the conditional using index($0,
"--role pulse") and index($0, "--session-key supervisor-pulse") can falsely
match inside other text; update the condition that currently checks index($0,
".opencode run"), "/full-loop", and the two index(...) checks to use
token-boundary regex matches instead (e.g. replace the index(...) checks with
match($0, /(^|[[:space:]])--role[[:space:]]*pulse($|[[:space:]])/) and match($0,
/(^|[[:space:]])--session-key[[:space:]]*supervisor-pulse($|[[:space:]])/)) so
only exact argument tokens for "--role pulse" and "--session-key
supervisor-pulse" trigger the exclusion; keep the rest of the condition (the
.opencode run and /full-loop checks and the count++ action) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5235b3a1-60f2-424d-b454-bf99988cbb25

📥 Commits

Reviewing files that changed from the base of the PR and between aefc200 and 17eaa70.

📒 Files selected for processing (2)
  • .agents/scripts/pulse-wrapper.sh
  • .agents/scripts/tests/test-pulse-wrapper-worker-count.sh

…failure

Addresses CodeRabbit CHANGES_REQUESTED on PR #4357.
Swap trap/setup order so teardown_test_env EXIT is registered before
setup_test_env is called — cleanup now runs even if setup fails under set -e.

Closes #4282
@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, 412 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Mar 13 07:02:31 UTC 2026: Code review monitoring started
Fri Mar 13 07:02:31 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 412

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 412
  • VULNERABILITIES: 0

Generated on: Fri Mar 13 07:02:33 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

…ve_workers

Use regex token-boundary matching for --role pulse and --session-key
supervisor-pulse instead of substring index() checks, preventing
accidental exclusion of workers whose command text contains these
tokens in free-form context.

Addresses CodeRabbit review feedback on PR #4357.
@alex-solovyev
Copy link
Collaborator

Dispatching worker to address unresolved CodeRabbit suggestion.

  • Model: sonnet (anthropic/claude-sonnet-4-6)
  • Branch: bugfix/4282-pulse-wrapper-quality-debt
  • Scope: Address CodeRabbit suggestion: harden supervisor exclusion to argument boundaries (token-boundary matching for --role pulse and --session-key supervisor-pulse)
  • Attempt: 1 of 1

@alex-solovyev
Copy link
Collaborator

Addressed CodeRabbit feedback: replaced substring index() checks for --role pulse and --session-key supervisor-pulse with regex token-boundary matching (/(^|[[:space:]])--role([=[:space:]])pulse([[:space:]]|$)/) to prevent accidental exclusion of workers whose command text contains these tokens in free-form context.

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Mar 13 07:04:24 UTC 2026: Code review monitoring started
Fri Mar 13 07:04:24 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 412

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 412
  • VULNERABILITIES: 0

Generated on: Fri Mar 13 07:04:27 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@alex-solovyev
Copy link
Collaborator

Review feedback addressed

Both CodeRabbit suggestions have been applied:

1. Harden supervisor exclusion to argument boundaries (nitpick on pulse-wrapper.sh lines 1920–1923)
Addressed in commit f4f1088. The index() substring checks for --role pulse and --session-key supervisor-pulse have been replaced with token-boundary regex matches:

$0 ~ /(^|[[:space:]])--role([=[:space:]])pulse([[:space:]]|$)/ &&
$0 ~ /(^|[[:space:]])--session-key([=[:space:]])supervisor-pulse([[:space:]]|$)/

This prevents accidental exclusion of workers whose command text contains these tokens in free-form context (e.g. a worker prompt that mentions --role pulse as text).

2. Register cleanup trap before setup (actionable comment on test-pulse-wrapper-worker-count.sh line 109–112)
Addressed in commit 26b2b5e. trap teardown_test_env EXIT is now registered before setup_test_env is called, ensuring cleanup runs even if setup fails under set -e.

@alex-solovyev alex-solovyev merged commit d09db5e into main Mar 13, 2026
21 checks passed
@alex-solovyev alex-solovyev deleted the bugfix/4282-pulse-wrapper-quality-debt branch March 13, 2026 07:07
alex-solovyev added a commit that referenced this pull request Mar 13, 2026
Three issues from CodeRabbit review on PR #4357 (GH#4282):

1. Unify global capacity counting: prefetch_active_workers() used a
   grep pipeline that diverged from count_active_workers(). Replace
   with the same awk filter so the active-worker snapshot shown to the
   pulse agent is always consistent with the global capacity counter.

2. Narrow /pulse exclusion to argument boundaries: count_active_workers()
   had a !( newline ) awk pattern that caused a GNU awk parse error
   (unexpected newline after '!'). Collapse to a single-line !(...) guard.
   prefetch_active_workers() now uses the same token-boundary regex
   (--role pulse + --session-key supervisor-pulse as whole arguments)
   instead of a broad substring grep that could hide legitimate workers.

3. Exact --dir matching in has_worker_for_repo_issue(): replace
   index($0, path) > 0 (substring match) with a regex that anchors
   path as a whole --dir argument (space or = form, optional trailing
   slash). Prevents sibling-path false positives such as /tmp/aidevops
   matching /tmp/aidevops-tools.

Add four regression tests covering the new behaviours:
- prefetch_active_workers excludes supervisor pulse
- prefetch_active_workers count matches count_active_workers
- has_worker_for_repo_issue rejects sibling-path match
- has_worker_for_repo_issue accepts exact path match

Closes #4282
alex-solovyev added a commit that referenced this pull request Mar 13, 2026
Three issues from CodeRabbit review on PR #4357 (GH#4282):

1. Unify global capacity counting: prefetch_active_workers() used a
   grep pipeline that diverged from count_active_workers(). Replace
   with the same awk filter so the active-worker snapshot shown to the
   pulse agent is always consistent with the global capacity counter.

2. Narrow /pulse exclusion to argument boundaries: count_active_workers()
   had a !( newline ) awk pattern that caused a GNU awk parse error
   (unexpected newline after '!'). Collapse to a single-line !(...) guard.
   prefetch_active_workers() now uses the same token-boundary regex
   (--role pulse + --session-key supervisor-pulse as whole arguments)
   instead of a broad substring grep that could hide legitimate workers.

3. Exact --dir matching in has_worker_for_repo_issue(): replace
   index($0, path) > 0 (substring match) with a regex that anchors
   path as a whole --dir argument (space or = form, optional trailing
   slash). Prevents sibling-path false positives such as /tmp/aidevops
   matching /tmp/aidevops-tools.

Add four regression tests covering the new behaviours:
- prefetch_active_workers excludes supervisor pulse
- prefetch_active_workers count matches count_active_workers
- has_worker_for_repo_issue rejects sibling-path match
- has_worker_for_repo_issue accepts exact path match

Closes #4282
alex-solovyev added a commit that referenced this pull request Mar 13, 2026
Three issues from CodeRabbit review on PR #4357 (GH#4282):

1. Unify global capacity counting: prefetch_active_workers() used a
   grep pipeline that diverged from count_active_workers(). Replace
   with the same awk filter so the active-worker snapshot shown to the
   pulse agent is always consistent with the global capacity counter.

2. Narrow /pulse exclusion to argument boundaries: count_active_workers()
   had a !( newline ) awk pattern that caused a GNU awk parse error
   (unexpected newline after '!'). Collapse to a single-line !(...) guard.
   prefetch_active_workers() now uses the same token-boundary regex
   (--role pulse + --session-key supervisor-pulse as whole arguments)
   instead of a broad substring grep that could hide legitimate workers.

3. Exact --dir matching in has_worker_for_repo_issue(): replace
   index($0, path) > 0 (substring match) with a regex that anchors
   path as a whole --dir argument (space or = form, optional trailing
   slash). Prevents sibling-path false positives such as /tmp/aidevops
   matching /tmp/aidevops-tools.

Add four regression tests covering the new behaviours:
- prefetch_active_workers excludes supervisor pulse
- prefetch_active_workers count matches count_active_workers
- has_worker_for_repo_issue rejects sibling-path match
- has_worker_for_repo_issue accepts exact path match

Closes #4282
alex-solovyev added a commit that referenced this pull request Mar 13, 2026
#4456)

Three issues from CodeRabbit review on PR #4357 (GH#4282):

1. Unify global capacity counting: prefetch_active_workers() used a
   grep pipeline that diverged from count_active_workers(). Replace
   with the same awk filter so the active-worker snapshot shown to the
   pulse agent is always consistent with the global capacity counter.

2. Narrow /pulse exclusion to argument boundaries: count_active_workers()
   had a !( newline ) awk pattern that caused a GNU awk parse error
   (unexpected newline after '!'). Collapse to a single-line !(...) guard.
   prefetch_active_workers() now uses the same token-boundary regex
   (--role pulse + --session-key supervisor-pulse as whole arguments)
   instead of a broad substring grep that could hide legitimate workers.

3. Exact --dir matching in has_worker_for_repo_issue(): replace
   index($0, path) > 0 (substring match) with a regex that anchors
   path as a whole --dir argument (space or = form, optional trailing
   slash). Prevents sibling-path false positives such as /tmp/aidevops
   matching /tmp/aidevops-tools.

Add four regression tests covering the new behaviours:
- prefetch_active_workers excludes supervisor pulse
- prefetch_active_workers count matches count_active_workers
- has_worker_for_repo_issue rejects sibling-path match
- has_worker_for_repo_issue accepts exact path match

Closes #4282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants