Skip to content

Refuse a module's bare text once, end the page before it presents, and say the page has the problem - #2594

Merged
max-sixty merged 4 commits into
mainfrom
agent-a358e2fd04468f9c8
Oct 12, 2026
Merged

max-sixty merged 4 commits into
mainfrom
agent-a358e2fd04468f9c8

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

This closes issue 81 of the Lit follow-up review (that review's numbering, not a GitHub issue).

What was wrong

A page whose module stages bare text into a shadow root is refused by elementOver (runtime/passages.js). Every later reader of the page's words then raised the refusal again: each repaint frame (paintTouchControls → standing → walkOrigin → pageReadingBlock → … → elementOver), each key through the keyboard dispatch, a resize through version.js's reading-region restore, and a selection through the composing surface's listeners. Each was an uncaught error and another report. A wheel, a resize and three presses took one page from 6 errors to 25. The "Leaf couldn't start" notice meanwhile waited for a server update, which can't fix a module's mistake. #2585 made the prepaint record only the first fault, but the loop kept throwing.

Stopping each reader that rereads the page would have meant keeping a list of readers, and a first version that stopped the rendering loop and the page keys still missed selection. So the fix sits where every reader passes: the walk.

Behaviour that changed

  • The walk refuses a root's bare text once. Before crossing into a declared shadow root, the walk checks it for bare text (refusesBareText). A root that has some is refused for good (refuseShadowRoot, runtime/shadow.js). From then on every walk, and the list of declared roots that getComposedRanges is handed (shadowRootsIn), reads that host by its own children, the way an undeclared root reads. Those children are the words the file holds. No reader throws, so the agent gets one report, made at that point with reportPageError.
  • Before presentation, the refusal is the page's own startup failure. It goes through the existing path as lf-startup-failed marked page: true. The prepaint takes data-lf-interactive off, so the readable fallback shows at once. presentPage never stamps a page declared failed, because a later state answer would otherwise present the reading without those words. The recorded decision stands: such a page does not present.
  • The notice says the page has the problem. A fault marked page reaches the bootstrap through lf-startup-fault. The notice reads "Leaf couldn't start: this page has a problem its author needs to fix.", and the bootstrap no longer polls for a replacement server.
  • After presentation, a refusal leaves the page running without those words and is reported once.
  • elementOver is a plain throw again, kept as the assertion for any node handed to it directly.

Measured

Added Removed
Source (leaf.js, bootstrap.js, passages.js, prepaint.js, shadow.js) 91 25
Tests 46 8

About two thirds of the added source lines are comments.

Validation

  • test_a_module_that_stages_bare_text_is_refused_in_its_own_name now also asserts the notice's wording, the readable fallback, and exactly one console error and one error event in the log across a wheel, a resize, two key presses, a click, a drag-select and a double-click. It fails on main, where the notice waits for the server. leaf-dev flake ran it, and test_the_first_startup_fault_names_the_page, 18 times each with no failures.
  • A probe that appends bare text to a presented page and then scrolls, resizes, presses keys and selects gets one report. The page keeps data-lf-interactive and data-lf-presented.
  • These pass: test_render_projection.py and test_render_startup.py in full, the startup and layer-mismatch tests in test_site.py and test_widget_quality.py, the sample tests in test_render_controls.py, the shadow and editor tests in test_render_anchors.py and test_render_files.py, and pnpm run test:runtime (371).
  • test_a_window_sample_is_a_whole_leaf_window_that_scrolls_inside fails locally on main as well (scrollY 444 against 408), so this change doesn't cause it.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 4 commits October 12, 2026 05:56
…s the problem

A page whose module stages bare text into a shadow root was refused by every
reader of its words, again and again: each repaint frame threw the refusal at the
touch controls, each key threw it from the keyboard dispatch, and a resize threw it
from the reading-region restore. A wheel, a resize and three presses took one page
from 6 errors to 25. The "Leaf couldn't start" notice meanwhile waited for a server
update, which cannot fix a module's mistake.

Behaviour that changed:

- passages.js `elementOver`, which every reader of the page's words passes through,
  is the one point that ends the page. Its first refusal declares the page failed
  (`lf-startup-failed`, marked `page: true`), so the readable fallback shows at once,
  and every later call throws the same refusal, which `reportCarried` drops.
- A page declared failed stops rendering and taking page keys: leaf.js calls the new
  `stopRendering` (rendering.js), which retires every queued and future rendering
  callback, and unmounts the keyboard controller. Each of those read the page again.
  This applies to every declared startup failure, not only the refusal.
- A fault that is the page's own reaches the bootstrap as `page`, and the notice
  reads "Leaf couldn't start: this page has a problem its author needs to fix." It
  no longer polls for a replacement server.
- The page still does not present, as the bare-text test records. It now reports one
  error, to the console and to the agent's log, across a wheel, a resize and three
  presses; the test asserts that, the notice, and the readable fallback.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…en on

Review of the previous commit found the stop list incomplete: a selection still
threw the refusal from the composing surface's listeners, each an uncaught error
and a second report to the agent, and a refusal after presentation tore down a
page the user was working in. Stopping each reader that rereads the page was a
list of readers; the deeper fix is that no reader can meet the bare text twice.

Behaviour that changed:

- The walk asks a declared root for bare text before crossing in
  (`refusesBareText`, passages.js). A root that holds some is refused for good
  (`refuseShadowRoot`, shadow.js), so from then on every walk, and every list of
  declared roots (`shadowRootsIn`, which `getComposedRanges` is handed), reads its
  host by the host's own children, as an undeclared root reads. No reader throws.
- The one refusal is reported to the agent there, once, and before the page
  presents it is declared the page's own startup failure as before: readable
  fallback at once, the page-problem notice, and now `presentPage` never stamps a
  page declared failed, since a later state answer would otherwise present the
  reading without those words.
- A refusal after presentation leaves the page running without those words and
  reports once; it no longer takes the interactive mark off a page in use.
- `stopRendering` and the keyboard unmount are gone: nothing reads the refused
  text again, so nothing needs stopping.
- The bare-text test now also drags a selection and double-clicks.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…, and say what a late refusal leaves behind

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit ab69e84 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a358e2fd04468f9c8 branch October 12, 2026 14:33
leaf-agent added a commit that referenced this pull request Nov 5, 2026
…n the page is read (#5569)

A page whose x-shadow widget stages bare text into its shadow root is
supposed to be refused before it presents: the readable fallback shows,
the notice says the page has a problem, and the agent gets one error
naming the widget (#2594). That refusal only fired because some walk of
the page's words met the root first, and before #5371 the margin's
points (`placePoints`) read the whole page on every document pass. #5371
made that read lazy, which was the point: a pass where every point still
stands reads nothing. Now a page with no comment to find again presents
without reading itself at all, so the module's bare text is never
refused, the page presents, and the console stays silent. That is why
`test_a_module_that_stages_bare_text_is_refused_in_its_own_name` timed
out waiting for the error.

This change makes the check explicit. Just before the page marks itself
upgraded, startup asks every declared shadow root the page reading would
cross into (`refuseBareText` in `passages.js`, called from `leaf.js`).
That is the moment the refusal's contract already names. Like the
reading's walk, it crosses into each root it admits and on into the
stages inside that one, so a malformed widget nested in another widget's
root is refused too. It skips hosts inside Leaf's own surfaces, as
`readPage` does. #5371's lazy reading stays as it is. The added startup
work is one look at each stage's direct children.

**Verification**
- Restoring the eager `pageText()` in `placePoints` makes the test pass
on main, which confirms the cause.
- With this change the test fails on main and passes on this branch.
- A runtime case in `tests/runtime/passage-boundaries.test.mjs` stages
bare text inside another stage's root; it fails with a sweep of the
body's stages alone and passes with this change.
- `tests/browser/projection/test_widget_actions.py` and
`tests/browser/test_shadow_stage.py` pass (17 tests), as do `pnpm run
test:runtime` (822), `pnpm run check:browser` and the pre-commit hooks.

The issue's other test,
`test_a_comment_on_a_closed_tab_s_document_never_reads_as_earlier_data`,
is already fixed on main. #5371 added it with the `.lf-fp-quote`
locator, while #5454 renamed that quote's class to `.lf-thread-quote`
and updated the test. It failed through run
[42010431285](https://github.com/max-sixty/leaf/actions/runs/42010431285),
has passed in every `ci` push run since
[42029761182](https://github.com/max-sixty/leaf/actions/runs/42029761182),
and passes locally.

Closes #5487 — automated triage

---------

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