Skip to content

Read the pointer where the browser dispatched the press from - #48

Merged
max-sixty merged 7 commits into
mainfrom
fix/ci-32988551776
Aug 26, 2026
Merged

max-sixty merged 7 commits into
mainfrom
fix/ci-32988551776

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The runtime keeps one record of where the pointer is, and every consumer of it asks a hit-test question: what a press would take (aimedItem), whether a mark is under the hand (refreshHover's markAt), design mode's target. That record was kept from mousemove, and Chromium rounds a legacy mouse event's clientX/clientY to whole pixels while carrying the true position on the pointer events. Measured on the page that first showed this: pointerdown reports 400.5, 2301.2734375, mousedown reports 400, 2301. So the record is an answer about a place the pointer is not, and within a pixel of a seam that place is a different item.

It surfaced as red ci: on design-decision.html the sweep aims at a choose group's centre, y = 474.2734, while the browser puts the cell boundary at 474.109 — so an ⌥-press landed on opt-redis while the outline, asked at the rounded 474, was drawn on opt-jwt. f72029b widened --lf-address-col from 30px to 36px, which reflowed the options and moved that centre 0.8px inside the boundary. Nothing about the aim changed; the seam moved under it.

That half is already closed on main. a2318a1 takes the press from aimedItem() rather than the pointerdown target, so the outline and the press can no longer disagree — they are one reading asked twice. What it does not do is make that reading the browser's own: both now answer at the rounded point, so within a pixel of a seam the reader is shown the wrong item and the press faithfully takes the wrong item. markAt and design mode's target have no second reading to be made to agree with at all.

Solution

Record the pointer from pointermove rather than mousemove, in both writers of that record (runtime/anchors.js and leaf.js), so the position every hit test is asked at is the position the browser hit-tests with. The two comments that named the old event are updated with it.

The alternative — having the press ask elementFromPoint too — was rejected here because it would make an ⌥-press take a different item than an ordinary click at the same spot; a2318a1 solved that side differently, and the two changes compose.

Testing

test_the_aim_reads_the_pointer_where_the_press_is_dispatched_from holds a seam under the aim on purpose, rather than relying on the corpus landing near one. A fixed box puts a boundary between two whole pixels, AIM_SEAM binary-searches the browser's own hit test for it, and the aim lands within a quarter pixel of it — the point is the midpoint of the seam and the whole-pixel boundary rounding turns at, so the true point and its rounded twin are on opposite sides. Which of the two is over which item follows where in the pixel the seam fell, so the item the aim is held to is read off the point rather than named; the disagreement itself is asserted first, so a seam that drifted onto a whole pixel fails the test rather than leaving it proving that two agreeing readings agree.

Bug-back, measurements and runs

Reverting the two recorders to mousemove — with a2318a1 in the tree — still fails the new test, and fails it at the promise:

>       expect(page.locator(".lf-aim")).to_have_attribute("data-for", seam["at"])
E       AssertionError: Locator expected to have attribute 'seam-lower'
E       Actual value: seam-upper

The fixture's numbers, taken in a headless Chromium running AIM_SEAM's search verbatim: the hit test stops answering seam-upper at 319.3125 — .31 of the pixel, and 0.98px above that box's own bottom edge (320.296875), which is the hit-region slack the seam is searched for rather than computed from. The point the search returns is 319.40625, 0.094px past the seam, at: seam-lower / rounded: seam-upper.

Rebased onto main at 5d1d383, so this is verified against the tree that contains a2318a1:

  • tests/test_render_controls.py -k aim — 19 passed at -n0, including test_an_aimed_press_does_only_what_the_outline_promised over all ten corpus pages
  • pre-commit — passed

The full --run-nightly suite runs on this PR.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

ci failed again on main with the same assertion this PR fixes — run 32991903552, on 0ec78ba ("Move design mode into its runtime owner"), which predates the commit here:

FAILED tests/test_render_controls.py::test_an_aimed_press_does_only_what_the_outline_promised[design-decision]
AssertionError: ⌥-clicking lf-options "Where should a session l" in design-decision.html promised opt-jwt and commented on opt-redis
assert 'opt-redis' == 'opt-jwt'

Same test, same page, same pair of items, and the rest of the suite green (1 failed, 1243 passed) — consistent with the seam diagnosis in the PR body rather than anything the design-mode move touched. That makes five consecutive red commits on main for this one assertion.

No action needed here; recording the recurrence so the run isn't diagnosed a second time.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Two further commits carry the same single failure — run 32992750676 on 442677a and run 32992796142 on e897769 — each 1 failed, 1243 passed on test_an_aimed_press_does_only_what_the_outline_promised[design-decision], promised opt-jwt and commented on opt-redis. That is six consecutive commits on the same assertion.

Worth recording because those commits are the runtime refactor moving code out of leaf.js, which is one of the two files this PR patches: the fix could have been dislodged without conflicting. It wasn't. On today's main head 8c7ee7b both recorders are still at their sites — leaf.js:3307 and runtime/anchors.js:1061 — and the API reports this PR MERGEABLE against it. No rebase needed.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

A fifth commit carries it — run 32993716700 on 1444a2f ("Move the selection composer into its runtime owner"), again 1 failed, 1243 passed on test_an_aimed_press_does_only_what_the_outline_promised[design-decision] with the same promised opt-jwt and commented on opt-redis. ci on main's current head 8c7ee7b is still running.

The reason for saying so rather than just adding a tally row: the four commits since this PR's base are a refactor series moving code out of leaf.js into runtime owners, which is the file one half of this patch edits. As of 8c7ee7b both recorders are still where the patch puts its hands — leaf.js:3307 and runtime/anchors.js:1061 — and GitHub still reports the PR MERGEABLE, so the series has not dislodged it yet. Each further move through that file is a chance it does.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff and the pointer path around it. The fix reads correct to me: every consumer of the pointer record asks a hit-test question — aimedItem's elementFromPoint, design mode's designTarget(document.elementFromPoint(...)), refreshHover's markAt — so fixing the recorder rather than the press is the right depth, and it leaves an ⌥-press taking the same item an ordinary click at that spot would. ci is green on this head including --run-nightly, so the corpus assertion that has been red on main passes here. Commenting rather than approving because GitHub rejects self-approval.

On the drift the tally comments above raise: the refactor series has not reached either hunk. main's current head 8c7ee7b still has both recorders where this patch edits them — document.addEventListener("mousemove", ...) in leaf.js and in runtime/anchors.js — and GitHub reports the PR MERGEABLE, so the patch still lands on the live listeners rather than on a copy left behind.

One behaviour the description doesn't name: pointermove fires in gestures where mousemove was suppressed. Cancelling a pointerdown takes the compatibility mouse events with it, and the panel-edge resize handle does exactly that on purpose (event.preventDefault() then setPointerCapture, under "Refusing the press stops the compatibility mouse events") — so the recorder and refreshHover were silent for the length of an edge drag and now run on every move of one, as they now also do for touch and pen. I could not build a defect out of it: the handle keeps the boundary under the grab point, so markAt lands on the handle rather than on prose, and refreshHover is rAF-coalesced and returns early where the page has no marks. The one place it opens is past the width clamp, where the handle stops tracking while the pointer keeps going and a mark under it would light up mid-resize. If that ever shows, a data-lf-sizing guard in refreshHover is the cheap answer; worth a look during a sweep rather than a change here.

Two small things, neither worth a CI round on its own — happy to push both together if you want them:

  • AIM_SEAM straddles the seam as advertised only while the seam's fractional part is under 0.5. y = (hi + Math.floor(hi) + 0.5) / 2 sits above the seam in that case, but at 0.5 or above it sits below it, so the two readings come back swapped rather than equal — and the guard's message ("the aim point and the whole pixel it rounds to are on the same item") describes the other failure. The fixture's top: 300.3px pins the fraction near .297 and the comment is right that it holds there on every machine, so this is about what a drift would print, not about the fixture.
  • test_a_scroll_under_a_held_aim_moves_the_promise_with_the_page's docstring still opens "Only the mousemove used to re-ask the aim". That is the same history-sentence shape as passages.js's "rebuilt per candidate ancestor per mousemove", which this diff did update to "per pointer move". Outside the diff, so no inline suggestion.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generalisation holds. AIM_SEAM's point is the midpoint of the seam and the whole-pixel boundary rounding turns at, so it is on the opposite side of the seam from its rounded twin in both directions, and reading the promised item off at rather than naming it is the right shape. I checked the swap the commit message claims rather than taking it: at top: 300.3px the reading is {at: seam-lower, rounded: seam-upper}, at top: 300.7px it is {at: seam-upper, rounded: seam-lower}, and both pass the new assertion where the old one would have failed the second on readings that were still disagreeing. The docstring's other repair is right too — test_a_scroll_under_a_held_aim_moves_the_promise_with_the_page no longer says mousemove.

Two numbers the prose states, though, and neither is what the fixture produces. Both are inline suggestions; neither is worth holding this behind, given main has now carried the failing assertion for six commits — apply them at merge or drop them.

Measured in a headless Chromium on this fixture, the browser's hit test stops answering seam-upper at 319.3125, which is 0.98px above that box's own bottom edge (320.296875) — the AIM_SEAM comment already anticipates that ("a box's hit region is not always its border box"), so nothing is wrong there. But it means the point the search returns is y = 319.40625: 0.094px past the seam, sitting at .41 of its pixel. So "a third of a pixel from a seam" overstates the gap by four times, and "resting in the first third of that pixel" names a region that is mostly over the upper item, not the lower one. The construction bounds the gap at a quarter pixel in general — y is the midpoint of the seam and a boundary at most 0.5 away — so no fixture fraction makes "a third" reachable.

How the numbers were taken

Standalone Chromium (chromium.launch()), the fixture's own markup and stylesheet, running AIM_SEAM's search verbatim:

top box bottom hit-test seam fraction y at rounded
300.3px 320.296875 319.3125 .3125 319.40625 seam-lower seam-upper
300.7px 320.6875 319.7031 .7031 319.60156 seam-upper seam-lower

Stable across device_scale_factor 1 / 1.5 / 2 / 3 and across serif, sans-serif and monospace at 11/13/16/20px — so the fixture comment's claim that the fraction does not come from the fonts holds, and the .31 is the stylesheet's number to within a LayoutUnit.

Commenting rather than approving because GitHub rejects self-approval. lint is green on this head; test is still running.

Comment thread tests/test_render_controls.py Resolved
Comment thread tests/render_cases_layout.py Resolved
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

This run's failure is already fixed on main, so this is the last of these — not a fourth "still red".

Run 32997377871 on 0acb4de is the same assertion again (promised opt-jwt and commented on opt-redis), but it predates a2318a1, "Take an aimed press from the reading that promised it", which landed on main at 18:07 and takes the press from aimedItem() instead of the pointerdown target — the alternative this PR's body rejected. I ran the corpus test on e457203 here: test_an_aimed_press_does_only_what_the_outline_promised is 10 passed, 181.94s at -n0, design-decision included. Red main is closed.

What that leaves for this PR is the narrower half of its own diagnosis rather than the CI fix: main still records the pointer from mousemove in both writers (anchors.js:1061, leaf.js:3157), so the record every consumer hit-tests with is still a rounded neighbour of where the browser dispatches from. a2318a1 makes the outline and the press agree by asking one reading twice; it does not make that reading the browser's own, so design mode's target and refreshHover's markAt keep the pixel of slack. Whether that is worth a change on its own is your call — this PR is no longer holding anything red, and its branch is based on 0ec78ba, before the fix.

Verification
$ uv run pytest "tests/test_render_controls.py::test_an_aimed_press_does_only_what_the_outline_promised" -q -n0
..........                                                               [100%]
10 passed in 181.94s (0:03:01)

at e457203 (main, which contains a2318a1). The failing run's own job was 1 failed, 1248 passed, 6 skipped, same single case.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Answering the question the last comment left open — whether the recorder half is worth a change on its own now that a2318a1 has closed red main. It is, and the new test is what shows it rather than prose about design mode: on a merge of this branch with main at 5d1d383, reverting the two recorders to mousemove still fails test_the_aim_reads_the_pointer_where_the_press_is_dispatched_from, and it fails at the promise — .lf-aim names seam-upper while the pointer sits over seam-lower.

That is the shape of what a2318a1 left. Taking the press from aimedItem() makes the outline and the press agree, so nothing breaks its promise any more; both now answer at the rounded point, which within a pixel of a seam is a different item than the one under the hand. The reader is shown the wrong item and the press faithfully takes the wrong item. Same for refreshHover's markAt and design mode's target, which have no second reading to be made to agree with.

The two changes compose rather than compete: on that merge, test_an_aimed_press_does_only_what_the_outline_promised is 10 passed at -n0, design-decision included. The branch merges into current main clean (the keyboard and runtime splits do not touch either hunk), and ci is green on this head including --run-nightly — run 32997577608. This PR is no longer holding anything red either way; it is now a correctness change with its own gate, and yours to take or drop.

The two review nits are in as 2fd1d62: AIM_SEAM's point straddles the seam in both directions, so the test reads the promised item off the point rather than naming one, and the scroll test's docstring no longer says mousemove. The two suggestions on that commit are still open.

The probe

A worktree at probe/seam-teeth, this branch merged with origin/main (5d1d383), no conflicts. Recorders reverted with the merge in place:

$ uv run pytest "tests/test_render_controls.py::test_the_aim_reads_the_pointer_where_the_press_is_dispatched_from" -q -n0
FAILED - AssertionError: Locator expected to have attribute 'seam-lower'
Actual value: seam-upper
    14 × locator resolved to <div class="lf-ui lf-aim" data-for="seam-upper"></div>
1 failed in 6.60s

Recorders restored, same tree:

$ uv run pytest "tests/test_render_controls.py::test_an_aimed_press_does_only_what_the_outline_promised" -q -n0
..........                                                               [100%]
10 passed in 141.01s (0:02:21)

Not pushed — the branch is left based on 0ec78ba.

The aim's outline and the press it promises are two readings of one question, and
they came from different doors: the outline hit-tests the pointer record the
runtime keeps, while the press takes the target the browser resolved for it. That
record was kept from `mousemove`, whose clientX and clientY are rounded to whole
pixels — so within a pixel of a seam the two name different items, and the reader
is shown an outline on one item and gets a composer anchored to the next.

It surfaced on design-decision.html, where a wider address column moved the choose
group's centre point 0.8px inside a cell boundary: ⌥ over the group outlined
opt-jwt and the press commented on opt-redis. The pointer events carry the
position they were rounded from, so the record comes off `pointermove` and every
consumer of it — the aim, the cursor's half of the same promise, the hover
reading, design mode's target — asks about where the pointer is.

The corpus case reaches this only while a seam happens to lie under a group's
centre. test_the_aim_reads_the_pointer_where_the_press_is_dispatched_from holds a
seam there on purpose: a fixed box puts one between two whole pixels, and the aim
lands a third of a pixel past it, where the true point and its rounded twin name
different items. Both are asserted before the gesture, so a seam that drifted onto
a whole pixel fails the test rather than leaving it proving that two agreeing
readings agree.
AIM_SEAM's point straddles the seam in both directions — it is halfway
between the seam and the whole pixel rounding turns at, so under a
fraction of .5 the true point is over the lower item and its rounded twin
over the upper one, and from .5 up the two swap. The test named the first
of those, so a fixture that drifted past .5 would have failed on readings
that were still disagreeing, under a message reporting the opposite
("on the same item"). It reads the promised item off the point instead
and requires the pair to differ, which is the property the test is for;
the guard message names the one thing that would end it, a seam landing
on a whole pixel.

Verified both directions: with the fixture at top: 300.7px the reading
comes back {at: seam-upper, rounded: seam-lower} and the test passes,
where the old assertion would have failed. Bug-back with the recorder
reverted to mousemove still fails at the promise.

Also updates a history sentence in the scroll test's docstring that
still said mousemove, the same shape as the passages.js comment the
first commit updated.
The seam test's two prose numbers describe a fixture that does not produce
them. Measured in headless Chromium on this fixture, the browser's hit test
stops answering the upper item at 319.3125 — .31 of the pixel, and 0.98px above
that box's own bottom edge, which is the hit-region slack `AIM_SEAM` is searched
rather than computed for. The point the search returns is 319.40625, 0.094px
past the seam.

So "a third of a pixel from a seam" overstates the gap four times, and the
construction bounds it at a quarter pixel for any fixture: the point is the
midpoint of the seam and a whole-pixel boundary at most 0.5 away. And "resting
in the first third of that pixel" names a region mostly over the upper item,
since the seam falls past it at .31.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed in full after the rebase — the force-push moved the branch onto 67e3c78, so LAST_REVIEW_SHA names a commit that no longer exists. The two nits from the last round are in as applied, verbatim on the second one, and I've resolved both threads. The premise measures out independently: on this box a pointermove at 100.5, 200.3125 arrives with those numbers and the mousemove beside it arrives at 100, 200, so fixing the recorder rather than each reader is the right depth and the test is holding the right thing.

Two things the change opens that aren't in the body, both outside the diff — neither is worth holding this behind, and I'm happy to push either or both if you want them.

The click's markAt is still asking at the rounded point. refreshHover now reads the true point (markAt(pointer.x, pointer.y)), but the document click listener in leaf.js — the one under if (designOn), const threadId = markAt(ev.clientX, ev.clientY) — takes the event's own coordinates, and a click is a legacy mouse event, so those are the rounded ones. markAt compares against getClientRects(), whose top/bottom are floats, so the two readings can now differ by up to half a pixel at a mark's rect edge where before this change they were both rounded and could not. That is the same disagreement this PR removes from the aim, newly opened one surface over: lf-over-mark is described at its own line as "the promise that a press here opens something", and paintHover lights the reciprocal card in the panel, so the shape is a quote that lights up under the hand and a click on it that opens nothing. It isn't a one-line swap — that handler has no ev.detail guard, so a keyboard-synthesized click arrives with clientX === 0, and reading pointer there would open the thread under a parked pointer on an Enter press.

A stationary tap fires mousemove but no pointermove. Measured rather than reasoned from the spec: a touch tap in Chromium is pointerdown → mousemove → mousedown → click, with no pointermove anywhere in it. So on a touchscreen the record a tap used to update is now not updated at all. It is not a regression for the ⌥ press — the compat mousemove lands after pointerdown, so aimedItem() at claimPress was already reading a stale record there — but the refreshHover() and refreshAim() that tap used to drive are gone with it: design mode's outline no longer follows a tap onto the element it is about to open on (the press itself still lands, through designTarget(ev.target)), and the hover paint stops answering. Nothing in the suite covers touch — PHONE in test_site.py is a viewport with no has_touch — so this is invisible either way. If it is worth closing, pointerdown is the door, and the same probe says it carries the true fractional point on touch (150.5, 170.5 for a tap dispatched there), so recording from it would be right about the position as well as present for the gesture.

Commenting rather than approving because GitHub rejects self-approval. lint is green on this head; test is still running.

How the two sequences were taken

Playwright's pinned headless Chromium, listeners at document, printing type clientX,clientY:

context(has_touch=True, is_mobile=True); touchscreen.tap(150.5, 170.5)
  ['pointerdown 150.5,170.5', 'mousemove 151,171', 'mousedown 151,171', 'click 151,171']

mouse.move(100.5, 200.3125)
  ['pointermove 100.5,200.3125', 'mousemove 100,200']

The first line is the one that matters for the touch note — pointerdown carries the fraction, the compat mousemove rounds it and arrives after, and no pointermove is dispatched for a tap that doesn't move. The second is the PR's own premise, re-measured.

refreshHover now reads the pointer record at the true point, but the
document click listener still asked markAt with its own clientX and
clientY. A click is a legacy mouse event, so those arrive rounded to a
whole pixel, while markAt measures against getClientRects, whose edges
are floats — so within a pixel of a mark's edge the hover lit one
thread's quote and the press on it opened its neighbour's conversation.

That is the disagreement this branch removes from the aim, left standing
one surface over. The click reads the record instead. A click carrying no
press — offer's click() supplying the keys a span doesn't come with —
carries 0,0 rather than a position, and the record would answer for
wherever the pointer is parked, so that one keeps reading the event.

The test reuses the seam fixture with a comment on each item either side
of it, so the disagreement is a pair of cards rather than a hit and a
miss: it asserts which thread the press opened against the one the hover
had just promised. Without the fix it fails with the hover on seam-lower
and the press opening the seam-upper thread.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Actioned the first of the two things the last review raised, since both are opened by this change rather than merely near it. The click surface is in as 3192ce5 with a gate; the touch one I'd leave, and the reason is a correction to what that review said the door was.

The click's markAt now asks at the recorded point. leaf.js:3290 reads pointer where the click carries a press and keeps the event's own coordinates where it doesn't — ev.detail is 0 for the click offer synthesizes for a span, which arrives at 0,0 and would otherwise have opened whatever thread the parked pointer was over. The test is the one the review's framing asked for rather than prose about the seam: it reuses AIM_SEAM_PAGE with a comment on each item either side of the seam, so the disagreement is two cards rather than a hit and a miss, and it asserts the thread the press opened against the one .lf-thread.lf-mark-hover had just promised. Reverting the hunk fails it at exactly the described shape — hover on seam-lower, press opening the seam-upper thread.

The touch door is narrower than that review claimed. pointerdown restores the record for a plain tap, but not for the two gestures the review named as what a tap lost. claimPress is registered at capture on document (leaf.js:3243) and calls ev.stopPropagation() on every press it claims, and stopPropagation from a document capture listener skips that same document's bubble listeners — measured, not read off the spec: with both registered, a click logs ['capture'] alone. Design mode claims every tap on page words, so a bubble recorder would never see the pointerdown whose outline the review wanted followed. Getting there means the recorder installing at capture ahead of claimPress, and createAnchors runs at leaf.js:6984 — thousands of lines after the press listeners register, so the ordering is a startup-order change and not an added event name. What's left for the cheap version is the hover paint under a stationary tap, on a surface with no hover, and the suite holds no touch context to gate any of it. Yours if you want it; I'd rather not spend a startup-order change on it uninvited.

Verification
$ uv run pytest tests/test_render_anchors.py -q
52 passed in 115.13s

$ uv run pytest tests/test_render_navigation.py -q
38 passed in 41.89s

$ uv run pytest tests/test_render_conversations.py -q
36 passed in 35.89s

$ uv run pytest tests/test_render_controls.py -q
126 passed in 497.18s (0:08:17)

With the leaf.js hunk reverted and the test kept:

E   AssertionError: the hover promised the thread on seam-lower, and the press at the same
    point opened: § paragraph · The item above the seam. … About seam-upper.
1 failed in 1.53s

uvx pre-commit run --all-files is clean. The propagation reading, in a standalone Chromium with a stopPropagation capture listener and a plain bubble listener both on document:

stopPropagation at document capture -> ['capture']

ci is running on this head.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The click surface is the right place to close this, and the new test holds the right pair — the hover's promise and the press asserted against each other, with the expected card read off the point rather than named. I checked the claim rather than taking it: with the leaf.js hunk reverted and the test kept, it fails with the hover on seam-lower and the press opening the seam-upper thread.

One finding on this commit, and it is the touch door — but not the one the comment above argues about. Reading the record instead of the event's own coordinates makes a tap on a quote open no thread at all.

Measured in Playwright's Chromium, listeners at document:

tap    pointerdown 150.5,170.5 detail=0 | mousemove 151,171 detail=0 | mousedown 151,171 detail=1 | mouseup detail=1 | click 151,171 detail=1
mouse  pointermove 100.5,200.3125 | mousemove 100,200 | pointerdown 100.5,200.3125 | mousedown 100,200 | click 100,200 detail=1

A tap's click carries detail=1, so it takes the markAt(pointer.x, pointer.y) branch — and no pointermove is dispatched anywhere in a tap, so the record it reads is still { x: -1, y: -1 } unless a mouse moved earlier in the session. markAt(-1, -1) asks elementFromPoint, gets null, and pageWords(null) is Boolean(null) && … — so the handler falls through to the visual/fab path and nothing opens.

End-to-end on this head: AIM_SEAM_PAGE with a comment on each item, opened in a has_touch=True context, tapped at the seam.

AssertionError: tap at {'x': 150.5, 'y': 319.40624237061365, 'at': 'seam-lower', 'rounded': 'seam-upper'} opened no thread
assert None

With this commit's leaf.js hunk reverted, the same tap opens a thread (seam-upper — the rounded reading, but a conversation rather than silence). So before this commit a tap on a quote opened its conversation; after it, a tap on a quote does nothing, and opening a thread from its own quote is the tap's only route to it from the page side. That is wider than "the hover paint under a stationary tap, on a surface with no hover".

It also looks like a depth question rather than a reader-side one. Every other consumer of the record either guards the stale value — aimedItem's if (pointer.x < 0) return null, aimTarget's designIsOn() && pointer.x >= 0 — or has null as its right answer (refreshHover paints no hover). The click has neither: there, null means "no thread here" while a thread is under the finger. And a pointer.x >= 0 guard on the reader would not close it, because on a hybrid device the record is a live mouse position, so a tap would open whatever the mouse was last parked over — a wrong thread instead of none.

The recorder is where it closes. Adding pointerdown to the anchors recorder passes both the touch probe above and this commit's own new test, in that tree:

for (const type of ["pointermove", "pointerdown"])
  document.addEventListener(type, (ev) => {
    pointer.x = ev.clientX;
    pointer.y = ev.clientY;
    refreshHover();
  });

pointerdown carries the true fractional point on touch (150.5,170.5 above), so it is right about the position as well as present for the gesture, and the capture-order objection doesn't reach this surface: claimPress returns at if (!aimedPress) return; before any stopPropagation when it claims nothing, so an unclaimed tap reaches a bubble listener whenever it registers. The presses it does claim are ⌥ and design mode, and the design branch of this handler reads ev.target rather than the record. The one judgement call in it is whether refreshHover() should run on pointerdown on a surface with no hover; recording without it for that event is the narrower version, and it still fixes the tap.

Happy to push it, with a has_touch gate for the tap so the suite holds the case — the corpus has no touch context today, which is why this is invisible to ci either way.

Commenting rather than approving because GitHub rejects self-approval. lint is green on this head; test is still running.

How the two probes were taken

Event sequences, standalone Chromium (chromium.launch()), capture listeners on document printing type clientX,clientY detail:

context(has_touch=True, is_mobile=True); touchscreen.tap(150.5, 170.5)
  ['pointerdown 150.5,170.5 detail=0', 'mousemove 151,171 detail=0', 'mousedown 151,171 detail=1', 'mouseup 151,171 detail=1', 'click 151,171 detail=1']

mouse.move(100.5, 200.3125); mouse.click(100.5, 200.3125)
  ['pointermove 100.5,200.3125 detail=0', 'mousemove 100,200 detail=0', 'pointerdown 100.5,200.3125 detail=0', 'mousedown 100,200 detail=1', 'mouseup 100,200 detail=1', 'click 100,200 detail=1']

The end-to-end probe is this commit's own fixture and comments, driven through the repo's serve/open_page harness with browser.new_context(has_touch=True) and page.touchscreen.tap(seam["x"], seam["y"]), asserting document.activeElement?.closest('.lf-thread'). On this head it fails as quoted; with the leaf.js hunk reverted it passes; with the hunk kept and pointerdown added to the anchors recorder, it passes alongside test_a_press_on_a_mark_opens_the_thread_the_hover_promised (2 passed).

Nothing else in the incremental drew a finding: showThread focuses synchronously inside the click handler, so reading document.activeElement straight after mouse.click is an ordering the page has already made rather than a race, and the !ev.detail guard matches the idiom claimPress already uses for the same synthesized-click case.

Comment thread plugins/leaf/skills/leaf/assets/leaf.js Resolved
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

test came back red on this head, and it is main's failure rather than this branch's — closing out the "ci is running" line above rather than leaving it to be re-diagnosed.

One case, tests/test_interact_document.py::test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag, on assert re.search(r"function markHere\(\)...PAGE_PAINT_ATTRIBUTE\.ask", js) where js is assets/leaf.js. 9664448 ("Split ask model and view runtimes") moved markHere into runtime/asks/view.js and left the test grepping leaf.js, so the assertion is now asking a file that no longer holds the function. ci on main went red on that same commit and that same case — run 33003757211, 1 failed, 1254 passed. A PR's test runs the merge with base, which is how it reaches this branch: the case passes on 3192ce5 alone (1 passed in 0.47s).

A tend-ci-fix run for 9664448 has been in progress since 19:33, so main's red has an owner and I've left it there rather than carrying an unrelated fix into this PR. Nothing on this head is outstanding otherwise: lint is green, and locally the full interactive render corpus passes on 3192ce5 — anchors 52, controls 126, navigation 38, conversations 36, and drafts/options/outbox/projection/startup/widgets 283 together.

The click reads the pointer record now, and a tap dispatches no
pointermove: pointerdown, then the compatibility mouse events and a click
carrying detail=1. So under a finger the record was still {-1, -1}, the
click's markAt asked elementFromPoint about a point off the page, and a
tap on a quote opened no thread at all where before it opened one.

The recorder is where that closes rather than the reader. Every other
consumer either guards the start value (aimedItem, aimTarget) or has null
as its right answer (refreshHover paints no hover); the click has
neither, and null there means "no thread here" while a thread is under
the finger. A pointer.x >= 0 guard on the reader would not close it
either — on a hybrid device the record is a live mouse position, so a tap
would open whatever the mouse was last parked over.

A tap's pointerdown carries the true fractional point, so the finger gets
the reading the mouse gets rather than the rounded one its own click
would have given. No hover refresh on that event: a mouse has already
moved to the point and refreshed there, and there is no hover to paint
under a finger.

The test taps the seam fixture in a has_touch context — the only way to
get a gesture with no pointermove in it — with a comment on each item, so
a wrong reading is a visible thread rather than a miss. Without the
recorder it fails with the tap opening nothing.
main moved the aim and the click surface out of leaf.js into
runtime/composing/aim.js and runtime/composing/surface.js while this
branch was changing both. The two hunks move with them: the aim's
recorder reads `pointermove` in aim.js, and the click asks markAt at the
record in surface.js, which takes `pointerAt` for it the way createAim
already does.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

The touch door is in, at the recorder the last review named, and the branch is merged with main — which had moved both of this PR's hunks into new files while it sat.

The tap. I reproduced the finding before changing anything: the review's probe, written as this PR's own test, fails on 3192ce5 with a tap on the quote for seam-lower opened: None. runtime/anchors.js now records the point from pointerdown as well as pointermove, without a hover refresh on that event — a mouse has already moved to the point and refreshed there, and there is no hover to paint under a finger. My earlier propagation argument was wrong in the way the review said: claimPress returns before it stops anything when it claims nothing, so a plain tap reaches a bubble listener, and the presses it does claim read ev.target or a record the mouse already wrote. No startup-order change was needed.

The test taps the seam fixture in a has_touch context — the only way to get a gesture with no pointermove in it — with a comment on each item, so a wrong reading is a visible thread rather than a miss. It also holds the finger to the true point rather than its rounded twin, since a tap's pointerdown carries the fraction: it asserts seam['at'], the same item the mouse test asserts.

The merge. main split the aim into runtime/composing/aim.js and the click surface into runtime/composing/surface.js after this branch was opened, so both of this PR's leaf.js hunks conflicted. They moved with their code: the aim's recorder reads pointermove in aim.js, and the click asks markAt at the record in surface.js, which now takes pointerAt the way createAim already does. The branch merges clean into main at d07de1e as well.

One thing on this head is not mine: test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag fails on the merge because main is red on it, and #51 is the fix. Expect test to stay red here until that lands.

Verification

Both hunks reverted one at a time on the merged tree, to check each is load-bearing:

$ # pointerdown recorder removed from anchors.js
$ uv run pytest "tests/test_render_anchors.py::test_a_tap_on_a_quote_opens_its_thread" -q -n0
FAILED - AssertionError: a tap on the quote for seam-lower opened: None

$ # surface.js click reverted to markAt(ev.clientX, ev.clientY)
$ uv run pytest "tests/test_render_anchors.py::test_a_press_on_a_mark_opens_the_thread_the_hover_promised" -q -n0
FAILED - the hover promised the thread on seam-lower, and the press at the same point opened: … About seam-upper.

On the merged tree as pushed:

$ uv run pytest tests/test_render_anchors.py -q -n2
53 passed in 112.40s

$ uv run pytest tests/test_render_controls.py tests/test_render_navigation.py \
    tests/test_render_conversations.py tests/test_render_widgets.py -q -n4
1 failed, 243 passed in 534.45s

That one is test_a_press_leaves_its_neighbours_where_they_were[gallery], a worker crash under -n4 on a 4-core runner rather than an assertion; it passes at -n0 (10 passed in 206.57s) and the whole controls file passed at -n2 earlier in this session.

$ uv run pytest tests -q -n4
1 failed, 585 passed, 6 skipped in 120.97s

The one failure is main's test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag, above. uvx pre-commit run is clean on the changed files, and node --check passes on all four touched JS files.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recorder is the right depth and the test holds the right thing. I checked the commit's own claim rather than taking it: with the anchors.js hunk reverted and the test kept, test_a_tap_on_a_quote_opens_its_thread fails with a tap on the quote for seam-lower opened: None, and the whole of test_render_anchors.py is green with the hunk in (53 passed, under xdist).

One finding, and it is about the sentence that justifies leaving refreshHover() off this event rather than about leaving it off. The record still reaches the hover reader — one gesture later, through pageShifted. refreshHover reads pointer.x/y, and pageShifted calls it on every scroll, resize and paintAnchors. Measured on LONG_PAGE in a has_touch context: tap 200px below a marked passage, then scroll that passage under the point the finger touched, and body.lf-over-mark is true with lf-mark-hover at size 1 — a quote lit as indicated, and its card lit in the panel, with nothing resting on either. With this hunk reverted the same sequence leaves both empty.

It is not a regression, though, and that is what decides how much it is worth. A touch drag already painted the same wash before this commit, because a drag does dispatch pointermove until the browser cancels it — I put a finger down on the mark and moved it four pixels, and the wash came up on the reverted tree exactly as it does here. So pointerdown is the only statement of the pointer's place for a tap, not on touch generally, and "there is no hover to paint under a finger" is a description of the finger rather than of what the layer paints. The hole predates the recorder; what this commit changes is that a tap reaches it too.

That splits into two things, and only the first is this PR's:

  • The two claims in the comment, which the inline suggestion corrects.
  • A hover that paints where no pointer rests, which is its own change: the record answers "where the pointer is resting" for refreshHover and aimTarget and "where the press landed" for the click, and on touch those have come apart. Carrying whether the recorded point is one a pointer is over — set by both recorders off ev.pointerType — and having refreshHover clear rather than paint when it is not, closes it for the drag as well as the tap. Happy to push that separately; it wants its own test and shouldn't ride on the red-main fix.

Commenting rather than approving because GitHub rejects self-approval. lint is green on this head; test is still running, and the comment above expects it to carry main's test_the_ancestor_exclusions_ask_for_a_marker_and_not_a_tag — #51 is closed unmerged, and main's own ci on dc0d949 and b68ce37 hasn't finished, so I can't confirm that from here either way.

How the two probes were taken

Both through the repo's own serve/open_page harness on this head, LONG_PAGE, one comment anchored to p30, browser.new_context(..., has_touch=True), reading document.body.classList.contains('lf-over-mark') and CSS.highlights.get('lf-mark-hover')?.size.

Tap, then scroll the mark under it. p30 scrolled to centre, mark at 279.7, 460.7; page.touchscreen.tap(279.7, 660.7); document.body.scrollBy({top: -200, behavior: 'instant'}).

tree after tap after scroll
this head {over: false, hover: 0} {over: true, hover: 1}
pointerdown recorder removed {over: false, hover: 0} {over: false, hover: 0}

Touch drag onto the mark, via CDP Input.dispatchTouchEvent (Playwright's touchscreen has only tap): touchStart at the mark, four touchMoves 1–4px below it. Capture listeners on document saw

pointerdown 279.7,520.7 | pointermove 279.7,505.7 | pointermove 279.7,490.7 | pointercancel

for the longer drag — the pointermoves are why this path needs no pointerdown recorder — and the short drag onto the mark reported {over: true, hover: 1} mid-drag and after the lift on both trees.

Nothing else in the incremental drew a finding. claimPress is at capture on document and stopPropagations only a press it claims, so the ⌥ and design presses never reach this bubble listener — and they don't need to, reading aimedItem() and ev.target at capture instead. Nothing else in the layer stops pointerdown propagation. The test's read of document.activeElement straight after the tap held over eight consecutive runs and one full-file xdist run.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Correction to my last comment: test is green on ad89c57, not red. main repaired that reading itself in d07de1e — it now asks whichever runtime file defines markHere rather than reading leaf.js by path — and #51 is closed unmerged as superseded. My local run merged 8ba3077, which predates that; CI merges current main, which has it. Both required checks are green on this head.

The comment claimed `pointerdown` is the only statement of the pointer's
place on touch, and that there is no hover to paint under a finger. A drag
dispatches `pointermove` until the browser cancels it, so the first holds
for a tap rather than for touch; and `refreshHover` reads the record on
every `pageShifted`, so the layer does paint a hover from it — a hole the
drag already reached before this recorder existed. Comment only.
@max-sixty
max-sixty merged commit dbc0065 into main Aug 26, 2026
7 checks passed
@max-sixty
max-sixty deleted the fix/ci-32988551776 branch August 26, 2026 22:24
max-sixty added a commit that referenced this pull request Oct 12, 2026
…rt (#2531)

A widget bound to a data source no longer fails a second time when it
leaves the page and comes back. Before this change, a bound lf-diff,
lf-text-document or lf-visual-review whose source had failed to render
failed again on every return and logged a second console error. This is
review item #48 from the Lit survey follow-up, numbered in that review
rather than as a GitHub issue.

## Behaviour that changed

- **`watchData` (data.js).** Previously, when a subscriber returned, it
was sent the newest snapshot even when that snapshot was the one already
painted. Now it is sent one only when the source reading changed while
it was away, or when it left while its paint's promise was still
running. The resend existed because widgets drop unfinished paints when
they leave: lf-text-document and bound lf-diff both bump a rendering
counter on departure. That one case is now stated exactly. A paint that
finished, including one that failed, stays as it is.
- **`clocked` (presence.js) gains `resume()`.** When a widget leaves,
data.js stops its paint's clock subscription. With no repaint on return,
nothing would put that subscription back, so `resume()` returns the kept
painting's time readings to the shared clock. The next tick repaints any
reading that has aged, such as "2h ago".
- **Two examples depended on the old resend:**
- lf-pr-brief built a new `clocked` paint on every connection, and only
the data callback ever painted it. After a return, its "Observed …" age
stopped updating. It now keeps one paint for its lifetime, stopped when
it leaves and resumed when it returns.
- lf-atlas-tree re-armed its held reading only through the resend. When
it returns holding a newer reading, it now arms that reading itself.
- **`module-authoring.md`** now states the return rule and the
stop/resume pairing for `clocked`. Because data.js learns that a paint
is unfinished only from the promise its callback returns, the guide
tells authors to return the promise of any paint that finishes later. It
also says that a `whileConnected` start must restore whatever its
cleanup cleared, since a return no longer repaints unchanged data. No
current bound widget defers its content paint without returning that
promise. lf-visual-review and lf-trace defer only layout, which their
size observers schedule again when they return.

## Kept

lf-diff's inline-patch `settled` guard from #2503 stays. It applies only
to an inline patch, which is not a data delivery, so data.js never sees
it. It is the same rule enforced at a second boundary, not a copy of
data.js's. The other bound widgets have no local guard against the
resend. The cleanup in lf-text-document and lf-diff that drops a paint
on departure is what the new rule depends on. lf-trace's redraw on
return is for its own closed picture.

## Measured

| Item | Hand-written source (excl. tests, Markdown, generated corpus
copies) | Tests |
|---|---|---|
| #48 | +36 / −13 (net +23) | +77 / −13 (net +64) |

## Validation

- **Bound diff.** The #2503 lf-diff return test is now parametrized over
inline and bound patches. Its bound case reported the error twice on
`main` and passes here.
- **New data.js test.**
`test_a_returning_subscriber_is_repainted_only_where_its_departure_cut_the_paint`
checks that a widget is repainted after leaving mid-paint and not after
leaving with a finished paint. It fails on `main`.
- **Owner-lifecycle test.** It now expects no resend of an unchanged
reading, and a clock tick after the widget returns. With `resume()`
removed, the tick assertion fails.
- **PR brief clock test.** It now also runs after the brief leaves and
returns. With the old example widget, that case fails.
- **Focused runs, all passing:** diff controls; the data-subscription
startup tests; visual review; text document; call-diff; atlas; PR brief;
live widget subscription; four trace lifecycle tests. Pre-commit passes
on the changed files.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 23, 2026
An attribute that names one of the layer's words, such as `lf-column`'s
`tone` or `lf-code`'s `language`, now carries those words as a standard
JSON Schema `enum` in the vocabulary a page composes. Before this, its
schema said only `{"type": "string"}`. The words lived under `$tones`
and `$languages`, so an agent reading the entry went looking for them.
Claude Code reads `page/registry.json` directly, never `page
instructions`, and spent a model call on that lookup in most replies.

Composing the vocabulary (`registry.layer.stamp_composition`, at `page
init` and over a page's own declarations) now writes each list into the
attribute's `enum`. That is `registry.contract.stamp_words`, beside
`$decisions` and `$states`. Source registries still declare only
`x-tone` or `x-language`, so a new tag that takes a tone still needs
only that key, and the lists stay the one home of the words.

That leaves one mechanism where there were three:

- **Validation** reads the `enum` through the attribute schema it
already checks. The separate `DECLARED_WORDS` pass and its
`unknown-word` finding are deleted. An unknown tone now reads `'success'
is not one of ['ok', 'warn', 'danger']`.
- **`page instructions --use`** lists the words of every attribute whose
schema has an `enum`, read from the schema. That replaces #3690's
listing from the layer's lists.
- **Composition** stamps before it validates the examples, so examples
are checked against the vocabulary as pages read it.

This bumps the page protocol from 21 to 22. No page runtime reads the
property schemas, but a page vendored before this change carries a
registry without the `enum`. A Leaf at the same number would then stop
checking that page's tones and languages. The bump has the session
holding such a page re-vendor it on its first command, and the stamped
registry checks again.

Measured with Claude Code waiting journeys, side by side on this
branch's base `7c0aa359f` and on the change, 7 completed runs per arm:

| | Before | After |
|---|---|---|
| Registry lookup calls per reply, mean | 2.14 | 0.43 |
| Replies that looked up the tones | 6 of 7 | 2 of 7 |
| Model calls per reply, mean | 5.43 | 3.86 |
| Whole reply, median | 26.4 s | 18.9 s |
| Generation, median | 17.9 s | 13.0 s |

The whole-reply drop is within the run-to-run spread at this sample
size. The lookup is gone from most replies, and removing that lookup was
the point. One Codex App Server journey and one Pi journey were also run
to spot-check that both still see the words.

This is the coordinator's #48 follow-up to Max's decision #40 on the
overnight report.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

2 participants