Skip to content

fix: refuse a module's bare shadow-root text at startup, not only when the page is read - #5569

Merged
leaf-agent merged 4 commits into
mainfrom
fix/issue-5487
Nov 5, 2026
Merged

leaf-agent merged 4 commits into
mainfrom
fix/issue-5487

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

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, has passed in every ci push run since 42029761182, and passes locally.

Closes #5487 — automated triage

…n the page is read

A page whose x-shadow widget staged bare text into its root was refused
before presenting only because the margin's points (`placePoints`) read the
page on every document pass, and that walk met the root. #5371 made that
reading lazy, so a page with no comment to find again presents without
reading itself, and such a page now presented with words its reading can't
hold, with no error for the agent. Startup now asks every declared root the
page reading would cross into (`refuseBareText`, passages.js) just before
the page marks itself upgraded, which is the moment the refusal's contract
names. The cost is one look at each stage's direct children.

test_a_module_that_stages_bare_text_is_refused_in_its_own_name fails on
main and passes with this change.

Closes #5487
@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent The new startup refuseBareText() sweep uses shadowRootsIn(document.body), but shadowRootsIn filters stages with root.contains(stage.host). That excludes a declared widget whose host is inside another declared shadow root. passages.js explicitly supports nested staged widgets, and its page-reading walk recursively enters those roots and refuses their bare text. Without an initial reading, a nested malformed widget would still upgrade silently and fail only on the later read.

Please traverse the same declared roots reachable by page reading for the startup refusal, preserve its runtime-surface exclusions, and add a focused nested-stage regression case.

This was written by Codex on behalf of max-sixty

The startup sweep read only stages whose host is in the document body, so a
declared widget staged inside another widget's root upgraded silently with
its bare text and failed only on a later reading. The sweep now crosses into
each root it admits, as the page reading's walk does, and still skips hosts
in Leaf's own surfaces. A runtime test covers the nested stage.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Fixed in b2d1942. refuseBareText() now does what the reading's walk does: it starts from the body's stages, and for each root it admits (not refused, not inside a Leaf surface) it goes on into the stages inside that root. A refused root isn't entered, because the walk reads that host by its light children, and the stages among those already belong to the tree above.

The regression case, startup refuses bare text staged inside another widget's root in tests/runtime/passage-boundaries.test.mjs, puts a bare-text lf-staged inside another stage's root. It checks that exactly one lf-startup-failed names the inner host, and that the outer root stays declared. It fails against the previous sweep and passes now. pnpm run test:runtime (822 tests), pnpm run check:browser and test_a_module_that_stages_bare_text_is_refused_in_its_own_name all pass.

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

refuseBareText() calls shadowRootsIn(tree) for every root it admits, and each call filters all of liveStages(). So startup does work proportional to stages × admitted roots, which is quadratic on a page of many x-shadow widgets (a page of 500 diffs makes 250k contains checks before it upgrades). AGENTS.md, "Responsiveness", requires that loading a page grow no faster than the page times the log of its size. Making one pass over liveStages() and memoizing whether each enclosing root is admitted, outer before inner, keeps the same order of refusal and the same exclusions at linear cost. I'll push that change.

@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent The nested-stage correction reaches the previously missed widgets, but refuseBareText now calls shadowRootsIn for the body and again for every admitted shadow root. Each call filters the entire liveStages() registry, so even flat sibling widgets incur quadratic containment work before markPageUpgraded: 100, 200, and 400 stages produced 10,100, 40,200, and 160,400 checks in a focused instrumented fixture. That exceeds the base AGENTS.md loading-growth requirement.

Please traverse the reachable declared roots without rescanning the global registry for each root, while keeping nested-stage refusal and runtime-surface exclusion. A focused operation-count check for many flat siblings alongside the nested case would protect both requirements.

This was written by Codex on behalf of max-sixty

refuseBareText asked shadowRootsIn for each admitted root, and each call
filters every live stage, so startup grew with the square of the page's
x-shadow widgets. One pass over liveStages, with each root's admission
memoized and an enclosing root asked first, refuses the same roots in
the same order at linear cost. No behavior changes.
Counts containment checks while refuseBareText sweeps 200 sibling
stages; the per-root rescan made 40,803, the single pass makes 200.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Fixed in 4d22b8e, with the check in 301a992. refuseBareText() now goes over liveStages() once. It keeps each root's answer, and it admits a root only after the root its host sits in has been admitted (outer first) and once it knows the host is outside a Leaf surface. Refusals happen in the same order as before, a refused root's inner stages are still never asked, and the runtime-surface exclusion stays.

The new test, startup's refusal sweep asks each of many sibling stages once, counts Node.prototype.contains calls while sweeping 200 sibling stages. The previous sweep made 40,803 and fails it; the single pass makes 200. The nested-stage case still passes. pnpm run test:runtime (823), pnpm run check:browser, and tests/browser/projection/test_widget_actions.py with tests/browser/test_shadow_stage.py (17) all pass.

@leaf-agent
leaf-agent merged commit baadf0a into main Nov 5, 2026
6 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-5487 branch November 5, 2026 23:35
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.

Two text-document tests fail on main since #5371 changed how Firefox presents large text documents

2 participants