Repository navigation
Make Leaf pages complete reactive applications - #666
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
Two cases pass on main and fail on this branch, both in nightly-marked modules
the test job never discovers, so they land red on nightly after merge. Both
already fail at f72b8f56, so they arrived earlier in the branch and no review
has named them yet.
A fail-soft that also fails hides the cause that started it.
test_render_projection.py::test_a_module_that_stages_bare_text_is_refused_in_its_own_name
asserts the page's first console error names the module at fault. On this head it
is leaf: Presentation failed: presentation and fail-soft failed, which names
neither <lf-drift id="drift-note"> nor the text it staged. presentation.ts
wraps the original reason and the fallback failure in an AggregateError whose
message is that summary, and the reporter installed by
setPresentationFailureReporter formats reason?.message alone — so .errors,
which holds the specific refusal, never reaches the console. That is the failure
mode the test's own docstring names: "a bug report against leaf rather than
against the module that caused it." The inline suggestion makes the case pass;
I applied it to this head and ran it.
The data-readiness case does not account for the error it added.
test_render_startup.py::test_data_readiness_settles_and_reports_failed_subscribers
gained a synchronous-throwing subscriber and asserts
data subscriber failed: synchronous update projection failed is reported once,
but the consume_browser_errors call above it still lists only the mount and
update fragments, and that helper's all(...) accounting rejects any entry no
fragment covers. Adding
"data subscriber failed: synchronous update projection failed",to that call is the whole fix — verified green. The line sits outside the diff, so
it is not an inline suggestion; say the word and I will push both fixes.
The new pinned-revision gate freezes a page's conversation vocabulary at r1.
pinned_thread_markup_errors asks every captured registry, so admissible thread
markup is the intersection of every revision's vocabulary. A widget introduced in
r2 — a page-local one, or one a later Leaf layer ships — can never appear in
leaf comment --markup or leaf reply --markup again, and the refusal names no
remedy because revisions are immutable and there is none. The trade against a
widget that renders inert in an older pinned document is yours to make, but it is
a standing authoring constraint that neither conversation-threads.md nor
SKILL.md mentions. The same increment now records revision on every
markup-bearing event and page_data_document_readings already reads it, so
scoping the gate to revisions at or after the message's own is available if the
intersection is stronger than intended.
What I ran
Merged tree, uv run pytest --run-nightly -p no:randomly -n0, both cases
isolated:
this head ad476d1b 2 failed in 6.76s
worktree f72b8f56 2 failed in 11.65s
worktree cff0eee7 2 passed in 7.56s (main; the projection case is byte-identical there)
The wider selection on this head — tests/test_render_startup.py tests/test_render_export.py tests/test_render_outbox.py tests/test_render_projection.py --run-nightly — is 336 passed / 4 failed; the
other two are test_render_export.py's two subprocess exports, which fail in
this sandbox for want of an installed Chrome, not on the branch.
Also run and green on this head: tests/test_interact_contract.py,
tests/test_interact_document.py, tests/test_interact_server.py,
tests/test_interact_session.py, tests/test_revision_delivery.py,
tests/test_website_server.py (798 passed; the three failures are this
sandbox's read-only /tmp and missing IPv6), and the new and changed cases in
test_render_controls.py, test_render_navigation.py, test_render_outbox.py,
test_render_widgets.py, test_render_conversations.py.
/api/state on a freshly initialized page, same machine: 4.5 ms on cff0eee7,
17 ms here — the memo landed, and what remains is _capture_input_stamps
walking the page tree to build its key (68% of page_state under cProfile).
| reportPresentationFailure = (reason) => | ||
| report(`Presentation failed: ${reason?.message ?? reason}`); |
There was a problem hiding this comment.
The AggregateError presentation.ts builds when fail-soft also fails carries the
original refusal in .errors, and formatting reason?.message alone drops it — the
page then reports a generic presentation failure over a blank document and names
nothing the author can act on. Reporting the constituents restores the diagnostic and
makes test_a_module_that_stages_bare_text_is_refused_in_its_own_name pass; this form
is prettier-clean and I ran it on this head.
| reportPresentationFailure = (reason) => | |
| report(`Presentation failed: ${reason?.message ?? reason}`); | |
| report( | |
| `Presentation failed: ${ | |
| reason instanceof AggregateError && reason.errors?.length | |
| ? `${reason.message}: ${reason.errors | |
| .map((cause) => cause?.message ?? cause) | |
| .join("; ")}` | |
| : (reason?.message ?? reason) | |
| }`, | |
| ); |
| """ | ||
| failures: dict[str, list[int]] = {} | ||
| revisions = list_revisions(page_dir) | ||
| for revision in revisions[:-1]: |
There was a problem hiding this comment.
Every message with markup now reads every pinned revision's whole bundle to reach one
registry.json. This branch's own TODO.md measures a minimal default-layer revision at
~3.2 MB across 179 resources, and read_artifact's memo holds 8, so a page with more
revisions than that re-materializes each bundle on every leaf comment --markup and
leaf reply --markup. Reading the captured registry.json resource on its own would
give the gate what it asks for at a fraction of the cost.
…682) `publish-site` deployed release `5903b07f` and then failed its agent pass on [run 34777568838](https://github.com/max-sixty/leaf/actions/runs/34777568838), and the gate was reporting a live break rather than a flaky reading: on leaf.page today, a reader whose agent publishes a revision is thrown into an endless reload. The page never reaches the revision, never presents, and never shows the conversation again — `reply never became visible in Threads: {'panel': True, 'messages': []}` is that page, caught mid-reload with nothing rendered. ## What causes it #666 made every live revision activate by reloading the stable page address (`prepareActivation` in `skills/leaf/assets/runtime/version.js`), replacing the fetch of the revision document that preceded it. The Worker answers that address from the built site: `worker/src/index.ts` takes the edge branch for any page GET that is not an API request, and only falls through to the container when the edge answers 404, which the page root never does. So the reloaded document is the build's revision, the runtime reads it back as the revision it was leaving, asks to activate again, and the loop closes. The session's own `index.html` — the one its agent just wrote — is in the container the whole time. Session files already avoid this: `media`, `revisions` and `versions` miss at the edge and fall through. The live document is the one case the edge answers with a stale 200, so this adds it to the same rule — an active session reads its live document from its container. Passive readers, every static asset, and the release-addressed module graph are untouched. ## Verification Measured against the deployed release on leaf.page, driving the page the way the gate does: - posting a comment that asks the agent to publish left the page reloading `/examples/triage-board/` continuously for the whole six-minute observation, still on revision 1, still reading `Release triage`, never presented, no messages; - with the same session reading its live document from the container — the routing this change makes — the agent's revision 2 arrives at the same address, headed `Deployment probe verified`, presented, conversation rendered, no browser errors. `npm run typecheck --prefix worker` and `npm test --prefix worker` pass (63 tests, including two new cases that fail without the change). ## The cost, and what it does not cover The container composes its document with page-relative asset paths, so an active reader's document loads the revision's modules from `/<page>/revisions/rN-<hash>/…`. The edge still serves those files, but under `public, max-age=0, must-revalidate` rather than the `immutable` year that `/_leaf-release/<release>/…` carries, so an active reader's reload revalidates its module graph instead of reading it from cache. That route is content-addressed by the revision's own digest, so marking build-present revision assets immutable would recover it; that is a separate change and this one does not make it. The local pre-deploy gate could not have caught this: `scripts/verify-site-local.sh` runs `verify_site.py` without `--agent`, so the Worker is exercised before the deploy but the agent turn only afterwards, against the public origin. <details><summary>An unrelated live defect found while reproducing this</summary> A session pinned to its container by the `__Host-leaf-container` cookie — the state a drained rollout leaves — cannot start `/examples/ship-review/` at all: the page throws `leaf: page failed to start: leaf: $command.widgets declares no command role`, then `Leaf application has not been mounted`, and never presents. It reproduces on every attempt, and only when the container serves the module graph as well as the document; `/examples/triage-board/` is unaffected, and the registry the two routes return is byte-identical and does carry `$command`. This change neither causes nor addresses it — with the container serving only the document, ship-review presents cleanly. </details> --------- Co-authored-by: leaf-agent <[email protected]> Co-authored-by: leaf-agent <[email protected]>
The nightly `ci` run on main was cancelled at the job's 135-minute timeout, not by anyone: `tests/test_render_controls.py::test_a_stale_package_widget_uses_recursive_parent_eligibility` wedged its browser at 22:59, held its xdist worker for the remaining 114 minutes, and the run ended with no summary and no `nightly.xml` artifact. This makes that test finish in seconds again. The fixture's `lf-quota.renderState` moved its owner on every render: ```js const rest = [...parent.children].filter(child => child.id && child !== this); parent.insertBefore(this, rest[index] ?? null); ``` `insertBefore` on an element the platform already has in place still removes and re-inserts it, which fires `disconnectedCallback` and `connectedCallback`. The module drops its subscription in the first and renews it in the second, and the renewed subscription renders — which moves the element again. Each turn is a fresh microtask, so the page never yields: the renderer sits at ~110% CPU, and Playwright cannot get a reply even to report its own 30-second timeout. That is why the suite hung rather than failing. The guard belongs in the fixture because the contract is already stated against it. `skills/leaf/references/packages.md` asks a module for "a total, idempotent `renderState(state)`" and names "a `renderState` that changes the page when handed the same state again" as a render-gate fault. Every shipped widget that rewrites the document keeps to it — `lf-board` returns early when the columns already hold the ordered cards, `lf-task` when the status attribute already reads the value — and the sibling placement fixture in `tests/test_render_projection.py` guards the same move with `if (parent.children[index] !== this)`. This fixture was the one that did not, so it now checks its position before moving. The move it exercises, and every assertion about where `#quota` ends up, is unchanged. Bisected to 859c6cc (#666, "Make Leaf pages complete reactive applications"): the test passed in 1.5s in the 2026-09-13 10:50 nightly on e2ebdcb, and hangs on every commit from 859c6cc onward, including current main. One thing that change leaves open, which this PR does not decide: before #666 a non-idempotent `renderState` was wasteful, and now it locks up the reader's tab. The render gate is documented to catch exactly this fault and did not catch this widget. Whether the runtime should bound a render that keeps re-entering itself is a question for the reactive runtime rather than for a test fixture. <details><summary>Reproduction and verification</summary> Before, on main at 7acc84b — no output, killed by the outer timeout: ``` $ timeout 600 uv run pytest -q -n0 --run-nightly \ "tests/test_render_controls.py::test_a_stale_package_widget_uses_recursive_parent_eligibility" Terminated EXIT=124 ``` After: `1 passed in 5.26s`. The loop, captured by counting `presentRender` calls per widget id and breaking after 400, then reading the stacks off the page: ``` renders: 404 invalidations: 396 at connect (runtime/widget-controller.js:402) at Object.subscribe (runtime/widget-controller.js:441) at HTMLElement.connectedCallback (widgets/lf-quota.js:34) at HTMLElement.renderState (widgets/lf-quota.js:55) at presentRender (runtime/widget-controller.js:284) ``` `uv run pytest -q --run-nightly tests/test_render_controls.py` — 90 passed, 4 failed in 5:00. The four are on main already, all named in the cancelled run's own log (`test_the_composed_corpus_declares_every_control_row_archetype`, `test_a_runtime_cannot_adopt_a_new_registry_while_it_is_loading`, `test_an_open_tab_reloads_before_posting_through_a_revendored_layer`, `test_a_covering_auxiliary_surface_keeps_a_replacement_document_inert`). That run reported 22 failures and 4 errors before it hung; this PR addresses the hang only. The everyday gate does not reach this file — `tests/test_render_controls.py` is `pytest.mark.nightly` throughout — so the proof for this change is the local run above and the next nightly. Failed run: https://github.com/max-sixty/leaf/actions/runs/34787351258 </details> Co-authored-by: leaf-agent <[email protected]>
Four nightly diff tests appended new `lf-diff` elements after page presentation, outside the immutable authored-widget descriptor capture. This authors the same inert-markup, malformed-hunk, rename, and final-empty-line specimens before serving the page, removing the dynamic DOM setup and frame polling. The stale construction had been latent since #666 and surfaced in the nightly run after #692. Runtime behavior and the patch-activation work in #689 are unchanged. The test guidance now describes the authored-lifecycle boundary directly instead of retaining the removed frame-poll exception. Validated with the repository pre-commit hooks and all nine `a_diff_` nightly cases. > _This was written by Codex on behalf of max-sixty_
#689) A live revision now reaches a reader through one door with two installs behind it, and one server fact decides which. Each revision's manifest records an `executable` digest over the inputs an open document cannot re-evaluate: the registry vocabulary without its `$layer` stamp, every captured JavaScript module, and the inline module bodies. When the arriving revision's digest matches the document's, the authored page is patched in place at text-node granularity, so caret, selection, hover, scroll, focus, element identity, and an armed key sequence survive because the nodes do. When it differs, the existing fresh-document path runs unchanged. Prose, markup, styling, and media never cost a reload; #666's reload-on-every-revision was the behavior this replaces, and the pre-#666 whole-`main` swap never kept identity inside `main` either. ## Where to read - `skills/leaf/scripts/leaf/revision_artifact.py`: the `executable` digest and the per-widget `widgets` digests (authored markup, pre-delivery), both computed once at capture. `files.active_descriptor` exposes `active.executable`; `revision_delivery.delivery_identity` writes `lf-revision`, `lf-executable`, and `lf-widgets` into every delivered document. - `skills/leaf/assets/runtime/dom-children.js`: `patchTree`, beside `setChildren`. A patch diffs the revision the page is standing on against the arriving one, both inert authored sources, and applies only that delta through a source-to-live map built at boot and kept by each patch, so anything the browser, a reader, the runtime, or a page module changed in the page (an open disclosure, a lent tab stop, a tokenizer's spans, a module's output) is left alone. Siblings are pinned by an exact signature through the vendored jsdiff and the edited stretches between pins are diffed again by kind; text is spliced by its differing run so ranges outside it survive; declared widgets are atomic (kept when their authored digest is unchanged, keyed by id or by tag and ordinal); an element whose children a module took is kept or replaced whole; `retire` reports what actually left the tree. - `skills/leaf/assets/runtime/version.js`: `prepareActivation` decides patch versus reload; `activateRevision` is the patch install (roots, head, `main`, recapture through `installDocument`, reading landmark restored); the reload path and its handoff are unchanged. - `scripts/browser/application.ts`: `adopt(state, revision)` publishes the installed revision with the state that has a view of it, and `canAdopt` is asked before the install edits anything. - `scripts/preview.py`: re-vendors only when the runtime changed, so a prose edit in a preview takes the patch path. ## What is proven Restored from before #666: the same document and `main` survive a revision and a stamp; a parked pointer's hover Range rebinds onto the new node; an armed `g` sequence survives a revision. New: a prose-only edit keeps an untouched native selection and the focused element; a reader-opened `<details>`, a lent tab stop, highlight spans, and page-module output survive an edit elsewhere; an unnamed widget survives a revision that left it alone, including one held in a template; a paragraph a module moved is patched where it stands; a selection over kept words survives the words beside it changing; an insertion above an unided paragraph (same or different tag) keeps the reader's node; a rewritten widget is replaced while an untouched one keeps its element; template contents patch; an executable change still reloads exactly once; the digest is pinned by an eight-fault planted sweep. Live check on `examples/log-retention.html`: with a selection standing, pressing the newest-version chip keeps the selection, node, and document on this branch and reloads on main. On the final tip, locally: the everyday suite passes (1,118), and the seven nightly-marked browser modules the branch touches (`projection`, `navigation`, `application_boundary`, `startup`, `export`, `anchors`, `widgets`, with `--run-nightly -n0`) pass (678) except four `lf-diff` cases in `test_render_anchors.py` that fail identically on current main (`<lf-diff>` has no captured widget descriptor at a version address), so they are not this branch's. `npm run check:browser` and `test:browser` green; pre-commit green over every changed file. ## Left as it is The reload handoff now carries only what has a stable identity: the reading landmark, the comparison base, the pointer, and the margin's retained standing. The page-control focus restore (owner id, tag, first class, index, and a meaning string) was a heuristic and is deleted, so focus falls to `body` across a code change or a replaced control. Revisions saved before this change carry no digest: the live root regenerates on its next state read, but their historical addresses answer with a named error until then. Per-revision layer copying is unchanged and remains the TODO item on sharing resources by digest. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
`ci` on main [run 35021853659](https://github.com/max-sixty/leaf/actions/runs/35021853659) failed on `tests/test_render_application_boundary.py::test_current_readiness_releases_a_connected_page_widget`, which expected `data-render-order` to read `render,subscribe,` and got that pair four times over. The run is recorded as cancelled because the everyday `test` job failed and the steps behind it were dropped; the failure itself is the test. Four pairs is the settled value, not a corruption. One gesture publishes four distinct widget readings on its way through the round trip: the optimistic one the dispatch makes, the delivery outcome, the admitted event replacing the pending id, and the cleared ledger. The widget clears `data-render-order` in `choose`, so the attribute holds one pair for as long as the round trip takes and then grows to four. `expect(...).to_have_attribute` returns on the first matching frame, so the assertion only passed while its first poll landed inside that window — the transient the auto-retrying assertion was never meant to wait for, per **A state the page passes through is not a state to poll for** in `tests/CLAUDE.md`. On a loaded runner the round trip finished first and the poll read the settled value. The claim the assertion is making — the optimistic publication renders the owner and then runs its subscribers, before the log answers — is true synchronously inside the click. So the order is now read in the same `page.evaluate` that presses the button, where nothing can have arrived yet, and the contract for the readings that follow is stated as the property that holds of all of them: after `round_trip`, every recorded subscriber ran behind its own reading's render. Neither read can be overtaken by the delivery. The test is unchanged since #666 and this is its first failure; the race is latent rather than new, and [PR #739's own `test` job](https://github.com/max-sixty/leaf/actions/runs/35019652548/job/104552424929) passed on the same tree that failed here. <details><summary>Reproduction</summary> The CI value reproduces exactly on a fast machine by delaying the read — a copy of the test with `page.wait_for_timeout(500)` before the original assertion: ``` E AssertionError: Locator expected to have attribute 'render,subscribe,' E Actual value: render,subscribe,render,subscribe,render,subscribe,render,subscribe, ``` Instrumenting the widget's subscriber to record each reading shows the four publications the round trip makes: pending event with `delivery` unanswered, `delivery` answered, the admitted event with its `id`/`seq` in provenance, history and standing, and `delivery` empty. The repaired test passes with a 1.5s delay inserted before the settled read — the arrangement that reproduced the failure. `uv run pytest tests/test_render_application_boundary.py` passes (8 tests), and pre-commit passes on the changed file. </details> Co-authored-by: leaf-agent <[email protected]>
…ruled out (#768) The cutover list scored its candidates from a survey's estimates. Six of the rows ranked next were measured against the code, and every one was stale or overstated; an independent review then confirmed the six verdicts and corrected three of the reasons behind them. The rows now carry what was measured, and the ones the measurements ruled out have moved to the survey note, whose table is now named Rejected. What the measurements found: - **`html` as the page scroller** was already done: `26feec8b` made the switch on 2026-08-29, `theme.css` holds the rule, and the runtime reads `document.scrollingElement`. The row is gone. - **Same-document View Transitions** claimed ~150 lines against a `motion.js` of 87. The update applies after the old state is captured, later than the gesture's own turn; pointer input misses the page while it animates; a fold collapses height so later content slides, which a root cross-fade does not draw; and board cards move inside their own scroller, whose clip a snapshot escapes under the Chrome 125 floor. #666 removed the paint-boundary transition version travel used, which also leaves `theme.css`'s `lf-versioning` rule dead — deleted here. - **idiomorph for the version patch**: a live-tree diff keeps only the reader state an exclusion names, while `dom-children.js` compares authored source with authored source and keeps all of it. It has needed no fix since #514 split it out. - **`tsc --checkJs`** runs in under a second, but a bug-back over six runtime fixes (#404, #448, #625, #660, #676, #757) found no error that the fix removed from the files it touched, and the errors it does report are inference artifacts. - **Browser-owned anchoring** was spiked on `agent-a4111d25e33d466d2`. All three capture paths cut over and the anchors matched the Python capture exactly, but Python grew by 168 lines, a quoted `leaf comment` went from 0.2 s to 1.3 s and now needs Chrome, and the anchor tests went from 8 s to 37 s: the refusals and the diagnostics for a quote the page does not show read authored source the rendered page no longer holds. - **The user-level daemon** nets roughly zero lines. The browser already receives pushes over `EventSource`, the 70 µs stat loop serves CLI writers in other processes, pid probing and most locks stay, Windows is not a goal, and a user-level database stops the page directory being the deployment unit. Two rows are new. A size-first sweep of the largest hand-written mechanisms found one candidate the defect-led survey missed: serving each page through starlette and uvicorn, which `mcp` already installs, keeping one process per page. And the keyboard system becomes item #24 under architecture simplification: the reader keeps every key, sequence, hint, and the one-press-per-layer Escape, while the code that infers which surfaces are open — where ten of the last 24 keyboard fixes landed — gives way to a layer stack that openers push and closes pop. No library owns that; the ones that came closest are in Rejected. The preamble now says effort and confidence are estimates unless a row cites a measurement. Checks: the everyday suite (1,135) and `test_a_revision_navigates_without_the_view_transition_api`, which exercises activation with the View Transition API switched off, both pass; pre-commit is green on the changed files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
`notes/workspace-followups.md` has been presenting finished work as the plan since 9 September. It opens with "Start #2, #3 and #4 as one coordinated contract batch; run the review-queue simplification #8 alongside it" — all four of those shipped that week — and carries thirteen briefs, each with a live "Next task" and "Done when", for work `TODO.md` dropped as complete. This removes them and leaves the six `TODO.md` still links: #11, #14, #19, #20, #22 and #23. The trim follows the convention #666 set and the reason `CLAUDE.md` gives for it: a note is never a second specification for shipped behavior. #666 removed #6, #7, #16 and #17 the same way, rewriting the two `Owner / dependencies` lines in surviving briefs that named them; it simply did not reach the rest. Each removal is evidenced by the commit that took the item out of `TODO.md`, not by a reading of the current code: | Brief | Removed from `TODO.md` by | | --- | --- | | #1, #3, #5 | [`0f7f06a6`](0f7f06a) — "Completed workspace items #1, #3, and #5 are removed from `TODO.md`" | | #2, #4, #8, #9 | [`28b5da99`](28b5da9) — "the completed #2, #4, #6, #8, #9, and #17 backlog entries are removed while preserving the deferred evaluation work" | | #13, #15 | [`6df40353`](6df4035) — "closes three bounded workspace follow-ups" | | #10, #12 | [`c9eaa2c6`](c9eaa2c) — the continuation cue and the adaptive Threads placement | | #18, #21 | [`e46c8b93`](e46c8b9) — the monitoring workspace and its package-owned root | Alongside the briefs, three group headings are now empty and go; the `Suggested work packages` table loses the rows whose whole scope landed; and four cross-references that named a removed ID are rewritten — #14's dependency on the Threads-placement experiment, #20's ordering behind #8, and the two sentences in `Reproduction record` and `Browser evidence` that pointed at briefs no longer here. #14 needed more than a rewritten pointer. The experiment it waited on was settled in two steps, and only the first removed an ID: [PR #520](#520) kept the adaptive placement and deferred the modal-focus work to #24, which landed in [PR #536](#536) as inertness, dialog semantics and focus containment for a covering workspace. That is the surface #14 exists to verify, so its `Done when` — "Avoid imposing a modal focus trap on a nonmodal panel" — described the containment #536 shipped as the defect to avoid. It now states the containment the shipped modality requires, and the dependency line names both settlements. The dated evidence sections themselves stay. They are the record of what was read in a browser on 8 September, not a plan, and the note's own header scopes them to that date. No test covers `notes/`, and this changes no behavior, so there is nothing to regress. `pre-commit` passes on the file; the `TODO.md` → note anchors all still resolve, and no surviving text references a removed ID. --------- Co-authored-by: leaf-agent <[email protected]>
…1219) Undo. The server's view of each revision now emits the final list of gestures that document can take back, and the browser applies no rule of its own: `z` takes the head, a widget's Undo filters it to its own entries. The view drops an approval of another stamp, an action whose widget and verb the document (or frozen thread markup) does not hold, and a page action a later revision restated. `z` no longer requires an action to have been made on the shown revision, the rule #450 stated for both paths and #666 dropped from the widget path so carried decisions stay undoable; a later revision's markup placing the unit is refused at the door (`absorbed`), and the restated case is now the view's. `z`, the widget undo branch, and reactions withdraw through one `withdraw(event)` door, and the controller no longer restates the candidate lookup. Behaviour that moved: - `z` takes back a decision carried into a later revision, as the widget's own Undo already could. - `z` takes back a thread widget's action even while its element is not rendered, instead of skipping to an older gesture. - A reaction chip withdraws a standing reaction while an unrelated gesture is sending or a reading is being applied; like a widget's Undo, it waits (with the same notice) only while another accepted action awaits presentation or the reaction itself is unsent. The `z` walk alone needs the page settled, since its target is whatever is newest. - A widget undo the page refuses now says why. Server view. The publisher resolves the shown revision's view once, as `effective.view` less its transport basis, replacing `effective.updates`, `publishedAt`, and `lifecycle`. `runtime.view`, updates.js, the undo walk, and projection coverage read it. Semantic news now reads page obligations from the shown revision rather than the active one, so an Ask a waiting activation adds becomes news when a revision holding it is presented. state-application's `stale()` is the publisher's `overtaken(state)`, which `adoptable()` also uses. Watchers. `watchAsks` is now `watchProjection` with its own reading, as `watchUpdates` and `watchHistory` already were: first call on the next microtask, coalesced per microtask, nothing while the owner is disconnected. It no longer calls synchronously, and it may repeat an unchanged set. packages.md, projection-watch.js, and updates.js state that. `COLLAPSE` lives in runtime/collapse.js, which passages.js, the composing modules, and projection/model.js import; the Python parity test reads it there. passages.py's comment still names leaf.js as its home; that file is held by another change. Checks run locally: `npm run check:browser`, `npm run test:browser`, `npm run test:runtime`, pre-commit, `tests/test_interact_server.py`, `tests/test_interact_contract.py`, the everyday browser files this touches (`test_render_semantic_news.py`, `test_render_application_boundary.py`), and the nightly undo, watcher, and version selections (`test_render_outbox.py`, `test_render_reactions.py`, and `-k` selections of projection, widgets, margin, options, navigation). > _This was written by Claude Code on behalf of max-sixty_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
The Leaves drawer keyed each neighbour row, and the focus it keeps across a repaint, by the neighbour's URL. A neighbour whose server came back on another port therefore read as one page leaving and another arriving. The focused link was removed, and focus fell back to the drawer. Each entry in `state.others` now carries `page_key` (`state.page_key`, the identity that page's state-home records already use) beside `url`. The drawer keys rows and focus by `page_key` and links by `url`. A restarted neighbour keeps its node and its focus, and Enter opens the new address. The fresh-server check is unchanged: a neighbour with no running server still leaves the list. `test_a_leaf_served_at_a_new_address_keeps_its_row_and_focus` restarts a focused neighbour on a new port. It takes the route a taken port's refusal names: the service record is deleted, and the old port stays held. The test fails on main because the row lost its node and focus. With this change it passes. This resolves comparisons proposal #5, which is removed from `notes/comparisons.md`. **Is there a more underlying fix? No.** I tried these candidates: - Enter on the retained link opens the new address. Covered in the new test. - The retained node's `href` follows the new URL. Covered in the new test. - Other code that reads a neighbour's identity: a grep of the runtime and the Python found none. `presence.js` reads only the neighbours' activity. - During a restart, the row is absent from the moment the old server stops until the new server publishes. A measurement showed about 70 ms of that gap falls after `start_server` returns and before the first row publication. The drawer treats an absent row as removal, and the proposal keeps that behaviour (it retains the fresh-server checks). So the gap is outside this change. - History: the keying lines have stayed as written since #666 and #1214, with no earlier patch to this condition. Tests run: the new test (it fails on main and passes here); the drawer's browser tests in `test_render_controls.py` and `test_render_navigation.py` (49 passed); the neighbour tests in `test_interact_server.py` (21 passed); pre-commit. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Fifteen tests waited a fixed time, from 50 ms to 11 s, and then asserted that something had not happened: a receipt not sent, a probe not repeated, a pane not scrolled. On a slower machine the unwanted thing can land after the wait, and the test passes with the bug present. `tests/AGENTS.md`'s "Absences", as #5522 rewrites it, says to wait instead for an event the page orders after the moment the unwanted thing would have happened, and then check that it is absent. Fourteen of these tests now do that, and the fifteenth drops its check, since nothing can produce what it checked for. | Test | Waited | Now waits for | |---|---|---| | `test_render_read_state::test_modal_blocks_exposure_until_user_returns_to_threads` | 100 ms | `rendered`, then `round_trip`: the read pass the resize set off has run, and any receipt it sent has come back | | `test_render_read_state::test_oversized_message_needs_contiguous_traversal` | 100 ms | the same, after the scroll | | `test_render_read_state::test_a_page_seat_the_open_panel_stands_over_is_not_read` | 1.5 s | the same, after the scroll | | `test_render_drawing::test_a_second_finger_takes_back_the_stroke_the_first_began` | 100 ms | `rendered`: every repaint the release queued has run | | `test_render_floating_panel::test_writing_reaches_the_field_however_the_panel_stands` | 300 ms | `rendered`: the resume has drawn what it decided | | `test_render_anchors::test_a_failed_deferred_hydration_waits_for_a_user_retry` | 250 ms | the page's clock run a minute forward, past any backoff a retry would wait out, then `rendered`, with the page counting its own `/api/deferred` fetches | | `test_render_startup::test_slow_history_keeps_decisions_safe_and_status_honest[ready]` | 50 ms | the planted fault's `pageerror`, then `rendered` | | `test_render_startup::test_user_view_context_waits_for_a_samples_viewport_allocation` | 11 s | the page's clock run 11 s forward, then a check that the view restoring the frame is the only one sent since it went to zero | | `test_panes::test_reading_keys_follow_the_focused_pane_without_moving_its_sibling`, first press | 250 ms | `scroll_settled` on the pane, then on the document | | the same, second press | 250 ms | the same | | `test_freshness::test_status_changes_coalesce_behind_one_state_read`, two waits | 500 ms each | the second freshness look asked after the change, which the page asks only once it has handled the first, with the page counting its own looks and state reads | | `test_changes_in_place::test_a_to_do_running_on_an_element_marks_it` | 300 ms | `told`: the page has taken in the to-do | | `test_wait::test_the_stop_hook_watch_wakes_the_session_only_for_input` | 1 s | two more passes of the watch over the pending input, with each pass's wait shortened to zero | | `test_site::test_a_page_that_starts_after_a_fault_takes_its_notice_back` | 3 s | the page's clock stepped a second at a time, three times, each step taken with no probe round in flight, with the page counting the probe's own fetches | | `test_site::test_a_probe_in_flight_leaves_a_page_that_started_alone` | 2 s | the page having handled the held probe round's answer | | `test_projected_data::test_data_written_while_a_fresh_revision_starts_shows_once_it_has_started` (renamed from `test_data_written_during_fresh_revision_startup_waits_for_activation`) | 100 ms | nothing: the check is removed (below) | Four of these count requests in the page rather than through Playwright. A route handler's list and a `request` event reach Python on their own schedule, after the page's call, so a count read right after an ordered event could still be missing the request it is checking for. Three of the waits needed more than an ordered event: - **The started-page probe test.** The supervisor sets the timer for its next round only once the last round's answer lands, so a clock run while a round is in flight fires nothing. The test therefore waits until no round is in flight and steps the clock a second at a time, waiting out any round each step starts. It throws its planted fault from a `DOMContentLoaded` listener, because a timer's callback under Playwright's installed clock throws without firing the page's `error` event (measured: the callback ran, the page's `error` listeners saw nothing, and `data-lf-startup-error` stayed unset), and the supervisor would never start. The test first checks that the supervisor recorded the fault in `data-lf-startup-error`. - **Both probe tests** count only the supervisor's probe, which asks for `registry.json` past the cache. The runtime's own read of the same address used to count too, so `handled >= 1` could hold before the held round was answered. Each probe also carries a `Leaf-Test-Probe` header, so the in-flight test's route holds the probe alone; the runtime's read goes through, and the page comes up on its own rather than through a planted `data-lf-upgraded`. - **The deferred-hydration test** runs the page's clock forward, since `rendered` doesn't wait for a timer and a retry on a backoff would come after it. The projected-data test checked, 100 ms after writing data during a fresh revision document's startup, that the update had not painted. That guarded a newer source reading painting into a document that was still activating, a case from before #666, when an activation could hold the page while the new document was already mounted. Since #666 a revision that changes the page's code starts a fresh document. The test holds that document's `registry.json` for all of startup, and widgets import their modules only after it arrives (`widget-loader.js`), so no widget exists to paint the update. No product change short of drawing widgets before their registry can bring the case back. The checks after the release stay: the update shows, and so does the new revision's text. ## Controls For each test, a throwaway product change made the unwanted thing happen, and the converted check caught it. Each browser test ran four ways: as is and with the change, at CPU 1x and at `--cpu-throttle 10`. As is, every run passed; with the change, every run failed at the converted check. None of the changes is committed. | Test | Change | |---|---| | modal | `thread/read.js` reads a message under an open modal | | oversized message | `thread/read.js` takes any traversal as contiguous | | page seat under the panel | `thread/read.js` measures the message without the panel's clip | | second finger | `drawing.js` keeps the stroke when it is dropped | | resume | `drafts.js` reports the writing place unavailable after resuming it | | deferred hydration | `lf-diff.js` retries a failed load on the next task, and separately on a 1.5 s backoff | | post-upgrade fault | `prepaint.js` marks a startup error, a task later, for an error after upgrade | | sample viewport | `user-view.js` reports a zero-sized view | | panes, first press | the `d` key also scrolls the sibling pane two frames later | | panes, second press | the `d` key scrolls the focused pane a further 40 px two frames later | | freshness | `state-feed.js` asks again while a read is in flight | | to-do | `margin-bars.js` marks a to-do's target before it is running | | stop-hook watch | `session.py` wakes on the second pass over pending input (a model test, so no throttle) | | started page's probe | `bootstrap.js` drops both of the probe's `started` checks; over the clock's three steps the count rose from 1 to 4 at 1x and from 2 to 5 at 10x | | in-flight round | `bootstrap.js` acts on a round's answer after the page started; a second document, `?_leaf-recovered=`, was requested | ## What ran Each touched test as is and with its change, at CPU 1x and 10x, one at a time (`uv run --frozen pytest <test> -n0 -q`, then with `--cpu-throttle 10`), from scripts that applied and restored each change, and the projected-data test as is at both. Every touched test together at 51e0bf3, with `-n 2`: 19 passed; the four tests changed since then each passed as is at 1x and 10x, and the freshness and projected-data tests again at 1x after the last change. Not run: Firefox or WebKit, and the rest of each test file. The sleeps removed total about 21 s, 11 s of it in the sample-viewport test; the deferred-hydration test's minute of clock adds about 3 s. The rule is #5522; #5523 holds the fixes to the scaling checks and the playground wait. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…amps from files.py (#6039) This is the weekly duplicate sweep of `src/leaf/` and `hooks/` (ISO week 46). It moves four capabilities that were implemented more than once to one home each, and moves every caller. Behavior does not change. Every replaced copy computed the same result as the home it now calls. - **Applying non-overlapping `(start, end, text)` edits to a source.** The new home is `structure.splice`, which is `revision_delivery._spliced` moved and generalised to str or bytes. It replaces five copies: - `revision_delivery._spliced`, from #3313, removed. - The reverse-slice loop in `revision_artifact.bind_imports`, from #1280. - The loop in `structure.rewrite_attribute_references`, from #1658. - The loop in `leaf_dev.docs.compose`, from #2660. - The loop in `leaf_dev.arrangement_eval`, from #4629. The four reverse-slice loops copied the whole source once per edit. Each of them applies edits that don't overlap and don't start at the same offset, so splicing them in one pass gives the same output. - **The file name of a stamped version.** `live_shell` wrote `f"v{version}.html"` inline, from #666. It now calls `files.version_name`. - **Whether a note stamps a revision.** `validation/source_history.py` scanned for the note inline, from fe4e8ea. It now calls `files.stamped_version`, which was added in the same commit. - **The `sha256:` digest of a revision's HTML.** `revision_artifact._capture_artifact` hashed `document.data` again, from #666. It now reads `SourceDocument.digest`, from #606, which holds the same value. I left `compose_document`'s two-insertion loop in `revision_delivery.py` alone. `splice` orders edits at the same offset by their text, but that loop relies on list order when `<html>` and `<head>` are both implicit. **Verification.** `ruff` and `ty` pass on the touched files. These model tests pass: `test_module_url_delivery`, `test_revision_delivery`, `test_live_shell_artifact`, `test_product_page`, `test_interact_document`, `test_interact_anchors` and `test_interact_layer`, 626 tests in all. In `dev/tests/model/test_product_page.py`, the second case of `test_a_composed_part_refuses_an_authored_copy` fails at `assert slot in authored`, before `compose` runs. Its fixture string expects `<img` followed by `alt="Sandbox` at 16 spaces of indentation, and `docs/index.html` on `main` now indents that line by 18. The failure is in the test's fixture, not in this change. <details><summary>Sets found but not consolidated here</summary> Another open pull request already changes each of these: - **Claude Code and Codex config homes, and the inline-delivery opening, repeated in `leaf_dev`.** #6014 moves them onto `harness.claude_code_config`, `harness.codex_home` and `hook_transport.INLINE_OPENING`. - **`hooks._awaits_agent` repeats `holding.running_turns`.** #6032 rewrites `running_turns`. - **The "N user updates with no answer" sentence**, written in both `activity.unanswered` and the `page-open-owes` finding. `activity.py`, `findings.py` and `session.py` are all being changed in #5979, #6018 and #6032. - **Raster magic bytes**, read in both `media._UPLOAD_TYPES` and `revision_delivery.media_size`. `media.py` is being changed in #6014. These are not worth a shared helper, because they are one-line stdlib idioms or the copies differ in meaning: - `json.dumps(..., sort_keys=True)` used as a cache key. - Compact `json.dumps` with `separators=(",", ":")`. - The `script_kind(...) in {"module", "classic"}` membership test. - `lock_is_held(page_dir / SERVER_LOCK)`. - Inline closed-object JSON schemas. **Not consolidated, needs a separate look.** `sample_content._non_json_number` repeats `http.reject_json_constant`. The real question is where Leaf refuses non-finite numbers. The HTTP path refuses NaN and numbers past a double's range. Sample fixtures refuse only NaN and infinity. No other reader of event JSON in `src/leaf/` passes `parse_constant`. Sharing the helper would change the `sample-json` message without settling that question, so it is left out of this PR. </details> Co-authored-by: leaf-agent <[email protected]>
Summary
Why
Reader actions could previously cross several independently scheduled DOM and server projections. That made simple transitions such as returning to a swipe queue appear late or disappear, and made revision activation depend on mutable files beside captured HTML. This change gives each browser reading one semantic owner and makes presentation readiness prove that every required view has either committed or visibly retained its prior state.
Deliberate follow-ups
TODO.mdrecords the work that is not required for this first correct slice: patch markup-only revisions in place so the browser naturally retains transient state; move the remaining Leaf-owned generated UI and compatibility readings onto the publisher/Lit path; and content-address repeated immutable revision resources. The current fresh-document path remains the explicit fallback when the captured executable graph changes.Verification
uv run pytest tests— 1,116 passeduv run pre-commit run --all-files— passednpm run check:browser && npm run test:browser— 34 passednpm run typecheck --prefix worker && npm test --prefix worker— 61 passed