Skip to content

fix(workflow): prevent scheduled scan gaps and starvation - #7645

Open
bmurphy201 wants to merge 1 commit into
block:mainfrom
bmurphy201:forge/workflow-scheduler-20260914
Open

bmurphy201 wants to merge 1 commit into
block:mainfrom
bmurphy201:forge/workflow-scheduler-20260914

Conversation

@bmurphy201

Copy link
Copy Markdown

Summary

  • drive the scheduler with a fixed ticker and an exact window from the prior successful scan, so scan and execution time cannot create blind cron gaps
  • retain the prior successful cursor after a failed or partial database scan, and coalesce a prolonged gap to the latest due cron instant
  • keyset-page every enabled scheduled workflow instead of permanently truncating the global scan at 1,000 rows
  • freeze each scan at its start time and add a matching partial database index so concurrent inserts cannot extend one scan indefinitely

Root cause

The loop previously slept for 60 seconds after completing each scan but looked back only 60 seconds for due cron instants. Any scan or execution work made the real interval longer than the lookup window. The global query also returned only the oldest 1,000 enabled scheduled workflows on every tick, leaving all later rows permanently unvisited.

This was observed as a hosted scheduled workflow failing to fire while manual execution remained healthy. Hosted relay logs were unavailable, so the production incident is consistent with these defects but does not prove that either was the only contributing cause.

Behavior

The durable (community_id, workflow_id, scheduled_for) claim remains the cross-pod at-most-once boundary. After an extended failed scan, the scheduler claims only the latest due cron instant rather than replaying an unbounded burst of side effects.

Validation

  • env -u BUZZ_ACP_SESSION_POLICY bin/just ci
  • affected package suites: buzz-db 122 passed / 253 ignored; buzz-workflow 171 passed / 2 ignored
  • PostgreSQL test discovery guard passed; the new 1,002-row snapshot-bound pagination regression is included in the ignored PostgreSQL CI lane
  • exact head tested: 028762d6ac33bd52a8fd49b96b31d536b738576e

Related work

AI-assisted implementation, reviewed and tested against current main before submission.

Signed-off-by: Forge <command@colonyspark.com>
@bmurphy201
bmurphy201 requested a review from a team as a code owner September 14, 2026 20:18
@github-actions

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 4cd82f513214aad11c2b742ce7cc7c681e8e32a0...028762d6ac33bd52a8fd49b96b31d536b738576e.
A new review must complete for this exact range. When manual authorization
is required, a Block organization member must comment exactly
@buzz-security-review 028762d6ac33bd52a8fd49b96b31d536b738576e to authorize a new review.
Any previous review applies only to its recorded range.

@bmurphy201

Copy link
Copy Markdown
Author

Maintainers: this fixes two production scheduler gaps we reproduced in a hosted Buzz workflow: elapsed scan time can leave cron blind spots, and the enabled-schedule query stops after 1,000 rows. Bill Murphy has authorized merge and deployment for our affected workspace. The exact PR head passed the full local just ci gate, plus the database and workflow regression suites. GitHub reports the PR mergeable, DCO, Semgrep, and zizmor passing. Please review and merge when the repository gates are satisfied; our account cannot merge or enable auto-merge under the base policy.

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.

Scheduled (cron) workflows never fire on a hosted multi-tenant relay; manual trigger works

1 participant