Skip to content

Take a comment anchor the runtime already resolved instead of re-reading it off the file - #174

Merged
max-sixty merged 3 commits into
mainfrom
fix/ci-33430997904
Sep 1, 2026
Merged

max-sixty merged 3 commits into
mainfrom
fix/ci-33430997904

Conversation

@leaf-agent

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

Copy link
Copy Markdown
Collaborator

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.

This was written by Codex on behalf of max-sixty

…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 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 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.

Comment thread tests/test_interact_server.py Resolved
…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.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

The whitespace half of the rationale was wrong, and the review is right about why: quoteFrom collapses a live selection with a regex spelled to the same set COLLAPSE_CHARS enumerates, so a selection's quote and the file-side canonical one agree. What arrives uncollapsed is what earlier runtimes write, which test_a_quote_finds_its_passage_whatever_its_whitespace names outright. validation.md, the comment on anchored_comment_rejection, and the new test's docstring now say it that way, so a later change reads the contract that holds rather than one the runtime already closed.

The other refusal — words only the rendering produces — is unchanged and is now what the door test proves.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

ci on main is red with exactly this pair, and this branch still fixes it after main moved. Run 33443453081 on c5198ef and run 33443479562 on 0eec71a both came back 3 failed, 1587 passed: test_a_quote_finds_its_passage_whatever_its_whitespace, test_a_widgets_label_takes_a_comment_inside_the_control_it_labels, and the catalog preview digest. The Button-fold set is gone from main since #169 landed, so these two are what is left of the standing red, and they are this PR's.

I re-ran them here rather than reading the shapes across: on 2cae083 (main's head now) both fail at -n0, on the same Page.wait_for_function timeouts CI reports — the comment never reaches the log, so no highlight and no thread ever arrive. With this branch merged onto 2cae083, both pass in 8s, and test_render_anchors.py, test_interact_server.py, test_interact_anchors.py, test_interact_mcp.py together are 176 passed on the merge. No merge conflict against the three commits main has taken since this branch's base.

The runs, the merge, and the third failure

On 2cae083, unmerged:

FAILED tests/test_render_anchors.py::test_a_widgets_label_takes_a_comment_inside_the_control_it_labels - TimeoutError: Page.wait_for_function: Timeout 30000ms exceeded.
FAILED tests/test_render_anchors.py::test_a_quote_finds_its_passage_whatever_its_whitespace - TimeoutError: Page.wait_for_function: Timeout 30000ms exceeded.
2 failed, 55 deselected in 64.76s

Same two on 2cae083 with fix/ci-33430997904 merged in: 2 passed in 8.05s.

The one red in the 177 is test_interact_mcp::test_stdio_protocol_carries_the_app_resource_and_private_tool_result, with asyncio.run() cannot be called from a running event loop — the same-process artifact this PR's body already names. It is my -n 2 selection putting a Playwright sync test ahead of it, not the branch: tests/test_interact_mcp.py alone on the merge is 6 passed.

The third failure on both main runs is test_site::test_the_public_catalog_is_a_visual_index_of_full_page_routes — preview inputs changed — rerun scripts/example-previews.py. That is the class #168 named and #133 measured, and it is untouched by this PR: fc-list on this runner still has none of Charter, Iowan Old Style or Georgia (DejaVu, Lato and Liberation only), so a recapture from CI would substitute the gallery's typography. Merging this PR moves the digest again in any case. So expect main to stay red on that one test after this lands, until the refresh is taken from the authoring machine.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Re-verified at main's new tip, and one thing in my last comment has stopped being true: merging this now clears the whole red rather than leaving one test behind. 4b42d15 "Remove the catalog preview freshness digest" deletes the digest assertion from tests/test_site.py and inputs_sha256 from the manifest, so preview inputs changed — rerun scripts/example-previews.py can no longer fire — grep -rn 'preview inputs changed\|inputs_sha256' tests/ scripts/ docs/ on 4b42d15 returns nothing. This pair is all that is left.

Run 33446122333 on b38c6e0 is the third ci on main to come back 3 failed, 1587 passed with the same three, and the two anchor cases still reproduce at -n0 on 4b42d15 — two commits past the 2cae083 I measured last time, neither of which touches skills/leaf/scripts/ or tests/test_render_anchors.py. With this branch merged onto 4b42d15 both pass.

The two runs, unmerged and merged

4b42d15, unmerged:

FAILED tests/test_render_anchors.py::test_a_widgets_label_takes_a_comment_inside_the_control_it_labels - TimeoutError: Page.wait_for_function: Timeout 30000ms exceeded.
FAILED tests/test_render_anchors.py::test_a_quote_finds_its_passage_whatever_its_whitespace - TimeoutError: Page.wait_for_function: Timeout 30000ms exceeded.
2 failed, 55 deselected in 65.25s

fix/ci-33430997904 (6642f19) merged onto 4b42d15 in a throwaway worktree, no conflicts: 2 passed, 55 deselected in 8.98s. Both runs --run-nightly -n0, same runner and Chrome.

git log --oneline b38c6e0..4b42d15 -- skills/leaf/scripts/ tests/test_render_anchors.py is empty, which is why the shapes carry across unchanged from the run above.

@max-sixty
max-sixty merged commit 9aca0f8 into main Sep 1, 2026
3 checks passed
@max-sixty
max-sixty deleted the fix/ci-33430997904 branch September 1, 2026 00:14
max-sixty pushed a commit that referenced this pull request Sep 1, 2026
## 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]>
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