Repository navigation
Stop the margin re-rendering every frame on a page with a standing reaction - #298
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
#289 is the other open PR touching tests/test_render_margin.py, and its committed prose is what this change falsifies. Its HEARTBEAT_PAGES table carries the gallery with settles=False beside the comment "Its own margin never settles — measured, render runs about seven times a frame through changedOffers on an untouched gallery", and the test's docstring builds the whole two-page reading on it: "the gallery cannot, because its own margin never comes to rest." Those renders through changedOffers are the loop this removes, so once this lands settles=False is a stale claim rather than a property of that page — and the gallery may then be able to take the settled reading only the corpus can take there today, which would be the stronger reading of the two. Whichever of the two lands second is where that gets reconciled; the textual conflict in the same file is the reminder.
#298 stopped `dockSeats` restating every seat's offer, so the gallery's margin now comes to rest: ten frames on an untouched page report no mutation record and no `lf-margin-layout`, where the same ten frames reported about 1700 records before it. The `settles=False` reading this branch gave that page, and the prose explaining it, were statements about the loop #298 removed. Both pages now read each beat across a settled frame, so the `settles` parameter goes and the frame's writers — `scheduleMarginLayout`, `scheduleRoving`, `scheduleButtonLabels` — are watched on the gallery for the first time. That is the stronger reading: with `holdTabStop`'s seat guard reverted, the gallery passed silently under the old reading and goes red under this one. The settled gallery shows a fourth measurement the corpus cannot: two of its rows stand where they would overlap, so `layoutMarginRows` clears the push off a row to read where it naturally sits and puts it back. It is named `row push` and asked of the write, the way the posture probe is, so a restated `top` from another writer still arrives unnamed. The probe set is now expected per page rather than globally, because neither page shows all four.
|
Reconciled on #289, which landed second: |
…289) ## Problem The living margin's `render` is bound to the `lf-actions` heartbeat, so every write in it runs every two seconds on a page nobody has touched. Most of those writes restate what the node already says, and each one is a mutation record a screen reader rebuilds its buffer from — the defect [`decisions/view.js` already names](https://github.com/max-sixty/leaf/blob/161d081e87f2dc684807d94d0a1cda6fd160760c/skills/leaf/assets/runtime/decisions/view.js#L121) — and a fresh dirty box for whatever reads next. Restating is only half of it. Two writers taking turns over one attribute say something different each time, so no record of theirs restates anything, while the second leg is exactly what `leaf.js`'s `disclosureWatch` reads as news. `marginButton` wrote the disclosure default `aria-expanded="false"` on a reading and `syncThreadRelation` stripped it two calls later, so an untouched page ran a full `paintKeys()` on every heartbeat: measured, 140 news records over five refreshes, every one `aria-expanded` on `.lf-margin-marker`. ## Solution `keeps(node, name, value)` and `keepsHidden(node, hidden)`, stated once with the reason, applied to the heartbeat's writers: `marginButton`'s anatomy declarations and role, `marginButtonState`, `syncThreadRelation`, `paintMarker`, the options group and its spill, `syncControls`, `render`'s host, marker, Page-map button and nav, `render`'s `data-lf-external`, `syncForwardedButtonState`'s proxy forwarding, `optionControlNode`'s owner attribute, `readingOptionNode`'s and `syncInlineOffers`' kinds and labels, `marginButtonState`'s `aria-busy`, `buildThreadCard`'s thread and label, and `lf-draft`'s pencil, Save and restore reach. `keeps` lives in `widget-elements.js` and is published through the widget API, because the draft pencil is a module and a module does not duplicate a runtime helper. It compares against what the attribute reads back as — `String(value)` — since a boolean or a count compared raw is never equal to the attribute already standing. Who writes a reading's relation and who seats it are declared rather than inferred from the role. `marginButton` takes `writesRelation` and `writesSeat`, both true by default. The margin's three `role: "reading"` fittings declare the relation away, and its two markers declare the seat away as well: `syncThreadRelation` decides `aria-controls` and `aria-expanded` together and removes both when the reading opens no thread, and `holdTabStop` writes every row's `tabindex` on the frame after each pass. The role could not stand in for either — `reading` is a published `BUTTON_ROLES` member, and a marker and a reading option wear the same one while only the marker is a row. `writesRelation` is carried on the Button record, because `optionControlNode` rebuilds a proxy from one and a proxy that re-inferred the default would write a relation its source has no writer for. `controlsShownByOwner`'s measurement exemption becomes a `toggleAttribute`, which is a no-op where the flag already stands. The end state each pass is identical; only the redundant writes go. ## What the reading covers, and what it leaves standing Half of `render` runs in a frame callback — `scheduleMarginLayout`, `scheduleRoving` and `scheduleButtonLabels` are its whole tail — so a watch that dispatches five refreshes in one synchronous task measures the synchronous half alone. Both pages now let a frame settle between beats, and ask one question of the pass rather than two: **what it wrote without changing**, which is the value an attribute opened the pass with standing again at the end of it. A same-value write and a pair of writers taking turns are one reading there. The gallery reads that way because #298 landed. Its margin used to re-render every frame, so a beat there could not be read across a settled frame and the frame's writers went unwatched on that page; measured on this head, ten frames on an untouched gallery now report no mutation record and no `lf-margin-layout`, where the same ten frames reported about 1700 records before #298. Reverting `holdTabStop`'s seat guard shows what the change is worth: the gallery passed silently under the old synchronous reading and goes red under this one. That reading found two of this branch's own guards comparing against a value another writer had just moved, and both are closed above: the marker seat (270 records over five heartbeats on the corpus, all on `.lf-margin-marker`) and the proxy's relation. What remains on the settled reading is not a name restated. Each is a **probe** — a measurement that modifies the DOM to read it and puts it back: | Probe | Owner | Read on | | --- | --- | --- | | clearing a row's docked and waiting classes to measure where it can hang | `margin-layout.js` | corpus | | clearing the push off a hanging row to read where it naturally sits | `margin-layout.js` | gallery | | reading the rail again once the docked rows are back in flow | `margin-layout.js` | corpus | | lifting the fold rule off a contributed control to read how its owner paints it | `controlsShownByOwner` | gallery, corpus | The push probe is the settled gallery's: two of its rows stand where they would overlap, and no corpus row does. So the set is expected per page rather than globally, named beside each page's population. Both probes over a row are asked of the write rather than of the row, so a `top` or a class restated by another writer still arrives unnamed. The test names all four rather than filtering them, and asserts the named set for reach: a new unchanged write cannot arrive unnamed, closing a probe turns the test red rather than passing quietly, and a run that stopped letting the frame run could not return the clean `[]` it returns when nothing is wrong. One of the three wrote where nothing moved, at both ends — `layoutMarginRows` cleared the classes off rows carrying neither, and marked a row the posture read had already left docked — and `add` and `remove` re-serialize the attribute whether or not the tokens stand. Both halves are guarded here, the second after the reading below found it: the guard on the clear, written the other way round. The other two are `main`'s measurement pattern and closing them is a change to what the margin measures rather than to what it writes; see the note below. ## Testing - `test_an_unchanged_heartbeat_restates_no_margin_name` roots its watch at every `.lf-margin-item` and every inline host as well as the nav and Page-map button, asserts that reach the way it asserts the population, and reads the disclosure watch's own news beside the unchanged writes. It runs on two pages, because one could not state the reach: the corpus draws no reading option and no status reading, so the writers those reach ran unwatched. Both pages carry the settled reading. - `test_an_option_proxy_writes_no_relation_its_source_has_no_writer_for` states the proxy seam, which no shipped page draws. - `test_an_unchanged_heartbeat_re_marks_no_docked_row` states the docked half of the class probe, which neither page above reaches: the corpus stands still but hangs every row it draws, and its compact posture withholds them as `lf-waiting` rather than docking them, while the gallery stands still too but docks no row at that viewport at all — measured, none of the eighteen it draws wears `lf-docked`. A page with one target under `COVERING` docks and settles, so the reading can be taken. It reads the narrowing too, so the guard cannot cost the mark. - Bug-backs, each reverting one guard with the rest in place: `keeps` without the `String` fails on both pages; `writesSeat` fails on both pages with the marker seat's turns, and on the gallery only under the settled reading; the layout probe's class guard fails on the corpus; `writesRelation` off the record fails the proxy test with the `aria-expanded` add and remove; the re-mark guard fails the docked reading with five same-value `class` writes over five beats. - `uv run pytest tests` — 864 passed, 6 skipped, on this head with main merged in. `tests/test_render_margin.py` — 76 passed. `tests/test_render_controls.py tests/test_render_widgets.py tests/test_render_drafts.py tests/test_render_options.py --run-nightly` — 268 passed, 1 failed: `test_a_comment_inside_a_widget_stays_out_of_what_the_widget_reads`, which fails identically with this branch's runtime changes stashed and is red on main's own nightly at `9d8b83dd`. - `pre-commit run` on the changed files — clean. <details><summary>Two findings this branch does not fix, with their measurements</summary> **The layout pass measures in a modified DOM and restores it.** All three probes above are one shape, and it is `margin-layout.js`'s and `controlsShownByOwner`'s rather than this branch's. On the corpus at 1440×900 over five settled heartbeats they account for 350 records: 270 `class` on `.lf-margin-item` (the waiting clear and re-mark, 27 rows a beat — every row that page draws is withheld rather than docked, so both writes move a token), 70 `data-lf-button-primary` on `.lf-sug-reject` (7 controls a beat), and 10 `style` on `nav.lf-living-margin`. On the gallery the visibility probe alone is 188 pairs a beat. There is no cheaper end state for the last one while the margin reads a contributor's intent through a CSS rule it owns itself: the exemption and the fold flag are one attribute, so exempting a folded control is always a state change, and every ancestor-scoped alternative is either more records or a full-document style invalidation twice a pass. The change that closes it is a declared retraction rather than a computed-style probe, which is a change to what the margin measures. **The feature gallery never stopped rendering its margin — fixed on main by #298.** Measured at rest here before that landed, with nothing dispatched: 10 `lf-margin-layout` events over 10 frames, 1764 mutation records over the same window, and ~185ms a frame against the corpus's ~15ms. #298 took the render out of `dockSeats`; with main merged in, the same window on the gallery reports 0 layouts and 0 records, and reverting its one-line change here restores 10 and about 1700. That is what lets this branch take the settled reading on both pages. </details> --------- Co-authored-by: leaf-agent <[email protected]>
…frame (#394) ## Problem `ci` on main failed on [run 34084018735](https://github.com/max-sixty/leaf/actions/runs/34084018735) with 19 nightly failures. Most of them are the interaction gallery's contained frames taking the page's focus, which #383 fixes, and the reaction readings #371 retired, which landed as #385. Two survive on today's main (`e6adf0b2`) and neither is covered by either. `test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus` times out waiting for `pageSettled`, because the corpus never settles once the ring walk stands on a control in a docked margin cluster: `layoutMarginRows` floats that cluster out of static flow to read where it can hang and docks it back, a document tree has one focus, so the move blurs the control and the restore focuses it again — and `keyboard/dispatch.js` answers that pair by painting the standing chrome. That paint's layout asks for the next placement, so the page laid its margin out, rebuilt its whole key line and refolded its banner row on every frame for as long as the reader stood there. This is the second time this cycle has closed on a different edge; #298 cut the `dockSeats` one. #373 cuts the other edge of this same loop, and has the same ring test green: it keeps a docked row docked while the room it answered about holds, so `moveHost` is never reached in the case that loops. The two compose rather than compete — that one removes a caller's reason to move the host, this one stops any placement move from painting the standing chrome, so it also holds for the callers it does not touch (`float`, the inline `target.after`, and both branches of the Page-map render). Either can land alone and fixes the failing run; landing both is deliberate belt-and-braces, and neither is based on the other. `test_a_reload_mid_flight_never_wedges_round_trip` waits the corpus's whole answer-all cascade out inside one 30-second budget, and the corpus gained an ask in #354. The fact under test — that a ledger carried across a navigation does not wedge the new document — has already settled on that document's first trip. ## Solution `runtime.placingChrome` says a chrome placement is in flight, `moveHost` raises it around the move and the focus it hands straight back, and the focus painters skip while it stands. `moveHost` asks for the paint itself in the one case the placement really did move the reader: the control they were standing on did not survive it. The flag lives in `context.js` rather than beside `living-margin.js`'s existing `settlingOptionsFocus` because what has to know is every reader of where the reader stands, not just the options state machine. The gate test now waits for the new document's first trip rather than for its whole cascade, so the reading stops tracking how many asks the corpus happens to carry. It waits on the press's own attempt leaving the outbox's `pending`, which is delivery with retries folded in: `acked` is counted in a `finally` around the fetch, so a post that throws counts one and is retried, and an empty `pending` is only the momentary gap between the cascade's trips. ## Testing - `test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus`: red on `e6adf0b2`, green with this change. It is the gate — I could not reduce the cycle to a small fixture, and dropped a candidate regression test that passed with the change reverted rather than land coverage that says nothing. - `test_a_reload_mid_flight_never_wedges_round_trip`: red under `-n4` on `e6adf0b2`, green with this change. Its new reading still fails on a wedged first trip: with `/api/event` aborted on the reloaded document it gives up on `sends=16 acked=16 pending=1`, the shape `acked > 0` would have gone green on. - `uv run pre-commit run --all-files`. - The full `--run-nightly` run promised when this opened never got posted — that session ended before it finished. CI runs the nightly cases of `tests/test_render_gate.py` on this PR, the module it touches; the rest of the nightly suite the runtime change drives runs after main moves. <details><summary>How the cycle was found</summary> At the failing wait, `moving()` reported three running transitions on one `.lf-margin-button-label`, restarting continuously. A document-wide `MutationObserver` over one second on that page showed the whole chrome rebuilding at frame rate with nothing dispatched: 125 `lf-key` inserts and 125 removals, 52 `.lf-btn.lf-others` moves between `lf-banner-actions` and `lf-banner-menu`, 50 same-value `style` writes on `nav.lf-living-margin`, and 25 moves of one `.lf-margin-item.lf-docked` between `MAIN` and its `SECTION`. A stack captured inside a `focusout` listener named the mover: ``` at /runtime/living-margin.js:2073 | at moveHost (/runtime/living-margin.js:2379) | at moveExternalHost (/runtime/living-margin.js:2073) | at Object.float (/runtime/living-margin.js:1644) ``` with a second identical one from `Object.dock`, 50 focusouts per second between them, and `requestAnimationFrame` stacks from `paintHere` and from `layoutMarginRows`'s dispatch at 25 per second each. </details> --- Automated fix for [failed run](https://github.com/max-sixty/leaf/actions/runs/34084018735) --------- Co-authored-by: leaf-agent <[email protected]>
…frame (#394) ## Problem `ci` on main failed on [run 34084018735](https://github.com/max-sixty/leaf/actions/runs/34084018735) with 19 nightly failures. Most of them are the interaction gallery's contained frames taking the page's focus, which #383 fixes, and the reaction readings #371 retired, which landed as #385. Two survive on today's main (`e6adf0b2`) and neither is covered by either. `test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus` times out waiting for `pageSettled`, because the corpus never settles once the ring walk stands on a control in a docked margin cluster: `layoutMarginRows` floats that cluster out of static flow to read where it can hang and docks it back, a document tree has one focus, so the move blurs the control and the restore focuses it again — and `keyboard/dispatch.js` answers that pair by painting the standing chrome. That paint's layout asks for the next placement, so the page laid its margin out, rebuilt its whole key line and refolded its banner row on every frame for as long as the reader stood there. This is the second time this cycle has closed on a different edge; #298 cut the `dockSeats` one. #373 cuts the other edge of this same loop, and has the same ring test green: it keeps a docked row docked while the room it answered about holds, so `moveHost` is never reached in the case that loops. The two compose rather than compete — that one removes a caller's reason to move the host, this one stops any placement move from painting the standing chrome, so it also holds for the callers it does not touch (`float`, the inline `target.after`, and both branches of the Page-map render). Either can land alone and fixes the failing run; landing both is deliberate belt-and-braces, and neither is based on the other. `test_a_reload_mid_flight_never_wedges_round_trip` waits the corpus's whole answer-all cascade out inside one 30-second budget, and the corpus gained an ask in #354. The fact under test — that a ledger carried across a navigation does not wedge the new document — has already settled on that document's first trip. ## Solution `runtime.placingChrome` says a chrome placement is in flight, `moveHost` raises it around the move and the focus it hands straight back, and the focus painters skip while it stands. `moveHost` asks for the paint itself in the one case the placement really did move the reader: the control they were standing on did not survive it. The flag lives in `context.js` rather than beside `living-margin.js`'s existing `settlingOptionsFocus` because what has to know is every reader of where the reader stands, not just the options state machine. The gate test now waits for the new document's first trip rather than for its whole cascade, so the reading stops tracking how many asks the corpus happens to carry. It waits on the press's own attempt leaving the outbox's `pending`, which is delivery with retries folded in: `acked` is counted in a `finally` around the fetch, so a post that throws counts one and is retried, and an empty `pending` is only the momentary gap between the cascade's trips. ## Testing - `test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus`: red on `e6adf0b2`, green with this change. It is the gate — I could not reduce the cycle to a small fixture, and dropped a candidate regression test that passed with the change reverted rather than land coverage that says nothing. - `test_a_reload_mid_flight_never_wedges_round_trip`: red under `-n4` on `e6adf0b2`, green with this change. Its new reading still fails on a wedged first trip: with `/api/event` aborted on the reloaded document it gives up on `sends=16 acked=16 pending=1`, the shape `acked > 0` would have gone green on. - `uv run pre-commit run --all-files`. - The full `--run-nightly` run promised when this opened never got posted — that session ended before it finished. CI runs the nightly cases of `tests/test_render_gate.py` on this PR, the module it touches; the rest of the nightly suite the runtime change drives runs after main moves. <details><summary>How the cycle was found</summary> At the failing wait, `moving()` reported three running transitions on one `.lf-margin-button-label`, restarting continuously. A document-wide `MutationObserver` over one second on that page showed the whole chrome rebuilding at frame rate with nothing dispatched: 125 `lf-key` inserts and 125 removals, 52 `.lf-btn.lf-others` moves between `lf-banner-actions` and `lf-banner-menu`, 50 same-value `style` writes on `nav.lf-living-margin`, and 25 moves of one `.lf-margin-item.lf-docked` between `MAIN` and its `SECTION`. A stack captured inside a `focusout` listener named the mover: ``` at /runtime/living-margin.js:2073 | at moveHost (/runtime/living-margin.js:2379) | at moveExternalHost (/runtime/living-margin.js:2073) | at Object.float (/runtime/living-margin.js:1644) ``` with a second identical one from `Object.dock`, 50 focusouts per second between them, and `requestAnimationFrame` stacks from `paintHere` and from `layoutMarginRows`'s dispatch at 25 per second each. </details> --- Automated fix for [failed run](https://github.com/max-sixty/leaf/actions/runs/34084018735) --------- Co-authored-by: leaf-agent <[email protected]>
Problem
Main's nightly run 33950527888 failed 13 tests. Ten are already repaired on main by #286, #291 and #297; the three that remain are all on the feature gallery, and they share one cause: that page never stops rendering its margin, so its main thread runs back-to-back ~350ms tasks forever and every Playwright read of it waits on one.
The cycle is a layout hook that restates content.
syncLayoutends in the anchor runtime'sdockSeats, which calledrecord.margin.update()on every reaction seat;update()restates the offer, so it ran a full margin render; a margin render ends inpaintKeys, which ends inpaintHere, whose animation frame ends insyncLayout. Any page carrying a standing reaction closed that loop and ran a whole margin render every frame with nothing dispatched and nothing on the page moving. #289 measured the same thing from the other side and named it as a finding it did not fix.Solution
dockSeatsasks the margin to repack its rows —scheduleMarginLayout()— rather than to restate what the seats offer. That is what the hook is for: the chrome moved, so the rows a seat hangs in have to be packed again. The end state is the same pass the render was scheduling anyway, minus the render.test_a_settled_page_with_a_standing_reaction_stops_rendering_its_margincountslf-margin-layoutover 30 frames on a settled gallery and asserts at most one, which is the two-second heartbeat's share. It asserts the reaction seat first, because a page with no seat visits nothing indockSeatsand would pass saying nothing.How the cause was found, and the numbers
told()failed withwaiting for X, the page last applied X— the two readings equal. They were equal: the page had taken in what the server held, butpage.wait_for_functioncould not complete inside its 500ms round, because on that page a trivially truewait_for_functiontook ~700ms and a barepage.evaluate("() => true")took ~370ms. Alongtaskobserver on the same page reported ten consecutive tasks of 325–394ms over three seconds, with nothing dispatched.A CDP sampling profile named the loop:
and a stack capture on
paintHereclosed it: 42 of 48 calls over two seconds arrived frompaintKeysreached from that same margin render, i.e. one per frame.Bug-back on the new test with the one-line fix reverted: 30 margin layouts over 30 frames, against
<= 1. The suite is also faster where it touched the gallery — the seven tests #291 covers ran in 329s on main and 243s with this change.Testing
test_the_feature_gallery_exercises_core_reader_workflows,test_the_feature_gallery_exercises_live_and_snapshotted_external_data,test_r_immediately_opens_the_gallery_reactions_and_digit_chooses— passed. The first was reproducing on main before the change (121s, failing) and now passes in 18s.uv run pytest tests— 864 passed, 6 skipped.--run-nightlyontest_render_margin.py,test_render_anchors.py,test_render_navigation.py,test_render_reactions.py— 279 passed;test_render_aim.py,test_render_semantic_selection.py— 74 passed;test_render_controls.py,test_render_conversations.py,test_render_pages.py— 196 passed.pre-commit run --all-files— passed.Automated fix for failed run