Repository navigation
Take a comment anchor the runtime already resolved instead of re-reading it off the file - #174
Conversation
…ing it off the file The embedded Leaf review (027bdb1) widened the event door's anchored-comment gate from `holds`/`response`/visual anchors to every anchor, then re-captured each one against the version file and refused any whose quote did not equal the capture's. The MCP app needs that reading — it renders the authored source with no runtime behind it, so nothing has resolved its selection — but the served runtime's anchors are already answered against the rendered page, which holds words no file reading can produce and writes its quote in the whitespace the selection found. Both halves of that refused a comment a reader can make: - `test_a_quote_finds_its_passage_whatever_its_whitespace` posts five spellings of one passage and gets one thread, because the raw quote is compared against a collapsed capture; - `test_a_widgets_label_takes_a_comment_inside_the_control_it_labels` comments on a tab's own name, which `capture_anchor` refuses outright — the label is an `lf-tab` attribute the file reading places in the widget's source. `EventEndpoint(page_dir, capture_anchors=True)` now carries the capture, and `mcp_app.apply_event` is its one caller; the served page's door returns to the gate it had. The quote equality check goes with it: `capture_anchor` raising is the validation, and a stored quote's whitespace is the browser's to write. A new door test posts the three spellings a rendering can produce and reads back what the log kept, so neither the refusal nor a rewrite can return unnoticed.
leaf-agent
left a comment
There was a problem hiding this comment.
The change itself reads right: the file-side reading cannot confirm words a module renders, so the served door had to stop asking it to, and capture_anchors puts the capture on the transport that actually reaches the door unresolved. The wiring is clean — _ENDPOINTS is private to mcp_app, http.py keeps the default, and test_mcp_refuses_an_anchor_on_static_widget_source still holds the capture on that side.
One thing the new door test does not do: it passes with the served-door capture switched back on. I checked by setting capture_anchors=True on the EventEndpoint built in http.py (the "event_endpoint": entry in the served handler map) and re-running it — still green. All three spellings collapse to text the file holds, so capture_anchor resolves each one, and the quote-equality comparison that would have refused them is now gone unconditionally. What the re-capture actually turned back is the other regression the PR cites — a passage only the rendering holds, a tab's own name — and no post in the test reaches that, so the PR's "neither the refusal nor a rewrite ... can return unnoticed" only holds for the rewrite.
Adding the widget-source anchor test_interact_mcp already uses makes the test fail with the capture re-enabled (400, "a widget's data body is its source, not its words") and pass on this branch. Suggestion inline; I ran it both ways.
Separately, the whitespace half of the rationale — validation.md's "writes its quote in the whitespace the selection made", the comment on anchored_comment_rejection, and this docstring — does not hold for the current runtime. quoteFrom in assets/runtime/passages.js collapses with a regex spelled to the same character set as passages.py's COLLAPSE_CHARS, deliberately, so a live selection's quote and the file-side canonical one agree. The spellings that do arrive uncollapsed are the ones earlier runtimes stored, which test_a_quote_finds_its_passage_whatever_its_whitespace names outright. Worth stating it that way in validation.md, since that is what a later change reads for the contract.
…ase correctly The new door test passed with the served-door capture switched back on: all three spellings collapse to text the file holds, so the capture resolves each one. Post a widget-source quote too — the file reading turns that down outright (400, "a widget's data body is its source") — so the test fails with capture_anchors=True on the served endpoint and passes here. The whitespace half of the rationale did not hold: quoteFrom in assets/runtime/passages.js collapses a live selection to the same character set passages.py's COLLAPSE_CHARS enumerates, so a selection's quote and the canonical one agree. The spellings that arrive uncollapsed are the ones earlier runtimes write, as test_a_quote_finds_its_passage_whatever_its_whitespace names. Say that in validation.md, the gate comment, and the test docstring.
|
The whitespace half of the rationale was wrong, and the review is right about why: The other refusal — words only the rendering produces — is unchanged and is now what the door test proves. |
|
I re-ran them here rather than reading the shapes across: on The runs, the merge, and the third failureOn Same two on The one red in the 177 is The third failure on both |
|
Re-verified at Run 33446122333 on The two runs, unmerged and merged
|
## Problem [Run 33445784773](https://github.com/max-sixty/leaf/actions/runs/33445784773) on `bdf9f44` came back **4 failed, 1586 passed, 6 skipped**. Three belong elsewhere: the anchor pair is what #174 already carries and fixes, and the catalog preview digest is gone from the suite as of `4b42d15`. The fourth is new — `test_render_navigation::test_a_label_press_keeps_the_controls_keyboard_standing` read `'/\nsearch page\nesc\nlet go\n?\nmore\nd / u\npage down / up'` where it wanted `unselect`, mid-drag, with `getSelection()` already holding `after state`. `rung()`'s first rung is `unselect` whenever `pageSelection()` stands, so at that moment Escape would have cleared the selection while the line promised to let go of the control. The line was not wrong about the selection — nothing had repainted it. [`selectionchange`](https://github.com/max-sixty/leaf/blob/a08b2cf7709b8003cb92f885e25acf76ef618622/skills/leaf/assets/runtime/composing/surface.js#L463) returns early while `pointerSelecting` stands, deliberately, so the bar is not re-decided under a live drag, and no other writer repaints inside a press. The word the test read was therefore whichever side of the drag the frame that the press itself scheduled (through `focusout` → `paintHere`) happened to land on: after the moves on an idle machine, before them on a loaded one, and then stale until the two-second heartbeat. ## Solution The `pointerSelecting` branch now repaints when the answer crosses — once per press in each direction. The bar keeps waiting for the release, so nothing about `updateFab` or the snap changes; only the line follows the drag. A drag that grows a selection already standing paints nothing, which is what keeps a whole `paintHere` out of every frame of a drag. `hold_selection` gains `frame_the_press`, which lets the press's own frame land before the drag begins, and the test states it. Under that ordering the line's only route to the word is the selection the drag makes, which is the behaviour the assertion was always meant to be about. ## Testing The failure reproduces deterministically once the ordering is stated, and the fix is what clears it. - With `frame_the_press=True` and the runtime change reverted: `FAILED … assert 'unselect' in '/\nsearch page\nesc\nlet go\n?\nmore\nd / u\npage down / up'` — the run's exact line. - With both: `1 passed`. Suites, all on `4b42d15`: `uv run pytest tests` (the PR gate) **749 passed, 6 skipped in 4:48**. Under `--run-nightly`, `test_render_navigation.py` **63 passed**; `test_render_aim/reactions/conversations/commands/margin.py` **155 passed**; `test_render_controls/drafts/options/options_addition/options_settled/outbox/projection/widgets/startup.py` **394 passed**. `test_render_anchors.py` fails only on the two #174 already owns. `node --check` on the module, `ruff check`/`ruff format --check` and `[email protected] --check` on the touched files: all clean. `pre-commit` itself is not on this sandbox's PATH, so `eslint` and `typos` went unrun here and CI's `lint` job is the first to run them. <details><summary>How the ordering was measured</summary> A probe recorded every change to `.lf-keyline` through a `MutationObserver` while driving the same drag. Press, then drag, reading at the end: ``` SEL: after state LINE(now): /|search page|esc|unselect|?|more|d / u|page down / up LOG@read: [[39, '…|esc|unselect|…']] LOG@3s: [[39, '…|esc|unselect|…'], [1895, '…|esc|unselect|…']] ``` One repaint at 39ms — the press's frame, landing after the ten moves — and then nothing until the heartbeat at 1895ms. Inserting a 120ms wait between the press and the moves, which is what a loaded runner supplies for free: ``` SEL: after state LINE(now): /|search page|esc|let go|?|more|d / u|page down / up LOG@read: [[38, '…|esc|let go|…']] LOG@3s: [[38, '…|esc|let go|…'], [1892, '…|esc|unselect|…']] ``` The same run's line, and the word arriving 1.9 seconds later from the heartbeat rather than from anything the reader did. With the fix, the same probe repaints during the drag and the press's frame no longer decides it. </details> --- Automated fix for [failed run](https://github.com/max-sixty/leaf/actions/runs/33445784773) Co-authored-by: leaf-agent <[email protected]>
Summary
Leaf's browser runtime resolves comment anchors against the rendered page before posting them. The event endpoint was resolving them again against the authored file, which rejected widget-rendered text and rewrote quotes from older runtimes.
Limit that file-side capture to the MCP transport, whose selections reach the endpoint unresolved. The served runtime now keeps the anchor it already resolved.
The tests cover both paths: the served endpoint accepts rendered-only text and preserves earlier whitespace spellings, while MCP still rejects anchors on static widget source.