Skip to content

Local AI unusable on DGX Spark (Windows ARM64): shared GPU memory is not CUDA-allocatable, and a capability failure rolls back the whole setup - #1237

Closed
RomneyDa wants to merge 1 commit into
mainfrom
fix/gpu-memory-join-stable-id
Closed

RomneyDa wants to merge 1 commit into
mainfrom
fix/gpu-memory-join-stable-id

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Bug report, not a merge candidate. The commit on this branch is retained only to show what
was tried and why it is the wrong fix. Please do not merge it. See "Why the obvious fix is wrong".

Summary

On a DGX Spark (GB10) running Windows ARM64, Local AI is unusable and the failure is expensive:
setup runs to completion, downloads a multi-GB model, then fails at the very last step with an
opaque HTTP 500, and rolls back everything including the gateway.

Underneath are three separate issues. Only the first is a straightforward bug.

1. NVML and DXGI are joined on adapter name, and the names disagree

NvmlHostHardwareProbe attaches DXGI shared memory to an NVML device by matching adapter name:

DxgiGpuMemoryInfo? dxgiMemory = nvmlNameCounts[normalizedName] == 1
    ? FindDxgiMemoryByName(dxgiMemoryByName, name)
    : null;

On this hardware the two APIs report different names for the same adapter, so the match fails
silently:

NVML name : 'JMJWOA-Generic-GPU'    shared            : null
DXGI name : 'RTX Spark GPU'         SharedSystemMemory: 30.07 GiB
=> JOIN RESULT: NO MATCH - shared memory dropped

This part is a genuine defect: a silent no-match is indistinguishable from an adapter that has no
shared memory, and nothing is logged.

2. Why the obvious fix is wrong

The commit here joins on PCI identity instead (nvmlDeviceGetPciInfo_v3 against the VendorId /
DeviceId / SubSystemId that DXGI_ADAPTER_DESC1 already reads and discards). It works: the
adapter then reports 46.01 GiB instead of 15.94 GiB, and every catalog model becomes Eligible.

That is the wrong outcome. Measured with the patched build:

llama-server reports the same optimistic figure and then cannot honour it.

CUDA0 : JMJWOA-Generic-GPU (46332 MiB, 46114 MiB free)

Qwen3.5 9B, the smallest model in the catalog, allocates:

Buffer Size
model 5040.86 MiB
KV 8192.00 MiB
RS 201.00 MiB
compute 2752.13 MiB
total on CUDA0 16186.0 MiB (15.81 GiB)
ggml-cuda.cu:106: CUDA error
CUDA error: out of memory

It dies at 15.81 GiB, against NVML's dedicated figure of 15.94 GiB (16320 MiB). Qwen3.6 35B
fails the same way earlier, on a single 21087.70 MiB model-buffer request.

So CUDA advertises 46.3 GiB but can only allocate about 15.9 GiB of device memory here. The shared
portion is host memory that DXGI reports and CUDA surfaces, but it does not back device allocations
under WDDM. NVML's dedicated figure is the one that predicts real behaviour, and the current
name-join failure accidentally produces the correct answer on this machine.

Fixing the join without changing capacity semantics would make eligibility worse: models are
selected that cannot load, and the user finds out only after a multi-GB download.

Worth noting the platform context: the unified memory that makes Spark good at local inference is
addressable under DGX OS / Linux, not through WDDM. With about 15.9 GiB usable, no model in the
catalog fits (the smallest requires 21.47 GiB).

3. A capability failure destroys the whole setup

verify-local-ai-inference is terminal, so its failure rolls back all completed steps:

verify-local-ai-inference -> rollback_ok
capture-local-ai-gpu-baseline -> rollback_ok
start-local-ai-runtime -> rollback_ok
persist-local-ai-manifest -> rollback_ok
acquire-local-ai-model -> rollback_ok      <- deletes the downloaded model
acquire-local-ai-runtime -> rollback_ok
reconcile-local-ai-installation -> rollback_ok
ensure-wsl-platform -> rollback_ok
...
_pipeline -> pipeline_failed

Local AI is one capability, but its verification failure takes down the WSL gateway too, and
discards a 12 GB download. The failure screen then offers only Close: no retry, and no way back
to the model dropdown one step earlier, even though choosing a smaller model is the obvious next
move. Repeating the attempt means re-downloading.

Suggested direction

  1. Join on stable identity, but keep the reported capacity honest. Shared/non-local memory should
    not count toward CUDA-allocatable capacity on WDDM. If it is surfaced at all it should be
    separate from the number eligibility is judged against.
  2. Log an explicit warning when NVML and DXGI each see exactly one NVIDIA adapter but fail to match.
    That single line would have made this diagnosable in minutes.
  3. Verify inference capability, or at least attempt a small allocation, before downloading
    gigabytes.
  4. Do not roll back the gateway when an optional capability fails. Offer retry and model selection
    from the failure screen, and keep verified downloads.

Environment

  • NVIDIA DGX Spark (GB10), Windows 11 Pro 10.0.28000, ARM64
  • Driver 592.96, CUDA 13.1, NVML dedicated 16320 MiB, DXGI shared 30.07 GiB, 46.07 GiB system RAM
  • llama-server b10488 (b10488-cuda13-arm64), ARCHS include 1210, BLACKWELL_NATIVE_FP4 = 1
  • Reproduced with both qwen3.6-35b-a3b-mtp-q4-k-m and qwen3.5-9b-mtp-q4-k-m

Note: reaching the failure at all required lowering MinimumNvidiaDriverVersion from 615.0 to 580.0
locally, since this host has driver 592.96 and no 615+ Windows ARM64 driver appears to be published
for this SKU. That local change is not part of this branch. Related: #1235.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codex review: found issues before merge. Reviewed August 26, 2026, 6:43 PM ET / 22:43 UTC.

ClawSweeper review

What this changes

The branch replaces NVML/DXGI display-name matching with PCI-identity matching and carries PCI identifiers through GPU discovery.

Merge readiness

⛔ Blocked by patch quality or review findings - 8 items remain

Keep open for maintainer direction. This MEMBER-authored draft explicitly says it is a non-mergeable reproducer, and its PCI join would make WDDM shared memory count as CUDA allocation capacity, causing false-eligible model downloads and later allocation failure.

Priority: P2
Reviewed head: 05994b9359d1b57805bb998b797c9e2bfc934cdb
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The branch provides useful hardware evidence but intentionally retains a P1-invalid implementation rather than a mergeable fix.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored draft is explicitly a non-mergeable reproducer, so the external-contributor proof gate does not apply.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored draft is explicitly a non-mergeable reproducer, so the external-contributor proof gate does not apply.
Evidence reviewed 5 items Branch creates the unsafe association: The PCI match supplies DXGI shared memory to GpuInfo whenever a unique identity match exists.
Eligibility consumes shared memory as allocation capacity: Current main adds SharedGpuMemoryBytes to both effective total and free memory used for model qualification.
Download precedes inference verification: The default setup pipeline acquires the model before starting the runtime and running inference verification, so the requested earlier feasibility check is not implemented by this branch.
Findings 2 actionable findings [P1] Keep shared DXGI memory out of WDDM eligibility
[P2] Cover PCI identity matching before relying on it
Security None None.

Live Verification

Command: dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore --filter "FullyQualifiedName~LocalInferenceQualificationTests"

Result: FAIL (failed) — execution before step 1 run: sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

Assertions:

  • FAIL expect_output: Passed!

How this fits together

Local AI hardware discovery combines NVML CUDA-memory facts with DXGI shared-memory facts before model eligibility selects a runtime and downloads a model. The resulting selection feeds setup-time inference verification and the Local AI recovery UI.

flowchart LR
A[NVML device memory] --> C[GPU memory association]
B[DXGI shared memory] --> C
C --> D[Eligibility capacity calculation]
D --> E[Model selection]
E --> F[Setup download and inference verification]
Loading

Decision needed

Question Recommendation
Should Windows WDDM Local AI treat DXGI shared memory as diagnostics only while preserving dedicated NVML memory for eligibility, and should optional Local AI verification failure preserve completed setup artifacts? Use dedicated NVML capacity on WDDM: Keep PCI association for diagnostics and warnings, but do not let DXGI shared memory qualify models; address setup recovery in a separate focused change.

Why: The branch proves that a PCI join is technically possible but also demonstrates that its resulting capacity contract is wrong on the reported hardware; the supported WDDM capacity and recovery policy require maintainer intent.

Before merge

  • Keep shared DXGI memory out of WDDM eligibility (P1) - This match now populates shared memory for the GPU, and the selector adds that value to CUDA capacity. On the reported DGX this changes a 15.9 GiB allocation limit into a 46 GiB eligible result, so users can download a model that llama-server cannot load.
  • Cover PCI identity matching before relying on it (P2) - The existing probe tests cover normalized names and ambiguous name matches, but none exercise PCI matches, ambiguous PCI identities, or name fallback when PCI fields are absent. Add those cases before this becomes a merge candidate.
  • Resolve merge risk (P1) - Merging this branch would turn DXGI shared memory into model-selection capacity even where WDDM CUDA allocations fail at the smaller NVML dedicated-memory limit.
  • Resolve merge risk (P1) - The requested pre-download feasibility and failure-recovery policy span GPU qualification and setup behavior, while this two-file branch changes only discovery.
  • Complete next step (P2) - A maintainer must choose the Windows allocation-capacity and optional-capability recovery policy before a safe replacement can be scoped.
  • Improve patch quality - Choose the WDDM allocatable-capacity contract before turning this reproducer into a replacement PR.
  • Improve patch quality - Add PCI association and allocation-capacity regression cases, then capture redacted current-head DGX or equivalent WDDM behavior.

Findings

  • [P1] Keep shared DXGI memory out of WDDM eligibility — src/OpenClaw.Shared/Inference/NvmlHostHardwareProbe.cs:97-100
  • [P2] Cover PCI identity matching before relying on it — src/OpenClaw.Shared/Inference/NvmlHostHardwareProbe.cs:97-100
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +98, tests +0 The two production files alter hardware facts used for model selection without covering the new PCI match, fallback, or ambiguity behavior.

Merge-risk options

Maintainer options:

  1. Keep the reproducer out of the merge queue (recommended)
    Retain this draft as diagnostic evidence until maintainers choose the WDDM capacity contract and a focused replacement can preserve it.
  2. Prepare a narrow replacement
    Separate PCI identity diagnostics from allocatable-memory eligibility and add DGX-like regression coverage before proposing a mergeable patch.

Technical review

Best possible solution:

Keep NVML dedicated memory as the WDDM eligibility limit, retain stable identity only for diagnostics and mismatch warnings, then separately design tested capability-failure recovery that preserves completed gateway setup and verified artifacts.

Do we have a high-confidence way to reproduce the issue?

Unclear for a current-main live run: the supplied DGX evidence used a local driver-threshold adjustment, but source proves the branch would add matched DXGI shared memory to the eligibility calculation.

Is this the best way to solve the issue?

No. PCI identity is useful for diagnostics, but the current selector treats the associated shared memory as CUDA-allocatable capacity, which the supplied WDDM evidence says is false.

Full review comments:

  • [P1] Keep shared DXGI memory out of WDDM eligibility — src/OpenClaw.Shared/Inference/NvmlHostHardwareProbe.cs:97-100
    This match now populates shared memory for the GPU, and the selector adds that value to CUDA capacity. On the reported DGX this changes a 15.9 GiB allocation limit into a 46 GiB eligible result, so users can download a model that llama-server cannot load.
    Confidence: 0.99
  • [P2] Cover PCI identity matching before relying on it — src/OpenClaw.Shared/Inference/NvmlHostHardwareProbe.cs:97-100
    The existing probe tests cover normalized names and ambiguous name matches, but none exercise PCI matches, ambiguous PCI identities, or name fallback when PCI fields are absent. Add those cases before this becomes a merge candidate.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ff3fb35a7d32.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: The reported Local AI setup failure has a concrete but hardware-specific user impact and needs a bounded policy decision.
  • merge-risk: 🚨 compatibility: Existing Windows users can be offered models that appear eligible but cannot allocate under WDDM after this memory-accounting change.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This MEMBER-authored draft is explicitly a non-mergeable reproducer, so the external-contributor proof gate does not apply.

Evidence

What I checked:

Likely related people:

  • Joel: Introduced the current-main managed Local AI feature and its effective-memory calculation. (role: introduced local AI eligibility; confidence: high; commits: ccd64bbb7d68; files: src/OpenClaw.Shared/Inference/Catalog/LocalInferenceSelector.cs)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-26T21:40:43.382Z sha cce6ebb :: found issues before merge. :: [P2] Add PCI identity regression coverage
  • reviewed 2026-08-26T22:18:36.243Z sha cce6ebb :: found issues before merge. :: [P1] Do not treat DXGI shared memory as CUDA capacity | [P2] Cover the PCI identity matching cases

@RomneyDa RomneyDa changed the title fix(inference): join NVML and DXGI on PCI identity, not adapter name Local AI unusable on DGX Spark (Windows ARM64): shared GPU memory is not CUDA-allocatable, and a capability failure rolls back the whole setup Aug 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 26, 2026
Shared GPU memory is discovered through DXGI and attached to the NVML device it
belongs to by matching adapter *name*. The two APIs do not always report the same
name for the same physical adapter, and when they disagree the match silently
fails, SharedGpuMemoryBytes stays null, and the adapter is assessed on its
dedicated pool alone.

On a unified-memory part that is the difference between working and not. Measured
on a DGX Spark (GB10) engineering unit:

  NVML name : 'JMJWOA-Generic-GPU'   shared: null
  DXGI name : 'RTX Spark GPU'        SharedSystemMemory: 30.07 GiB
  => no match, 30.07 GiB discarded

The adapter is then judged to have 15.94 GiB instead of 46.01 GiB, and every model
in the catalog fails eligibility with InsufficientGpuMemory:

  Qwen3.6 35B-A3B  required 34.11 GiB  detected 15.94 GiB  Unsupported
  Qwen3.6 27B      required 39.93 GiB  detected 15.94 GiB  Unsupported
  Qwen3.5 9B       required 21.47 GiB  detected 15.94 GiB  Unsupported

There is no diagnostic pointing at the cause: the failure reads as "this machine
is too small", not "the join failed".

DXGI already reads VendorId, DeviceId and SubSystemId in DXGI_ADAPTER_DESC1 and
discards them. NVML exposes the same identity via nvmlDeviceGetPciInfo_v3, which
packs pciDeviceId as (deviceId << 16) | vendorId. This joins on that identity and
keeps the name match as a fallback, so behaviour is unchanged wherever the names
already agree or PCI identity is unavailable. The identity match requires exactly
one candidate, so an ambiguous set still attributes nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01BE8kMbmSjPCwd8i9GJEsqx
@RomneyDa
RomneyDa force-pushed the fix/gpu-memory-join-stable-id branch from cce6ebb to 05994b9 Compare August 26, 2026 22:39
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 26, 2026
joelagnel pushed a commit to joelagnel/openclaw-windows-node that referenced this pull request Aug 28, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
@shanselman

Copy link
Copy Markdown
Collaborator

Closing this research PR because it explicitly is not a merge candidate. The useful DGX/PCl investigation is preserved in issue discussion and the current follow-up work in #1239.

@shanselman shanselman closed this Aug 28, 2026
joelagnel added a commit to joelagnel/openclaw-windows-node that referenced this pull request Aug 28, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
joelagnel pushed a commit to joelagnel/openclaw-windows-node that referenced this pull request Aug 28, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
joelagnel added a commit to joelagnel/openclaw-windows-node that referenced this pull request Aug 28, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
joelagnel added a commit to joelagnel/openclaw-windows-node that referenced this pull request Aug 28, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
joelagnel added a commit to joelagnel/openclaw-windows-node that referenced this pull request Aug 31, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
joelagnel added a commit to joelagnel/openclaw-windows-node that referenced this pull request Sep 2, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
joelagnel added a commit to joelagnel/openclaw-windows-node that referenced this pull request Sep 2, 2026
Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.
shanselman added a commit that referenced this pull request Sep 2, 2026
* fix(local-ai): use CUDA for allocatable GPU memory

Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes #1191.

Related: Dallin's #1237 and Pedro's #1239.

* refactor(local-ai): capture CUDA GPUs with a functional pipeline

Split CaptureCudaGpus into TryCaptureGpu (per-device capture) and
WithCudaContext (context create/destroy) and reassemble via
Enumerable.Range(...).Select(...).Where(...).ToList().

Suggested in review: #1253 (review)

* fix(local-ai): bound GPU admission by dedicated device memory

CUDA-reported memory alone is not a safe Local AI admission bound on WDDM.
On the recorded DGX Spark, cuMemGetInfo advertised 46,332 MiB because CUDA
surfaces the shared host pool, while llama-server still died allocating
16,186 MiB against roughly 15.9 GiB of real device memory.

Cap the CUDA-reported total at the adapter's DXGI dedicated video memory,
joined to the CUDA device by adapter LUID, and take free memory from the
adapter's local budget when it is available. Shared system memory is host
RAM, so it is never added to the number eligibility is judged against.
When no dedicated bound can be resolved, capacity stays unknown so
qualification retries instead of over-qualifying the device.

A reservation-based allocation gate was evaluated and rejected: on an
RTX 4080 SUPER with 16,375 MiB, cuMemAlloc accepted 32,751 MiB and
cuMemCreate accepted 65,536 MiB, so WDDM reservations cannot discriminate
allocatable capacity.

Also keep partial NVIDIA facts instead of collapsing them to a definitive
no-GPU verdict. Only an absent driver or a driver reporting no device
proves that no NVIDIA GPU exists; a failed cuInit, a failed device count,
and per-device name, UUID, LUID, or memory failures now leave the device
visible with missing facts null, which yields the retryable
HardwareFactsIncomplete state. An inconclusive GPU also outranks a
definitively unsupported one so recheck stays available.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

* fix(local-ai): keep non-DXGI CUDA hosts supported with an NVML bound

Capping admission capacity at the DXGI dedicated figure alone contracted
support: a unified-memory DGX or Blackwell part that reports no dedicated
video memory, a TCC device, or a headless GPU has no usable DXGI adapter
and would resolve no bound at all, leaving a supported host permanently
in the retryable incomplete state.

Add an NVML dedicated-memory source joined on device identity. NVML keys
on the same GPU-... UUID the CUDA driver reports, so the join is an exact
identity match rather than an adapter-name guess. NVML reports dedicated
device memory only and never the WDDM shared host pool, which is why it
reported 16,320 MiB on the DGX Spark where CUDA advertised 46,332 MiB and
llama-server died at 16,186 MiB.

DXGI stays preferred wherever it applies, so the conservative WDDM budget
behavior is unchanged. NVML is consulted only when DXGI supplies no
adapter or reports zero dedicated memory. Capacity remains
min(cudaTotal, dedicated) from a driver-reported source, with no raw CUDA
total and no invented constants, and when neither source resolves the
device still stays retryable rather than over-qualified.

nvml.dll is loaded only from fully qualified driver-owned paths, matching
the System32 pinning used for nvcuda.dll and dxgi.dll.

Adds regressions for the no-LUID, no-DXGI, zero-dedicated, DXGI-preferred,
identity-mismatch, and both-sources-failing cases, plus a hardware-gated
proof that the non-DXGI path yields the same qualification decision as the
DXGI path on real hardware.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

* fix(local-ai): combine GPU memory bounds conservatively

DXGI reports this process's WDDM budget while NVML reports device-wide
unallocated memory. Preferring whichever source resolved first let the
same GPU be called ready or busy purely by source availability.

Combine instead: when both sources identify the device, take the smaller
dedicated bound and the smaller free reading. The admission decision is
then deterministic and conservative regardless of which sources a host
exposes, and a device is never admitted on the larger of two bounds.

Also free the NVML loader reference, widen the interop catch to the
marshalling and SEH failures the previous implementation handled, keep
library cleanup reachable when shutdown throws, narrow the NVML remarks
to what the recorded Windows evidence supports, and note that MIG compute
instances are out of scope.

Adds disagreeing-bounds, case-insensitive multi-device identity join, and
exact allowed-path regressions, and makes the hardware tests fail loudly
instead of passing silently when integration is enabled without a GPU.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

* test(local-ai): skip GPU proofs on hosts without an NVIDIA device

The two hardware proofs were gated only by OPENCLAW_RUN_INTEGRATION, so
hosted GPU-less CI runners ran them and failed on the explicit
"requires an NVIDIA GPU" assertions.

Gate them on the device instead. NvidiaHardwareFactAttribute skips when no
NVIDIA GPU is detected, so ordinary CI stays green, while an explicit
hardware proof run with OPENCLAW_RUN_GPU_PROOF=1 still requires the device
and fails loudly if it is missing.

No production logic changes.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

---------

Co-authored-by: Pedro Larroy <[email protected]>
Co-authored-by: Scott Hanselman <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4
larroy pushed a commit to larroy/openclaw-windows-node that referenced this pull request Sep 3, 2026
…aw#1253)

* fix(local-ai): use CUDA for allocatable GPU memory

Query the CUDA driver directly for device identity and total/free allocatable memory instead of combining NVML and DXGI accounting. This should qualify both discrete RTX and UMA devices using the same allocator-visible source of truth.

Closes openclaw#1191.

Related: Dallin's openclaw#1237 and Pedro's openclaw#1239.

* refactor(local-ai): capture CUDA GPUs with a functional pipeline

Split CaptureCudaGpus into TryCaptureGpu (per-device capture) and
WithCudaContext (context create/destroy) and reassemble via
Enumerable.Range(...).Select(...).Where(...).ToList().

Suggested in review: openclaw#1253 (review)

* fix(local-ai): bound GPU admission by dedicated device memory

CUDA-reported memory alone is not a safe Local AI admission bound on WDDM.
On the recorded DGX Spark, cuMemGetInfo advertised 46,332 MiB because CUDA
surfaces the shared host pool, while llama-server still died allocating
16,186 MiB against roughly 15.9 GiB of real device memory.

Cap the CUDA-reported total at the adapter's DXGI dedicated video memory,
joined to the CUDA device by adapter LUID, and take free memory from the
adapter's local budget when it is available. Shared system memory is host
RAM, so it is never added to the number eligibility is judged against.
When no dedicated bound can be resolved, capacity stays unknown so
qualification retries instead of over-qualifying the device.

A reservation-based allocation gate was evaluated and rejected: on an
RTX 4080 SUPER with 16,375 MiB, cuMemAlloc accepted 32,751 MiB and
cuMemCreate accepted 65,536 MiB, so WDDM reservations cannot discriminate
allocatable capacity.

Also keep partial NVIDIA facts instead of collapsing them to a definitive
no-GPU verdict. Only an absent driver or a driver reporting no device
proves that no NVIDIA GPU exists; a failed cuInit, a failed device count,
and per-device name, UUID, LUID, or memory failures now leave the device
visible with missing facts null, which yields the retryable
HardwareFactsIncomplete state. An inconclusive GPU also outranks a
definitively unsupported one so recheck stays available.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

* fix(local-ai): keep non-DXGI CUDA hosts supported with an NVML bound

Capping admission capacity at the DXGI dedicated figure alone contracted
support: a unified-memory DGX or Blackwell part that reports no dedicated
video memory, a TCC device, or a headless GPU has no usable DXGI adapter
and would resolve no bound at all, leaving a supported host permanently
in the retryable incomplete state.

Add an NVML dedicated-memory source joined on device identity. NVML keys
on the same GPU-... UUID the CUDA driver reports, so the join is an exact
identity match rather than an adapter-name guess. NVML reports dedicated
device memory only and never the WDDM shared host pool, which is why it
reported 16,320 MiB on the DGX Spark where CUDA advertised 46,332 MiB and
llama-server died at 16,186 MiB.

DXGI stays preferred wherever it applies, so the conservative WDDM budget
behavior is unchanged. NVML is consulted only when DXGI supplies no
adapter or reports zero dedicated memory. Capacity remains
min(cudaTotal, dedicated) from a driver-reported source, with no raw CUDA
total and no invented constants, and when neither source resolves the
device still stays retryable rather than over-qualified.

nvml.dll is loaded only from fully qualified driver-owned paths, matching
the System32 pinning used for nvcuda.dll and dxgi.dll.

Adds regressions for the no-LUID, no-DXGI, zero-dedicated, DXGI-preferred,
identity-mismatch, and both-sources-failing cases, plus a hardware-gated
proof that the non-DXGI path yields the same qualification decision as the
DXGI path on real hardware.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

* fix(local-ai): combine GPU memory bounds conservatively

DXGI reports this process's WDDM budget while NVML reports device-wide
unallocated memory. Preferring whichever source resolved first let the
same GPU be called ready or busy purely by source availability.

Combine instead: when both sources identify the device, take the smaller
dedicated bound and the smaller free reading. The admission decision is
then deterministic and conservative regardless of which sources a host
exposes, and a device is never admitted on the larger of two bounds.

Also free the NVML loader reference, widen the interop catch to the
marshalling and SEH failures the previous implementation handled, keep
library cleanup reachable when shutdown throws, narrow the NVML remarks
to what the recorded Windows evidence supports, and note that MIG compute
instances are out of scope.

Adds disagreeing-bounds, case-insensitive multi-device identity join, and
exact allowed-path regressions, and makes the hardware tests fail loudly
instead of passing silently when integration is enabled without a GPU.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

* test(local-ai): skip GPU proofs on hosts without an NVIDIA device

The two hardware proofs were gated only by OPENCLAW_RUN_INTEGRATION, so
hosted GPU-less CI runners ran them and failed on the explicit
"requires an NVIDIA GPU" assertions.

Gate them on the device instead. NvidiaHardwareFactAttribute skips when no
NVIDIA GPU is detected, so ordinary CI stays green, while an explicit
hardware proof run with OPENCLAW_RUN_GPU_PROOF=1 still requires the device
and fails loudly if it is missing.

No production logic changes.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4

---------

Co-authored-by: Pedro Larroy <[email protected]>
Co-authored-by: Scott Hanselman <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Copilot-Session: a82f3722-db31-4cf3-b2b6-6350078584c4
@shanselman
shanselman deleted the fix/gpu-memory-join-stable-id branch September 7, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants