← Back to Pull requests

Actionable errors for invalid backend names; don't corrupt backend state on failed selection #3658

Closed
unknown closed this pull request without merging on Nov 03, 2026 16:33 UTC
View on GitHub
unknown unknown commented on Nov 02, 2026 19:45 UTC
Author

Addresses the AssertionError: No functional client was found. part of #2072.

Problem

After the lazy backend-initialization refactor, requesting a backend name that doesn't match a registered platform name (e.g. set_default_backend("CPU") instead of "cpu", or "rocm" when the selected artifact has no ROCm support) reaches Registration.initialize_backends with a filter that matches nothing and trips an unconditional assertion. On unmodified main (CPU only):

| Scenario | Result |
|---|---|
| set_default_backend("CPU") | AssertionError: No functional client was found. |
| set_default_backend("rocm") on a non-rocm artifact | same misleading assertion |
| fresh session, first call set_default_backend("gpu") without a GPU backend | assertion and state left with initialized = true + null default client → every later op fails with AssertionError: Client is null |
| set_default_backend("gpu") then XLA.client("cpu") | default client silently flipped to CPU (default recomputed from the newly-initialized subset only) |
| client re-init fails in update_global_state! | freed client left in state.clients |

Changes

  • XLA.client(::String) validates the name up front and throws an ArgumentError that names the requested backend, lists the backends valid in this session, suggests the right name on a case-only mismatch, and points at the configuration docs when a GPU backend isn't registered because of the selected Reactant_jll artifact. Names stay case-sensitive.

  • client("gpu") / client(name) say precisely why there is no client (not registered vs. initialization failed) instead of a bare KeyError.

  • Registration.initialize_backends no longer asserts; it recomputes the default only when there is none or the current default was freed/re-created, across all live clients; and it delete!s a client from the dict before freeing it.

  • XLA.default_backend() falls back to initializing not-yet-attempted backends if a filtered initialization left no default, and errors clearly otherwise.

  • New test/core/backend_selection.jl.
  • After

    julia> Reactant.set_default_backend("CPU")
    ERROR: ArgumentError: Requested backend "CPU" is not valid. Valid backends in this session are: "cpu", "gpu" ("gpu" selects the first available of "cuda", "metal", "rocm"). Backend names are case-sensitive. Did you mean "cpu"?
    
    julia> Reactant.set_default_backend("rocm")   # non-rocm artifact
    ERROR: ArgumentError: Requested backend "rocm" is not valid. Valid backends in this session are: "cpu", "gpu" (...). Backend names are case-sensitive. The "rocm" backend is not registered, which usually means that `Reactant_jll` selected an artifact without "rocm" support. See https://enzymead.github.io/Reactant.jl/stable/introduction/configuration for how to force a specific artifact and debug the installation.
    
    julia> Reactant.set_default_backend("gpu")    # fresh session, no GPU backend
    ERROR: No GPU client found. No GPU backend (cuda, metal, rocm) is registered in this session, ...
    julia> Reactant.devices()                     # session still usable
    1-element Vector{Reactant.XLA.PJRT.Device}: ...
    

    Diff: 395 lines (+296 / -99) across 4 files Reviewer: giordano Review duration: 1248m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 395 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%
    60%
    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.358
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3658"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 17.1% · Safe to merge
    17.1%