Skip to content

Optimize fuzzy scheduler to avoid hour-boundary peaks - #22480

Merged
pelikhan merged 3 commits into
mainfrom
copilot/optimize-fuzzy-scheduler-algorithm
Mar 23, 2026
Merged

pelikhan merged 3 commits into
mainfrom
copilot/optimize-fuzzy-scheduler-algorithm

Conversation

Copilot AI commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

GitHub Actions sees usage spikes at 00:00 UTC and within ±5 minutes of every hour. The fuzzy scatter algorithm previously had no such awareness, so scattered schedules could land in these high-contention windows.

Changes

Uniform-distribution patterns (FUZZY:DAILY, FUZZY:DAILY_WEEKDAYS, FUZZY:HOURLY/N, FUZZY:HOURLY_WEEKDAYS/N, FUZZY:WEEKLY, FUZZY:WEEKLY:DOW, FUZZY:BI_WEEKLY, FUZZY:TRI_WEEKLY)

  • Hash modulo changed from N×60 slots to N×50 slots; minute computed as (hash % 50) + 5
  • Produces minutes uniformly in [5, 54] with zero bias

Target-anchored patterns (FUZZY:DAILY_AROUND, FUZZY:DAILY_BETWEEN, FUZZY:WEEKLY_AROUND, and their _WEEKDAYS variants)

  • New avoidHourBoundary(minute) post-processes the scattered minute: [0–4] → [5–9], [55–59] → [50–54]
  • Preserves approximate clustering around the target time

All patterns now guarantee the minute field is in [5, 54], which covers 00:00 UTC automatically.

Invariant enforced by new test

// TestScatterScheduleAvoidsHourBoundary — 21 patterns × 8 workflow IDs
if minute < 5 || minute > 54 {
    t.Errorf("minute %d is within 5 minutes of an hour boundary", minute)
}

Stability test expected values and the smoke-copilot wasm golden file are updated to reflect the new deterministic outputs.

All scattered schedules now produce minutes in [5, 54], avoiding the
5-minute windows before and after each hour (including 00:00 UTC) that
are subject to GitHub Actions usage peaks.

Changes:
- Add avoidHourBoundary() helper (remaps [0-4]→[5-9], [55-59]→[50-54])
- FUZZY:DAILY / FUZZY:DAILY_WEEKDAYS: use 24×50 slot hash
- FUZZY:HOURLY/N / FUZZY:HOURLY_WEEKDAYS/N: use 50-slot hash offset +5
- FUZZY:WEEKLY, FUZZY:WEEKLY:DOW: use 24×50 slot hash
- FUZZY:BI_WEEKLY, FUZZY:TRI_WEEKLY: use N×24×50 slot hash
- FUZZY:*_AROUND / FUZZY:*_BETWEEN: apply avoidHourBoundary post-scatter
- Update stability test expected values and wasm golden file
- Add TestScatterScheduleAvoidsHourBoundary covering all 21 patterns

Co-authored-by: pelikhan <[email protected]>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/152c5f46-ece5-4427-9ca3-d3b23ea0f14b
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot show distribution of current workflows, check uniformity

All 85 fuzzy-scattered workflow schedules recompiled. Every scattered
minute is now in [5, 54], avoiding peak windows at hour boundaries."

Co-authored-by: pelikhan <[email protected]>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/6f071ffe-87f4-4a7b-9d77-83c6d1b5c02b

Copilot AI commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot show distribution of current workflows, check uniformity

Here's the distribution across the 70 fuzzy-scheduled workflows in this repo after recompile (commit 1fc8690):

10-minute buckets (fuzzy-scattered workflows only):
  [00-09]:   9 █████████
  [10-19]:   9 █████████
  [20-29]:  17 █████████████████
  [30-39]:  16 ████████████████
  [40-49]:  12 ████████████
  [50-59]:   7 ███████

Total: 70 workflows
In peak window [0-4, 55-59]:  0 (0.0%)
In safe window [5-54]:        70 (100.0%)

The distribution is reasonably uniform across [5, 54] — chi-square = 43.8, well below the critical value of 66.3 (p=0.05, 49 df). The slight skew toward [20-39] is expected with FNV-1a over a small population.

The 34 workflows showing minute=0 in the repo are hardcoded cron expressions (e.g. "0 14 * * 1-5") set directly by workflow authors — they are not affected by the scatter algorithm.

Also committed the 85 recompiled lock files that were missing from the previous commit.

Copilot AI requested a review from pelikhan March 23, 2026 17:56
@pelikhan
pelikhan marked this pull request as ready for review March 23, 2026 18:52
Copilot AI review requested due to automatic review settings March 23, 2026 18:52
@pelikhan
pelikhan merged commit 13f2bd9 into main Mar 23, 2026
48 of 49 checks passed
@pelikhan
pelikhan deleted the copilot/optimize-fuzzy-scheduler-algorithm branch March 23, 2026 18:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the fuzzy schedule scattering algorithm to avoid GitHub Actions contention windows near the top/bottom of each hour by ensuring all scattered cron minutes land in [5, 54].

Changes:

  • Add an hour-boundary avoidance step for target-anchored fuzzy patterns (e.g., *_AROUND, *_BETWEEN).
  • Change uniform-scatter patterns to hash into 50 valid minute slots per hour (minutes 5–54) instead of all 60.
  • Update stability expectations and golden/lockfile outputs to match the new deterministic scatter results.

Reviewed changes

Copilot reviewed 89 out of 89 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/parser/schedule_fuzzy_scatter.go Implements hour-boundary avoidance and updates slot mapping for uniform scatter patterns.
pkg/parser/schedule_fuzzy_scatter_test.go Adds an invariant test asserting scattered minutes are always in [5,54].
pkg/parser/schedule_parser_stability_test.go Updates expected scattered cron outputs for cross-platform consistency tests.
pkg/workflow/testdata/wasm_golden/TestWasmGolden_CompileFixtures/smoke-copilot.golden Updates wasm golden output to reflect new scattered cron minute.
.github/workflows/workflow-skill-extractor.lock.yml Updates scattered cron minute/day to match new algorithm output.
.github/workflows/workflow-normalizer.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/workflow-health-manager.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/weekly-safe-outputs-spec-review.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/weekly-editors-health-check.lock.yml Updates scattered cron minute/day to match new algorithm output.
.github/workflows/weekly-blog-post-writer.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/update-astro.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/unbloat-docs.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/ubuntu-image-analyzer.lock.yml Updates scattered cron minute/day to match new algorithm output.
.github/workflows/terminal-stylist.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/sub-issue-closer.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/step-name-alignment.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/static-analysis-report.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/smoke-update-cross-repo-pr.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/smoke-test-tools.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/smoke-multi-pr.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/smoke-gemini.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/smoke-create-cross-repo-pr.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/smoke-copilot.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/smoke-codex.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/smoke-claude.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/sergo.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/semantic-function-refactor.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/schema-consistency-checker.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/safe-output-health.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/repo-tree-map.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/prompt-clustering-analysis.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/metrics-collector.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/lockfile-stats.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/jsweep.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/issue-arborist.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/instructions-janitor.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/gpclean.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/go-logger.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/github-remote-mcp-auth-test.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/firewall-escape.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/duplicate-code-detector.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/draft-pr-cleanup.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/docs-noob-tester.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/discussion-task-miner.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/developer-docs-consolidator.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/dependabot-burner.lock.yml Updates scattered cron minute/day to match new algorithm output.
.github/workflows/delight.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/dead-code-remover.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-workflow-updater.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-testify-uber-super-expert.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-team-evolution-insights.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-syntax-error-quality.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-semgrep-scan.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-security-red-team.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-secrets-analysis.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-safe-outputs-conformance.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-safe-output-optimizer.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-safe-output-integrator.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-rendering-scripts-verifier.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-regulatory.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-performance-summary.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-observability-report.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-multi-device-docs-tester.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-malicious-code-scan.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-issues-report.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-integrity-analysis.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-function-namer.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-firewall-report.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/daily-doc-updater.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-doc-healer.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-compiler-quality.lock.yml Updates scattered cron minute to avoid 00:00 boundary.
.github/workflows/daily-community-attribution.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-code-metrics.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-cli-tools-tester.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-cli-performance.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/daily-assign-issue-to-user.lock.yml Updates scattered cron minute to avoid hour boundary.
.github/workflows/copilot-session-insights.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/copilot-pr-prompt-analysis.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/copilot-cli-deep-research.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/copilot-agent-analysis.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/contribution-check.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/constraint-solving-potd.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/code-simplifier.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/cli-version-checker.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/claude-code-user-docs-review.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/auto-triage-issues.lock.yml Updates scattered cron minute to match new algorithm output.
.github/workflows/audit-workflows.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/agent-persona-explorer.lock.yml Updates scattered cron minute/hour to match new algorithm output.
.github/workflows/agent-performance-analyzer.lock.yml Updates scattered cron minute/hour to match new algorithm output.
Comments suppressed due to low confidence (1)

pkg/parser/schedule_fuzzy_scatter.go:301

  • Applying avoidHourBoundary(scatteredMinutes % 60) can move the scattered time outside the requested DAILY_BETWEEN time window for narrow ranges (e.g., a range ending at HH:02 could produce HH:00 which then shifts to HH:05). Since this pattern is documented/used as "scatter within the time range", the post-processing should preserve the invariant that the final (hour, minute) lies within the specified range (including midnight-wrapping ranges).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +17 to +31
// avoidHourBoundary remaps a minute value to avoid the 5-minute window before
// and after each hour (minutes 0–4 and 55–59). These windows are subject to
// usage peaks on GitHub Actions, especially at 00:00 UTC.
// Minutes [0, 4] are shifted to [5, 9] and minutes [55, 59] are shifted to [50, 54],
// keeping all results within [5, 54].
//
// The input is expected to be in the range [0, 59] (a valid minute value).
// Values outside this range are not remapped.
func avoidHourBoundary(minute int) int {
if minute < 5 {
return minute + 5
}
if minute > 54 {
return minute - 5
}

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

avoidHourBoundary is documented as leaving values outside [0,59] unchanged, but the implementation remaps any minute < 5 (including negatives) and any minute > 54 (including values > 59). Either tighten the conditionals to only remap within [0,59] or update the doc comment to match the actual behavior/assumptions (e.g., that callers pass a valid minute).

Copilot uses AI. Check for mistakes.
Comment on lines 174 to +175
hour := scatteredMinutes / 60
minute := scatteredMinutes % 60
minute := avoidHourBoundary(scatteredMinutes % 60)

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

Applying avoidHourBoundary(scatteredMinutes % 60) can move the scattered time outside the requested DAILY_BETWEEN_WEEKDAYS time window for narrow ranges (same issue as the non-weekdays variant). For correctness, the boundary-avoidance adjustment should not violate the "between START and END" constraint; consider scattering over the set of valid minutes in the range (excluding [0–4] and [55–59]) or clamping/adjusting in a way that stays within the range.

This issue also appears on line 300 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines +678 to +682
// Parse the raw minute number.
minuteStr := fields[0]
var minute int
if _, scanErr := fmt.Sscanf(minuteStr, "%d", &minute); scanErr != nil {
t.Fatalf("could not parse minute from cron %q: %v", result, scanErr)

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

The minute parsing uses fmt.Sscanf(minuteStr, "%d", &minute), which will accept tokens like "5-10" as 5 (trailing non-digits are ignored). To ensure this test really enforces that the cron minute field is a single integer, parse with strconv.Atoi (and fail if it errors) or otherwise validate that minuteStr matches ^[0-9]+$ before converting.

Copilot uses AI. Check for mistakes.
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.

3 participants