Repository navigation
fix(local-ai): bound GPU admission by dedicated device memory - #1253
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
cd3a6d6 to
c6765a7
Compare
|
Codex review: needs real behavior proof before merge. Reviewed September 2, 2026, 7:15 PM ET / 23:15 UTC. ClawSweeper reviewWhat this changesThis PR replaces Local AI GPU qualification with CUDA device identity plus conservative DXGI and NVML dedicated-memory bounds, excluding shared system RAM from admission. Merge readiness⛔ Blocked before merge - 4 items remain Keep open: current main still counts DXGI shared memory in Local AI qualification, while this branch replaces that path with identity-bound dedicated-memory limits. The declared DGX/Blackwell proof pool remains unrun at the exact head, so the target hardware path needs evidence before merge. Priority: P1 Review scores
Verification
How this fits togetherLocal AI setup reads Windows and NVIDIA hardware facts to choose a model before download and startup. These facts feed onboarding, install reuse, and the local inference runtime’s GPU verification. flowchart LR
A[CUDA device facts] --> B[Identity-matched memory bounds]
C[DXGI local video budget] --> B
D[NVML dedicated memory] --> B
B --> E[Local AI eligibility]
E --> F[Setup and onboarding]
F --> G[Model download and runtime verification]
Before merge
Agent review detailsSecurityNone. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the conservative identity-bound design only after the declared DGX/Blackwell pool confirms exact-head preflight, setup or reuse, restart, and fixed-prompt inference behavior. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main adds shared GPU memory to qualification, and the branch’s DGX regression recreates the unsafe capacity calculation. Exact-head native output also confirms the cap on an RTX 4080, although not on DGX/Blackwell hardware. Is this the best way to solve the issue? Unclear for merge readiness: the identity-bound dedicated-memory approach is a narrow, maintainable correction with focused coverage, but the declared target hardware still needs exact-head end-to-end proof. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 0b5d8606e788. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
c6765a7 to
aff93c1
Compare
f84912d to
effc11a
Compare
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)
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)
8b66f30 to
fa28506
Compare
Adversarial review consensusReviewed the complete 18-file diff from base Verdict: one actionable MEDIUM-risk defect should be fixed before merge. No CRITICAL findings. Both models agree: HIGH consensus
Adjudication: practical severity is MEDIUM. On CUDA 13 drivers, UUID failure should be rare, so HIGH is aggressive. The behavior is nevertheless real and directly violates the PR's partial-facts and retry contract. On CUDA 9.2 through 11.3, the Suggested fix: isolate native failures per device, fall back to legacy Only one model flagged: LOW consensus
Cross-checks found no DLL hijack path because all CUDA imports use Validation was review-only. No files were changed and no tests were run as part of this review. |
fa28506 to
c5a3c5b
Compare
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)
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.
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)
c5a3c5b to
79ef5c5
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Maintainer decision: preserve supported non-DXGI CUDA hosts. We are not accepting a DXGI-only Local AI support contraction for DGX/Blackwell UMA, TCC, or headless devices. Keep the conservative DXGI/WDDM bound, add an allocation-safe identity-joined fallback or explicit allocation-proven gate for supported non-DXGI platforms, and prove it on exact-head hardware. Raw CUDA total and arbitrary capacity constants are not acceptable. |
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
Maintainer decision addressed: no DXGI-only support contractionHead is now What changedCapacity resolution is now a two-source, identity-joined chain rather than DXGI-only:
NVML reports dedicated device memory only and never the WDDM shared host pool, which is exactly why it reported 16,320 MiB on the DGX Spark in #1237 where CUDA advertised 46,332 MiB and llama-server died at 16,186 MiB. So the fallback is allocation-safe on the platform that motivated this work. Constraints held: Exact-head hardware proof of the non-DXGI path
Regressions addedNo-LUID, no-DXGI-adapter, zero-dedicated-memory, DXGI-preferred-over-NVML, identity-mismatch (NVML entry for a different UUID must not be used), and both-sources-throwing. Plus the two hardware-gated proofs above under Validation at this head
Still blockedFull model download, llama-server launch, and fixed-prompt inference remain unverified at this head. The available GPU correctly qualifies for no catalog model (smallest requires 21,980 MiB), so end-to-end inference proof needs the I have not merged this. Intended order remains #1253, then #1281, then #1290. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
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
Second rubber-duck pass applied: head is now
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
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
CI gating fix: head is now
|
Merged current
|
…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
Summary
nvcuda.dllloading to System32.Closes #1191. Related investigation: #1237 and #1239.
The intended merge order places this before #1281 and #1290.
Why capacity is capped rather than taken raw from CUDA
cuMemGetInfois not a safe admission bound on WDDM. On the DGX Spark recorded in #1237, CUDA advertised 46,332 MiB because it surfaces the WDDM shared host pool, while llama-server still died withCUDA error: out of memoryat 16,186 MiB (15.81 GiB) against roughly 15.9 GiB of real device memory. Shared system memory is host RAM and never backs a device allocation, so it is used for nothing here: the dedicated figure only ever lowers reported capacity, never raises it.capacity = min(cudaTotal, dedicated). No arbitrary constants: every bound is a driver or OS reported fact.Why there is no allocation-proven gate
An allocation gate was implemented and then empirically disproved on real hardware at this head (RTX 4080 SUPER, 16,375 MiB CUDA total, driver 620.02). WDDM reservations do not fail on oversubscription:
Neither
cuMemAllocnor the VMMcuMemCreatepath discriminates allocatable capacity on WDDM, so a reservation gate would have reported a false "proven" result while adding a multi-gigabyte allocation to setup. The conservative dedicated-memory bound is used instead, per the recommendation in #1237 that shared memory must be kept separate from the number eligibility is judged against.Non-DXGI hosts stay supported
A DXGI-only bound would contract support. A unified-memory DGX or Blackwell part that reports no dedicated video memory, a TCC device, or a headless GPU may have no usable DXGI adapter, and would resolve no bound at all.
Resolution order is therefore:
cuDeviceGetLuidagainstDXGI_ADAPTER_DESC1.AdapterLuid). Preferred, so the conservative WDDM budget behavior is unchanged wherever it applies.nvmlDeviceGetMemoryInfototal, joined by the sameGPU-...UUID the CUDA driver reports. NVML reports dedicated device memory only, never the shared host pool, which is why it reported 16,320 MiB on the DGX Spark where CUDA advertised 46,332 MiB.Both joins are on device identity, never on adapter name.
nvml.dllis loaded only from fully qualified driver-owned paths, matching the System32 pinning used fornvcuda.dllanddxgi.dll.Fail-closed behavior
When neither source resolves a bound,
GpuVisibleMemoryBytesstays null. That yields the retryableHardwareFactsIncompletestate rather than an over-qualification, so the worst case is "Local AI unavailable, recheck available" instead of a large download that cannot start.Required proof pools
windows-11-arm64: native ARM64 CUDA detection and app build behavior changed.windows-wsl-dgx-blackwell: NVIDIA DGX/Blackwell detection, Local AI setup, and inference qualification changed.windows-winui-interactive: onboarding eligibility and Local AI presentation depend on the new hardware facts.Validation
Current head:
fb0260599dcc287411354fc33c156acf2c8f2ce5Windows 11 x64, .NET SDK 10.0.303, NVIDIA driver 620.02:
.\build.ps1: passed. Documentation gate (48 Markdown files, 7 proof pools) plus Shared, Cli, WinNodeCli, SetupEngine, and WinUI all built successfully.dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj: 3,904 passed, 32 environment-gated skips.dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj: 2,829 passed.dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj: 1,028 passed.dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj: 706 passed.LocalInferenceQualificationTests: 50 passed, including the DGX capacity regression, the CUDA-free-inflation regression, the missing/failing UUID regressions, and the no-LUID, no-DXGI, zero-dedicated, DXGI-preferred, identity-mismatch, and both-sources-failing fallback regressions.LocalInferenceHardwareProbeTestswithOPENCLAW_RUN_GPU_PROOF=1: 2 passed on a real NVIDIA GPU. These skip automatically on hosts with no NVIDIA device, so GPU-less CI stays green.CI on the previous head
03975b60was green, including the aggregatetestjob and all three E2E suites.Rubber-duck review was run before publication and raised three blocking issues, all fixed:
cuInitstill became a definitiveNoNvidiaGpu. Driver availability is now tri-state, and only an absent driver or a driver reporting no device is definitive.That pass also surfaced two of my own defects, both fixed before publication: an incorrect
IDXGIAdapter3::QueryVideoMemoryInfovtable slot, and an over-strict free-memory rule that blanked out capacity on an ordinary discrete GPU whose CUDA total slightly exceeds the DXGI dedicated figure.Real behavior proof
Standalone current-head hardware proof, collected on this branch (not from integration SHA
38a172f1). Windows 11 x64, NVIDIA GeForce RTX 4080 SUPER, driver 620.02, compute capability 8.9, redacted GPU UUID.Default path
Non-DXGI fallback path, proven on the same hardware at this head
LocalInferenceHardwareProbeTestsforces the DXGI source to supply nothing, so resolution must fall back to the NVML identity join exactly as it would on a host DXGI cannot describe:nvidia-smion the same host reports16376 MiBtotal and8900 MiBfree, so the NVML dedicated figure matches the driver exactly.What this demonstrates on real hardware at this head:
HardwareFactsIncomplete.Unsupported/InsufficientGpuMemory), so the fallback does not change the outcome on a host where both sources exist.GPU-3c102124-..., the same UUIDcuDeviceGetUuid_v2produced.00000000:00018980andcuDeviceGetLuidreturned the identical value.SharedSystemMemoryof 104,673 MiB on this adapter and none of it reaches qualification. Under the pre-Do not count DXGI shared system memory as CUDA capacity on discrete GPUs #1191 accounting this device would have been credited with well over 100 GiB.GPU-...manifest identity is unchanged, so existing installs keep their GPU selector.The reservation results quoted in the Summary were captured from the same host and head.
Not verified / blocked: full model download, llama-server launch, GPU-placement verification, and fixed-prompt inference were not run at this head. This 16 GiB device correctly qualifies for no catalog model (the smallest requires 21,980 MiB), so end-to-end inference proof needs the
windows-wsl-dgx-blackwellpool. DGX/Blackwell capacity behavior is covered here by the recorded #1237 numbers replayed as unit regressions plus the non-DXGI fallback proven on the hardware available, not by a live DGX run.Security and compatibility
nvcuda.dllimports are restricted toDllImportSearchPath.System32, enforced by a test that scans every nvcuda import in the assembly rather than one type.dxgi.dllis likewise pinned to System32, andnvml.dllis loaded only from fully qualified driver-owned paths, enforced by a test.GPU-...manifest identity, so GPU selection and upgrade behavior are stable.