Skip to content

feat: prioritize human-initiated workspace builds over prebuilds in queue #18882

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blink-so[bot]
Copy link
Contributor

@blink-so blink-so bot commented Jul 15, 2025

Summary

Implements a priority queue system for provisioner jobs to ensure human-initiated workspace builds are processed before prebuild jobs, improving user experience during high queue periods.

Changes

  • Database: Added priority column to provisioner_jobs table with migration
  • Queue Logic: Updated AcquireProvisionerJob query to order by priority DESC, created_at ASC
  • Priority Assignment: Human-initiated jobs get priority 1, prebuilds get priority 0
  • API: Exposed priority field in SDK and conversion functions
  • Testing: Added comprehensive test to verify priority queue behavior

How it works

  1. When creating provisioner jobs, the workspace builder checks if the initiator is the PrebuildsSystemUserID
  2. Human-initiated jobs get priority = 1, prebuild jobs get priority = 0
  3. The AcquireProvisionerJob query now orders by priority first, then creation time
  4. This ensures human jobs are always acquired before prebuild jobs, regardless of creation time

Testing

  • Added unit test that verifies priority-based job acquisition
  • Test creates both human and prebuild jobs and confirms acquisition order
  • Existing tests should continue to pass as the change is backward compatible

Impact

  • Users: Faster workspace build times when prebuilds are queued
  • System: No performance impact, just changes query ordering
  • Backward Compatibility: Existing jobs get default priority 0, new logic applies to future jobs

Fixes the issue where prebuilds could delay human-initiated workspace builds during busy periods.

…ueue

This change implements a priority queue system for provisioner jobs to ensure
that human-initiated workspace builds are processed before prebuild jobs,
improving user experience during high queue periods.

Changes:
- Add priority column to provisioner_jobs table (1=human, 0=prebuild)
- Update AcquireProvisionerJob query to order by priority DESC, created_at ASC
- Set priority in workspace builder based on initiator (PrebuildsSystemUserID)
- Expose priority field in API and SDK
- Add comprehensive test for priority queue behavior

Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
@SasSwart SasSwart self-requested a review July 16, 2025 12:52
@mtojek mtojek requested a review from johnstcn July 17, 2025 13:02
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

I'd rather not add a new column here, as this requires a migration and migrations are difficult to backport, and this seems like something we would want to backport. We could instead add an explicit CASE WHEN on initiator_id to perform the ordering.

EDIT: can you please also link an associated GH issue, if it exists?

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.

1 participant