Skip to content

feature: Inqueue timeout mechanism to prevent resource blocking by unschedulable PodGroups#5101

Open
rishisulakhe wants to merge 1 commit intovolcano-sh:masterfrom
rishisulakhe:feature/inqueue-timeout
Open

feature: Inqueue timeout mechanism to prevent resource blocking by unschedulable PodGroups#5101
rishisulakhe wants to merge 1 commit intovolcano-sh:masterfrom
rishisulakhe:feature/inqueue-timeout

Conversation

@rishisulakhe
Copy link

@rishisulakhe rishisulakhe commented Mar 12, 2026

Which issue(s) this PR fixes:

Fixes #5006 #4617

Backgroud

Volcano's scheduler uses a logical queue-based resource view. When a job is enqueued, its
MinResources are reserved against the queue's capacity. However, actual schedulability depends
on real node-level conditions that the enqueue check doesn't evaluate. This mismatch causes:

  • Jobs stuck in Inqueue consuming queue quota without making progress
  • Other schedulable jobs blocked from enqueueing due to perceived capacity exhaustion
  • Particularly severe with FIFO dequeue strategy where a stuck head-of-line job blocks everything

Solution

  • New inqueuetimeout plugin — votes to dequeue PodGroups that have been Inqueue longer than a
    configurable timeout without any pods being scheduled
  • New framework hooks (JobDequeueable/JobDequeued) — mirrors the existing
    JobEnqueueable/JobEnqueued pattern for clean plugin integration
  • Inqueued condition tracking — records a PodGroupInqueuedType condition with timestamp when
    a PodGroup enters Inqueue, persisted in etcd across scheduler restarts
  • Resource accounting — capacity and proportion plugins register JobDequeuedFn callbacks to
    subtract reserved inqueue resources when a job is dequeued

Configuration

Global default via plugin arguments:

tiers:
- plugins:
  - name: inqueuetimeout
    enableJobEnqueued: true
    arguments:
      inqueue-timeout: 5m

Per-PodGroup override via annotation:

metadata:
  annotations:
    volcano.sh/inqueue-timeout: 10m

Disabled by default ;users opt in by enabling the plugin.

Copilot AI review requested due to automatic review settings March 12, 2026 20:16
@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hwdef for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 12, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue in the Volcano scheduler where jobs could get stuck in the 'Inqueue' state, consuming queue quota without making progress and blocking other schedulable jobs. The solution introduces a new inqueuetimeout plugin that proactively identifies and dequeues such stalled jobs based on a configurable timeout. This enhancement improves scheduler efficiency, resource utilization, and overall fairness by preventing head-of-line blocking and ensuring that resources are promptly released for active jobs.

Highlights

  • New inqueuetimeout Plugin: Introduced a new scheduler plugin that automatically dequeues jobs (PodGroups) that have been in the 'Inqueue' state for longer than a configurable timeout, preventing resource starvation and head-of-line blocking.
  • New Framework Hooks for Dequeuing: Added JobDequeueable and JobDequeued framework hooks to mirror the existing enqueue pattern, allowing plugins to participate in the job dequeuing process and manage associated resources.
  • Inqueue Condition Tracking: Implemented tracking of a PodGroupInqueuedType condition with a timestamp when a PodGroup enters the Inqueue state, which is persisted across scheduler restarts to enable accurate timeout calculations.
  • Resource Accounting for Dequeued Jobs: Updated the capacity and proportion plugins to register JobDequeuedFn callbacks, ensuring that reserved inqueue resources are correctly released when a job is dequeued due to timeout.
  • Flexible Timeout Configuration: Provided options for configuring the inqueue timeout globally via plugin arguments and on a per-PodGroup basis using annotations, allowing users to opt-in and customize the behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • pkg/scheduler/actions/enqueue/enqueue.go
    • Imported v1 for Kubernetes core API types.
    • Added logic to iterate through jobs and dequeue those that are JobDequeueable and in PodGroupInqueue phase, resetting their phase to PodGroupPending.
    • Implemented recording of PodGroupInqueuedType condition with a timestamp when a PodGroup is enqueued.
  • pkg/scheduler/framework/session.go
    • Added jobDequeueableFns and jobDequeuedFns maps to the Session struct to manage new dequeue-related plugin functions.
    • Initialized jobDequeueableFns and jobDequeuedFns maps in the openSession function.
  • pkg/scheduler/framework/session_plugins.go
    • Added AddJobDequeueableFn to register functions for determining if a job can be dequeued.
    • Added AddJobDequeuedFn to register functions to be called when a job is dequeued.
    • Implemented JobDequeueable method to invoke registered jobDequeueableFns and determine if a job should be dequeued.
    • Implemented JobDequeued method to invoke registered jobDequeuedFns when a job is dequeued.
  • pkg/scheduler/plugins/capacity/capacity.go
    • Added a JobDequeuedFn callback to subtract reserved inqueue resources from the queue's capacity when a job is dequeued.
  • pkg/scheduler/plugins/factory.go
    • Imported the new inqueuetimeout plugin package.
    • Registered the inqueuetimeout plugin builder with the framework.
  • pkg/scheduler/plugins/inqueuetimeout/inqueuetimeout.go
    • Added a new plugin file defining the inqueuetimeout plugin.
    • Implemented New function to create an instance of the plugin.
    • Defined PluginName, InqueueTimeout argument key, and AnnotationInqueueTimeout constant.
    • Added getTimeout function to retrieve timeout duration from global arguments or per-PodGroup annotations.
    • Added getInqueueTimestamp function to extract the inqueue timestamp from a PodGroup's conditions.
    • Implemented OnSessionOpen to parse global timeout arguments and register the JobDequeueableFn to vote for dequeuing jobs that exceed their inqueue timeout.
  • pkg/scheduler/plugins/inqueuetimeout/inqueuetimeout_test.go
    • Added a new test file for the inqueuetimeout plugin.
    • Included TestInqueueTimeoutPlugin with various test cases for different timeout configurations and job states.
    • Included TestGetInqueueTimestamp to verify the extraction of inqueue timestamps from PodGroup conditions.
  • pkg/scheduler/plugins/proportion/proportion.go
    • Added a JobDequeuedFn callback to subtract reserved inqueue resources from the queue's proportion when a job is dequeued.
  • staging/src/volcano.sh/apis/pkg/apis/scheduling/types.go
    • Added PodGroupInqueuedType constant to define a new condition type for tracking inqueue status.
  • staging/src/volcano.sh/apis/pkg/apis/scheduling/v1beta1/types.go
    • Added PodGroupInqueuedType constant to define a new condition type for tracking inqueue status in v1beta1 API.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new inqueuetimeout plugin to address jobs getting stuck in the Inqueue state. The implementation includes new framework hooks (JobDequeueable/JobDequeued), adds condition tracking for when a job is enqueued, and updates resource accounting in the capacity and proportion plugins. The changes are well-structured and the new feature is a valuable addition to prevent resource starvation.

I have one suggestion regarding the implementation of Inqueued condition tracking to ensure its correctness when jobs are re-enqueued.

Comment on lines +112 to +118
job.PodGroup.Status.Conditions = append(job.PodGroup.Status.Conditions, scheduling.PodGroupCondition{
Type: scheduling.PodGroupInqueuedType,
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: "Enqueued",
Message: "PodGroup moved to Inqueue state",
})

Choose a reason for hiding this comment

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

high

Appending a new Inqueued condition every time a job is enqueued can lead to multiple conditions of the same type. The getInqueueTimestamp function will always pick the first (and oldest) one, which will cause incorrect timeout calculations if a job is dequeued and then re-enqueued. You should use the existing ssn.UpdatePodGroupCondition helper function to either update the existing Inqueued condition or add a new one if it doesn't exist. This ensures the timestamp is always current.

Suggested change
job.PodGroup.Status.Conditions = append(job.PodGroup.Status.Conditions, scheduling.PodGroupCondition{
Type: scheduling.PodGroupInqueuedType,
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: "Enqueued",
Message: "PodGroup moved to Inqueue state",
})
ssn.UpdatePodGroupCondition(job, &scheduling.PodGroupCondition{
Type: scheduling.PodGroupInqueuedType,
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: "Enqueued",
Message: "PodGroup moved to Inqueue state",
})

@rishisulakhe rishisulakhe changed the title inqueue-timeout plugin and related tests feature: Inqueue timeout mechanism to prevent resource blocking by unschedulable PodGroups Mar 12, 2026
Copy link
Contributor

Copilot AI left a comment

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 introduces an inqueue-timeout mechanism to prevent PodGroups from occupying queue quota indefinitely when they cannot make scheduling progress, by adding a new inqueuetimeout plugin and wiring dequeue hooks into the scheduler framework.

Changes:

  • Add PodGroupInqueuedType condition type and record an “Inqueued” timestamp when PodGroups enter Inqueue.
  • Add new session plugin hooks (JobDequeueable / JobDequeued) and invoke them from the enqueue action to dequeue timed-out inqueue jobs.
  • Update capacity/proportion plugins to release reserved “inqueue” resources when a job is dequeued; add unit tests for the new plugin.

Reviewed changes

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

Show a summary per file
File Description
staging/src/volcano.sh/apis/pkg/apis/scheduling/v1beta1/types.go Adds PodGroupInqueuedType condition constant for the v1beta1 API.
staging/src/volcano.sh/apis/pkg/apis/scheduling/types.go Adds PodGroupInqueuedType condition constant for the internal scheduling API.
pkg/scheduler/framework/session.go Extends session state with new dequeue-related function registries.
pkg/scheduler/framework/session_plugins.go Adds registration + invocation paths for JobDequeueable/JobDequeued hooks.
pkg/scheduler/actions/enqueue/enqueue.go Dequeues timed-out Inqueue jobs and records an Inqueued condition/timestamp on enqueue.
pkg/scheduler/plugins/inqueuetimeout/inqueuetimeout.go Implements the inqueuetimeout plugin logic (global + per-PodGroup timeout).
pkg/scheduler/plugins/inqueuetimeout/inqueuetimeout_test.go Adds unit tests for dequeue voting and timestamp extraction behavior.
pkg/scheduler/plugins/capacity/capacity.go Releases reserved inqueue resources on dequeue via AddJobDequeuedFn.
pkg/scheduler/plugins/proportion/proportion.go Releases reserved inqueue resources on dequeue via AddJobDequeuedFn.
pkg/scheduler/plugins/factory.go Registers the new inqueuetimeout plugin builder.

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

Comment on lines +113 to +118
Type: scheduling.PodGroupInqueuedType,
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: "Enqueued",
Message: "PodGroup moved to Inqueue state",
})
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Setting the new PodGroupInqueuedType condition to Status: ConditionTrue will make the job controller treat it as the latest "non-scheduled" condition and emit Warning events (see recordPodGroupEvent which warns on any latest ConditionTrue that is not PodGroupScheduled). Consider setting this condition to ConditionFalse (or otherwise preventing it from being selected as an active warning condition) so enabling/disabling the timeout feature doesn’t introduce noisy Warning events.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +85
for _, cond := range job.PodGroup.Status.Conditions {
if cond.Type == scheduling.PodGroupInqueuedType {
return cond.LastTransitionTime.Time
}
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

getInqueueTimestamp() returns the first PodGroupInqueuedType condition it encounters. If multiple Inqueued conditions ever exist (e.g., due to append-on-enqueue), this will return a stale timestamp. Either enforce uniqueness of this condition when writing it, or update this helper to select the most recent matching condition (e.g., max LastTransitionTime).

Suggested change
for _, cond := range job.PodGroup.Status.Conditions {
if cond.Type == scheduling.PodGroupInqueuedType {
return cond.LastTransitionTime.Time
}
}
var (
latest time.Time
found bool
)
for _, cond := range job.PodGroup.Status.Conditions {
if cond.Type == scheduling.PodGroupInqueuedType {
t := cond.LastTransitionTime.Time
if !found || t.After(latest) {
latest = t
found = true
}
}
}
if found {
return latest
}

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +118
// Record Inqueued condition with timestamp for inqueue timeout tracking
job.PodGroup.Status.Conditions = append(job.PodGroup.Status.Conditions, scheduling.PodGroupCondition{
Type: scheduling.PodGroupInqueuedType,
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: "Enqueued",
Message: "PodGroup moved to Inqueue state",
})
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Recording the Inqueued timestamp by blindly appending a new PodGroupInqueuedType condition can create multiple conditions of the same type over time (e.g., dequeue -> pending -> enqueue again). With the current getInqueueTimestamp() implementation (it returns the first match), a re-enqueued PodGroup may keep using an old timestamp and get immediately dequeued again. Use ssn.UpdatePodGroupCondition(...) (upsert by type) or otherwise ensure only one PodGroupInqueuedType exists / the latest timestamp is used.

Suggested change
// Record Inqueued condition with timestamp for inqueue timeout tracking
job.PodGroup.Status.Conditions = append(job.PodGroup.Status.Conditions, scheduling.PodGroupCondition{
Type: scheduling.PodGroupInqueuedType,
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: "Enqueued",
Message: "PodGroup moved to Inqueue state",
})
// Record Inqueued condition with timestamp for inqueue timeout tracking.
// Use UpdatePodGroupCondition to upsert by type so only one Inqueued condition exists.
cond := &scheduling.PodGroupCondition{
Type: scheduling.PodGroupInqueuedType,
Status: v1.ConditionTrue,
LastTransitionTime: metav1.Now(),
Reason: "Enqueued",
Message: "PodGroup moved to Inqueue state",
}
ssn.UpdatePodGroupCondition(job.PodGroup, cond)

Copilot uses AI. Check for mistakes.
Signed-off-by: Rishi Prasad Sulakhe <rishiprasadsulakhe@gmail.com>
@rishisulakhe rishisulakhe force-pushed the feature/inqueue-timeout branch from 92f9367 to ca053c0 Compare March 17, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inqueue PodGroups occupy queue resources even when pods cannot be scheduled

3 participants