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

Closed
wants to merge 2 commits into 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

  • Queue Logic: Updated AcquireProvisionerJob query to use CASE WHEN on initiator_id to order by priority
  • Priority Assignment: Human-initiated jobs get priority 1, prebuilds get priority 0 (via SQL CASE WHEN)
  • Testing: Updated comprehensive test to verify priority queue behavior using initiator_id

How it works

  1. The AcquireProvisionerJob query now uses a CASE WHEN statement to prioritize jobs:
    • Jobs with initiator_id != PrebuildsSystemUserID get priority 1 (human-initiated)
    • Jobs with initiator_id = PrebuildsSystemUserID get priority 0 (prebuilds)
  2. The query orders by this calculated priority first, then creation time
  3. This ensures human jobs are always acquired before prebuild jobs, regardless of creation time

Testing

  • Updated unit test that verifies priority-based job acquisition
  • Test creates both human and prebuild jobs and confirms acquisition order
  • Existing tests 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: No migrations required, works with existing data

Related to provisioner queue issues like #15843 and #16488 - this addresses the specific case where prebuilds can 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?

johnstcn added a commit that referenced this pull request Jul 22, 2025
Continues from #18882

- Reverts extraneous changes
- Adds explicit `ORDER BY initiator_id = $PREBUILDS_USER_ID` to
`AcquireProvisionerJob`
- Improves test added for above PR

---------

Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
@mtojek
Copy link
Member

mtojek commented Jul 28, 2025

I guess we can close it now.

@mtojek mtojek closed this Jul 28, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2025
Address review feedback by removing the priority column migration
and instead using a CASE WHEN statement in the AcquireProvisionerJob
query to prioritize human-initiated jobs over prebuilds.

This approach avoids the need for a migration while maintaining
the same functionality.

Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
@blink-so blink-so bot reopened this Jul 28, 2025
@mtojek mtojek closed this Jul 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy