Skip to content

fix: prevent .NET 10 COM wrapper memory leak in production - #1215

Merged
shanselman merged 2 commits into
openclaw:mainfrom
jacobtomlinson:fix/dotnet10-comwrapper-leak
Aug 26, 2026
Merged

shanselman merged 2 commits into
openclaw:mainfrom
jacobtomlinson:fix/dotnet10-comwrapper-leak

Conversation

@jacobtomlinson

Copy link
Copy Markdown
Contributor

Summary

  • disable System.Diagnostics.Debugger.IsSupported only for non-dev Release builds
  • preserve managed debugger support for ordinary Debug/F5 and explicit DevBuild=true builds
  • add a contract test that pins the configuration and identity condition

Why

A live OpenClaw Companion process reached about 13.5 GB private memory. Heap analysis found 13.76 GB retained by duplicate System.Runtime.InteropServices.ComWrappers+ManagedObjectWrapperHolder[] entries, including two 4 GB arrays rooted through ChatPage and ReactorHostControl.

This matches the open .NET 10 runtime regression dotnet/runtime#129191. The runtime's diagnostics-only CCW registry appends duplicate wrapper references on every managed-to-native crossing. Setting System.Diagnostics.Debugger.IsSupported=false bypasses that registry. This PR scopes the workaround to production Release artifacts so local debugging remains available.

Validation

  • ./build.ps1
    • all builds succeeded
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
    • 3,812 passed, 32 skipped, 0 failed
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore
    • 2,704 passed, 0 skipped, 0 failed
  • focused contract test
    • 1 passed, 0 failed
  • autoreview with Codex gpt-5.6-sol, high reasoning
    • clean, no accepted/actionable findings

Real behavior proof

Generated OpenClaw.Tray.WinUI.runtimeconfig.json and app-identity.txt from current-head ARM64 builds:

Configuration DevBuild Identity System.Diagnostics.Debugger.IsSupported
Release false release false
Release true dev omitted
Debug false release omitted

This is a build/runtime configuration change with no user-visible UI state, so screenshot proof is not applicable.

Work around dotnet/runtime#129191 for Release production builds while preserving managed debugger support in Debug and explicit DevBuild builds.

Co-authored-by: Copilot <[email protected]>
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

@jacobtomlinson jacobtomlinson added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 25, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 7:42 PM ET / 23:42 UTC.

ClawSweeper review

What this changes

This PR emits a .NET runtime configuration switch only for non-development Release tray builds, with a build-matrix test for Release, Debug, DevBuild, and MSIX variants.

Regression provenance

Possible regression — suspected (failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for a maintainer decision on the intentional production-debugging tradeoff. The narrowly scoped runtime switch, matrix test, and clean three-way merge support the implementation; likely related people: @shanselman (high confidence).

Priority: P1
Reviewed head: 725ea5afadc60611d7ff0c880b8c543113f3ca0d
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused workaround has direct configuration-matrix proof and targeted coverage; only the intentional Release-debugging tradeoff needs maintainer acceptance.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body supplies current-head generated runtime-configuration results for Release, DevBuild, and Debug cases, directly showing the changed build boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies current-head generated runtime-configuration results for Release, DevBuild, and Debug cases, directly showing the changed build boundary.
Evidence reviewed 4 items Scoped production condition: The project emits System.Diagnostics.Debugger.IsSupported=false only when Configuration is Release and DevBuild is not true, leaving Debug and explicit development builds unchanged.
Build-matrix coverage: The added theory evaluates the MSBuild item for Release x64 and ARM64, MSIX, DevBuild, and Debug cases, asserting the switch value and its absence outside ordinary production builds.
Current-main merge check: A three-way merge of the PR base, current main, and PR head is clean for both changed files.
Findings None None.
Security None None.

Live Verification

Command: dotnet msbuild src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj -nologo -v:q -getItem:RuntimeHostConfigurationOption -p:Configuration=Release -p:DevBuild=false -p:RuntimeIdentifier=win-x64

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: System.Diagnostics.Debugger.IsSupported

How this fits together

The WinUI tray project converts build properties into the runtime configuration consumed by the Companion application. This change decides whether production startup disables a .NET diagnostics feature implicated in COM-wrapper memory retention.

flowchart LR
A[Build configuration] --> C[Tray project]
B[DevBuild setting] --> C
C --> D{Release and non-dev?}
D -->|Yes| E[Disable debugger diagnostics]
D -->|No| F[Retain debugger diagnostics]
E --> G[Companion runtime]
F --> G
Loading

Decision needed

Question Recommendation
Should ordinary Release Companion artifacts disable managed debugger diagnostics to mitigate the reported .NET 10 COM-wrapper retention, while retaining diagnostics only for Debug and explicit DevBuild builds? Accept the scoped production workaround: Merge the Release-only switch, preserving managed debugging through Debug and DevBuild artifacts while mitigating the reported production memory path.

Why: This is an intentional compatibility and operational-debugging tradeoff, not a mechanical correctness question that source review can decide.

Before merge

  • Resolve merge risk (P1) - Merging intentionally removes managed debugger diagnostics from ordinary Release artifacts; production debugging must use an explicit DevBuild artifact while this workaround remains active.
  • Resolve merge risk (P1) - The contract test proves runtime-option emission, not the upstream .NET runtime's memory-retention behavior under a long-running managed-to-native workload.
  • Complete next step (P2) - A maintainer must explicitly accept the Release-debugging compatibility tradeoff before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +8, tests +103 The production behavior is one conditional runtime item; most of the patch is explicit matrix coverage for build modes and package variants.

Merge-risk options

Maintainer options:

  1. Accept the scoped production debugger tradeoff (recommended)
    Merge with the documented understanding that ordinary Release artifacts disable managed debugger diagnostics while Debug and DevBuild artifacts retain them.
  2. Pause for a debugger-preserving mitigation
    Keep the PR open if maintainers require managed debugger diagnostics to remain available in standard production artifacts.

Technical review

Best possible solution:

Land the scoped workaround only after a maintainer explicitly accepts the temporary Release-debugging limitation, then revisit or remove it when the upstream .NET runtime regression is fixed.

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

No. The PR documents a heap trace and proves generated configuration behavior, but it does not provide a repeatable current-head COM-wrapper retention reproduction.

Is this the best way to solve the issue?

Yes for the stated temporary mitigation. The project-level condition covers Release packaging variants while preserving the intended Debug and DevBuild diagnostic paths.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The PR targets reported production memory retention that can make the Companion process unusable.
  • merge-risk: 🚨 compatibility: Ordinary Release artifacts would intentionally no longer expose managed debugger diagnostics.
  • merge-risk: 🚨 availability: The setting changes production runtime behavior to mitigate severe memory growth.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies current-head generated runtime-configuration results for Release, DevBuild, and Debug cases, directly showing the changed build boundary.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies current-head generated runtime-configuration results for Release, DevBuild, and Debug cases, directly showing the changed build boundary.

Evidence

What I checked:

Likely related people:

  • shanselman: Scott Hanselman authored the PR's matrix-test commit and prior available history on the tray project and installer assertion surface. (role: recent tray build and validation contributor; confidence: high; commits: 725ea5afadc6, 12b84457a464, 4206611f2b2e; files: src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj, tests/OpenClaw.Tray.Tests/InstallerIssAssertionTests.cs)

Rank-up moves

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

  • Confirm that temporarily disabling managed debugger diagnostics in ordinary Release artifacts is an acceptable production tradeoff.

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 (1 earlier review cycle)
  • reviewed 2026-08-25T11:00:15.012Z sha 5216838 :: needs maintainer review before merge. :: none

@shanselman
shanselman merged commit c446f34 into openclaw:main Aug 26, 2026
17 checks passed
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 26, 2026
@jacobtomlinson
jacobtomlinson deleted the fix/dotnet10-comwrapper-leak branch August 27, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants