Skip to content

Tray pegs one core and grows to 16 GB: unbounded render loop in Reactor chat root (ApplyInputs called during Render) #1325

Closed

Description

@larroy

Summary

The WinUI tray app enters an unbounded render loop in the Reactor chat root. The UI thread pegs one core indefinitely, the tray stops responding to input, and the managed heap grows without limit — I observed 16.1 GB working set and ~10.2 hours of CPU over 10.1 hours of uptime (≈1.01 cores pegged continuously since launch).

The memory growth is a direct consequence of the render loop, not a separate leak. Fixing the loop fixes both symptoms.

Environment

  • Commit 08c825b7, local Debug build, net10.0-windows10.0.22621.0, win-arm64
  • .NET SDK 10.0.400 / runtime 10.0.11
  • Windows 11 Enterprise 10.0.28000, ARM64
  • Microsoft.UI.Reactor 0.1.0-preview.12

Evidence

The UI thread never leaves Render()

Four independent dotnet-stack samples of the UI thread (0x5A60, 26,776 s CPU) were all inside the render loop:

Microsoft.WinUI!ABI.Microsoft.UI.Xaml.Controls.IBorderMethods.get_Child(...)
Reactor!Microsoft.UI.Reactor.Core.Reconciler.ReconcileComponent(...)
Reactor!Microsoft.UI.Reactor.Core.Reconciler.Update(...)
Reactor!Microsoft.UI.Reactor.Core.Reconciler.ReconcilePanelChildrenInto(...)
...
Reactor!Microsoft.UI.Reactor.Hosting.ReactorHostControl.Render()
Reactor!Microsoft.UI.Reactor.Hosting.ReactorHostControl.RenderLoop()
Microsoft.InteractiveExperiences.Projection!ABI.Microsoft.UI.Dispatching.DispatcherQueueHandler.Do_Abi_Invoke(int)
OpenClaw.Tray.WinUI!OpenClawTray.Program.Main(string[])

It never returns to pumping messages, which is why the tray is unresponsive. Background threads (node websocket, logging) keep working normally — the log kept advancing the whole time, so the app looks alive while the UI is wedged.

The heap is 99.7% COM callable wrappers

dumpheap -stat on a full dump — note the heap holds only 115,596 objects total, i.e. the visual tree is completely normal-sized (517 BorderElement, 416 ButtonElement, 315 TextBlockElement):

          MT   Count       TotalSize  Class Name
7ff8cd3ec7e8     955  15,846,538,856  System.Runtime.InteropServices.ComWrappers+ManagedObjectWrapperHolder[]
Total 115,596 objects, 15,898,028,565 bytes

37 of those arrays account for 15.85 GB; two are 4.29 GB each. gcroot traces them through dependent handles to exactly two managed objects — OpenClawTray.Pages.ChatPage and Microsoft.UI.Reactor.Hosting.ReactorHostControl. The backing list for ChatPage:

Name: System.Collections.Generic.List`1[[ComWrappers+ManagedObjectWrapperHolder]]
    _items    0000008268000048   ManagedObjectWrapperHolder[]  (4,294,967,320 bytes)
    _size            355567468
    _version         355567468

_size == _version means 355 million Add calls and not one removal. Every render pass mints fresh CCWs as these objects cross into WinRT, and .NET's per-object ComWrappers holder list is append-only and never trimmed. So heap size is purely a function of loop iterations.

Consistent with this, the finalizer thread had burned 913 s in WinRT.IObjectReference.Finalize(), and a GC thread another 4,928 s.

Root cause

The cycle is in OpenClawReactorChatRoot / ChatComposerViewModel, and it is unconditional and self-sustaining:

  1. Chat/OpenClawReactorChatRoot.cs:312 calls props.ComposerSession.ApplyInputs(...) directly inside Render() — a side effect performed during render.
  2. It passes Revision: ++inputsRevisionRef.Current (OpenClawReactorChatRoot.cs:313), so the revision advances on every render. The staleness guard in ApplyInputs (Chat/ChatComposerViewModel.cs:238, if (_inputs is { } current && inputs.Revision <= current.Revision) return;) can therefore never reject anything.
  3. Mutate → DrainQueue (Chat/ChatComposerViewModel.cs:421-423) runs next(); RenderRevision++; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null)); — unconditionally, with no check for whether the mutation actually changed anything.
  4. Chat/ReactorChatComposer.cs:77 is subscribed to exactly that event: void OnChanged(...) => setRenderRevision(vm.RenderRevision); — a state change, which schedules another render.
  5. Back to step 1, at full CPU speed.

There are two compounding defects here. Note that the guard in ApplyInputs returns from inside the Mutate lambda, so even on the path where it does reject the stale input, Mutate still bumps RenderRevision and raises PropertyChanged. Either defect alone would sustain the loop given the other.

A contributing factor for why nothing memoizes out: ChatTimelinePresentationContext is a record rebuilt every render carrying freshly-allocated delegates (e.g. dataProvider.ResolveAssistantMediaAsync as a method group, and inline lambdas such as () => setScrollToBottomToken(...) at OpenClawReactorChatRoot.cs:326), so ReactorChatTimelineProps never compares equal to the previous props and the whole subtree re-reconciles each pass.

Suggested fix

  • Move the ApplyInputs call out of Render() into a UseEffect keyed on the actual input values, and derive Revision from content rather than incrementing it per render.
  • Independently, make DrainQueue skip RenderRevision++ / PropertyChanged when the mutation was a no-op. That breaks the cycle defensively even if a side effect is reintroduced into a render path later.
  • Optionally, stabilize the delegates on ChatTimelinePresentationContext (cache via UseRef/UseCallback) so unchanged subtrees can actually bail out of reconciliation.

Secondary, unrelated finding

Services/DeviceStatusProvider.cs:39-52 samples PerformanceCounter.NextValue() on a fixed 2 s timer. In the same dump I caught two threads simultaneously inside PerformanceMonitor.GetData — each sample is taking longer than the 2 s period, so callbacks overlap and pile up. That API also allocates a large buffer for the entire Processor category on every call. Recommend re-arming the timer via Change after each sample completes instead of using a fixed period.

Repro

Not yet reduced to a deterministic sequence — the loop was already running when investigated. It requires the Reactor chat surface to be mounted (ChatPage + ReactorChatComposer); given that ApplyInputs is called unconditionally on every render of the chat root, any render of a mounted chat root should be sufficient to start it. Happy to try to pin down an exact trigger if that would help.

Diagnostic method

dotnet-stack report (repeated samples), dotnet-counters collect --counters System.Runtime, and dotnet-dump collect --type Full + dumpheap -stat / gcroot / dumpobj. Note dotnet-gcdump cannot complete against the process in this state — the heap walk never finishes even with a 600 s timeout; a full dump was required.

Activity

  1. added
    P0
    clawsweeper:fix-shape-clear
    clawsweeper:queueable-fix
    clawsweeper:source-repro
    impact:crash-loop
    issue-rating: 🦞 diamond lobster
    no-stale
    on Sep 4, 2026
  2. clawsweeper commented on Sep 4, 2026

    @clawsweeper

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed September 4, 2026, 3:21 PM ET / 19:21 UTC.

    Summary
    Current main still contains the reported render-to-notification feedback path. This is a source-reproducible P0 tray-chat bug; the active-landing status indicates it already has maintainer ownership, so it should not receive a competing repair job.

    Reproducibility: yes. from source. Current main renders an unconditional, monotonically revised input update, then unconditionally notifies a subscriber that schedules another Reactor update.

    Regression provenance
    Regression provenance — verified: source commit 686afdc8d4a2 by Barbara Kudiess; canonical PR #1098 (blame-to-merge-commit).

    Next step
    The bug has a small, source-proven repair shape, but status: 🚢 actively landing shows active maintainer ownership; do not open a competing repair job.

    Review details

    Best possible solution:

    Apply composer inputs from a semantic-effect boundary rather than Render, suppress notifications for rejected or unchanged input projections, add regression coverage for no-op invalidation, then prove idle tray behavior on Windows.

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

    Yes, from source. Current main renders an unconditional, monotonically revised input update, then unconditionally notifies a subscriber that schedules another Reactor update.

    Is this the best way to solve the issue?

    Yes, with a semantic input-change guard in addition to moving the side effect out of Render. That breaks both the immediate cycle and the stale-input notification path without adding product surface.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The repair needs current-head native tray proof that an idle mounted chat surface stops scheduling renders, while preserving the architecture ledger's root/composer ownership boundary.

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

    Label changes

    Label changes:

    • remove clawsweeper:queueable-fix: Current issue advisory state no longer selects this label.
    • remove clawsweeper:fix-shape-clear: Current issue advisory state no longer selects this label.

    Label justifications:

    • P0: The source-visible cycle can make the tray UI unresponsive while consuming a CPU core and exhausting memory.
    • impact:crash-loop: The composer notification loop repeatedly schedules rendering from the mounted chat surface.
    Evidence reviewed

    What I checked:

    Likely related people:

    • Barbara Kudiess: Raw commit 686afdc adds src/OpenClaw.Tray.WinUI/Chat/ChatComposerViewModel.cs:136 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 686afdc8d4a2; files: src/OpenClaw.Tray.WinUI/Chat/ChatComposerViewModel.cs)
    • Caleb Eden: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    How this review workflow works
    • 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.
  3. larroy commented on Sep 4, 2026

    @larroy
    CollaboratorAuthor

    Seems related to dotnet/runtime#129191

  4. added
    status: 🚢 actively landing
    on Sep 4, 2026
  5. removed
    clawsweeper:queueable-fix
    clawsweeper:fix-shape-clear
    no-stale
    on Sep 4, 2026
  6. removed
    status: 🚢 actively landing
    on Sep 4, 2026
  7. locked as resolved and limited conversation to collaborators on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0clawsweeper:source-reproimpact:crash-loopissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions