Skip to content

Name a page by its first startup fault, and draw a late widget subscriber through its paint - #2585

Merged
max-sixty merged 5 commits into
mainfrom
fix-startup-fault-and-late-subscriber
Oct 12, 2026
Merged

max-sixty merged 5 commits into
mainfrom
fix-startup-fault-and-late-subscriber

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

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

(a) The bare-text refusal test's teardown errors

test_a_module_that_stages_bare_text_is_refused_in_its_own_name errored at teardown in 2 of 5 local full-file runs after #2575, with late readingBlock page errors and a repeated write of data-lf-startup-error. The mechanism:

  • A page whose module stages bare text is refused by every reader of its words, not only by presentation. On each repaint, the touch controls read the page's reading block (paintTouchControls → standing → walkOrigin → pageReadingBlock → readingBlock → pageText → elementOver) and throw the same refusal, uncaught. Every input adds more: a wheel, a resize and three key or pointer presses took one page from 6 errors to 25.
  • Each uncaught error before presentation reached the prepaint's fault, which wrote the same reason to data-lf-startup-error again, a write that changes nothing (write_watch.js).
  • The test consumed its errors right after the first refusal. Under load, a later refusal and the repeated write arrived after the consume and failed teardown.

#2575 did not cause this. With a 3 s wait after the refusal, the runtime from before #2575 produces the same late errors and the same unchanged write.

Behaviour that changed

  • The first startup fault names the page. prepaint.js now writes data-lf-startup-error and lfStartupException, and dispatches lf-startup-fault, for the first fault only. A later fault only takes the interactive mark off where it is incomplete. The bootstrap's report already kept the first fault (fault ??= reason), and its recover already ignored every fault after the first.
  • The bare-text test closes its page before consuming, as tests/AGENTS.md ("Browser errors") says for a recurring fault.
  • A subscriber added after the first render draws through readingPaint. It used to draw on a separate path that ran only the new callback, so a failure was reported as Presentation failed: …. It now redraws the standing reading through the widget's paint, as refresh() does, which runs renderState and every subscriber again with the same reading. A failure is reported once, as paint failed for <tag>#<id>: …, and the widget shows its fail-soft box. presentRender loses its draw parameter and its try/catch, because readingPaint's paint never throws. Every shipped widget subscribes once, so only a second subscription reaches this path.

Measured

Added Removed
Source (prepaint.js, widget-controller.js) 17 23
Tests 67 1

Validation

  • test_the_first_startup_fault_names_the_page (new) fails on main, where the root names the last fault, a declared one. It also checks that an incomplete fault after an uncaught one still takes off data-lf-interactive.
  • test_a_subscriber_added_after_the_first_render_fails_by_the_paint_rule (new) fails on main: the report reads Presentation failed: late subscriber failure.
  • With a 3 s wait and user input before page.close(), the bare-text test passes.
  • leaf-dev flake ran the three tests 18 times each with no failures. The full test_render_projection.py passes (179), as do test_render_application_boundary.py and the startup-fault tests in test_render_startup.py, test_site.py, test_render_pages.py, test_render_sample_delivery.py and test_widget_quality.py. pnpm run test:runtime passes (371).

Not in this change

A refused page still runs its repaint frame, which throws at the touch controls on every frame, as it did before this PR. Whether the refusal should instead happen once, at the widget's upgrade, changes the bare-text test's decision that the page does not present, so it goes to the user as a separate item.

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

max-sixty and others added 5 commits October 12, 2026 05:05
…re consuming its refusals, and draw a late subscriber through its paint

A page whose module stages bare text is refused by every reader of its words, not
only by presentation: each repaint's touch controls read the reading block and throw
the same refusal, uncaught, before the page presents. Each of those reached the
prepaint's fault handler, which wrote the same `data-lf-startup-error` again, a write
that changes nothing. The prepaint now names the page by its first fault, as the
bootstrap's report already did; a later fault only takes the interactive mark off
where it is incomplete.

The bare-text refusal test consumed its errors while repaints were still throwing, so
under load a later refusal and the repeated write arrived after the consume and
failed teardown. It now closes the page first, as tests/AGENTS.md says for a
recurring fault. The same late errors occur on the runtime before #2575, so that
change did not cause them.

A subscriber added to a widget controller after its first render was drawn by a
separate path that bypassed `readingPaint`, so its failure was reported as
"Presentation failed". It now redraws the standing reading through the paint, which
runs `renderState` and every subscriber again with the same reading, as a refresh
does, and reports a failure once as that paint's.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tup test's fixed faults without closing

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

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The “Left for a decision” section leaves the refused-page behavior unresolved: its repaint still stops at the touch controls, and the startup notice waits for a server update that cannot correct the module. Choosing whether that page presents would change the bare-text refusal contract. I’m withholding approval until that decision is settled.

@max-sixty

Copy link
Copy Markdown
Owner Author

@leaf-agent The refused page's repaint behaviour is unchanged by this PR: the late refusals from the touch controls occur identically on the runtime from before #2575 and on main, and this PR neither adds nor removes them. Issue 78 asked for the teardown flake's mechanism and its fix, and for the late-subscriber path to go through readingPaint; both are complete here. Whether a module that stages bare text should be refused once at its upgrade (fail-soft or a declared incomplete start) reverses the bare-text test's recorded decision that the page does not present, so it goes to the maintainer as a separate item rather than holding this fix. The PR body now says so under "Not in this change". Please review the change on its own scope.

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

@max-sixty
max-sixty merged commit b5be8ab into main Oct 12, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix-startup-fault-and-late-subscriber branch October 12, 2026 12:33
max-sixty added a commit that referenced this pull request Oct 12, 2026
…d say the page has the problem (#2594)

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_

---------

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