Repository navigation
Contain Leaf sample navigation while preserving native delivery - #2255
Conversation
Keep opaque samples on native scoped delivery and exchange presentation commands over a private port. Leaf focus, local reveal, native layer transitions and editor selection placement prevent outer navigation before it occurs, while authored browser APIs remain available. Preserve native resource loading and reconnect on reload; route hosted samples to their allocating container without parent credentials. Read exposure obtains fresh parent geometry across opaque boundaries. Correct Escape return hints and expose the canonical interaction log reader. Regressions cover Chromium and WebKit editor entry, native modules/XHR/forms/popups/nested samples/reload, child capability scope and parent visibility.
…navigation # Conflicts: # skills/leaf/assets/runtime/anchor-travel.js # skills/leaf/assets/runtime/banner-toolbar.js # skills/leaf/assets/runtime/composing/text-field.js # skills/leaf/assets/runtime/interaction-gallery.js # skills/leaf/assets/runtime/keyboard/command-reference.js # skills/leaf/assets/runtime/keyboard/layer-stack.js # skills/leaf/assets/runtime/landing-scroll.js # skills/leaf/assets/runtime/media.js # skills/leaf/assets/runtime/sample.js # skills/leaf/assets/runtime/thread/page-comment.js # skills/leaf/assets/runtime/thread/panel.js # skills/leaf/packages/command-hub/widgets/lf-command.js # skills/leaf/packages/default/runtime/annotation-overlay/margin-projection.js # skills/leaf/packages/default/widgets/lf-sample.js # tests/input_work_watch.js # tests/test_interact_server.py # tests/test_render_controls.py
Use one Leaf CodeMirror adapter for composers and file editors, preserving local alignment and margins before document-local outward reveal. This closes the classic-scrollbar native fallback and retains PageUp/PageDown caret placement. Keep navigation installed across state replacement and reconnect. Expose failed readiness only after retirement finishes so an immediate Reset starts a fresh allocation. Native document fixtures exercise real opaque child delivery.
leaf-agent
left a comment
There was a problem hiding this comment.
A failed child document request can strand the sample. The iframe load handler only releases the load slot; readiness still waits for a message from the child's bootstrap. If that document returns 404 before bootstrap runs, no message arrives, host.ready stays pending, and Reset remains disabled. I reproduced this by returning 404 for the child document: the iframe loaded while its readiness promise did not settle. The document failure needs to reject readiness and retire that allocation so Reset can start a new child.
Use the document producer header for credentialless initial admission, and retire failed allocations before Reset. Later native navigation cancels private presentation without removing its destination; valid reload reconnects. Opaque pagehide telemetry uses the same credential-aware native fetch as ordinary flushes. Browser observations retain document replacement listeners and exact causal input across enrolled private ports while authored Worker ports stay native. Update tests that depended on removed resource packaging and prove older input cannot excuse losing newer words.
…navigation # Conflicts: # notes/browser-support.md
Visual review keyboard routes now focus then reveal through the canonical document-local scroll owner. Unsupported focus options fail at the API boundary instead of silently losing intent. The regression proves a bottom-edge short-case verdict reveals the next taller case. Frame visibility observations now use the driver-owned cross-origin reading, removing a redundant ancestor walk that WebKit rejects after a blank frame becomes opaque; held-paint controls retain explicit visibility input.
leaf-agent
left a comment
There was a problem hiding this comment.
WebKit form departure still fails the new sample journey. I ran test_sample_native_departure_keeps_destination_and_reset[form-webkit_browser] twice; both runs completed its assertions, then clean_browser rejected a console access-control error for the old sample's api/state request. The revoked-sample path in PageEndpoint._sample_request returns a bare _not_found() while active sample responses receive _sample_headers(), so a late request after Reset loses the child CORS headers. This appears to explain the WebKit error. Preserve those headers on a revoked child capability, or settle the outstanding state read before release, so the form departure journey finishes cleanly.
…navigation # Conflicts: # tests/test_render_files.py
leaf-agent
left a comment
There was a problem hiding this comment.
The updated head still fails two paths this change covers:
- The restored gallery reports “Ready — motion will start only when you press Play” while
test_interaction_gallery_waits_for_a_restored_frame_tabexpects “Loading” during the held child state read. The new allocation matcher sees the request, but the readiness assertion failed in both CI and a focused local rerun. The gallery can offer Play before that restored child is ready. - WebKit still logs an access-control error for the departed child’s
api/staterequest after Reset. The explicit revoked-capability probe receives 404, but the form and script journeys fail at browser-error cleanup in CI; the form journey also failed locally. The new response headers therefore have not resolved the outstanding old-document request noted in my earlier review.
CI failed: the gallery restore and WebKit sample departure journeys remain red.
Read compositor anchor geometry through an independent unpainted probe rather than choosing a source camera from the measured holder. Stop sticky scroll credit at fixed containing blocks. Keep healthy page/window crossing and verified opposing 20px holder, inset and child layout faults, including the historical-camera coincidence case. Restore the normal observer verification cadence. Gallery readiness waits for the actual runtime entry; a pending state read can legitimately present offline after 10s. Native-departure checks prove the old freshness read was cancelled, scope WebKit teardown refusals to that exact capability, and keep a separate fresh revoked-capability preflight HTTP 404 assertion. No runtime restriction or beforeunload latch. Validation: 79 passed, 6 skipped related browser checks under VERIFY1; final 8 return/fault cases passed at VERIFY30;4 Chromium/WebKit departure cases passed; focused restored-gallery/slow-state cases and pre-commit passed.
leaf-agent
left a comment
There was a problem hiding this comment.
The new camera reader calls getComputedStyle(selection.frame), but anchorFor can supply a virtual content-start handle when words sit directly in a scroller. That handle has getBoundingClientRect but is not an Element, so the motion watcher throws on every read. I reproduced the resulting console error in test_native_attachment_measures_solver_and_scroll_origin_together[False-before-discovery-inner]; the broad CI run reports the same error across the send-placement cases. Handle virtual anchor frames at this boundary while retaining the independent source-pose measurement.
The pinned CI test job and a focused local test reproduce a getComputedStyle error in the new native camera reader.
Floating content-start anchors expose a virtual geometry handle rather than an Element. Read native CSS styles only for Element frames, matching the camera consumer domain and preserving virtual attachment measurements. Reproduced the CI teardown failure; 33 focused attachment and movement-fault cases pass, plus Opus independently verified 22 cases at 6x CPU throttling.
…s painted name (#2306) Two browser tests fail on main at 8bff2b4. Neither is among the `fix/ci-38051185604-*` PRs. **Page Map End leaves the last row out of view** (`test_page_map_filtering_keeps_search_and_close_in_place`, all three viewports; red in main CI run [38067192989](https://github.com/max-sixty/leaf/actions/runs/38067192989)). #2255 moved walk and search landings from native focus scrolling to Leaf's document-local `scrollIntoView`. That function returned early when no reading region held the destination, and no reading region holds a row in a modal layer. So End focused the Page Map's last row and left it below the list's scrollport. A destination with no reading region now has its enclosing boxes reveal it at the nearest edge, out to the fixed layer. The walk also stops at a fixed box whether or not that box clips, so an `overflow: visible` fixed wrapper no longer lets the reveal scroll the pane behind it. **The thread card's top-row reading depends on font metrics** (`test_the_thread_card_opens_on_its_latest_message_under_its_own_name`, fails on macOS, passes on Linux CI). On macOS the card lands with its top 7px into the previous message's pushed-off sticky head. That 7px is the head's blank foot, followed by the 16px gap before the next message's name. The test probed at half a head's height and hit the gap. The test now reads the first name painted in the card, requires that name's head to start in the top row, and checks that the words under the head belong to the same message, which is stricter than the old `under in (named, -1)`. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
A Leaf page can now show another Leaf page from the same machine in an `<iframe>`. Before, page `a`'s frame of page `b` stayed empty, because every served document carried `frame-ancestors 'self'` and the two pages run on two `leaf server` ports. Closes #5008 ## For Max This moves a trust boundary, and you chose to land it. After this change, any live Leaf page's scripts can frame every other live page under the same state home and dress its decisions in a different interface. That includes third-party scripts a page loads, such as a charting library from a CDN. The key cookie already reached every port on the host, so such a script's requests to `b` already carried it; what's new is that the script can show `b`'s live controls inside its own page and cover them. Before, only `b`'s own origin could do that. The case for it is that every page under the state home is the same user's, written by their agents, and already reachable with the same key. The cost is that a page's third-party scripts, trusted with that page, can now frame every live page. ## What changed A page's running server now adds to `frame-ancestors` the exact origin of every other Leaf server that holds its lease under the same state home (`PageEndpoint._frame_ancestors`, which reads `presence.live_servers`). Nothing is asked of page authors: `a`'s source holds `<iframe src="http://127.0.0.1:<b's port>/">`, the bare address, and the key cookie from the user's arrival at `a` authorizes it. - The reading happens at each framed document, so a server started after `b` can frame it. A server whose lease has ended is left out, since its port may since belong to any process. - A top-level navigation (`Sec-Fetch-Dest: document`) has no ancestors to admit and skips the reading, so ordinary page loads pay nothing. - A temporary server (`--lifetime temporary`), which has its own key and keeps no service record or row, and leaf.page still send `frame-ancestors 'self'` alone. - A server at a bare IPv6 address is left out of the list. CSP's source grammar has no IPv6 literal, and Chromium logs such a source as an error on every framed document, so a page served at one can't frame another. - `page check --render` answers a frame of each other live Leaf page with a stand-in page ("Another Leaf page, checked on its own."), since its browser holds no key for that page and that page's server refuses the gate's origin as a framer (`render_gate.scheme.stand_in_other_leaves`). Without it, every framing page failed the check with a 401 console error its author couldn't fix, whose text pointed toward putting the key in the `src`. Only a child frame's navigation stands in: a script, stylesheet, image or `fetch()` the framing page loads from that server reaches the server as it would without the stand-in. A frame of any other address, a mistyped port included, still loads and fails. - `live_leaves` (the `others` menu and `page list`) now reads the same `live_servers` walk. `server.page_origin` is the one spelling of a page's origin; `page_url` and `TemporaryPageServer.origin` build on it. - The sample-child exemption is now "never set the header" rather than "delete it afterwards", so a widened policy can't reach a sample child. - `validation.md`'s "Delivery policy" states the rule, and "Browser validation" the stand-in. "Delivery policy" also claimed sample children carry the header, which they haven't since #2255. - `live-samples.md`, which told authors a served page frames only inside its own origin, now says a page may frame another live Leaf page by its address without the `?t=` key, and that the render check shows a stand-in there. - The comment in `browser/runtime/frame-visibility.js` that said a framed Leaf document always has a same-origin parent now describes the cross-port case. That comment edit changes the runtime's source hash, so `dist/kernel/kernel.json` is rebuilt; no bundle changed. ## Security argument - **The key cookie already reaches every port.** Cookies are scoped by host, not port, so the host-key cookie (`SameSite=Strict`, `HttpOnly`) is sent to every server on the page's host, Leaf or not, and a frame from another port is same-site. The browser test shows it: a frame request from another server's page at another port carries the key cookie. `frame-ancestors` is the only defence against another local server framing a live page and dressing its decisions in a different interface. - **Admitting same-key Leaf servers exposes no new key.** Every server that publishes a row in the state home serves with that state home's key (`server.host_key`). That key already authorizes a bare link to each of them, and the `others` menu links them. The framing ability itself is new, and "For Max" above says what it admits. - **Getting listed takes the user's own access.** A listed origin needs a row in the state home (mode 0700) and a held server lease beside an enabled `service.json`. Only a process running as the user can arrange that, and such a process can already read the key from `access.json`. - **No wildcard.** `http://127.0.0.1:*` would admit any local web server, such as a dev server on `:3000`, to frame a live page with the user's key cookie. The policy lists exact origins instead. - **Only live leases count.** The origins come from `server.running_server`, which requires the server lease to be held and to name the recorded incarnation. A stale row or `service.json` for a stopped server admits nothing, so a foreign process that later binds a dead Leaf server's port can't frame. The list is read when each framed document is served; a back/forward cache restore could carry a list read before a framer stopped (an untested hypothesis). - **`--host`.** A server started with `--host NAME` is listed as `http://NAME:<port>`, the origin its URL names. Two pages served under the same name share a host, so the frame is same-site and the cookie flows into it as on loopback. The repro passes with both pages under `--host localhost`; a tailnet name wasn't tried. An independent review tried a missing or forged `Sec-Fetch-Dest` (only ever yields the full list), a framer killed with `kill -9` (`'self'` on the next request), a plain `http.server` on the dead framer's port (refused although the cookie reaches `b`), temporary and other-state-home servers (excluded), and leaf.page (unchanged). ## Evidence The issue's steps, scripted against a scratch `XDG_STATE_HOME` with each page's server started by `leaf server start --lifetime persistent` and `b`'s bare address in `a`'s `<iframe>`: - Before: `b`'s policy was `frame-ancestors 'self'`, the frame stayed empty, and Chromium logged `Framing 'http://127.0.0.1:59935/' violates the following Content Security Policy directive: "frame-ancestors 'self'"`. - After: `b`'s policy is `frame-ancestors 'self' http://127.0.0.1:65327` (`a`'s origin). The frame shows `b`'s heading, with no console messages. `leaf page check --render a` passes, and its screens show the stand-in in the frame. - With `--lifetime temporary`, as the issue's steps run, both before and after are refused. Each temporary server has a key of its own, so its `src` must carry the key, and it keeps no record for another server to find. The fix applies to `server start` and `server run` with the session or persistent lifetime, and to `leaf-dev preview --user`. Cost, on a real persistent server beside 80 fake live neighbours (this Mac's state home had 80 live servers at the time), 60 requests each: | | median | p90 | policy | |---|---|---|---| | top-level document, 0 neighbours | 1.77 ms | 2.08 ms | 22 B | | top-level document, 80 neighbours | 1.92 ms | 2.52 ms | 22 B | | framed document, 80 neighbours | 8.49 ms | 10.05 ms | 1862 B | Each live neighbour costs a framed document about 75 µs (a lease probe and two record reads). ## A framed page, in Chromium and Firefox Driven with Playwright, `a` framing `b` (900×640) with an `lf-options` ask in `b`: - Works: `b` presents. Picking an option in the frame lands in `b`'s log. A page comment typed in `b`'s panel lands in `b`'s log and opens its thread in `b`'s panel, which sits inside the frame while `a`'s panel stays at the window's foot. Keys follow focus: after a click in the frame `?` opens `b`'s keyboard reference, and after a click in `a` it opens `a`'s. `localStorage`, where drafts live, is shared between the framed `b` and `b` in a tab of its own. - Differs: `b` can't read `a`'s frame element across origins, so it counts itself shown whenever its tab is, even scrolled out of `a`'s view (`frameVisibility()` is null on screen and scrolled away). A same-origin frame reads its frame element instead. - Differs: `b` reports the frame's viewport (900×640) as the user's window, so while that is its newest report, `b`'s `page check --render` lays `b` out at the frame's size. ## Tests - `tests/process/test_interact_server.py::test_a_page_admits_frames_only_from_live_leaf_servers_under_its_key`: a real persistent server's document names a live neighbour's origin exactly, and leaves out a neighbour whose server stopped. A mutation that read records without checking the leases failed it. - `tests/browser/startup/test_hosting.py::test_a_live_page_admits_only_leaf_parents_under_its_key` replaces `test_a_live_page_refuses_a_same_site_parent_at_another_port`. One live child page is framed by another server's page at another port, which is refused although its frame request carries the key cookie, and by another live Leaf page, where it presents. That other server is a temporary Leaf server, standing in for any server on the host outside the live set. On `main`'s `http.py` the second frame is refused. - `tests/browser/test_render_gate.py::test_a_frame_of_another_live_leaf_page_is_checked_on_its_own`: a page framing a live Leaf page and a temporary server's page fails the gate only for the second. With the stand-in disabled, it also fails for the first's 401. On a page with the stand-in installed, a `fetch()` to the live server gets that server's 401 while the frame beside it shows the stand-in; when the stand-in answered every request to the origin (5d5a3b4), the fetch got its 200. - Ran on the current head: those three; the process and model tests that read neighbour rows, the CSP header or `page_url` (neighbour discovery and rows, the served state schema, sample capabilities, the website's routes, `page list`, a network-facing bind, the IPv6 address); by node id, the two neighbour-row tests and the end-to-end `page check --render` test that now live in `tests/journeys/`; the two All pages browser tests in `test_render_controls.py` that serve a live neighbour; the render gate test of a refused document and the hosting test of same-origin embedding; `pnpm run test:runtime` (750 passed), `pnpm run check`, and pre-commit on the changed files. - Not run: the nightly `tests/journeys/test_interact_server.py::test_server_round_trip`, whose `'self'` assertion is on a temporary server and so unchanged; WebKit beyond a CSP grammar probe. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Leaf's sample navigation could move or focus the containing page. Put prevention in Leaf's focus, reveal, native-layer, and CodeMirror owners, so switching a sample conversation leaves the outer control focused and the page still. Authored scripts and embedded frames retain their browser behavior.
Samples use opaque native documents with capability-scoped HTTP delivery and a private presentation channel. Native modules, relative imports, XHR, forms, popups, nested samples, and reload work without a resource packager or fetch relay. The website routes credentialless child requests to the allocating container. Fresh exposure readings preserve read state across the boundary; Full view retains the same frame and drafts. Initial HEAD admission checks the document producer's header and retires failed allocations before Reset. Destroy cancels held admission requests and queued load waits, while pending allocations finish so their capabilities can be released. Every child response, including a revoked capability's refusal, carries the credentialless child headers. Preflight grants no page access and succeeds before capability lookup, so the subsequent request receives its HTTP refusal after revocation. Later native navigation keeps its destination visible, cancels private presentation commands, and leaves Reset available; a valid Leaf reload reconnects. Admission verifies what the server offers before navigation, rather than promising to classify a later opaque destination.
The shared LeafEditorView adapter serves composers and file editors, including restored states. It prevents WebKit retained-selection focus and CodeMirror's classic-scrollbar native reveal from escaping, while preserving local caret alignment, margins, PageUp and PageDown. Visual-review keyboard navigation reveals its verdict through the document-local scroll owner, and unsupported focus options fail explicitly. Escape hints describe the actual return destination. Gallery playback runs inside the sample instead of reaching through its document.
Opaque-child telemetry shares credential-aware native delivery. Browser observations retain input listeners across document replacement, preserve exact causal input across enrolled private ports, and read cross-origin frame visibility from the driver; authored Worker ports retain native traffic. The motion observer measures the compositor source pose through an independent native anchor probe, including transitions between page and window placement. Its native CSS probe accepts element frames; virtual content-start anchors retain their geometry-handle observation path. Sticky descendants stop at their fixed containing block. Measured holder, inset and child layout faults remain failures even when they coincide with an earlier source pose. Gallery startup tests hold the declared runtime entry rather than treating a pending state read as an indefinite readiness block. Native-departure coverage forces an outstanding freshness read, proves its cancellation, and accounts only for teardown refusals from that departed capability; a separate fresh preflight still requires an actual HTTP 404 after revocation.
Validation: Claude Opus 5.5 reviewed the implementation and fixes; its implementation and test-boundary findings are resolved and the final review has no blockers. Focused Chromium and WebKit journeys, local/server capability tests including revoked-child refusals, visibility/read-state and disposal/queued-load lifecycle tests, Worker routing and TypeScript checks, 306 runtime tests, and repository pre-commit checks pass. The final observer repair passes 33 focused attachment and movement-fault cases; Opus independently reran all 22 affected virtual-anchor cases with verified 6x CPU throttling. The PR runs the broad suite and site delivery gates.
Tradeoff: opaque frames have separate browser cache partitions. With compiled installations, the 17-frame gallery measured 786 → 816 requests and 6.72 → 35.01 MB of response bodies across all frames, after every sample reached ready. Presentation measured 3.46 → 3.81 seconds on the shared machine; timing is diagnostic. A shared immutable URL control still transferred the graph separately. Native delivery and DOM/data isolation are retained; no parent focus or scroll restoration is used.