From ca2fc50338ea986a63c31eff97fa3c340a62c1fc Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 18 Jul 2026 09:12:11 +0000 Subject: [PATCH] feat(system): expose raw detected capability for model meta resolution Model meta gallery entries express hardware fallback through candidate ordering rather than a capability map, so they need the undecorated detected capability string without Capability's default/cpu fallback chain. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto --- pkg/system/capabilities.go | 11 +++++++++++ pkg/system/capabilities_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/pkg/system/capabilities.go b/pkg/system/capabilities.go index 034f1d011..9e74a2e8b 100644 --- a/pkg/system/capabilities.go +++ b/pkg/system/capabilities.go @@ -63,6 +63,17 @@ func (s *SystemState) CapabilityFilterDisabled() bool { return s.getSystemCapabilities() == disableCapability } +// ReportedCapability returns the raw detected capability string (e.g. "metal", +// "nvidia-cuda-12", "default") with no map-membership fallback applied. +// +// Why this exists alongside Capability: Capability resolves against a caller +// supplied map and falls back to "default" then "cpu" when the detected value +// is absent. Model meta entries express fallback through candidate ordering +// instead, so they need the undecorated value. +func (s *SystemState) ReportedCapability() string { + return s.getSystemCapabilities() +} + func (s *SystemState) Capability(capMap map[string]string) string { reportedCapability := s.getSystemCapabilities() diff --git a/pkg/system/capabilities_test.go b/pkg/system/capabilities_test.go index 1bb13b647..117e3ffdb 100644 --- a/pkg/system/capabilities_test.go +++ b/pkg/system/capabilities_test.go @@ -164,3 +164,28 @@ var _ = Describe("CapabilityFilterDisabled", func() { Expect(s.IsBackendCompatible("cpu-whisperx", "quay.io/cpu")).To(BeTrue()) }) }) + +var _ = Describe("ReportedCapability", func() { + var previous string + + BeforeEach(func() { + previous = os.Getenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY") + }) + + AfterEach(func() { + Expect(os.Setenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY", previous)).To(Succeed()) + }) + + It("returns the forced capability verbatim without map fallback", func() { + Expect(os.Setenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY", "nvidia-cuda-12")).To(Succeed()) + state := &SystemState{} + Expect(state.ReportedCapability()).To(Equal("nvidia-cuda-12")) + }) + + It("does not fall back to default when the capability is unusual", func() { + Expect(os.Setenv("LOCALAI_FORCE_META_BACKEND_CAPABILITY", "metal")).To(Succeed()) + state := &SystemState{} + Expect(state.ReportedCapability()).To(Equal("metal")) + Expect(state.ReportedCapability()).NotTo(Equal("default")) + }) +})