← Back to Pull requests

fix(server): allow disabling periodic idle vNPU cleanup to avoid premature reclamation #120

Closed
unknown closed this pull request without merging on Jul 30, 2026 02:15 UTC
View on GitHub
unknown unknown commented on Jul 25, 2026 04:24 UTC
Author

What & Why

Issue #86 reports that the periodic idle vNPU cleanup goroutine (startPeriodicCheckIdleVNPUs) destroys vNPUs based solely on IsContainerUsed == 0. Because a vNPU allocated to a Pod that is already Running but whose container has not yet started using the NPU also reports IsContainerUsed == 0, the cleanup can reclaim the vNPU too early — breaking workloads (e.g. npu-smi info fails inside the container shortly after the Pod starts).

#86 is framed as a discussion and lists several more thorough directions (combining IsContainerUsed with Pod allocation state, adding a protection window, or a Pod-referenced rule like mind-cluster's DestroyNotUsedVNPU). Those require deeper changes to the cleanup policy.

This PR takes a smaller, complementary step: give operators a switch to disable the periodic cleanup goroutine so the premature-reclamation symptom stops on affected nodes without waiting for the larger redesign.

Changes

  • New bool flag --enable_periodic_idle_vnpu_cleanup (default false). When false, Start() does not launch the periodic startPeriodicCheckIdleVNPUs goroutine.

  • The one-shot CleanupIdleVNPUs() on plugin restart (cmd/main.go) is intentionally left unconditional and unchanged — it is a separate entry point. The flag name (enable_periodic_...) and its help text make this boundary explicit to avoid the "total cleanup switch" ambiguity.

  • Wiring threaded through NewPluginServer.
  • Scope note

    This is a mitigation, not a full resolution of #86's cleanup-policy discussion. The flag defaults to false (periodic cleanup disabled) to stop the premature-reclamation symptom by default; setting it to true restores the previous behavior. Reviewers may prefer a different default — easy to adjust.

    Testing

  • go build ./internal/server/... ./cmd/... ✅

  • go vet ./internal/server/... ./cmd/... ✅

  • go test ./internal/server/ — 109 passed, consistent with baseline (ran 3×)
  • Modernizations (in the touched files)

    While editing these files I also applied the Go modernization lints the editor flagged. All behavior-preserving; happy to split into a separate PR if preferred:

  • interface{} → any

  • wg.Add(1) + go func(){ defer Done() } → wg.Go(...)

  • for i := 0; i < n; i++ → for i := range n

  • reverse index loop → slices.Backward
  • Refs #86

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    Added a CLI option --enable_periodic_idle_vnpu_cleanup to enable periodic cleanup of idle vNPU resources.
    Cleanup remains disabled by default.
    Bug Fixes
    Improved server goroutine lifecycle and shutdown coordination for more reliable startup and termination.
    Tests
    * Updated server tests to match the new cleanup configuration and constructor signature, including restart-related scenarios.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 371 lines (+278 / -93) across 4 files Reviewer: DSFans2014 Review duration: 7071m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 371 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #120"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.5% · Safe to merge
    18.5%