-
Notifications
You must be signed in to change notification settings - Fork 61
t4947: add cross-machine dispatch dedup via assignee check + pulse jitter #4948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,6 +63,26 @@ set -euo pipefail | |||||||||||||||||||||||||||||||||
| ####################################### | ||||||||||||||||||||||||||||||||||
| export PATH="/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin:${PATH}" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ####################################### | ||||||||||||||||||||||||||||||||||
| # Startup jitter — desynchronise concurrent pulse instances | ||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||
| # When multiple runners share the same launchd interval (120s), their | ||||||||||||||||||||||||||||||||||
| # pulses fire simultaneously, creating a race window where both evaluate | ||||||||||||||||||||||||||||||||||
| # the same issue before either can self-assign. A random 0-30s delay at | ||||||||||||||||||||||||||||||||||
| # startup staggers the pulses so the first runner to wake assigns the | ||||||||||||||||||||||||||||||||||
| # issue before the second runner evaluates it. | ||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||
| # PULSE_JITTER_MAX: max jitter in seconds (default 30, set to 0 to disable) | ||||||||||||||||||||||||||||||||||
| ####################################### | ||||||||||||||||||||||||||||||||||
| PULSE_JITTER_MAX="${PULSE_JITTER_MAX:-30}" | ||||||||||||||||||||||||||||||||||
| if [[ "$PULSE_JITTER_MAX" -gt 0 ]]; then | ||||||||||||||||||||||||||||||||||
| # $RANDOM is 0-32767; modulo gives 0 to PULSE_JITTER_MAX | ||||||||||||||||||||||||||||||||||
| jitter_seconds=$((RANDOM % (PULSE_JITTER_MAX + 1))) | ||||||||||||||||||||||||||||||||||
| if [[ "$jitter_seconds" -gt 0 ]]; then | ||||||||||||||||||||||||||||||||||
| sleep "$jitter_seconds" | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+77
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script assumes
Suggested change
References
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 540ac93 — added numeric validation with |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Use ${BASH_SOURCE[0]:-$0} for shell portability — BASH_SOURCE is undefined | ||||||||||||||||||||||||||||||||||
| # in zsh, which is the MCP shell environment. This fallback ensures SCRIPT_DIR | ||||||||||||||||||||||||||||||||||
| # resolves correctly whether the script is executed directly (bash) or sourced | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While using
local IFS=','with afor ... inloop is a common idiom for iterating over comma-separated values, it can be brittle if values contain whitespace. A more robust method in bash is to useread -rato parse the values into an array. This avoids unintended word splitting and handles various edge cases more gracefully, aligning with best practices for parsing delimited data in shell scripts.References
readcommand's delimiter (set viaIFS) should always match the delimiter of the input data to ensure correct parsing. This suggestion introducesreadfor more robust parsing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 540ac93 — switched to
IFS=',' read -ra assignee_arrayfor robust parsing.