← Back to Pull requests

feat(discovery): add InferencePool pod-to-worker projection #9954

Open
unknown opened this pull request with 455 lines diff across 5 files
View on GitHub
unknown unknown commented on Dec 03, 2026 07:55 UTC
Author

Description

Stacked on #9949 (feat/k8s-label-selector, base branch) and #9941 (feat/inference-pool-key, cherry-picked into this branch until both land on main).

Problem

SMG's Native Kubernetes Gateway API & InferencePool mode needs a deterministic projection from active InferencePool specs and watched Kubernetes Pods into pool-scoped worker endpoints ready for reconciliation, enforcing namespace isolation, Pod readiness, pool-level appProtocol (kubernetes.io/h2c vs HTTP), and IPv4/IPv6 URL formatting.

Solution

Add an isolated inference_pool module behind the existing kubernetes feature in smg-service-discovery providing InferencePoolTarget validation, project_inference_pool_endpoints, and crate-internal inference_pool_workers producing DiscoveredWorker records compatible with reconciler::DesiredState without touching the existing Kubernetes provider or reconciler.

Changes

  • Added crates/service_discovery/src/inference_pool.rs:

  • - H2C_APP_PROTOCOL (kubernetes.io/h2c), HTTP_APP_PROTOCOL (http), InferencePoolTargetError
    - InferencePoolTarget (new, from_matcher, key, selector, target_ports, connection_mode, selects): validates non-empty LabelSelectorMatcher, deduplicates non-zero target_ports, maps pool-level app_protocol fail-closed (Some("kubernetes.io/h2c") -> ConnectionMode::Grpc, None | Some("http") -> ConnectionMode::Http, anything else -> UnsupportedAppProtocol), and enforces strict same-namespace Pod selection
    - InferencePoolEndpoint (url(), discovery_id()) and project_inference_pool_endpoints: filters Ready, Running, non-terminating Pods with valid IPv4/IPv6 addresses, formats bracketed IPv6 URLs (http://[...]:port / grpc://[...]:port), and sorts pools deterministically by InferencePoolKey
    - Crate-internal inference_pool_workers: stamps smg.ai/inference-pool, smg.ai/pod-name, and smg.ai/pod-uid labels with distinct {pool}:{uid}:{port} discovery IDs so pool reassignment replaces the worker cleanly and overlapping pools deterministically keep the lowest InferencePoolKey in DesiredState
  • Added crates/service_discovery/tests/unit/inference_pool/tests.rs covering multi-port projection, readiness/phase/termination/namespace filtering, HTTP vs kubernetes.io/h2c gRPC + IPv6 bracketing, LeaderWorkerSet leader filtering, multi-pool isolation, deterministic overlap resolution, label stamping, and fail-closed spec validation

  • Wired #[cfg(feature = "kubernetes")] pub mod inference_pool; + crate-root re-exports in crates/service_discovery/src/lib.rs
  • Refs: #8616

    Test Plan

  • cargo +nightly fmt --all -- --check: passed (exit 0)

  • python3 scripts/check_unit_test_layout.py & ./scripts/branch-name-check.sh: passed (exit 0)

  • cargo clippy -p smg-service-discovery --all-targets -- -D warnings and cargo clippy -p smg-service-discovery --all-targets --all-features -- -D warnings: passed (0 errors, 0 crate warnings)

  • cargo test -p smg-service-discovery --all-features: 237 passed; 0 failed (including all inference_pool::tests::* cases)

  • cargo check -p smg: passed (exit 0)
  • Release note

    none (internal smg-service-discovery primitive behind the kubernetes feature for upcoming Gateway API InferencePool worker discovery)

    <details>
    <summary>Checklist</summary>

  • cargo +nightly fmt passes

  • cargo clippy --all-targets --all-features -- -D warnings passes

  • (Optional) Documentation updated

  • (Optional) Please join us on Slack #sig-smg to discuss, review, and merge PRs
  • </details>

    Diff: 455 lines (+341 / -114) across 5 files Reviewer: claude[bot] Review duration: 6m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.45) × (1 − Review Confidence (0.31)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 455 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 55% · Reviewer familiarity: 35%
    31%
    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.366
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9954"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 31% 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: 45.5% (MEDIUM) · Higher = larger blast radius
    45.5%
    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: 31% · Lower = rushed or shallow review
    31%
    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: 31.4% · Safe to merge
    31.4%