Repository navigation
Harden queued-editor measurement and capture a renderer stack on unresponsive (Refs #2401) - #2416
Closed
SawyerHood wants to merge 2 commits into
Closed
SawyerHood wants to merge 2 commits into
SawyerHood wants to merge 2 commits into
Conversation
…allback Issue #2401 reports the desktop renderer locking at ~100% CPU with unbounded RSS after clicking Edit on a queued message during an active turn, with the main thread sampled inside V8 microtask execution. The reported lead is QueuedMessagesList.measureInlineEditorMaxHeight: one ResizeObserver over the viewport, surface, list, editor, composer shell and container whose callback reads layout, writes two states and realigns the queue scroll while the surface height animates for 260ms. This change does not fix that hang and must not close the issue. The root cause is not attributable from the issue's evidence: every MutationObserver, queueMicrotask and Promise site reachable from the Edit path was audited and none self-sustains; the surface-height state map has a fixed point in every host because the footer is rendered sticky inside the timeline scroll area (the viewport height is independent of the surface and the only couplings are monotone and clamped); and a ResizeObserver loop is delivered once per frame and loop-limited by the browser, with DefaultLane setStates, so it cannot pin the main thread in microtask execution or block Cmd+R. The hang lives in code the report does not reach, most likely content- or plugin-dependent, and needs a captured renderer stack. What this hardens: the callback measured synchronously inside the observer delivery and again from a window resize handler, which can precede that delivery in the same frame. Both now only schedule one pending requestAnimationFrame, so the effect measures at most once per frame and never from inside the observer callback, where a layout write would re-enter observer delivery. The cost is one frame of latency on the max-height update and realignment during the open animation. The first-paint measurement in the layout effect and getInlineEditorSurfaceMaxHeight are unchanged, and so is the separate realignment the surfaceHeight layout effect schedules when that state changes; it can still land in the same frame as a measured realignment and remains frame-bounded. The queued editor's typeahead reservation now bails out of a re-render when the typeahead reports an unchanged layout. Its ResizeObserver reports a fresh object on every delivery, and a changed reservation resizes the editor row, which is one of the observed boxes above. Verification: the new test "measures once, on the next frame, when the observer delivers and the window resizes together" models one frame as the browser delivers it (one window resize event, then one observer callback carrying an entry per observed target) and asserts zero synchronous measurements, an untouched scroll position, then exactly one measurement and the expected realignment on the next frame. It fails on the previous code (expected 2 to be +0) and passes with this change. The ResizeObserver stub now notifies every live observer (the previous stub only reached the last-constructed one) and the scroll-body mock's getScrollElement is identity-stable like the real context value. @bb/app typecheck, lint and the full test suite (431 files, 3357 tests) pass. Refs #2401 Co-Authored-By: Claude <[email protected]>
…nsive Issue #2401 reports the desktop renderer locking at ~100% CPU with an RSS past 10 GiB after Edit on a queued message during an active turn. Both macOS process samples bottom out in V8 microtask execution and do not name the application callback, so the root cause is not attributable from the report and the previous commit could only harden the suspected path. The next occurrence needs more than a working-set number. The main process now listens for BrowserWindow "unresponsive" on every application window. Once per hang (re-armed by "responsive") it attaches webContents.debugger with protocol 1.3, sends Debugger.enable and Debugger.pause, and on the Debugger.paused event records the top 64 call frames (functionName, url, lineNumber, columnNumber), Runtime.getHeapUsage, the renderer's working set from app.getAppMetrics and the build identity (version, commit, channel, Electron version) so minified frames can be mapped. The report is written to renderer-hang-window-<id>-<timestamp>.json in the desktop log directory; its path is printed to the main-process stderr, and the renderer is then resumed and the debugger detached. A pause takes effect only when V8 next checks for an interrupt. A hang that still yields between tasks reaches that promptly and gives up a stack; a renderer executing a single never-returning synchronous or microtask loop -- the #2401 class, where Cmd+R is also dead -- never does. Verified on Electron 41.7.0: even with the Debugger domain pre-enabled, Debugger.pause is acked in ~1 ms but no Debugger.paused arrives for a for(;;) or self-rescheduling microtask loop. For that class the capture instead times out and the report records which protocol step went unanswered ("Debugger.enable" when the main thread never yields at all, since attach and Debugger.enable are ordinary main-thread messages) together with the renderer's working set -- itself diagnostic of a fully pinned main thread. The README and module doc state this limitation rather than promising a stack unconditionally. Guards: one 5 s deadline covers the whole capture; on expiry the debugger is detached and the timed-out step is recorded. A single debugger session backs every capture, so a "responsive" seen mid-capture only re-arms the window once that capture finishes rather than opening the gate to a second, overlapping capture on the same session. A failed attach is logged and swallowed, a destroyed window produces no report, reading the renderer memory can never throw into the handler, and the core never throws. Note that while any debugger client (including open DevTools) is attached, Chromium suppresses the "unresponsive" event, so no report is produced in that state. Debugger.disable is not sent and Debugger.resume is not awaited: both are main-thread replies a resumed loop may never deliver, and detaching disposes the inspector session anyway. Verification: test/desktop-renderer-hang-diagnostic.test.ts drives the pure core with a fake debugger client (paused delivery with frame truncation, attach failure, timeouts at Debugger.enable and Debugger.paused, a stalled heap read, a failed command, a window destroyed mid-capture, a write failure), asserting the file contents, the resume-before-detach order and that detach runs exactly once; test/desktop-renderer-hang-diagnostic-wiring.test.ts drives the Electron wiring (once per hang, re-arm on "responsive", and no overlapping capture on a busy debugger). @bb/desktop typecheck and the full test task pass. Refs #2401 Co-Authored-By: Claude <[email protected]>
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
#2401 reports the desktop renderer locking at ~100% CPU with RSS past 10 GiB after clicking Edit on a queued message during an active turn; Cmd+R does not recover, Force Reload does. Both macOS process samples bottom out in V8 microtask execution and do not name the application callback.
This PR does not fix that hang and must not close the issue (it uses
Refs). Two independent investigations and four verification passes audited the Edit path and concluded the root cause is not attributable from the report: everyMutationObserver,queueMicrotask, and Promise site reachable from Edit is one-shot or rAF-coalesced;getInlineEditorSurfaceMaxHeighthas a fixed point in every host because the footer is sticky inside the timeline scroll area; and aResizeObserverloop is delivered once per frame and loop-limited by the browser, so the reported lead cannot pin the main thread in microtask execution or block Cmd+R. The remaining suspects are content- or plugin-dependent code (a plugin composer slot notifying a store from a microtask would present exactly as reported, since React 19.2's nested-update guard does not count a cascade re-entered via a microtask) or Chromium itself.What changed
Two commits:
fix(app): defer queued-editor measurement out of the ResizeObserver callback— hardening of the reported lead inQueuedMessagesList.tsx. The observer and window-resize callbacks now only schedule one pendingrequestAnimationFrame; the layout reads, two state writes, and scroll realignment run at most once per frame and never from inside the observer callback. Cost: one frame of latency during the 260 ms open animation. The typeahead reservation inQueuedMessageInlineEditorSlotbails out of a re-render when the reported layout is unchanged.feat(desktop): capture a renderer stack when a window becomes unresponsive— newapps/desktop/src/desktop-renderer-hang-diagnostic.ts. On BrowserWindowunresponsive(once per hang, re-armed onresponsive) the main process attacheswebContents.debugger, sendsDebugger.enable+Debugger.pause, and writes the top 64 call frames,Runtime.getHeapUsage, the renderer working set, and the build identity torenderer-hang-window-<id>-<timestamp>.jsonin the desktop log directory, then resumes and detaches. One 5 s deadline; attach failure, destroyed window, and write failure are logged and swallowed.Owner decision requested on commit 2. Live probes on the pinned Electron 41.7.0 (Xvfb) show the capture yields a stack only for a hang that still yields between tasks. For a never-yielding loop (the #2401 class),
Debugger.enablenever answers — and with the domain pre-enabled,Debugger.pauseis acked butDebugger.pausednever arrives — so the report records "timed out atDebugger.enable" plus the working set. Chromium also suppressesunresponsivewhile any CDP client (including DevTools) is attached, so a pre-armed session is not an alternative. The README and module doc state this limitation. If a stack for a pinned renderer is required, the remaining levers are non-cooperative (webContents.forcefullyCrashRenderer()+ crashReporter, or the macOS sample the reporter already provides); say the word and I will drop commit 2 from this PR.Reporter follow-up needed to attribute the hang:
bb plugin list --json, the leaf frames under the microtask runner in/tmp/bb-renderer-hang.txtand/tmp/bb-renderer-55035.sample, whether rich-text editing is enabled, and whether macOS Reduce Motion is on.How you verified
QueuedMessagesList.test.tsx: "measures once, on the next frame, when the observer delivers and the window resizes together" models one frame as the browser delivers it and fails on the previous component (expected 2 to be +0); the ResizeObserver stub was fixed to notify every live observer.desktop-renderer-hang-diagnostic.test.ts(9 tests) drives the pure core with a fake debugger client: paused delivery with frame truncation, attach failure, timeouts atDebugger.enable/Debugger.pause/Debugger.paused, stalled heap read, failed command, window destroyed mid-capture, write failure, resume-before-detach order, detach exactly once.desktop-renderer-hang-diagnostic-wiring.test.tscovers once-per-hang, re-arm onresponsive, and no overlapping capture.pnpm exec turbo run typecheck --filter=@bb/app --filter=@bb/desktop --forceandpnpm exec turbo run test --filter=@bb/app --filter=@bb/desktop --force: green (app 431 files / 3357 tests; desktop 37 files / 242 tests). EAP codename scan oforigin/main..HEAD: clean.Refs #2401