Skip to content

t1455: add adaptive pulse queue-governor and strict worker counting#4218

Merged
marcusquinn merged 1 commit intomainfrom
bugfix/t1455-adaptive-pulse-governor
Mar 12, 2026
Merged

t1455: add adaptive pulse queue-governor and strict worker counting#4218
marcusquinn merged 1 commit intomainfrom
bugfix/t1455-adaptive-pulse-governor

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Mar 12, 2026

Summary

  • add adaptive queue-governor metrics to pre-fetched pulse state with cycle mode (merge-heavy, pr-heavy, balanced) and recommended PR-vs-issue dispatch focus
  • tighten wrapper active-worker counting to only real issue workers (.opencode run + /full-loop Implement issue #) to avoid supervisor prompt noise
  • update pulse instructions to consume adaptive governor values and enforce issue-dispatch budgeting when PR pressure is high

Verification

  • shellcheck .agents/scripts/pulse-wrapper.sh
  • markdown-formatter check .agents/scripts/commands/pulse.md

Closes #4217

Summary by CodeRabbit

  • New Features
    • Introduced adaptive queue management system that dynamically adjusts workflow prioritization based on current workload. The system intelligently balances PR advancement with new issue dispatch, automatically limiting new work initiation during high-load periods to optimize processing efficiency.

@github-actions github-actions bot added the enhancement Auto-created from TODO.md tag label Mar 12, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces an intelligent, adaptive queue management system to optimize the allocation of resources between processing existing pull requests and dispatching new issues. By dynamically adjusting priorities based on current PR and issue backlogs, the system aims to improve overall throughput, ensure timely PR advancement, and prevent new issue work from overwhelming PR remediation efforts. This change enhances the system's responsiveness to varying workload pressures without requiring manual intervention.

Highlights

  • Adaptive Queue Governor: Added adaptive queue-governor metrics to the pre-fetched pulse state, including cycle modes ('merge-heavy', 'pr-heavy', 'balanced') and recommended PR-vs-issue dispatch focus.
  • Worker Counting Refinement: Tightened the wrapper's active-worker counting to exclusively include genuine issue workers (those running '.opencode run' and '/full-loop Implement issue #'), reducing supervisor prompt noise.
  • Pulse Instruction Updates: Updated pulse instructions to consume the new adaptive governor values and enforce issue-dispatch budgeting, particularly when PR pressure is high.
Changelog
  • .agents/scripts/commands/pulse.md
    • Added new variables for adaptive queue governor mode and dispatch percentages to the pulse state documentation.
    • Included a new section detailing the adaptive mode rules (merge-heavy, pr-heavy, balanced) for PR processing.
    • Documented the calculation and enforcement of an issue dispatch budget based on the adaptive queue mode.
  • .agents/scripts/pulse-wrapper.sh
    • Defined a new QUEUE_METRICS_FILE path for storing historical queue data.
    • Integrated the append_adaptive_queue_governor function into the prefetch_state process.
    • Modified the count_active_workers function to more precisely identify and count only active issue workers.
    • Implemented the append_adaptive_queue_governor function, which calculates and logs adaptive queue mode and dispatch focus percentages based on PR and issue queue trends.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Walkthrough

This PR introduces an adaptive queue governor mechanism for the pulse dispatch system. It adds dynamic queue-pressure metrics to pre-fetched state (queue mode, dispatch percentages), integrates calculation logic into the prefetch flow, updates pulse documentation with adaptive mode rules, and refines worker-detection patterns to exclude supervisor noise.

Changes

Cohort / File(s) Summary
Adaptive Mode Documentation
.agents/scripts/commands/pulse.md
Added "Adaptive mode rule (t1455)" section documenting three queue modes (merge-heavy, pr-heavy, balanced) with corresponding priorities. Inserted guidance at Steps 1 and 3 to enforce issue-dispatch budget constraints based on PULSE_QUEUE_MODE and NEW_ISSUE_DISPATCH_PCT variables sourced from pulse-state.txt.
Adaptive Queue Governor Implementation
.agents/scripts/pulse-wrapper.sh
Introduced QUEUE_METRICS_FILE variable for persistent queue metrics tracking. Added append_adaptive_queue_governor() function that derives dynamic dispatch strategy from current PRs, issues, and historical deltas, computing queue mode and focus percentages. Integrated governor calls into prefetch_state pipeline after priority allocations and other prefetch steps. Updated count_active_workers() with refined grep pattern to identify only real issue workers (.opencode run + /full-loop Implement issue patterns), excluding supervisor prompt noise.

Sequence Diagram

sequenceDiagram
    participant Prefetch as Prefetch State
    participant Governor as Adaptive Governor
    participant Metrics as Queue Metrics
    participant State as Pulse State
    participant Dispatch as Pulse Dispatch

    Prefetch->>Governor: invoke append_adaptive_queue_governor()
    Governor->>Metrics: read previous cycle counters
    Governor->>Governor: analyze PR/issue deltas
    Governor->>Governor: compute queue_mode<br/>(merge-heavy/pr-heavy/balanced)
    Governor->>Governor: calculate focus percentages<br/>(PR_REMEDIATION_FOCUS_PCT,<br/>NEW_ISSUE_DISPATCH_PCT)
    Governor->>Metrics: update with current cycle metrics
    Governor->>State: write adaptive guidance<br/>+ queue mode + budgets
    State->>Dispatch: provide queue mode & budgets
    Dispatch->>Dispatch: allocate dispatch capacity<br/>respecting PULSE_QUEUE_MODE
    Dispatch->>Dispatch: limit new issues by<br/>AVAILABLE × NEW_ISSUE_DISPATCH_PCT
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🎭 When PR queues grow heavy and issues stack high,
An adaptive governor learns—no more wondering why.
It measures, it shifts modes with grace and with care,
Balancing throughput through metrics it shares. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ❓ Inconclusive All changes are directly aligned with linked issue #4217 requirements; however, duplicate insertion of append_adaptive_queue_governor() function and calls within pulse-wrapper.sh represents potential quality concern requiring verification. Verify that duplicate function definitions and call sites in pulse-wrapper.sh are intentional or consolidate to single definitions; confirm no unintended code duplication exists in merged result.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly summarizes the main changes: adaptive pulse queue-governor addition and strict worker counting improvements, directly matching the changeset objectives.
Linked Issues check ✅ Passed Changes comprehensively address all acceptance criteria from #4217: adaptive queue-governor metrics in pre-fetched state with cycle modes [#4217], tightened worker counting logic [#4217], and pulse instructions updated with adaptive dispatch budgeting [#4217].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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/t1455-adaptive-pulse-governor
📝 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

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Thu Mar 12 17:11:43 UTC 2026: Code review monitoring started
Thu Mar 12 17:11:44 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 403

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 403
  • VULNERABILITIES: 0

Generated on: Thu Mar 12 17:11:46 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an adaptive queue-governor to the pulse wrapper and tightens the active worker counting logic. The changes in pulse-wrapper.sh implement the new governor logic, which dynamically adjusts dispatch focus based on PR and issue queue metrics. The documentation in pulse.md is updated accordingly to explain the new adaptive modes and configuration variables. My review focuses on improving the clarity and robustness of the new shell script logic. I've suggested a clearer way to count worker processes and recommended adding a warning if ripgrep (a dependency for the new governor) is not installed, referencing the rule about managing external dependencies in portable shell scripts.

count_active_workers() {
local count
count=$(ps axo command | grep '[/]full-loop' | grep -c '[.]opencode') || count=0
count=$(ps axo command | grep '\.opencode run' | grep '/full-loop Implement issue #' | grep -v '/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

The use of grep -c -v grep is a bit unconventional for counting processes while excluding the grep command itself. While it works by counting lines that don't contain "grep", a more common and arguably clearer idiom is to use grep -v grep | wc -l or to use the bracket trick in one of the patterns (e.g., grep '[.]opencode') to prevent grep from matching its own process. This would improve readability and maintainability for other developers.

Suggested change
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 Implement issue #' | grep -v '/pulse' | grep -v grep | wc -l) || count=0

Comment on lines +1705 to +1706
ready_prs=$(rg -c '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
failing_prs=$(rg -c '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "0")

Choose a reason for hiding this comment

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

medium

The script relies on rg (ripgrep) to calculate ready_prs and failing_prs. While it safely defaults to 0 if rg is not found, this can lead to the adaptive governor making suboptimal decisions without any warning to the user. It would be beneficial to explicitly check for rg and log a warning if it's missing, informing the user that the feature's effectiveness is reduced. This aligns with the principle of managing external dependencies in portable shell scripts, ensuring users are aware when non-built-in tools are not available, even if a fallback is in place.

Suggested change
ready_prs=$(rg -c '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
failing_prs=$(rg -c '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "0")
if ! command -v rg &>/dev/null; then
echo "[pulse-wrapper] WARNING: ripgrep (rg) not found. Adaptive queue governor metrics for ready/failing PRs will be disabled." >>"$LOGFILE"
ready_prs=0
failing_prs=0
else
ready_prs=$(rg -c '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
failing_prs=$(rg -c '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "0")
fi
References
  1. For shell scripts that need to be portable, prefer built-in tools like grep over external dependencies like jq for simple tasks, to avoid installation requirements on diverse systems.

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: 3

🤖 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/commands/pulse.md:
- Around line 55-57: The current assignments for PULSE_QUEUE_MODE,
PR_REMEDIATION_FOCUS_PCT, and NEW_ISSUE_DISPATCH_PCT can capture multiple
matching lines from pulse-state.txt (introducing newlines and breaking
comparisons); update each command that uses grep to select a single value (e.g.,
pipe the grep output to tail -1 to pick the most recent match) before cutting
the value so the variables contain a single scalar string suitable for
comparisons like [[ "$PULSE_QUEUE_MODE" == "pr-heavy" ]].

In @.agents/scripts/pulse-wrapper.sh:
- Around line 1705-1706: Replace the ripgrep calls that set ready_prs and
failing_prs with portable grep invocations: use grep -E -c with the same regex
patterns against "$STATE_FILE" and keep the 2>/dev/null || echo "0" fallback so
missing files still yield "0"; update the lines that assign ready_prs and
failing_prs (referencing those variable names and STATE_FILE) to use grep -E and
the original patterns '\[checks: PASS\].*\[review: APPROVED\]' and '\[checks:
FAIL\]|\[review: CHANGES_REQUESTED\]'.
- Around line 1683-1688: The backfill capacity check in count_active_workers()
is only matching issue workers and undercounts total active workers; update
count_active_workers() to broaden the grep pattern (e.g., match '/full-loop'
while still excluding '/pulse') so it reports all active full-loop workers,
ensuring enforce_utilization_invariants() uses the correct total when comparing
active_workers to max_workers; locate function count_active_workers and change
the grep filter accordingly (or alternatively document/rename it if you intend
it to be issue-only).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1eae2e18-551d-47da-8a23-8a21d14e1ad1

📥 Commits

Reviewing files that changed from the base of the PR and between 408bb01 and 888f9e3.

📒 Files selected for processing (2)
  • .agents/scripts/commands/pulse.md
  • .agents/scripts/pulse-wrapper.sh

Comment on lines +55 to +57
PULSE_QUEUE_MODE=$(grep '^PULSE_QUEUE_MODE=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo "balanced")
PR_REMEDIATION_FOCUS_PCT=$(grep '^PR_REMEDIATION_FOCUS_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo 50)
NEW_ISSUE_DISPATCH_PCT=$(grep '^NEW_ISSUE_DISPATCH_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo 50)
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 | 🟡 Minor

Multi-value grep returns could break variable comparisons.

If pulse-state.txt contains multiple PULSE_QUEUE_MODE= lines (e.g., from repeated governor calls or file corruption), grep returns all matching lines. The variable then contains newlines, causing string comparisons like [[ "$PULSE_QUEUE_MODE" == "pr-heavy" ]] to fail unexpectedly.

🛡️ Suggested fix using tail -1 to get the last (most recent) value
-PULSE_QUEUE_MODE=$(grep '^PULSE_QUEUE_MODE=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo "balanced")
-PR_REMEDIATION_FOCUS_PCT=$(grep '^PR_REMEDIATION_FOCUS_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo 50)
-NEW_ISSUE_DISPATCH_PCT=$(grep '^NEW_ISSUE_DISPATCH_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo 50)
+PULSE_QUEUE_MODE=$(grep '^PULSE_QUEUE_MODE=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | tail -1 | cut -d= -f2 || echo "balanced")
+PR_REMEDIATION_FOCUS_PCT=$(grep '^PR_REMEDIATION_FOCUS_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | tail -1 | cut -d= -f2 || echo 50)
+NEW_ISSUE_DISPATCH_PCT=$(grep '^NEW_ISSUE_DISPATCH_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | tail -1 | cut -d= -f2 || echo 50)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
PULSE_QUEUE_MODE=$(grep '^PULSE_QUEUE_MODE=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo "balanced")
PR_REMEDIATION_FOCUS_PCT=$(grep '^PR_REMEDIATION_FOCUS_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo 50)
NEW_ISSUE_DISPATCH_PCT=$(grep '^NEW_ISSUE_DISPATCH_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | cut -d= -f2 || echo 50)
PULSE_QUEUE_MODE=$(grep '^PULSE_QUEUE_MODE=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | tail -1 | cut -d= -f2 || echo "balanced")
PR_REMEDIATION_FOCUS_PCT=$(grep '^PR_REMEDIATION_FOCUS_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | tail -1 | cut -d= -f2 || echo 50)
NEW_ISSUE_DISPATCH_PCT=$(grep '^NEW_ISSUE_DISPATCH_PCT=' ~/.aidevops/logs/pulse-state.txt 2>/dev/null | tail -1 | cut -d= -f2 || echo 50)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/commands/pulse.md around lines 55 - 57, The current
assignments for PULSE_QUEUE_MODE, PR_REMEDIATION_FOCUS_PCT, and
NEW_ISSUE_DISPATCH_PCT can capture multiple matching lines from pulse-state.txt
(introducing newlines and breaking comparisons); update each command that uses
grep to select a single value (e.g., pipe the grep output to tail -1 to pick the
most recent match) before cutting the value so the variables contain a single
scalar string suitable for comparisons like [[ "$PULSE_QUEUE_MODE" == "pr-heavy"
]].

Comment on lines 1683 to 1688
count_active_workers() {
local count
count=$(ps axo command | grep '[/]full-loop' | grep -c '[.]opencode') || count=0
count=$(ps axo command | grep '\.opencode run' | grep '/full-loop Implement issue #' | grep -v '/pulse' | grep -c -v grep) || count=0
echo "$count"
return 0
}
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 | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check what worker dispatch patterns exist in the codebase
echo "=== Dispatch patterns in pulse.md ==="
rg --no-heading -n '/full-loop' .agents/scripts/commands/pulse.md | head -30

echo ""
echo "=== Mission worker dispatch patterns ==="
rg --no-heading -n 'headless-runtime-helper.sh run' .agents/scripts/commands/pulse.md | head -20

echo ""
echo "=== count_active_workers implementations ==="
rg --no-heading -A5 'count_active_workers\(\)' .agents/scripts/

Repository: marcusquinn/aidevops

Length of output: 3918


🏁 Script executed:

#!/bin/bash
# Check how count_active_workers is used in pulse-wrapper.sh
echo "=== Usage of count_active_workers in pulse-wrapper.sh ==="
rg --no-heading -B5 -A5 'count_active_workers\(\)' .agents/scripts/pulse-wrapper.sh | head -50

echo ""
echo "=== MAX_WORKERS and dispatch logic in pulse-wrapper.sh ==="
rg --no-heading -n 'MAX_WORKERS\|WORKER_COUNT\|count_active_workers' .agents/scripts/pulse-wrapper.sh | head -30

echo ""
echo "=== Check if pulse-wrapper.sh dispatches mission workers ==="
rg --no-heading -n 'mission\|Mission' .agents/scripts/pulse-wrapper.sh | head -20

Repository: marcusquinn/aidevops

Length of output: 584


🏁 Script executed:

#!/bin/bash
# Search for where count_active_workers is actually called
echo "=== Search for count_active_workers function calls ==="
rg --no-heading -n 'count_active_workers' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check what pulse-wrapper.sh dispatches ==="
rg --no-heading -n 'headless-runtime-helper\|\.opencode run' .agents/scripts/pulse-wrapper.sh | head -20

echo ""
echo "=== Get overall structure/purpose of pulse-wrapper.sh ==="
head -100 .agents/scripts/pulse-wrapper.sh | grep -E '^\#|^[A-Za-z_]+\(\)|script'

echo ""
echo "=== Check if count_active_workers is called anywhere ==="
rg --no-heading -n '\$count_active_workers\|count_active_workers' .agents/scripts/ --type sh

Repository: marcusquinn/aidevops

Length of output: 3237


🏁 Script executed:

#!/bin/bash
# Check context around line 1954 where count_active_workers is called
echo "=== Context around line 1954 (active_workers=$(count_active_workers)) ==="
sed -n '1945,1975p' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check for any logging or usage of active_workers variable ==="
rg --no-heading -B2 -A2 'active_workers=' .agents/scripts/pulse-wrapper.sh

Repository: marcusquinn/aidevops

Length of output: 2135


🏁 Script executed:

#!/bin/bash
# Check if mission/PR workers are dispatched from other contexts
echo "=== Check all worker dispatch points ==="
rg --no-heading -n 'headless-runtime-helper.sh run' .agents/scripts/*.sh | grep -v pulse.md

echo ""
echo "=== Check if there's queue enforcement for all worker types ==="
rg --no-heading -B5 -A5 'max_workers\|MAX_WORKERS' .agents/scripts/pulse-wrapper.sh | head -40

echo ""
echo "=== Check purpose/scope comments in pulse-wrapper.sh header ==="
head -50 .agents/scripts/pulse-wrapper.sh | tail -20

Repository: marcusquinn/aidevops

Length of output: 1370


🏁 Script executed:

#!/bin/bash
# Check if pulse-wrapper.sh dispatches any workers or just manages the pulse
echo "=== Search for dispatch/worker dispatch in pulse-wrapper.sh ==="
rg --no-heading -n 'dispatch\|queue\|Implement issue' .agents/scripts/pulse-wrapper.sh | head -20

echo ""
echo "=== Check if count_runnable_candidates matches same pattern ==="
rg --no-heading -B2 -A8 'count_runnable_candidates\(\)' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check what queued issues look like ==="
rg --no-heading -B2 -A8 'count_queued_without_worker\(\)' .agents/scripts/pulse-wrapper.sh

Repository: marcusquinn/aidevops

Length of output: 785


🏁 Script executed:

#!/bin/bash
# Check where mission and PR fix workers are actually dispatched from
echo "=== Check what pulse-wrapper.sh actually calls/dispatches ==="
rg --no-heading -n 'function\|^[a-z_]*() {' .agents/scripts/pulse-wrapper.sh | head -30

echo ""
echo "=== Look for dispatch_* or similar functions in pulse-wrapper ==="
rg --no-heading -B3 -A10 'dispatch\|enqueue' .agents/scripts/pulse-wrapper.sh | head -50

echo ""
echo "=== Check if there's a separate handler for mission/PR workers ==="
ls -la .agents/scripts/*.sh | grep -E 'mission|pr|queue|dispatch'

echo ""
echo "=== Look at mission-dashboard-helper to see if it has its own enforcement ==="
rg --no-heading -n 'max_workers\|count_active_workers' .agents/scripts/mission-dashboard-helper.sh

Repository: marcusquinn/aidevops

Length of output: 2376


🏁 Script executed:

#!/bin/bash
# Check function definitions without problematic regex
echo "=== Main functions in pulse-wrapper.sh ==="
rg --no-heading -n '^[a-z_]+\(\)' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check if mission-dashboard-helper has worker enforcement ==="
rg --no-heading -B5 -A10 'count_active_workers\|max_workers' .agents/scripts/mission-dashboard-helper.sh | head -50

echo ""
echo "=== Check cron-dispatch.sh for mission/PR dispatch logic ==="
rg --no-heading -n 'mission\|PR\|Address unresolved' .agents/scripts/cron-dispatch.sh | head -20

Repository: marcusquinn/aidevops

Length of output: 1220


🏁 Script executed:

#!/bin/bash
# Check what prefetch_active_workers does
echo "=== prefetch_active_workers function ==="
sed -n '880,940p' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check append_adaptive_queue_governor ==="
sed -n '1697,1750p' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check if pulse-wrapper.sh has any worker TYPE distinction ==="
rg --no-heading -n 'issue\|mission\|PR.*fix\|Address unresolved' .agents/scripts/pulse-wrapper.sh | head -20

Repository: marcusquinn/aidevops

Length of output: 4408


🏁 Script executed:

#!/bin/bash
# Check if enforce_utilization_invariants actually dispatches workers
echo "=== Full enforce_utilization_invariants function ==="
sed -n '1942,2000p' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check what calls enforce_utilization_invariants ==="
rg --no-heading -n 'enforce_utilization_invariants' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check if pulse-wrapper dispatches PR fix or mission workers ==="
rg --no-heading -B3 -A3 'PR\|mission\|Address unresolved\|Implement.*task' .agents/scripts/pulse-wrapper.sh | head -40

Repository: marcusquinn/aidevops

Length of output: 2780


🏁 Script executed:

#!/bin/bash
# Clarify: check if the narrow pattern is intentional by seeing how prefetch_active_workers is used
echo "=== Where is prefetch_active_workers output used? ==="
rg --no-heading -B5 -A5 'prefetch_active_workers' .agents/scripts/pulse-wrapper.sh | grep -v '^--$'

echo ""
echo "=== Check if mission workers or PR fix workers are explicitly SEPARATE from issue workers ==="
rg --no-heading -n 'run_pulse\|count_runnable_candidates\|count_queued_without_worker' .agents/scripts/pulse-wrapper.sh | head -5

echo ""
echo "=== Look at what run_pulse actually does ==="
sed -n '1289,1350p' .agents/scripts/pulse-wrapper.sh

echo ""
echo "=== Check if there's documentation about worker types in pulse.md ==="
head -100 .agents/scripts/commands/pulse.md | tail -50

Repository: marcusquinn/aidevops

Length of output: 8189


Backfill capacity check should account for all active worker types, not just issue workers.

The pattern /full-loop Implement issue # counts only issue workers. During backfill, enforce_utilization_invariants() exits when active_workers >= max_workers, but if PR-fix or mission workers are concurrently active, this check undercounts total capacity usage. This could cause the pulse agent to dispatch additional issue workers even when the system has already hit max_workers.

While prefetch_active_workers() correctly shows all /full-loop workers to the pulse agent, the backfill loop's separate capacity gate should match that scope. Consider broadening the pattern to grep '/full-loop' (excluding /pulse to avoid self-counting) or explicitly documenting that backfill is issue-only and relies on the pulse agent's prompt context to enforce cross-worker-type limits.

🤖 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 1683 - 1688, The backfill
capacity check in count_active_workers() is only matching issue workers and
undercounts total active workers; update count_active_workers() to broaden the
grep pattern (e.g., match '/full-loop' while still excluding '/pulse') so it
reports all active full-loop workers, ensuring enforce_utilization_invariants()
uses the correct total when comparing active_workers to max_workers; locate
function count_active_workers and change the grep filter accordingly (or
alternatively document/rename it if you intend it to be issue-only).

Comment on lines +1705 to +1706
ready_prs=$(rg -c '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
failing_prs=$(rg -c '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "0")
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Use grep instead of rg for consistency and portability.

The script uses grep throughout, but this function introduces a rg (ripgrep) dependency. While the || echo "0" fallback prevents failures when rg is unavailable, it silently returns incorrect counts rather than using the actual data.

♻️ Suggested fix using grep
-	ready_prs=$(rg -c '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
-	failing_prs=$(rg -c '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "0")
+	ready_prs=$(grep -cE '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
+	failing_prs=$(grep -cE '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "0")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ready_prs=$(rg -c '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
failing_prs=$(rg -c '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "0")
ready_prs=$(grep -cE '\[checks: PASS\].*\[review: APPROVED\]' "$STATE_FILE" 2>/dev/null || echo "0")
failing_prs=$(grep -cE '\[checks: FAIL\]|\[review: CHANGES_REQUESTED\]' "$STATE_FILE" 2>/dev/null || echo "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 1705 - 1706, Replace the
ripgrep calls that set ready_prs and failing_prs with portable grep invocations:
use grep -E -c with the same regex patterns against "$STATE_FILE" and keep the
2>/dev/null || echo "0" fallback so missing files still yield "0"; update the
lines that assign ready_prs and failing_prs (referencing those variable names
and STATE_FILE) to use grep -E and the original patterns '\[checks:
PASS\].*\[review: APPROVED\]' and '\[checks: FAIL\]|\[review:
CHANGES_REQUESTED\]'.

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

Labels

enhancement Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

t1455: add adaptive pulse queue governor for PR-heavy backlog periods

1 participant