Repository navigation
Write the margin's heartbeat names and states only when they change - #289
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
The write-on-change guards themselves check out: every keeps call site passes a string, getAttribute returns null for an absent attribute so the data-lf-offer empty-string case is right, classList.add does re-serialize the attribute so that guard earns its line, and nothing in the layer declares observedAttributes, so skipping a same-value write has no callback to lose. The two findings are both about the residue the PR says it leaves behind — one is more expensive than the body claims, and the test cannot see the half of the margin where the rest of it lives.
The aria-expanded seam is not inert — it repaints the key line every heartbeat. "What this does not close" frames it as 12 add/remove pairs of surplus mutation records. But leaf.js runs watchDisclosures(document), and disclosureWatch calls paintKeys() when any record's current value differs from its oldValue. The removal leg differs ("false" → null), so it passes that test. Measured on this head, corpus at 1440×900, over the same five heartbeats the new test uses: 280 records reach the watch, 140 of them read as news, all aria-expanded on .lf-margin-marker. Every heartbeat therefore runs a full paintKeys() — pruneScopedElements, a walk of every scopeRefs weak ref, reflectShortcuts, paintHere — on a page nobody has touched. That is the defect the comment above disclosureWatch says reading the old value closed, and skills/leaf/CLAUDE.md restates as "the page runs at its refresh rate with nobody touching it". It also needs less intent than the body says: the pass's own end state on these markers is no aria-expanded, since marginButton writes the disclosure default and syncThreadRelation(control, false) removes it two calls later in the same pass. What a thread-less disclosure should announce is a real question, but not one this needs answered — one writer owning the attribute gets the same end state.
The new test is blind to more than half the margin. Its roots are nav.lf-living-margin and .lf-page-map-toggle, but render docks every host with entry.offers.length outside the nav, beside its external perch (dock.after(host)). On the corpus at 1440×900 that is 16 of 28 hosts, and nothing under them is watched. Re-running the test's own restatement predicate against a document-wide observer over the same five heartbeats finds, from this file's own writers: data-lf-external × 80 (host.dataset.lfExternal = "1" in render, three lines below one of this PR's edits), aria-label and aria-disabled × 35 each on the option proxies (syncForwardedButtonState, which forwards unconditionally), and data-lf-button-primary × 80 (controlsShownByOwner's measurement set/restore, a set/restore pair like the one above rather than a writer restating itself). So restated == [] is a statement about the nav, not about the margin, and the docstring's "as is the one attribute two writers disagree over" reads as completeness it does not have. tests/CLAUDE.md names this shape directly: "A reading blind to one mechanism does not report that it is blind — it returns the same clean result it returns when nothing is wrong — so a green corpus is not evidence of a clean corpus. Assert a gate's reach the way its population is asserted."
Neither is a regression — both are true of main too, and everything the PR does change is an improvement. What makes them worth raising is that the PR reasons about exactly this residue and lands on a smaller account of it than the page gives.
How the numbers were taken
Both on 668fb47d with the branch applied, corpus at 1440×900 after margins_laid_out, five lf-actions dispatches — the same fixture, viewport and refresh count as the new test.
Watch news, replaying disclosureWatch's own filter:
const watch = new MutationObserver(records => {
seen.push(records.filter(r => r.target.getAttribute(r.attributeName) !== r.oldValue).length);
});
watch.observe(document, {subtree: true, attributeFilter: ['open', 'aria-expanded'], attributeOldValue: true});One batch of 280 records, 140 news, every sampled one {attr: 'aria-expanded', old: 'false', now: null, on: 'lf-margin-marker lf-ui lf-margin-button'}.
Restatements the test's roots miss, document-wide observer under the test's own said predicate, tallied by class and attribute:
115 lf-pick lf-ui @aria-disabled (outside this file)
115 lf-pick lf-ui @tabindex (outside this file)
80 lf-ui lf-margin-item lf-waiting @data-lf-external living-margin.js render
35 lf-margin-option-proxy … @aria-label syncForwardedButtonState
35 lf-margin-option-proxy … @aria-disabled syncForwardedButtonState
35 lf-margin-option-proxy … @data-lf-button-owner optionControlNode
80 @data-lf-button-primary (draft-pencil, sug-accept, shot-toggle) controlsShownByOwner
Attribution for the setAttribute half came from patching Element.prototype.setAttribute and reading the first living-margin.js frame off the stack; data-lf-external goes through the dataset setter, so it shows only in the observer tally.
uv run pytest --run-nightly tests/test_render_margin.py -k "restates_no_margin_name or bounded_by_refresh_count" — 2 passed, on this head.
`marginButton` wrote the disclosure default `aria-expanded="false"` on a reading, and `syncThreadRelation` stripped it two calls later in the same pass because the marker opens no thread. The removal leg differs from its old value, so `leaf.js`'s disclosure watch read it as news and ran a full `paintKeys()` on every heartbeat: 140 news records over five refreshes on the corpus at 1440×900, all `aria-expanded` on `.lf-margin-marker`. The end state on these markers is no `aria-expanded` either way, so `syncThreadRelation` is now the one writer of a reading's relation. The heartbeat test watched `nav.lf-living-margin` and the Page-map button, but `render` docks every host with offers beside its own perch out in the document — 16 of the corpus's 28 hosts. Rooting the watch at every host as well found 336 more restatements from `render`'s `data-lf-external`, the option proxies' unconditional forwarding, `optionControlNode`'s owner attribute, `controlsShownByOwner`'s measurement exemption, and the draft pencil's reach state. The test now asserts the reach the way it asserts the population, and reads the disclosure watch's own news beside the restatements, which no restatement predicate can see. `keeps` moves to `widget-elements.js` and joins the widget API, because the draft pencil is a module and a module does not duplicate a runtime helper.
leaf-agent
left a comment
There was a problem hiding this comment.
Both findings from the previous pass are closed, and I checked them rather than took the replies for it. A document-wide observer on the corpus at 1440×900, over the same five heartbeats, now reports zero restatements on any node this file writes — the 465 that remain are lf-pick, lf-btn, lf-grip and lf-operation-status, all outside living-margin.js — and zero open/aria-expanded news, so paintKeys() no longer runs on an untouched page. The reach assertion is the right shape: 28 hosts on that corpus, 16 of them docked outside the nav, and docked >= hosts / 2 fails rather than returning a clean [] if the watch ever stops covering them.
Two seams left, plus one thing the new test's fixture cannot reach.
Two heartbeat writers in this file are still unguarded, and the corpus cannot see either. The rule this PR adds to skills/leaf/CLAUDE.md — "Write a name or state through keeps(node, name, value) wherever the render runs on the lf-actions heartbeat" — is broken twice in living-margin.js itself. readingOptionNode writes node.dataset.lfKinds = choice.kind and node.setAttribute("aria-label", …) unconditionally, and syncInlineOffers — which render calls on every pass — writes host.dataset.lfMarginFor and the host's aria-label the same way. Neither is a regression, and neither fires here: the corpus at 1440×900 renders 0 .lf-margin-reading-option nodes and 0 inline hosts, which is why restated == [] holds. But a page with secondary readings, or with a widget frozen into a conversation, restates those on every heartbeat, and the inline hosts are div.lf-ui rather than .lf-margin-item, so they sit outside the new test's roots even when they exist. That is the same blindness as last pass in a new place — worth saying because the docstring and the thread reply both read as an account with nothing left over.
How the numbers were taken
On the merge commit for 161d081e, corpus at 1440×900 after margins_laid_out, five lf-actions dispatches — same fixture, viewport and refresh count as the new test. Observer rooted at document with the test's own said predicate, tallied by class and attribute, then split by whether the target is inside the test's roots:
50 lf-btn lf-operation-press lf-ui @aria-disabled
50 lf-btn lf-operation-press lf-ui @tabindex
20 lf-operation-status lf-ui @hidden
115 lf-pick lf-ui @aria-disabled
115 lf-pick lf-ui @tabindex
45 lf-btn lf-ui @aria-disabled
35 lf-grip lf-ui @aria-disabled
35 lf-grip lf-ui @tabindex
All 465 are outside the test's roots and outside this file. Nothing living-margin.js writes appears. Population on the same page: 28 .lf-margin-item, 0 .lf-margin-reading-option, 0 inline div.lf-ui[data-lf-margin-for].
`keeps` compared the caller's value against what `getAttribute` reads back, so a
boolean or a count handed over raw was never equal to the attribute already
standing and rewrote on every pass. It stringifies once now, and the four call
sites that were wrapping in `String(...)` hand their values over as they hold
them.
`marginButton` decided whether to write the `aria-expanded` default from the
role, but the role is not the writer: `reading` is a published `BUTTON_ROLES`
member, so a module contributing `{behavior: "disclosure", role: "reading"}`
through the widget API opted out of the default with no `syncThreadRelation`
behind it. The call now declares `writesRelation`, true by default, and the
margin's three reading fittings pass `false`.
Five more heartbeat writers in `living-margin.js` restated: `readingOptionNode`'s
`data-lf-kinds` and `aria-label`, `syncInlineOffers`' `data-lf-margin-for` and
`aria-label`, `marginButtonState`'s `aria-busy`, `buildThreadCard`'s
`data-lf-thread` and `aria-label`, and the two `tabindex` writes — the status
seat and the roving stop — which the corpus fixture could not see.
The heartbeat test reads a second page for that reason: the developer feature
gallery draws the reading option and the status readings the corpus has none of,
where the `tabindex` pair was restating 15 times per five heartbeats. Each page
names the population it is there for, and the watch is rooted at the inline
hosts too, which no shipped page draws at rest.
|
Both writers are guarded, and the fixture blindness is closed by reading a second page beside the corpus rather than by asserting harder on the corpus.
So the heartbeat test now runs on the corpus and that gallery, each naming the population it is there for — 28 items and the docked reach on the corpus, a reading option and the status readings on the gallery, since the corpus draws neither. The inline hosts are rooted too ( Measurements and bug-backsSame method as before: corpus and On the head you reviewed ( Population there: 17 margin items, 13 of them docked, 1 Bug-backs on this head, each reverting one guard with the rest in place:
|
leaf-agent
left a comment
There was a problem hiding this comment.
Both findings from the last pass are closed, and I read the guards rather than took the replies for them: keeps stringifies, the five leftover writers route through it, and writesRelation names the writer instead of inferring it from the role. What I can't confirm is the account the PR ends on — "336 → 0 restatements, nothing left over to name". The reading that carries that claim can't see the half of the render that runs in a frame callback, and two of this PR's own guards land there.
The five dispatches run in one synchronous task, so no requestAnimationFrame callback runs inside the measured window. render's tail is scheduleMarginLayout(); scheduleRoving(); scheduleButtonLabels(); — every one of those is an rAF body, and none of them runs between dispatchEvent calls in a for loop. observer.takeRecords() is read before the frame ever comes, so the window the test measures is render's synchronous half alone.
Letting the frame settle between beats — same corpus, same 1440×900, same five lf-actions, same roots, same said predicate — reports 625 records over five heartbeats, 135 of them same-value restatements the predicate is written to catch:
135 RESTATED .lf-margin-item @class "lf-ui lf-margin-item lf-waiting" -> same
135 CHANGED .lf-margin-item @class "lf-ui lf-margin-item" -> "... lf-waiting"
135 CHANGED .lf-margin-marker @tabindex -1 -> 0
135 CHANGED .lf-margin-marker @tabindex 0 -> -1
35 CHANGED .lf-sug-reject @data-lf-button-primary (add)
35 CHANGED .lf-sug-reject @data-lf-button-primary (remove)
10 CHANGED nav.lf-living-margin @style height: 10288px <-> 2882px
Drop the dispatches and hold the same wall time and the corpus reports 0 records, so every one of these is the heartbeat's rather than ambient.
Two of them are this PR's own guards going inert:
holdTabStop'skeeps(row, "tabindex", …).paintMarkercallsmarginButtonon every marker each pass and markers are spans (readingControlisoffer("span", className)), so the non-status branch'sif (control.tabIndex < 0) control.tabIndex = 0;writes0on every non-stop marker before the frame'sholdTabStopwrites-1back. 27 markers on the corpus, 54 records a heartbeat, forever. The guard only ever compares against a valuemarginButtonjust changed.controlsShownByOwner'stoggleAttribute("data-lf-button-primary", true). The thread reply reads it as "writes nothing where there is nothing to change", but the restore below removes the flag, so it never already stands: 7 add/remove pairs a heartbeat on the corpus, 188 a heartbeat on the gallery.
Neither is a regression — both mechanisms are main's, and everything this PR does change is an improvement. What makes them worth raising is that this is the third pass where the reading returns the clean [] it returns when nothing is wrong, and the docstring reads as an account with nothing left over. tests/CLAUDE.md's rule reaches the frame the same way it reached the docked hosts. Two readings would close it: let a frame run between beats, and count a value written and unwritten inside one pass — the same reading this PR already argues for on aria-expanded, since neither leg restates anything.
How the numbers were taken
On the merge commit for 126a1ac8, corpus at 1440×900 after margins_laid_out, five lf-actions dispatches — the test's own fixture, viewport and refresh count, its roots (nav.lf-living-margin, .lf-page-map-toggle, every .lf-margin-item, every inline host) and its said predicate. The only change is page.wait_for_timeout(150) after each dispatch instead of a synchronous loop, and the records are collected from the observer callback rather than takeRecords().
Control: the same run with the dispatches removed and the same 750ms of wall time reports 0 records on the corpus. The gallery is not usable for this — it reports 671 records with no dispatches at all, so its churn is not all the heartbeat's.
data-lf-button-owner also restates 72 times on the gallery over the same window (validateMarginControls's control.dataset.lfButtonOwner = offered.key, the one writer of that attribute this PR left unguarded), but the gallery's ambient churn accounts for 48 of them, so I'd take that one on a quieter page before calling it.
…ert there The restatement watch dispatched five refreshes in one synchronous task, so `render`'s tail — `scheduleMarginLayout`, `scheduleRoving`, `scheduleButtonLabels`, every one an rAF body — never ran inside the measured window. The corpus now lets a frame settle between beats and reads the pass whole, and asks one question of it rather than two: what the pass 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 two writers taking turns are one reading there, and the turns are what no restatement predicate can take. That reading found two of this branch's own guards comparing against a value another writer had just moved. `marginButton` seated every non-status marker at `tabindex="0"` each pass and the frame's `holdTabStop` wrote `-1` back: 270 records over five heartbeats on the corpus, all on `.lf-margin-marker`. `writesSeat` declares the writer the way `writesRelation` does, and the two markers pass it, because the role cannot stand in for it — a marker and a reading option wear the same one and only the marker is a row. `writesRelation` also stopped at the call site, so `optionControlNode` re-inferred the default when it rebuilt a Button from its record: the proxy took the disclosure default, wrote `aria-expanded`, and `syncForwardedButtonState` read `null` off the source and stripped it the same pass. It is on the record now and the proxy takes it from there. What remains on the settled reading is not a name restated. Each is a probe that modifies the DOM to measure it and puts it back — the layout pass clearing a row's docked and waiting classes, its second reading of the rail, and `controlsShownByOwner` lifting the fold rule off a contributed control. The test names all three rather than filtering them, and asserts the named set for reach, so a new unchanged write cannot arrive unnamed and a run that stopped letting the frame run cannot return a clean `[]`. One of them wrote where nothing moved: `layoutMarginRows` cleared classes off rows carrying neither, and `remove` re-serializes the attribute either way. The gallery keeps the synchronous reading, for the fittings the corpus has none of. Its own margin never settles — measured, `render` runs about seven times a frame through `changedOffers` on an untouched gallery, and ten frames report 1764 records with nothing dispatched at all — so the frame's writers are the corpus's reading to take.
leaf-agent
left a comment
There was a problem hiding this comment.
The frame half reads now, and both guards the last pass named as inert are closed — I checked them rather than took the body for it. writesSeat: false on the two markers takes the seat write out of marginButton, leaving holdTabStop's keeps(row, "tabindex", …) over rows.values() as the only writer of a row's seat, and the two writesSeat: false call sites are the only ones, both readingControl(...) spans that land in rows. optionControlNode passes record.writesRelation through, so the proxy no longer re-infers the disclosure default and syncForwardedButtonState has nothing to strip. The probe table with its set-equality reach assertion is the right shape: closing a probe turns the test red rather than passing quietly.
Two things on the reading itself.
The class probe matches more than the clear it names. record.target.className is the row's class at read time, and a docked row carries lf-docked for the whole pass, so the predicate holds for any same-value class write on a .lf-margin-item that is docked or waiting — which on the corpus is more than half of them, by the test's own docked >= hosts / 2. The inner comment says the tokens have to be in play, but what it tests is that they are standing, not that this record is one leg of the clear and re-add. So the docstring's "a new unchanged write cannot arrive unnamed" holds for the style and data-lf-button-primary probes and not for this one: a future class writer on a docked row arrives filed under margin-layout's measurement. Nothing writes class on a margin item on the heartbeat today besides layoutMarginRows — registerMarginItem's lf-margin-contribution add runs once, at registration — so this is reach rather than a live miss. Tightening it means asking whether the pass saw the row both with and without the tokens, rather than asking what it carries at the end.
The layout test's inert collector is inline below.
Four earlier threads are closed by this commit and I've resolved them: the synchronous-window one (the corpus settles frames now), the marker seat, the proxy relation, and the controlsShownByOwner toggle — that last one on the argument rather than a fix, and the argument holds: the exemption has to be written across the whole batch before the first getComputedStyle, so not writing it is not measuring.
Two readings in the margin tests reported clean for a reason other than the one they name. The heartbeat test filed a `class` record under margin-layout's measurement probe when the docked or waiting tokens were in play, read off the record's old value or the row's class at read time. A docked row carries those tokens from one end of the pass to the other, so any same-value `class` write on it — from a writer with nothing to do with the measurement — arrived named. Each record now carries what its write said: a record holds the value it replaced, so the next write of that attribute holds this one's result and the last write's result is what the attribute reads now. The probe is then the write that moved a token, which the clear and the re-mark each do and a restatement does not. The layout test collected records into `seen` and never read it, counting `observer.takeRecords()` alone. That is the whole reading today, because nothing awaits after the observer is created, but it is the inert-guard shape: letting a frame settle there sends the records to the callback and `takeRecords()` returns 0 with the measurement gone. It reads both now. Bug-backs: a foreign same-value `class` write on a token-carrying row is unnamed here and was filed under the probe by the old predicate; a write inside a frame callback with a settle before the read is counted here and invisible to `takeRecords()` alone. `uv run pytest tests` — 830 passed, 6 skipped. `uv run pytest tests/test_render_margin.py --run-nightly` — 73 passed.
|
Both are closed on The class probe is now asked of the write, not the row. Asking whether the pass saw the row both with and without the tokens still files any same-value Bug-back, on the corpus with everything else in place: a foreign The collector finding is answered on its own thread — the fix is to read Bug-backs and runsBoth on Class probe — injected before the observer in document.addEventListener('lf-actions', () => {
const row = document.querySelector(
'.lf-margin-item.lf-docked, .lf-margin-item.lf-waiting');
if (row) row.setAttribute('class', row.getAttribute('class'));
});Per-write predicate: red on the corpus, five Layout collector — injected into requestAnimationFrame(() => document.querySelector('.lf-margin-button')
?.toggleAttribute('data-lf-button-primary'));
for (let i = 0; i < 5; i++) layoutMarginRows();
await new Promise(resolve => requestAnimationFrame(() => setTimeout(resolve, 0)));
Runs on this head: |
leaf-agent
left a comment
There was a problem hiding this comment.
Both findings from the last pass are closed, and I read them rather than took the replies for them. The class probe is per-write now and the reading behind it holds: a record carries the value it replaced, so the next record for that (target, attribute) carries this one's result and the last one's result is what getAttribute reads back — and the whole walk stays inside one synchronous stretch after seen.splice(0), so nothing can move under it. hangs(record.oldValue) !== hangs(pass.wrote.get(record)) is then exactly "this write moved a token", which a restatement cannot be, so the tightening adds no false naming either. The layout test reads its collector.
One finding, and it is the same shape as the four before it — a reading that returns [] because its fixtures cannot reach the state.
layoutMarginRows guards the clear and not the re-add, and a row whose posture does not change restates its class every pass. The guard this commit adds is right about remove re-serializing the attribute whether or not the tokens stand — and add does the same thing. staysDocked rows take the continue above the guard, so they never reach the clear, and then land on row.classList.add("lf-docked") in the placement loop with lf-docked already standing. That is a same-value class write per docked row per layout pass, and render's tail schedules a layout on every beat.
The state is not exotic: hangs is () => !compact.matches and COVERING is (width <= 840px) (PANEL_W * 2), so on any window at or under 840px every shown row's hangs is false, every one of them docks, and every one of them is staysDocked on the next pass. Measured on examples/developer/feature-gallery.html at 800×900 over five settled heartbeats: 130 same-value class writes on .lf-margin-item.lf-docked, 13 docked rows, every one attributed to margin-layout.js line 177 by patching DOMTokenList.prototype.add. The fix is the guard three lines up, written the other way round.
What makes it worth raising rather than leaving as residue is that the new test cannot see it and its probe table reads as though it could. The corpus draws zero .lf-margin-item.lf-docked at 1440, 800 and 600 — 27 of its 28 items are lf-waiting, so the clear-and-re-mark pair the class probe names is the waiting leg, and the docked leg of that probe never runs on any fixture in this test. The one fixture that docks is the gallery, and it is read with settles: False, so layoutMarginRows never fires inside its window at all. So unnamed == [] is a statement about a page with no docked rows, and the docstring's "a new unchanged write cannot arrive unnamed" is untested for the half of the probe it is written about.
One caveat I could not close: the gallery renders continuously — which this PR's own body documents — and a no-dispatch control over the same window reports the same 130, so I cannot attribute them to the heartbeat on that page. The mechanism is the heartbeat's regardless, since render ends in an unconditional scheduleMarginLayout(); what I could not find is a fixture that both docks and comes to rest, which is the same gap as the one above.
How the numbers were taken
On the merge commit for 7f99b899, open_page + resized + margins_laid_out, five lf-actions dispatches with two frame() settles between beats — the test's own roots (nav.lf-living-margin, .lf-page-map-toggle, every .lf-margin-item, every inline host), its opened/wrote walk, and its three probe predicates copied verbatim, reporting the rows that come back unnamed.
corpus 1440x900 docked 0 waiting 27 items 28 unnamed 0
corpus 800x900 docked 0 waiting 28 items 28 unnamed 0
corpus 600x900 docked 0 waiting 28 items 28 unnamed 0
gallery 800x900 docked 13 waiting 4 items 17 unnamed 264
The gallery's 264, by target and attribute:
130 lf-ui lf-margin-item lf-docked @class
120 lf-react-mark lf-ui lf-margin-button @data-lf-button-owner
14 lf-ui lf-reacts lf-margin-contribution @data-lf-for
Every sampled class row is {old: "lf-ui lf-margin-item lf-docked", set: "lf-ui lf-margin-item lf-docked"} — a write whose before and after both carry the token, which is why the per-write predicate correctly declines to name it.
Attribution, with DOMTokenList.prototype.add wrapped to record a stack whenever every token it is handed is already present:
lf-docked :: at DOMTokenList.add | at layoutMarginRows (…/runtime/margin-layout.js:177:23)
Control: the same run with the dispatch removed and the same wall time reports the same 264, so the gallery is not a page this can be attributed on. The corpus is, and it never reaches the state.
`layoutMarginRows` reads the standing posture before it clears anything and leaves a row that still cannot hang where it is, so that row skips the clear and reaches the placement loop already carrying `lf-docked`. `add` re-serializes `class` whether or not the token is new, and this pass runs on the heartbeat through `render`'s tail, so the mark restated itself once per docked row every two seconds: a mutation record for a row that did not move. The guard the clear already carries, written the other way round, and applied to the waiting marks beside it so the three sites read alike. Neither page the heartbeat reading is taken on can state it. The corpus stands still but hangs every row it draws, and the compact posture that would dock them withholds them as `lf-waiting` instead; the gallery docks thirteen rows and never comes to rest. So the posture is reached directly: under `COVERING` a contributed row cannot hang whatever the local room, and a page with one target settles. Measured on that fixture without the guard, five beats wrote `class` five times; with it, none. The narrowing is read too, so the guard cannot cost the mark.
|
Fixed in fe831c6. The reading holds, including the part that made it worth raising: the corpus at 1440 draws no docked row, so
Verification
The corpus's 270 |
leaf-agent
left a comment
There was a problem hiding this comment.
The guard checks out and I read it rather than took the body for it. mark is an exact-token contains before add, the three sites it replaces are the only classList.add on this path, the clear below already asks the same question the other way round, and unregisterMarginRow's clear is off the heartbeat. Bug-back on this head — the three mark(...) calls reverted to classList.add with the rest of the branch in place — turns test_an_unchanged_heartbeat_re_marks_no_docked_row red with five {'was': 'lf-ui lf-margin-item lf-docked', 'now': 'lf-ui lf-margin-item lf-docked'} rows, so the new fixture does reach the posture the corpus withholds and the gallery cannot be read at.
One finding, and it is the reach rule rather than the guard.
The new test's clean [] does not say the layout pass ran. marks == [] is what the window returns when the guard holds, and it is also what it returns when nothing inside the window ever reaches layoutMarginRows — the same reading either way, which is the shape tests/CLAUDE.md names: "A reading blind to one mechanism does not report that it is blind — it returns the same clean result it returns when nothing is wrong." Measured: with layoutMarginRows returning at its first line for the whole observed stretch, the test passes green. The sibling test above it is built the other way — its probe-set equality is what makes a run that stopped letting the frame run go red — so the docstring's "Measured on this fixture before the guard, five beats wrote class five times" is a fact about the run that took it rather than something this test restates.
layoutMarginRows ends in document.dispatchEvent(new CustomEvent("lf-margin-layout")), so one line of listener states it. On this fixture it reads exactly one pass a beat; under the same neutering it reads passes: 0 and the test is red. Suggestions inline.
How the numbers were taken
All on the merge commit for fe831c68, tests/test_render_margin.py --run-nightly -k re_marks_no_docked_row, one bug-back at a time with the rest of the branch standing.
The guard is load-bearing — mark(row, name) at the three call sites reverted to row.classList.add(name):
1 failed
+ {'was': 'lf-ui lf-margin-item lf-docked', 'now': 'lf-ui lf-margin-item lf-docked'}, × 5
The reading is blind to the pass — layoutMarginRows given if (window.__stopLayout) return; at its first line, with the test setting window.__stopLayout = true immediately before the observer:
1 passed
Same neutering with the suggested passes reading in place:
AssertionError: {'passes': 0, 'marks': []}
assert {'passes': 0, 'marks': []} == {'passes': 5, 'marks': []}
And with the neutering removed, the suggested form green at {'passes': 5, 'marks': []}. Removing scheduleMarginLayout() from render's tail is not a usable bug-back here, which is worth recording: the window still reports five passes, so the layout reaches the beat by a second route and that edit proves nothing either way.
The test's clean marks reading is what the window returns when the guard holds and also what it returns when nothing inside the window reaches layoutMarginRows. Count the lf-margin-layout the pass dispatches after the marks, so a window blind to the layout goes red instead of green.
# Conflicts: # skills/leaf/packages/default/widgets/lf-draft.js
# Conflicts: # skills/leaf/CLAUDE.md # skills/leaf/assets/runtime/living-margin.js
…action (#298) ## Problem Main's nightly run [33950527888](https://github.com/max-sixty/leaf/actions/runs/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. `syncLayout` ends in the anchor runtime's `dockSeats`, which called `record.margin.update()` on every reaction seat; `update()` restates the offer, so it ran a full margin render; a margin render ends in `paintKeys`, which ends in `paintHere`, whose animation frame ends in `syncLayout`. 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 `dockSeats` asks 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_margin` counts `lf-margin-layout` over 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 in `dockSeats` and would pass saying nothing. <details><summary>How the cause was found, and the numbers</summary> `told()` failed with `waiting for X, the page last applied X` — the two readings equal. They were equal: the page had taken in what the server held, but `page.wait_for_function` could not complete inside its 500ms round, because on that page a trivially true `wait_for_function` took ~700ms and a bare `page.evaluate("() => true")` took ~370ms. A `longtask` observer on the same page reported ten consecutive tasks of 325–394ms over three seconds, with nothing dispatched. A CDP sampling profile named the loop: ``` (anon)@living-margin.js:836 <- [email protected]:818 <- [email protected]:2164 <- [email protected]:26 <- [email protected]:128 <- [email protected]:375 <- [email protected]:1190 <- [email protected]:233 <- leaf.js:533 (the paintHere frame) ``` and a stack capture on `paintHere` closed it: 42 of 48 calls over two seconds arrived from `paintKeys` reached 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. </details> ## Testing - The three failures this fixes, on this branch: `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-nightly` on `test_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. - The new test, three consecutive runs — passed. - `pre-commit run --all-files` — passed. --- Automated fix for [failed run](https://github.com/max-sixty/leaf/actions/runs/33950527888) Co-authored-by: leaf-agent <[email protected]>
#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.
|
#298 landed, and it falsified this branch's committed reading of the gallery. The gallery was here on That reading exposes a fourth measurement the corpus cannot give. Two gallery rows stand where they would overlap, so Measurements and runsAt 1440×900, Bug-backs, each with the rest of the branch in place:
Runs on |
leaf-agent
left a comment
There was a problem hiding this comment.
The layout-pass reading is closed and I checked it rather than took the commit message for it: passes counts lf-margin-layout, which layoutMarginRows dispatches after the marks, so the neutered-layout window that used to return the same clean reading a guarded one does now returns {'passes': 0, 'marks': []} against an expected {'passes': 5, 'marks': []}.
The settled gallery reading is the stronger one and its shape holds. Dropping settles for a per-page measurements set is not just a swap: the old form asserted the observed probes equalled every declared probe on the one settled page, which a probe no page reaches would have broken; the new form asserts observed equals the page's declared set, so a probe that fires anywhere must be declared there — a fifth probe entry that starts matching turns its page red instead of quietly absorbing a write, and a run that stopped settling returns set() against a non-empty expectation. row push is asked of the write for the same reason the posture probe is, so a restated top from another writer still arrives unnamed.
One nit inline. Note that tests/test_render_margin.py carries a module-level pytestmark = pytest.mark.nightly, so this PR's green test check deselects the whole file — the evidence for the increment is your own tests/test_render_margin.py run, not CI.
The comment said 28 items two lines before saying 29 of the 31 it draws wear `lf-waiting`. Measured on this head at 1440x900: 31 items, 29 waiting.
Problem
The living margin's
renderis bound to thelf-actionsheartbeat, 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 defectdecisions/view.jsalready names — 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'sdisclosureWatchreads as news.marginButtonwrote the disclosure defaultaria-expanded="false"on a reading andsyncThreadRelationstripped it two calls later, so an untouched page ran a fullpaintKeys()on every heartbeat: measured, 140 news records over five refreshes, every onearia-expandedon.lf-margin-marker.Solution
keeps(node, name, value)andkeepsHidden(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'sdata-lf-external,syncForwardedButtonState's proxy forwarding,optionControlNode's owner attribute,readingOptionNode's andsyncInlineOffers' kinds and labels,marginButtonState'saria-busy,buildThreadCard's thread and label, andlf-draft's pencil, Save and restore reach.keepslives inwidget-elements.jsand 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.
marginButtontakeswritesRelationandwritesSeat, both true by default. The margin's threerole: "reading"fittings declare the relation away, and its two markers declare the seat away as well:syncThreadRelationdecidesaria-controlsandaria-expandedtogether and removes both when the reading opens no thread, andholdTabStopwrites every row'stabindexon the frame after each pass. The role could not stand in for either —readingis a publishedBUTTON_ROLESmember, and a marker and a reading option wear the same one while only the marker is a row.writesRelationis carried on the Button record, becauseoptionControlNoderebuilds 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 atoggleAttribute, 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
renderruns in a frame callback —scheduleMarginLayout,scheduleRovingandscheduleButtonLabelsare 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. RevertingholdTabStop'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:
margin-layout.jsmargin-layout.jsmargin-layout.jscontrolsShownByOwnerThe 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
topor 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 —layoutMarginRowscleared the classes off rows carrying neither, and marked a row the posture read had already left docked — andaddandremovere-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 aremain'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_nameroots its watch at every.lf-margin-itemand 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_forstates the proxy seam, which no shipped page draws.test_an_unchanged_heartbeat_re_marks_no_docked_rowstates 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 aslf-waitingrather 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 wearslf-docked. A page with one target underCOVERINGdocks and settles, so the reading can be taken. It reads the narrowing too, so the guard cannot cost the mark.keepswithout theStringfails on both pages;writesSeatfails 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;writesRelationoff the record fails the proxy test with thearia-expandedadd and remove; the re-mark guard fails the docked reading with five same-valueclasswrites 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 at9d8b83dd.pre-commit runon the changed files — clean.Two findings this branch does not fix, with their measurements
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 andcontrolsShownByOwner's rather than this branch's. On the corpus at 1440×900 over five settled heartbeats they account for 350 records: 270classon.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), 70data-lf-button-primaryon.lf-sug-reject(7 controls a beat), and 10styleonnav.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-layoutevents over 10 frames, 1764 mutation records over the same window, and ~185ms a frame against the corpus's ~15ms. #298 took the render out ofdockSeats; 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.