Skip to content

fix(inference,setup): shared-memory capacity semantics and destructive rollback (PR #1237 follow-ups) - #1239

Closed
larroy wants to merge 3 commits into
openclaw:mainfrom
larroy:fix/gpu-memory-join-stable-id
Closed

larroy wants to merge 3 commits into
openclaw:mainfrom
larroy:fix/gpu-memory-join-stable-id

Conversation

@larroy

@larroy larroy commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Builds on #1237's NVML/DXGI PCI-identity join fix and addresses the two remaining issues that PR's description flagged but deliberately left unfixed:

  1. Shared memory wrongly counted as CUDA-allocatable capacity. LocalInferenceQualificationPolicy.GetEffectiveTotalMemoryBytes/GetEffectiveFreeMemoryBytes used to add DXGI-reported shared memory directly into NVML dedicated memory. DXGI shared memory is a WDDM host-RAM budget the GPU may borrow for graphics use — it does not back CUDA device allocations. Counting it as capacity can make a model appear eligible when the GPU cannot actually load it. Eligibility/free-memory checks now use NVML dedicated memory only.

  2. Capability-verification failure destroyed unrelated completed work. SetupPipeline rolled back every previously-completed step whenever any step failed with rollback enabled. A failed Local AI GPU/inference verification — which runs downstream of expensive model/runtime acquisition — would delete the just-downloaded multi-gigabyte GGUF and llama-server runtime. Adds SetupStep.RollsBackPrecedingStepsOnFailure (default true, preserving existing behavior everywhere else) and opts VerifyLocalAiGpuLoadStep/VerifyLocalAiInferenceStep out of it, since both are read-only verification steps whose failure shouldn't force re-acquisition of artifacts that are otherwise safely reused via each acquisition step's own CreatedThisRun-gated skip logic. The failed step itself is still rolled back regardless.

Testing

🤖 Generated with Claude Code

RomneyDa and others added 3 commits August 26, 2026 15:38
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
…city

DXGI-reported shared memory is a WDDM host-RAM budget the GPU may borrow
for graphics use; it does not back CUDA device allocations. Counting it
as capacity (as GetEffectiveTotalMemoryBytes/GetEffectiveFreeMemoryBytes
previously did) can make a model appear eligible when the GPU cannot
actually load it, per PR openclaw#1237's second finding.

Eligibility and free-memory checks now use NVML dedicated memory only.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… failure

SetupPipeline previously rolled back every completed step whenever any
step failed with RollbackOnFailure enabled. A failed Local AI GPU/inference
verification downstream of expensive artifact acquisition would delete
the just-downloaded multi-gigabyte model and llama-server runtime, per
PR openclaw#1237's third finding.

Adds SetupStep.RollsBackPrecedingStepsOnFailure (default true, preserving
existing behavior everywhere else) and opts VerifyLocalAiGpuLoadStep and
VerifyLocalAiInferenceStep out of it — both are read-only verification
steps whose failure shouldn't force re-acquisition of artifacts that are
otherwise reused via each acquisition step's own CreatedThisRun-gated
skip logic. The failed step itself is still rolled back regardless.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@clawsweeper

clawsweeper Bot commented Aug 27, 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: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed August 27, 2026, 3:27 AM ET / 07:27 UTC.

ClawSweeper review

What this changes

The PR makes Local AI model qualification use dedicated NVML memory only and preserves completed setup work when Local AI verification fails.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until real behavior proof is added - 5 items remain

Keep this PR open. Current main still has both reported behaviors, but the PCI join added here has no production consumer once shared memory is excluded from qualification, and external real-behavior proof is not yet posted.

Priority: P2
Reviewed head: 34b914b5315acc679324bad15a34603b3b5c1f58

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The two intended fixes have useful tests, but an unused native-probe path and absent posted real-behavior proof prevent merge readiness.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The body reports a DGX Spark result, but no redacted current-head terminal output, runtime log, recording, or linked artifact demonstrates the dedicated-memory decision or preserved artifacts after verification failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The body reports a DGX Spark result, but no redacted current-head terminal output, runtime log, recording, or linked artifact demonstrates the dedicated-memory decision or preserved artifacts after verification failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current main still aggregates shared memory: The current-main qualification policy adds DXGI shared memory to dedicated NVML capacity and free memory, so the reported false-eligibility behavior remains unresolved on main.
Current main rolls back all prior setup steps: When rollback is enabled, current main unconditionally rolls back completed steps after a failed step.
PCI join has no current production effect: The new PCI-based association populates shared-memory fields, but the PR changes the only production qualification readers to use dedicated NVML values only; repository search found no remaining production reader of those shared fields.
Findings 1 actionable finding [P2] Remove or give the PCI join a production consumer
Security None None.

Live Verification

Command: dotnet run --project .\src\OpenClaw.SetupEngine\OpenClaw.SetupEngine.csproj -- --dry-run --config .\src\OpenClaw.SetupEngine\default-config.json

Result: FAIL (failed) — execution before step 1 expect_output: 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: OpenClaw Setup Engine

How this fits together

Local AI setup probes GPU memory to decide whether a pinned local model fits, acquires the runtime and model, then verifies inference and GPU placement. The PR changes the eligibility decision and the rollback behavior after either verification failure.

flowchart LR
A[Windows GPU probes] --> B[Local AI eligibility]
B --> C[Runtime and model acquisition]
C --> D[Inference and GPU verification]
D --> E[Rollback policy]
E --> F[Reusable Local AI install]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The body reports a DGX Spark result, but no redacted current-head terminal output, runtime log, recording, or linked artifact demonstrates the dedicated-memory decision or preserved artifacts after verification failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Remove or give the PCI join a production consumer (P2) - The new lookup only populates SharedGpuMemoryBytes and FreeSharedGpuMemoryBytes, but this PR changes both production qualification readers to ignore those fields. The added NVML v3 query therefore has no observable product effect. Remove it from this focused fix or add the separate diagnostic contract that consumes it.
  • Resolve merge risk (P1) - Dedicated-only qualification deliberately makes some previously eligible WDDM configurations unavailable on their next setup run; the PR has no posted fresh-install or existing-install runtime evidence for that compatibility change.
  • Resolve merge risk (P1) - The changed verification failure path is covered by a mock pipeline test, but no posted current-head trace shows a real failed verification retaining the manifest, model, and runtime for a subsequent run.
  • Complete next step (P2) - The remaining blocker is contributor proof plus a scope correction, not a safe autonomous repair that can establish the contributor's real hardware behavior.

Findings

  • [P2] Remove or give the PCI join a production consumer — 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 +148/-26, tests +194/-7 The PR adds substantial native-probe support and regression coverage, so the currently unused production path deserves a scope check.

Merge-risk options

Maintainer options:

  1. Trim the unused PCI association (recommended)
    Remove the PCI identity collection and shared-memory association from this PR because qualification no longer consumes its result.
  2. Keep it only with a diagnostic contract
    Retain the PCI work only if this PR adds a concrete diagnostic consumer and proof for the information it exposes.

Technical review

Best possible solution:

Keep the dedicated-only qualification and scoped verification rollback changes, remove the unused PCI association until it serves a separate diagnostic surface, then add redacted current-head runtime proof for the changed setup recovery.

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

Yes, from source. Current main explicitly aggregates shared memory for eligibility and unconditionally rolls back completed steps after failure; the PR's reported DGX result itself has not been independently executed here.

Is this the best way to solve the issue?

No. The dedicated-only and rollback portions are narrowly targeted, but the PCI join should be removed or given a real diagnostic consumer because its shared-memory result is no longer consumed by production code.

Full review comments:

  • [P2] Remove or give the PCI join a production consumer — src/OpenClaw.Shared/Inference/NvmlHostHardwareProbe.cs:97-100
    The new lookup only populates SharedGpuMemoryBytes and FreeSharedGpuMemoryBytes, but this PR changes both production qualification readers to ignore those fields. The added NVML v3 query therefore has no observable product effect. Remove it from this focused fix or add the separate diagnostic contract that consumes it.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded Local AI eligibility and setup-recovery correction, with no demonstrated broad outage.
  • add merge-risk: 🚨 compatibility: Dedicated-only qualification changes whether existing WDDM hardware is offered Local AI during a future setup run.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports a DGX Spark result, but no redacted current-head terminal output, runtime log, recording, or linked artifact demonstrates the dedicated-memory decision or preserved artifacts after verification failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This is a bounded Local AI eligibility and setup-recovery correction, with no demonstrated broad outage.
  • merge-risk: 🚨 compatibility: Dedicated-only qualification changes whether existing WDDM hardware is offered Local AI during a future setup run.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports a DGX Spark result, but no redacted current-head terminal output, runtime log, recording, or linked artifact demonstrates the dedicated-memory decision or preserved artifacts after verification failure. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Joel: Introduced the managed Local AI feature that owns the qualification and setup-pipeline behavior. (role: feature introducer; confidence: high; commits: ccd64bbb7d68; files: src/OpenClaw.Shared/Inference/Catalog/LocalInferenceSelector.cs, src/OpenClaw.SetupEngine/SetupPipeline.cs)
  • larroy: The Local AI introduction records Pedro Larroy as a co-author, and this PR's focused commits continue work in that subsystem. (role: prior Local AI co-author and recent area contributor; confidence: high; commits: ccd64bbb7d68, 34b914b5315a; files: src/OpenClaw.SetupEngine/LocalAiSetupSteps.cs, src/OpenClaw.SetupEngine/SetupPipeline.cs)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Remove the unused PCI association or add its distinct diagnostic consumer and focused coverage.
  • Post redacted current-head terminal or log evidence showing dedicated-only qualification and a failed verification followed by retained artifacts on rerun, then update the PR body for re-review.

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.

@joelagnel

joelagnel commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

This breaks UMA architectures. Lets not merge. The correct fix is likely to use Cuda API to query available Cuda memory (which will include the shared memory)

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 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.
@karkarl

karkarl commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Adversarial review consensus

Recommendation: request changes. PR #1239 can leave its managed llama-server running after verification failure, retaining GPU memory and the listening port and potentially blocking an immediate retry.

Both models agree: HIGH consensus

Issue Opus Codex Fix confidence
Rollback opt-out at SetupPipeline.cs:223-235 preserves the running process along with file artifacts. Both verification steps have no failed-step cleanup, so StartLocalAiRuntimeStep.RollbackAsync at LocalAiSetupSteps.cs:715-736 is bypassed. Dispose and clear the transaction-owned runtime while preserving runtime/model/manifest files. Add a regression test asserting runtime disposal and ctx.LocalAiRuntime == null while artifact rollback remains suppressed. MEDIUM HIGH 95%

Only one model flagged: LOW consensus

Issue Opus Codex Fix confidence
VerifyLocalAiInferenceStep returns from the invalid post-refresh state at LocalAiSetupSteps.cs:818-824 without resetting the router, unlike its exception paths at 799-815. Reset before returning failure and test that RestartAsync is invoked. — MEDIUM 99%
Cancellation still performs full rollback at SetupPipeline.cs:305-315, deleting resumable artifacts. This may be intentional cancellation semantics and needs a policy regression test. LOW — 60% (disputed)

The NVML dedicated-memory eligibility change, DXGI shared-memory exclusion, PCI packing/subsystem matching, ambiguity handling, native struct layout, and fallback behavior were validated as correct and fail-closed. No concrete security vulnerability was found.

@shanselman

Copy link
Copy Markdown
Collaborator

Closing the current implementation. Its dedicated-memory direction is superseded and rollback can leave llama-server running; retain those requirements for a safer replacement.

@shanselman shanselman closed this Sep 2, 2026
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
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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants