Skip to content

t1478: fix(pulse-wrapper): add flock-based lock guard to prevent concurrent instances#4454

Merged
alex-solovyev merged 1 commit intomainfrom
bugfix/pulse-lock-guard
Mar 13, 2026
Merged

t1478: fix(pulse-wrapper): add flock-based lock guard to prevent concurrent instances#4454
alex-solovyev merged 1 commit intomainfrom
bugfix/pulse-lock-guard

Conversation

@alex-solovyev
Copy link
Collaborator

@alex-solovyev alex-solovyev commented Mar 13, 2026

Summary

Fixes concurrent pulse supervisor instances running simultaneously.

  • Adds flock-based lock guard in pulse-wrapper.sh to prevent multiple concurrent executions
  • Addresses the pattern where 3 pulse instances were found running concurrently

Closes #4452

Summary by CodeRabbit

  • Improvements
    • Strengthened instance locking mechanism to prevent concurrent execution conflicts and ensure stable operation during simultaneous instance launches.

…instances (GH#4409)

14 concurrent pulse instances ran simultaneously, each spawning workers
before the previous pulse could assess running workers, resulting in 52
active workers against a 24-slot pool.

Root cause: check_dedup() uses a PID file with a TOCTOU race window —
between reading the PID file and writing the new PID, another instance
can pass the same check.

Fix: Add flock(1) -n (non-blocking) as the primary instance lock in
main(), acquired before any other check. flock is atomic at the kernel
level — no race window. The lock auto-releases on process exit
(including crashes, OOM kills, SIGKILL). Falls back gracefully to
PID-based dedup on systems without flock (e.g., macOS).
@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!

@github-actions github-actions bot added the bug Auto-created from TODO.md tag label Mar 13, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

The change introduces a robust flock-based instance locking mechanism to .agents/scripts/pulse-wrapper.sh to prevent multiple concurrent supervisor instances. A new acquire_instance_lock() function and LOCKFILE constant enforce exclusive execution early in the main flow, with fallback to PID-based dedup if flock is unavailable.

Changes

Cohort / File(s) Summary
Instance Locking Enhancement
.agents/scripts/pulse-wrapper.sh
Added LOCKFILE constant and acquire_instance_lock() function implementing flock-based exclusive locking on FD 9. Lock acquisition enforced early in main execution path with exit on failure. PID-based dedup maintained as fallback when flock unavailable. Lifecycle documentation updated to reflect new locking guard.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🔒 One pulse at a time shall reign supreme,
No more duplicate instances haunt the dream,
Flock guards the gate with atomic delight,
Concurrent chaos banished to night! ⚡

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a flock-based lock guard to pulse-wrapper.sh to prevent concurrent instances, which directly addresses the linked issue #4452.
Linked Issues check ✅ Passed The PR implements the primary fix from #4452: adding a flock-based lock in pulse-wrapper.sh to prevent concurrent pulse supervisor instances, with fallback PID-based dedup for systems without flock support.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the flock-based locking mechanism in pulse-wrapper.sh; no unrelated modifications to other components or features are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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/pulse-lock-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:
Fri Mar 13 18:13:32 UTC 2026: Code review monitoring started
Fri Mar 13 18:13:32 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 414

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 414
  • VULNERABILITIES: 0

Generated on: Fri Mar 13 18:13:35 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@alex-solovyev alex-solovyev merged commit 8fcdb41 into main Mar 13, 2026
25 of 26 checks passed
@alex-solovyev alex-solovyev deleted the bugfix/pulse-lock-guard branch March 13, 2026 18:20
@marcusquinn marcusquinn added the review-feedback-scanned Merged PR already scanned for quality feedback label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Auto-created from TODO.md tag review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

t1478: fix: pulse multiple supervisor instances running simultaneously

2 participants