Skip to content

t4527: prevent pulse redispatch for already-merged tasks#4549

Merged
marcusquinn merged 3 commits intomainfrom
bugfix/4527-merged-pr-redispatch-guard
Mar 14, 2026
Merged

t4527: prevent pulse redispatch for already-merged tasks#4549
marcusquinn merged 3 commits intomainfrom
bugfix/4527-merged-pr-redispatch-guard

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Mar 14, 2026

Summary

  • Add a deterministic merged-PR guard in pulse-wrapper.sh so dispatch dedup skips issues already resolved by merged PRs.
  • Extend dedup logic to fallback on task IDs in issue titles, covering duplicate-issue patterns where the merged PR closed a different issue.
  • Update pulse dispatch guidance and add regression tests for direct close-keyword and task-ID fallback detection.

Closes #4527

Summary by CodeRabbit

  • New Features

    • Enhanced pulse orchestration system with comprehensive workflow rules, priority scheduling, and cross-repo coordination controls
    • Added merged PR detection to prevent duplicate task dispatch and improve dedup logic with three-layer validation
  • Tests

    • Expanded test coverage for merged PR detection and dispatch deduplication scenarios

@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

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 31 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: ea1e2de2-ffca-4605-95cb-86b0a9e0e800

📥 Commits

Reviewing files that changed from the base of the PR and between edbf320 and d1291bf.

📒 Files selected for processing (3)
  • .agents/scripts/commands/pulse.md
  • .agents/scripts/pulse-wrapper.sh
  • .agents/scripts/tests/test-pulse-wrapper-worker-detection.sh

Walkthrough

Introduces a third dedup layer detecting merged PRs to prevent task re-dispatch. Updates pulse orchestration documentation with comprehensive guard rails, priority scheduling, quality-debt workflows, and audit requirements. Implements merged-PR detection function and extends dispatch validation logic with corresponding test coverage.

Changes

Cohort / File(s) Summary
Pulse Orchestration Documentation
.agents/scripts/commands/pulse.md
Comprehensive pulse supervisor guidance including capacity checks, pre-dispatch validations (dedup, worker caps, merged-PR evidence), multi-layered priority ordering, quality-debt workflow with worktree dispatch and blast-radius limits, model-escalation policies, audit-quality state requirements, lineage/subtask mechanics, batch distribution strategies, and cross-repo TODO sync.
Dispatch Dedup Enhancement
.agents/scripts/pulse-wrapper.sh
New has_merged_pr_for_issue() function detects merged PRs via closes/fixes/resolves keywords or task-id fallback. Updated check_dispatch_dedup() signature adds third dedup layer for merged-PR evidence detection; skips dispatch if corresponding merged PR exists.
Test Infrastructure
.agents/scripts/tests/test-pulse-wrapper-worker-detection.sh
Adds GH-based test fixtures and mock gh wrapper (GH_SEARCH_FIXTURES, set_gh_search_fixtures()). Introduces three new tests validating merged-PR detection via closing keywords, task-id fallback, and dedup integration with merged-PR evidence.

Sequence Diagram

sequenceDiagram
    participant Supervisor as Supervisor<br/>(pulse)
    participant Wrapper as Pulse Wrapper<br/>Scripts
    participant GitHub as GitHub API
    participant Queue as Task Queue

    Supervisor->>Wrapper: check_dispatch_dedup(repo, issue)
    
    Wrapper->>Wrapper: Layer 1: Check exact<br/>repo+issue match
    alt Already dispatched
        Wrapper-->>Supervisor: SKIP (dedup exact)
    end
    
    Wrapper->>Wrapper: Layer 2: Check<br/>normalized title
    alt Title match found
        Wrapper-->>Supervisor: SKIP (dedup title)
    end
    
    Wrapper->>Wrapper: Layer 3: has_merged_pr_for_issue()
    Wrapper->>GitHub: gh pr list --search<br/>"closes `#NNN`" --state merged
    GitHub-->>Wrapper: [Merged PR results]
    
    alt Merged PR detected
        Wrapper->>Wrapper: Extract task-id from issue<br/>and search PR titles
        GitHub-->>Wrapper: [Task-id match results]
    end
    
    alt Any merged PR found
        Wrapper-->>Supervisor: SKIP (dedup merged PR)
    else No merged PR evidence
        Wrapper-->>Supervisor: PROCEED to dispatch
        Supervisor->>Queue: Enqueue worker
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • #1790: Adds PR-aware guards to pulse pipeline to avoid duplicate work and stale PRs through similar detection mechanisms.
  • #2295: Modifies pulse supervisor documentation with outcome-observation and agent-routing guidance in tandem with orchestration updates.
  • #4131: Strengthens supervisor-as-dispatcher boundary enforcement and pre-dispatch guardrails in pulse orchestration docs.

Suggested Labels

bug, enhancement

Poem

🎯 A duplicate lurks in the GitHub night,
Merged long ago, yet still in fight,
Three layers deep, we now shall see—
No wasted workers; dispatches decree! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% 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 clearly and concisely summarizes the main change: adding a guard to prevent pulse from re-dispatching tasks that already have merged PRs, directly addressing the problem described in the linked issue.
Linked Issues check ✅ Passed The pull request fulfills all primary coding requirements from issue #4527: implements merged-PR detection via 'closes' keyword, adds task-ID fallback detection for duplicate patterns, includes comprehensive regression tests, and updates dispatch guidance.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the merged-PR redispatch prevention objective: pulse.md documentation updates, pulse-wrapper.sh dedup enhancements, and new test coverage for the feature. No unrelated changes detected.

✏️ 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/4527-merged-pr-redispatch-guard
📝 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 00:49:44 UTC 2026: Code review monitoring started
Sat Mar 14 00:49:44 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 00:49:47 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@marcusquinn marcusquinn force-pushed the bugfix/4527-merged-pr-redispatch-guard branch from f6687c3 to edbf320 Compare March 14, 2026 01:08
@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:09:05 UTC 2026: Code review monitoring started
Sat Mar 14 01:09:05 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:09:07 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

🧹 Nitpick comments (1)
.agents/scripts/commands/pulse.md (1)

524-545: Prefer check_dispatch_dedup over re-stating its subchecks in the prompt.

This section re-encodes wrapper-owned logic even though the snippet already sources the helper that centralizes it. Using the consolidated function keeps the prompt and .agents/scripts/pulse-wrapper.sh aligned when dedup rules change again.

♻️ Collapse the prompt to the single shell helper
-# Check 1: exact repo+issue match via process list
-if has_worker_for_repo_issue <number> <slug>; then
-  echo "Worker already running for #<number> in <slug> — skipping"
-  continue
-fi
-
-# Check 2: normalized dedup via dispatch-dedup-helper (catches title variants)
-if ~/.aidevops/agents/scripts/dispatch-dedup-helper.sh is-duplicate "Issue #<number>: <title>"; then
-  echo "Duplicate dispatch detected for #<number> — skipping"
-  continue
-fi
-
-# Check 3: merged-PR evidence (direct close keyword OR task-id fallback)
-if has_merged_pr_for_issue <number> <slug> "<issue title>"; then
-  echo "Issue #<number> already has merged PR evidence — skipping dispatch"
+if check_dispatch_dedup <number> <slug> "Issue #<number>: <title>" "<issue title>"; then
+  echo "Duplicate or already-merged work detected for #<number> — skipping dispatch"
   continue
 fi
🤖 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 524 - 545, The snippet
duplicates the wrapper's dedup logic (has_worker_for_repo_issue,
dispatch-dedup-helper.sh is-duplicate, has_merged_pr_for_issue) instead of using
the centralized helper; replace the three separate checks with a single call to
check_dispatch_dedup (provided by sourcing pulse-wrapper.sh) so the script uses
the canonical dedup rules defined in pulse-wrapper.sh and stays in sync when
dedup behavior changes.
🤖 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/pulse-wrapper.sh:
- Around line 2193-2201: Update the keyword loop that builds the search query
for PRs so it checks all GitHub auto-close variants (close, closes, closed, fix,
fixes, fixed, resolve, resolves, resolved) instead of only "closes fixes
resolves"; modify the for-loop that iterates over keyword (which constructs
query="${keyword} #${issue_number} in:body" and uses gh pr list -> pr_json and
pr_count) to iterate the full nine-word set so merged PRs using singular or
past-tense forms are detected and the dedup guard prevents re-dispatch.

In @.agents/scripts/tests/test-pulse-wrapper-worker-detection.sh:
- Around line 87-120: The gh() stub currently only matches on the --search value
from GH_SEARCH_FIXTURES which lets has_merged_pr_for_issue() call gh pr list
with the wrong --repo or --state and still pass; update the gh() function to
parse and validate --repo and --state flags in addition to --search (or
construct fixture keys that include repo and state), match against a compound
key in GH_SEARCH_FIXTURES (e.g. "repo|state|search") inside gh(), and if
unexpected or missing --repo/--state values are provided, print a clear error
and return non‑zero so tests fail loudly; refer to the gh() stub,
GH_SEARCH_FIXTURES, and the has_merged_pr_for_issue() test call when making
these changes.

---

Nitpick comments:
In @.agents/scripts/commands/pulse.md:
- Around line 524-545: The snippet duplicates the wrapper's dedup logic
(has_worker_for_repo_issue, dispatch-dedup-helper.sh is-duplicate,
has_merged_pr_for_issue) instead of using the centralized helper; replace the
three separate checks with a single call to check_dispatch_dedup (provided by
sourcing pulse-wrapper.sh) so the script uses the canonical dedup rules defined
in pulse-wrapper.sh and stays in sync when dedup behavior changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c6f8d14c-eefe-4dab-959e-97dd4573bae4

📥 Commits

Reviewing files that changed from the base of the PR and between 118878f and edbf320.

📒 Files selected for processing (3)
  • .agents/scripts/commands/pulse.md
  • .agents/scripts/pulse-wrapper.sh
  • .agents/scripts/tests/test-pulse-wrapper-worker-detection.sh

- Expand has_merged_pr_for_issue keyword loop to all 9 GitHub auto-close
  variants (close/closes/closed, fix/fixes/fixed, resolve/resolves/resolved)
- Update gh() test stub to validate --repo and --state flags alongside
  --search using compound fixture keys (repo|state|query|payload format)
- Update all fixture strings in test functions to use compound key format
- Collapse three separate dedup if-blocks in pulse.md into single
  check_dispatch_dedup call (nitpick)
- All 7 tests pass; shellcheck clean on both modified .sh files
@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:24:57 UTC 2026: Code review monitoring started
Sat Mar 14 01:24:58 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:25:00 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

… flags

The previous commit added compound key matching but the stub still
silently returned [] when --repo or --state were missing. Now it
fails loudly with a diagnostic message, catching regressions where
has_merged_pr_for_issue() omits required flags.
@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:16:07 UTC 2026: Code review monitoring started
Sat Mar 14 03:16: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:16:10 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@alex-solovyev
Copy link
Collaborator

Pulse triage: CHANGES_REQUESTED from CodeRabbit. Fix needed in .agents/scripts/commands/pulse.md lines 524-545: collapse explicit dedup subchecks into single check_dispatch_dedup helper call. Worker slots full this cycle — queued for next pulse.

@marcusquinn
Copy link
Owner Author

All CHANGES_REQUESTED review feedback addressed:

  1. pulse.md (nitpick): Collapsed three separate dedup if-blocks into a single check_dispatch_dedup call — prompt now delegates to the wrapper-owned helper and stays aligned when dedup rules change.
  2. pulse-wrapper.sh (major): Expanded keyword loop from 3 to all 9 GitHub auto-close variants (close/closes/closed, fix/fixes/fixed, resolve/resolves/resolved).
  3. test stub (minor): Updated gh() stub to validate --repo and --state flags using compound fixture keys — fails loudly on unexpected inputs.

All 7 tests pass, shellcheck clean. @coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

@marcusquinn Thanks for the thorough follow-through on all three items! The fixes look well-targeted:

  1. pulse.md — Delegating to check_dispatch_dedup keeps the prompt lean and ensures it stays in sync with wrapper evolution automatically. ✅
  2. pulse-wrapper.sh — Covering all 9 GitHub auto-close keyword variants (close/closes/closed, fix/fixes/fixed, resolve/resolves/resolved) closes the gap where partial keyword sets could miss merged PRs. ✅
  3. Test stub — Compound fixture keys with strict flag validation make the mock fail loudly on unexpected inputs, which is the right posture for a deterministic guard. ✅

Kicking off a fresh 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: marcusquinn
Repo: marcusquinn/aidevops PR: 3996
File: TODO.md:116-116
Timestamp: 2026-03-10T03:50:19.987Z
Learning: For aidevops TODO.md workflow, the functional gate for auto-dispatch is the `blocked-by:` field; titles may remain aspirational (e.g., “Adopt X”) so long as a blocking evaluation task exists. Prefer enforcing `blocked-by:<eval-task>` over title renames.
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@marcusquinn marcusquinn merged commit 5bfe1aa into main Mar 14, 2026
12 checks passed
@marcusquinn marcusquinn deleted the bugfix/4527-merged-pr-redispatch-guard branch March 14, 2026 04:11
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.

fix: prevent re-dispatch of tasks with already-merged PRs (awardsapp duplicate PR pattern)

2 participants