Skip to content

fix: hold presentation through the first drawing after a skipped update - #4103

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-4097
Oct 25, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-4097

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

A bound diff could move the paragraph below it by 355px after Leaf reported its initial presentation complete. Lit leaves hasUpdated false after an update skips drawing while data is unread, so the first signal-driven retry could start without a presentation ticket. Its asynchronous updateComplete then held no barrier.

LeafElement now claims each connected update at its draw gate when it has no existing ticket. This preserves the asynchronous drawing guarantee introduced in #3982 while retaining the bound-value gating in #3929 and #3987. The external resolution behavior and shift tolerances are unchanged.

The new runtime regression fails before the fix and passes afterward. The reported browser case reproduces the 355px shift before the fix and passes afterward, both normally and with 6× CPU throttling. The data-readiness failure case, all 562 runtime tests, and pnpm run check pass. Rebuilt the committed kernel.

A served worktree-diffs comparison against the base loads the same 53 code requests through upgrade and initial server presentation, with 107 additional code bytes (17 JavaScript bytes) and no layout shifts in either arm. The added claim makes readiness wait for drawing already underway; it adds no resource dependency.

Closes #4097 — automated triage

An update skipped while bound data is unread leaves hasUpdated false. The subsequent signal-driven retry therefore bypasses requestUpdate’s existing-ticket path. Claim a connected update at its draw gate when no ticket exists, so asynchronous updateComplete holds presentation.

The new runtime regression fails without the fix. The reported seated diff test reproduces the 355px startup shift before the fix and passes after it, also at 6x CPU throttle. No resolution or shift tolerance changed.

Closes #4097
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Verified this head against #4093: all four variants of test_a_diff_shows_native_file_metadata_without_empty_disclosures pass on da950ea31749be92be42ab0f74f3892f94ece88d. Both manifest variants had reproduced the null shadow root before the fix. The existing metadata, source-path, evidence and comment-opening assertions remain intact. I withdrew the alternative #4102; this PR also resolves #4093's cause.

@leaf-agent
leaf-agent merged commit 070e6dd into main Oct 25, 2026
5 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-4097 branch October 25, 2026 19:19
max-sixty added a commit that referenced this pull request Oct 27, 2026
The margin's annotations were drawn twice per thread pass: once by their
own presenter, which waits only for the projection's chrome (the thread
region's `committed()` resolves after its synchronous start, before its
seats commit), and again when the thread pass committed
(`untracked(renderAnnotations)` in `thread/presentation.js`). A comment
gesture runs two thread passes (the local send, then the server's
reading), so the margin drew four times. Measuring also showed each of
those thread passes ran twice on `main`, because `anchor-placement.js`
advanced its version with `version.value += 1` inside the pass,
subscribing the pass to its own write.

## What changed

- **The thread pass paints no other owner's region.**
`thread/presentation.js` no longer calls `renderAnnotations` at commit,
and `createThreadPresentation` no longer takes it. What the pass decides
about a thread reaches the margin as readings its paint already follows
(`applicationPresenter` follows a paint's reads of values outside the
state): where the thread is placed (`anchor-placement.js` `placedAt`,
already a followed `version`), and now also whether a widget seats or
holds it and whether its reply is being edited.
- **`thread/surfaces.js`: `claimed` and `heldOut` are followed
readings.** One `ownership` signal moves when a commit changes the
claimed set or a hold changes the keys it keeps out; both compare sets,
so a commit that seats the same threads moves nothing. The module's own
reads in `prepare` and `commit` take the plain answer (`holdsOut`), so
the thread pass doesn't follow what it moves itself.
- **`thread/replies.js`: `replyIsEditing` is a followed reading.** A
`sessions` signal moves when a session opens or closes
(`openSession`/`closeSession`, the four membership writes), not when its
owner changes. The margin lists a resolved thread only while a session
stands (`threadHasDiscussion`), and previously relied on the thread
commit's redraw to notice a session starting or ending.
- **Version signals advance without reading themselves**
(`version-signal.js` `tick`, the one home, as `page-controls.js` `tell`
did by hand). `x.value += 1` reads the signal first, and inside a paint
subscribes that paint to its own write, so the region claims another
pass. `anchor-placement.js` had this form on `main` inside the thread
pass (its own commit, measured below); the new `ownership` and
`sessions` bumps had it too, as did five sites on `main` outside paints.
All are converted, and `no-restricted-syntax` in the private runtime's
eslint block refuses `.value +=`. The exact closures in
`.dependency-cruiser.mjs` admit `version-signal.js`, which imports
nothing.
- **Reply continuity waits for the margin's own commit alone.**
`continueReplies` starts once the margin region's own DOM has committed
(`regionCommitted("annotations")`, new in `semantic-state.js`: a
region's commit without the upstream DOM its paint follows, settled
unless the region owes a paint), read a microtask after the commit's
stretch so the margin's follow-on claim has landed. It does not wait for
the whole pass (`whenDocumentPresented()`), nor for `PRESENTATION_DOM`
entries, which are transitive down to the widgets, so neither a widget's
asynchronous preparation nor a commit it holds through a drag leaves a
displaced reply editor without focus meanwhile. It still runs in the
task that committed the seats.
- Comments in `semantic-state.js`, `annotation-inventory.js` and
`application.js` describe the mechanism (the followed-readings path is
the margin's; `obligations/view.js` still depends on
`PRESENTATION_DOM.thread`).

The margin still doesn't depend on the thread region committing: its
`after` chain is unchanged, so a held thread pass delays no margin
paint; it repaints again only when a reading the pass moved says so.

## Evidence

`uv run leaf-dev profile triage-board comment`, 3 runs each, with
temporary `performance.mark`s (not committed) at the start of each
thread pass (`renderReading`) and in `renderAnnotations`, counted per
trace between the last keydown and the `Sent` goal
(`.tmp/grind/count_paints.py`):

| | thread passes per comment | margin paints per comment | input→Sent
ms |
|---|---|---|---|
| `main` (`f00911ed1`) | 4, 4, 4 (each publication's pass starts twice,
~1 ms apart) | 4, 4, 4 (two per pass) | 89.1, 62.7, 60.5 |
| branch | 2, 2, 2 | 2, 2, 2 | 97.6, 68.1, 83.6 |

`renderAnnotations` was 8.7 ms inclusive per run in `main`'s top-12 JS
list and no longer appears in it. Elapsed times are noise on a loaded
host (load average ~25 on 18 cores during the runs); the counts are the
measurement.

## Tests

- `tests/runtime/thread-surfaces.test.mjs`: "a paint reading which
threads a seat claims follows the commit that changes them" fails on the
baseline reading and passes with the change. It also runs the commit
inside an effect, as the pass's resumed stretch does, and asserts that
effect runs once; it ran twice while `commit` filtered page threads with
the followed `heldOut`.
- `tests/runtime/region-presenter.test.mjs`: "a paint advancing a
version it does not read claims no second pass" (a `tick`ed paint paints
once, a `+=` paint twice, with the real presenter), and "the margin's
own commit is reachable while a widget holds its paint" (the page's
chain of regions, widgets to margin, with a widget's commit held open:
`regionCommitted("annotations")` settles while
`PRESENTATION_DOM.annotations()` and `whenDocumentPresented()` do not;
with the transitive wait it hangs).
- `pnpm run test:runtime`: 671 pass after merging current `main`. `pnpm
run check` passes. `test_seated_threads.py` and
`margin/test_card_reply.py` with `-k "reply or return or continu or
displac or moved or seat"`: 79 pass;
`test_r_settles_the_thread_seated_under_the_diff_line_the_user_stands_on`
times out on `lf-diff .lf-diff-fold-all` on `main` too, and a
margin-reload case reports the thread-actions size change `main` also
shows (#4341).
- `tests/browser/threads/test_seated_threads.py` and
`tests/browser/startup/test_thread_surfaces.py`: 51 of 52 pass after
merging `main` at `070e6dd54`. The one failure,
`test_a_user_on_a_thread_returning_to_the_diff_goes_with_it[close]`,
fails the same way on `main` (focus assertion at line 853).
- `test_a_resolution_from_elsewhere_moves_nothing_after_a_diff_thread`
errored after the earlier merge of `main` at `c26545cd3` (`p#after`
moved 355px). That is #4097, which `main` at `c26545cd3` also fails 5 of
5 runs; #4103 fixed it, and the branch passes 5 of 5 with it merged.
- `tests/browser/margin/test_entries.py`, `test_opening_threads.py`,
`test_card_reply.py`, `test_status.py`,
`tests/browser/threads/test_resolving.py`, and the held-arrival cases of
`test_agent_replies.py` and `test_arrivals.py`: pass (card_reply and
resolving re-run after the `replies.js` change).

## Not verified

- The `heldOut` follow (a hold changing between passes) is exercised
only by the held-arrival browser tests, not by a runtime test.
- Continuity's wait is proven at the presenter boundary (the margin's
own commit reachable under a held widget, with the page's region chain)
and by the seated-thread browser tests, not by a Node test driving
`createThreadPresentation` itself.
- Package pages whose `threadOutlets` render asynchronously; the bundled
widgets were covered by the browser tests above.

## Calls Max may reverse

- `replyIsEditing` is followed by every paint reading it, including
thread cards, so a reply session opening (first focus in a reply row) or
closing now claims a thread pass where an open thread previously claimed
none. A narrower alternative is a follow token the margin alone reads.
- The lint refuses `.value +=` on any member named `value` in the
private runtime; no DOM `input.value +=` exists there today.
- #4076 is closed rather than rewritten.

Closes #4076.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Externally resolved diff thread test reports a 355px passive shift

1 participant