Repository navigation
Build a scalable PR review packet - #189
Conversation
Add reusable pull-request metadata and captured diff views with stable line and selection anchors. Present the change through a review route, diagrams, evidence, risk decisions, and explicit outcomes. Keep async data projection and shadow-root comments stable across refreshes, and cover the new package, example, exports, and browser behavior.
# Conflicts: # docs/example-command-hub.jpg # docs/example-design-decision.jpg # docs/example-heat-loss.jpg # docs/example-live-progress.jpg # docs/example-postmortem.jpg # docs/example-pr-walkthrough.jpg # docs/example-previews.json # docs/example-release-notes.jpg # docs/example-ship-review.jpg # docs/example-triage-board.jpg # examples/corpus.html # examples/pr-walkthrough.html # skills/leaf/assets/theme.css # skills/leaf/packages/default/theme.css # tests/test_render_anchors.py
# Conflicts: # docs/example-pr-walkthrough.jpg # docs/example-previews.json # scripts/preview.py # skills/leaf/assets/runtime/composing/surface.js # skills/leaf/scripts/leaf/http.py # skills/leaf/scripts/leaf/served_state/page.py # tests/render_harness.py # tests/test_render_outbox.py
leaf-agent
left a comment
There was a problem hiding this comment.
Read the whole change and ran a second structured pass over the merged tree. The manifest-first split (contract-declared fragments, the /api/data door, in-place manifest projection in browser_data) reads clean, and validating fragment keys at the data set boundary rather than at delivery is the right seam. Three things below; the first is the one I'd want fixed before this lands.
A same-second replacement of a bound source is silently dropped. lf-diff keys its re-render on `${snapshot.snapshot ?? "current"}:${snapshot.updated}`, and updated comes from now_iso(), which is isoformat(timespec="seconds"). Two leaf data set calls to the same source inside one wall-clock second produce different revisions but the same updated, so acceptData accepts, notifyDataSubscribers fires, and the widget returns early holding the previous render. For the manifest form the fallout compounds: the DOM keeps the old manifest while loadDataFragment sends the new runtime.data.revision, so a key the replacement dropped comes back unknown fragment key — and loadManifestEntry sets entry.failed = true, which is never cleared except by a source change the widget just decided it didn't see. The file then shows "That file's diff failed to load" until the page is reloaded. lf-source, changed in the same PR, re-renders unconditionally and doesn't have this, which is what makes the guard itself the new thing. Either give the delivered envelope something that moves per write (the store already knows the revision _write_source returned) or compare the value rather than the timestamp; a stale-fragment error probably also wants to be retryable rather than terminal.
notifyDataSubscribers is all-or-nothing across every subscriber. await Promise.all(pending) means one package whose async render rejects skips PAGE_PAINT_ATTRIBUTE.dataRevision for the whole page and rejects back into receiveState/tick, which report read failed and re-read — failing the same way each poll. That is close to the inverse of what watchData's own comment promises ("A package that throws while mounting must not leave a listener behind to fail every later poll"): a synchronous throw still refuses the subscription, but a returned rejected promise both registers the listener and, now that skills/leaf/CLAUDE.md tells widgets to "return an asynchronous render promise so the page's data-readiness stamp waits for the projection", is the shape packages are being pointed at. None of the three shipped widgets can reach it — they all catch internally, and highlightBlocks catches per block — so this is about the layer staying open rather than a live break. Settling per subscriber and reporting the failures would keep one package from holding the readiness stamp.
What I checked and dropped
scrollToThread's hydration recursion terminates:lfRevealDatumreturnsnullonceentry.loaded/entry.failed, and a disconnected host isn't found bysectionOfin the first place.browser_datamutating in place is safe —read_datare-decodesdata.jsonon every call, no shared object.- The new
markdown.jslink/image filter holds:safeUrlresolves throughnew URL, sojavascript:and tab/newline-obfuscated variants fail the protocol set, and the vendored marked (18.0.11) falls back to its default renderer only on a literalfalse. sourceLines'unsupported ${part.type}throw isn't reachable from the vendored parser —hunkContentonly ever holdscontextandchange;\ No newline at end of filesetsnoEOFCR*flags without pushing a part.require_registry'ssys.exitinsidedata_fragmentwould escape theexcept (DataError, ValueError), but a served page always has a registry, so there's no reachable condition to guard.
leaf-agent
left a comment
There was a problem hiding this comment.
Read the delta against the previous review. Both findings are closed properly: the bound-source stamp now keys on the per-source revision the write returned rather than a second-resolution timestamp, entry.failed is gone so a refused fragment is retryable, and notifyDataSubscribers settles per subscriber and reports each rejection on the page-error channel instead of rejecting back into receiveState. The per-source revision also earns its keep beyond the collision it fixes — an unrelated source's write no longer moves this widget's stamp. One thing below, on the new mount path.
An asynchronous rejection on the first render now cancels the subscription, and nothing says so. watchData wraps the mount promise in a catch that calls document.removeEventListener("lf-data", update) before re-throwing, so a package whose initial render rejects is never asked to restate again — while the same rejection one poll later is reported and the listener stays. The two halves of the delta pull in opposite directions, and only one of them is written down: references/packages.md says the callback "runs immediately and again when Leaf asks subscribers to restate its view" and that a rejection "is reported as that subscriber's page error", which describes the update path exactly and the mount path not at all. A package author reading that has no way to know that one transient failure inside their first await leaves a live stopWatching handle over a dead subscription, showing stale data with no further error. The synchronous-throw case is at least self-announcing — watchData throws and the widget never gets its handle — but the asynchronous one returns normally and dies later. Suggestion inline for the doc half.
The behaviour is also unpinned. test_data_readiness_settles_and_reports_failed_subscribers calls stopMount() immediately, so the listener is removed either way, and its afterMount == before assertion holds vacuously now that the stamp is written unconditionally — before is already String(runtime.data.revision) at that point and the mount notification cannot change it. Deleting the catch wrapper leaves the suite green, which makes the docstring's "A rejected mount removes its listener" a claim the test does not check. Dispatching one lf-data after the rejected mount and asserting the callback was not called again would pin it.
What I checked and dropped
- The store's new per-source
revisionis validated once atread_data_store(1 <= source_revision <= revision, non-bool int) and reaches the browser throughbrowser_data, which sends the store whole;_write_sourcestripsrevisionfrom the captured copy, so the snapshot allowlist inread_data_storestill rejects it andwatchData's snapshot branch suppliesNumber(selected)— the two agree. - No
data.jsonis committed anywhere in the tree, and theexamples/*.data.jsoncompanions are contract values, not stores, so nothing in the corpus needs regenerating for the new field. cmd_data_clearwrites{"contract": ...}with norevision, and the newhas_currentunion reads that as no current value rather than a partial one.- Retrying a refused fragment is keyboard-reachable — the retry hangs off the
<details>toggle, andsummaryis focusable. lfPrepareExportnow retries a previously-failed entry rather than baking its error box, which is the sameentry.failedremoval working in the export's favour.- The window where the DOM holds the old manifest while
loadDataFragmentsends the newruntime.data.revisionstill exists betweenacceptDataand the widget's re-render, but it is now self-healing: the error is retryable and the re-render replaces the manifest anyway. - No other widget keys a re-render on
updated;lf-source,lf-worktree,lf-call-diff, andlf-pull-requestall restate unconditionally.
…layout change The nightly suite on main came back 10 failed. Most trace to #189, whose new pr-walkthrough page replaced the one two nightly-only tests still name and whose new package widget ships chrome the layer's markers never reached; two trace to #190's zero-height ToC anchor, which shortened the release page past a named scroll; and one is an ordering collision between Playwright's sync API and asyncio.run. - Point the two stale heading assertions at the page the example now is. - Route the data-bound diff test's comment through the anchored field, which is where #181 moved the press it still clicked. - Read the sticky sidebar's scroll position off the page instead of naming it. - Give the author's description a surface the layer's muted ink clears, and the changed rows' line numbers an ink that clears their own fill. - Build CallDiff's disclosure with offer, so an exported copy takes the press away, and give the location an href only where following it goes somewhere. - Read a covered run against what it paints, so clipped overflow stops reading as words on words. - Show a rendered diff and a scrolling code line in the corpus again, which is what the two unlit focus rings were missing. - Run the MCP stdio exchange on its own thread, since the session-scoped browser holds an asyncio loop open in the worker's main one.
## Problem [`ci` run 33516407327](https://github.com/max-sixty/leaf/actions/runs/33516407327) came back **10 failed, 1614 passed, 6 skipped**. Eight belong to #189, whose `ci` run was cancelled by #190's push before the nightly leg ever ran on it. #188's `test_mcp_app.py` case arrived on the same collision as the MCP test below and is carried here rather than left to red the next nightly. The everyday suite that gates a pull request does not run `test_render_*` or `test_site.py`, so a PR can land its nightly half unread — which is how these arrived, and how five more have arrived since, from #193, #194 and #200. `main` has moved a long way under this branch; the ones it now owns are taken on merge, and three of the new ones are cleared here. #203 reached `tests/conftest.py`'s `headless_shell` first, so the four `test_render_commands.py` setup errors are its. ## Solution Grouped by cause rather than by test, since several tests share one. **The example the tests still name.** #189 rewrote `examples/pr-walkthrough.html` into the Worktrunk review packet, and the shipped patch is now a collapsed manifest that builds no lines until a reader opens a file, which the scroller gate read as `getComputedStyle(null)`. The gate reads the diffs that have drawn lines, with its own non-vacuity floor kept. **The new package's chrome and surfaces.** `.lf-pr-description` stacked a second translucent accent onto a card that is already a tint of one, and the layer's own `--muted` reads 4.32:1 there; the description now sits on the raised-surface token. CallDiff's disclosure was a bare `<button>` rather than an `offer`, so an exported copy kept a hand over a press nothing can take. Its location anchor carried an `href` on the header row, which names no location at all — and `reachScrollers` reads a candidate for a focusable descendant before granting it a stop, so that hidden anchor answered "there is already a way in here" with a link nobody can reach, for a box whose words run off the side. **A reading that counted clipped text as painted.** `coveredWords` measured each run's whole rect, so an ellipsised name in a narrow column read as covering its neighbour. It now intersects each run with the boxes that clip it, stopping at an out-of-flow ancestor where a hidden overflow further out need not reach. The one test that plants this fault plants it properly now: the runtime's note is parked in a one-pixel box with hidden overflow, so opacity alone never put its characters on the screen. **Three focus rings the corpus stopped painting.** `code-pre-light` and `code-pre-shadow` are the tab stops on a scrolling code block and on a diff's lines, and with the old example gone no example held either. The page gets one rendered hunk and one code line long enough to scroll. Then `.lf-diff-review`: it took the outward ring it shared with `.lf-diff-next`, which stands on its own in the toolbar, while this one rides a file's summary row inside a box that clips at the row's bottom edge — its lower run fell 3px past what the sweep can see. It takes the inset the summary beside it already takes, and splitting the rule made each half declare the ring name neither had. **`--diffs-fg-number` on changed rows.** Surfaced by that rendered hunk: a changed row's number is drawn in the base its own fill is mixed from, green on green at 4.03:1. Pierre's number overrides now take the layer's tinted-surface inks. **A sidebar the page got shorter under.** #190's zero-height ToC anchor shortened the release page 58px, putting a named `scrollTo(0, 900)` past the stretch where the box stands on its own offset. Both edges of that stretch are the page's, so they are read off it, with a floor asserting the stretch exists before a point halfway along it says anything. **Playwright's loop against `asyncio.run` and `anyio.run`.** `sync_playwright()` keeps an asyncio loop running in its thread for its whole lifetime, and the `browser` fixture is session-scoped per xdist worker — so an MCP test's own loop start raises in any worker that has opened a browser and passes in one that has not, leaving the schedule to decide. Verified directly: `asyncio.events._get_running_loop()` is `None` before `sync_playwright()`, the loop inside it, `None` after. `interact_support.run_async` runs the entry point on a thread with no loop on it, and both MCP modules go through it — #204's three new exchanges included, since they landed on the direct call while this was in flight. **A declared verb no page replayed.** #194 added `lf-diff`'s `review` to the registry without an event for it on the standing-state page — the one fixture built so that exactly this fails rather than going unexercised. It gets a diff and a standing review. **A focus contract two site tests never heard about.** #193 kept the response field passive so a drag leaves the browser's own selection alone and a native copy still has something to take, and aligned the render tests with it. `test_site.py` is nightly-only. Its label test turned on `document.activeElement === field`, which is now false for the page's own words and the site's label alike — the discriminator was gone, not inverted — so it reads whether the field was offered at all, which is the difference it was always after. ## Testing `uv run pytest tests --run-nightly` and `pre-commit run --all-files` on this head. The everyday suite and lint are green on this branch in CI. Every claim about what `main` does was taken from a control run of the same tests in a clean checkout of `main`, not from reading. <details><summary>Where each failure landed</summary> | test | fix | | --- | --- | | `test_render_gate.py::test_the_runtime_holds_a_scroller_the_page_wrote` | reads the diffs that drew lines | | `test_render_export.py::test_an_exported_example_stands_on_its_own[pr-walkthrough]`, `[corpus]` | widget, probe, theme | | `test_render_controls.py::test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus` | example, then `.lf-diff-review`'s ring and both ring names | | `test_render_pages.py::test_a_left_sidebar_uses_the_margin_until_the_page_needs_it_back` | scroll position read off the page | | `test_interact_mcp.py::test_stdio_protocol_carries_the_app_resource_and_private_tool_result` | own thread | | `test_mcp_app.py::test_registered_server_prefers_full_page_and_keeps_snapshot_as_fallback` | own thread | | `test_render_projection.py::test_the_render_gate_applies_every_standing_action_a_second_time` | standing fixture (#194's) | | `test_site.py::test_the_label_is_chrome_rather_than_words_to_quote`, `::test_a_comment_lands_in_the_thread_with_its_quote` | the field is offered, not entered (#193's) | | `test_render_anchors.py::test_a_data_bound_diff_aims_and_selects_one_source_line` | **#194's and #193's, taken on merge** | | `test_site.py`, `test_render_export.py` stale `<h1>` | **#202's, taken on merge** | The two exported-copy cases each carried four faults, three of them masked: `offering` asserts before `covered`, which asserts before the copy's axe run, so each fix uncovered the next. The ring sweep did the same — the geometry fault stood in front of a naming check that had been silent about a rule missing its name since it was written. </details> <details><summary>Three this leaves, all of them main's</summary> **`test_render_controls.py::test_examples_have_no_serious_wcag_a_or_aa_violations[pr-walkthrough]` stays red.** The `.lf-pr-description` contrast above is fixed and confirmed gone. What holds the test red is 46 `nested-interactive` findings from #194: each file's "Mark reviewed" `<button>` sits inside that file's `<summary>`, and a disclosure with a focusable descendant is a serious WCAG failure. Clearing it means taking the press out of the disclosure and re-laying the row — `entry.node` is the `<details>` in ten places, and the theme, print and export rules key on it — which is a change to that widget's shape with visual verification of its own, not a line this branch should slip in. **`test_render_anchors.py::test_a_failed_fragment_hydration_waits_for_a_reader_retry` fails whenever anything runs before it.** Confirmed on unmodified `main`: three runs of the file at `-n4`, three failures, and the same failure at `-n0` over the whole file. It passes alone every time. `assert len(requests) == 2` sees one — the reopened disclosure's second fragment fetch never reaches the route. Arrived with #189. **`test_render_anchors.py::test_a_drag_released_mid_word_hugs_words_and_sentences` fails over the whole file and passes alone.** `assert 'inside' == 'inside it'` — the selection did not grow to the word boundary. It looks like the next instance of what #191 diagnosed, Chromium 151 collapsing a synthetic range on mouse release. Also still behind: the gallery's `docs/example-pr-walkthrough.jpg`. Regenerating here rewrites all nine stills in substituted faces, because `theme.css` asks for Charter and this runner's `fc-match` has none of the serif stack — the same reading #175 made. Left for the authoring machine. </details> --- Automated fix for [failed run](https://github.com/max-sixty/leaf/actions/runs/33516407327) > _This was written by Claude Code on behalf of @max-sixty_ --------- Co-authored-by: leaf-agent <[email protected]> Co-authored-by: Maximilian Roos <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Leaf can now present a pull request as a commentable review packet without making the agent transcribe the underlying evidence into authored markup.
What changed
/api/dataloads one exact file patch on demand, and standalone export hydrates every file before scripts are removed.Verification
uv run pre-commit run --all-filesuv run pytest tests— 765 passed