Skip to content

Prune the margin card's thread seat once it has stood in the page, and hold the shift watch's shadow roots weakly - #5316

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-5190
Nov 4, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-5190

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

The render gate's thread-card round trips retained a whole margin card per open on six corpus pages (#5190). This had two retainers, and both had to go before the counts held steady.

  • Runtime (inline.js). Since Make strict checking the default for maintained browser modules #4873 the margin card builds a new .lf-margin-thread section and seat body for each card it opens. Before that change, it reused the one section. The seat commits while the body is still detached, and the owner places it afterwards through claimSeatReplies. So #connected stayed false, and prune() never disposed the seat. Each opened card left its ThreadSeat in activeSeats and its HeldNews in holders, and those kept the card's nodes and listeners alive. Now claim(), the owner's placement signal, records that the seat stands in the document, and the next commit prunes the card the user closed.
  • Test harness (shift_watch.js). The shift watch kept every shadow root ever attached in a strong Set. A closed card's reply field (leaf-text's shadow root) therefore kept the card alive as long as the page lived, and live_counts read that as a leak. It now holds roots by WeakRef and still walks every live one, closed roots included. This fixes the measuring instrument and leaves the leak thresholds unchanged.

Verification. On main, test_page_fixture_renders[log-retention] reports the thread card leaks nodes: [2210, 2519, 3304, 4089]. With this change, the thread-card leak is gone from log-retention, review-a-plan, ship-review, thread-choice-hints, feature-gallery (nodes and listeners) and thread-panel-gallery. A probe of six t + Escape trips on log-retention reads a flat 2871 nodes and 1011 listeners. With only the harness fix it climbs from the third trip, and with only the runtime fix it climbs from the first. git bisect with that probe over the last passing and first failing nightlies lands on #4873.

Those six cases still fail locally on findings this change doesn't touch:

  • g opened no go-to, on every page, which also happens on unmodified main and is absent from the Nov 3 nightly.
  • feature-gallery's apparatus among authored <span>, which the Nov 3 nightly also reports.

pnpm run test:runtime (776), check:browser, the shift watch's shadow-root browser tests (23) and the margin card's reply tests pass. The one failure in that selection, test_an_offscreen_thread_card_arrives_with_its_anchor[above-or-below-up], also fails on main (#5146).

How the retainers were found

After four round trips, DOM.getDetachedDomNodes listed three detached SECTION.lf-margin-thread trees of about 280 nodes each, while the attached DOM stayed at 813 nodes. Shortest retainer paths in a heap snapshot (excluding weak and ephemeron edges) ran through the shift watch's roots Set (ShadowRoot → leaf-text → … → section). With that scope excluded, they ran through holders → HeldNews.#seat, the margin card's seat body, with activeSeats holding the seat itself.

Closes #5190 — automated triage

…d hold the shift watch's shadow roots weakly

Since #4873 the margin card builds a new section and seat body for each
thread card it opens. The seat commits while that body is still detached,
and its owner places it afterwards (`claimSeatReplies`), so the seat never
recorded that it had stood in the page and `prune` never disposed it. Every
opened card kept its ThreadSeat in `activeSeats` and its HeldNews in
`holders`, and through them the whole card, its nodes and listeners. `claim`
is the owner's signal that the seat now stands in the document, so it now
records that, and the next commit prunes the card the user closed.

The shift watch kept every shadow root ever attached in a strong Set, so a
closed card's reply field pinned the card for as long as the test ran, and
the render gate's surface round trips read that as the page leaking. It
now holds them by WeakRef and still visits each live one, closed roots
included.

With both, the thread card's round trips hold steady on log-retention,
review-a-plan, ship-review, thread-choice-hints, feature-gallery and
thread-panel-gallery. Either alone leaves the count climbing.

Closes #5190
@leaf-agent
leaf-agent merged commit 2a2b68d into main Nov 4, 2026
5 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-5190 branch November 4, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thread card round trips retain nodes across corpus pages

1 participant