Skip to content

Give widget controllers and clock paints the one return rule, and cut two leftovers - #2565

Merged
max-sixty merged 3 commits into
mainfrom
agent-a3b278001d9282912
Oct 12, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-a3b278001d9282912

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A widget driven by widgetController now draws on return by the same rule as watchData and watchProjection: only a reading that changed while it was away draws again, so a renderState that failed is reported once. clocked now follows its owner's lifetime, so no widget pauses and resumes its clock by hand. Two leftovers go: an optional Thread panel path nothing used, and the misleading openThreads. These are items 60–63 of the Lit survey follow-up review, numbered in that review rather than as GitHub issues.

Behaviour that changed

  • Item 61: the controller's return rule. widget-controller.js cleared its rendered reading on departure, so every return ran renderState and its subscribers again, and a failing render was reported again each time. It now paints through readingPaint, keyed by the reading. A return to an unchanged reading draws nothing and settles its presentation ticket; a reading that changed while away draws as before. defer(), an ancestor's refresh and the last unsubscribe owe a fresh draw (forget()). Time readings in renderState or a subscriber now subscribe to the shared clock, which module-authoring.md already said they did. A tick claims the draw through the controller's own publish, so it waits out a deferral or drag like any other reading.
  • Item 63: clocked follows its owner. clocked holds a watchOwner lifetime from construction. Its readings pause while the owner is away, and the next tick after a return repaints what aged. Before, the tick dropped a departed owner's paint for good, so lf-pr-brief stopped and resumed it by hand; that code and render.resume() are gone. stop() takes a paint off the clock until it paints again. tickClock now skips, rather than drops, an owner removed before its departure reaches the arrival batch. To avoid an import cycle, readingPaint moves from arrivals.js to presence.js beside clocked. presence.js imports watchOwner, and arrivals.js no longer imports presence.js. No other caller managed a clock's lifetime by hand.
  • Item 62: the optional Thread panel path is deleted. registerPanel({required: false}) nested its own clocked paint inside watchThreads and discarded its promise. Its only caller was test_two_standard_thread_lists_share_updates_but_not_local_state, so that test goes too. required is gone from registerPanel and registerThreadPanel: every panel joins the thread presentation.
  • Item 60: openThreads is split into two functions named for what they return. It returned every card with the panel open, and the open cards in page order with it shut. The t/T walk with the panel shut now calls openThreadsInPageOrder(). The queue walk's arrival by id looks among threadCards() when the panel is open and among openThreadsInPageOrder() when it is shut. The comment Walk one list of threads in the Threads panel, and report one position #2551 added to explain the old function is gone.
  • module-authoring.md states the return rule once for data, projection and controller subscriptions. The clocked paragraph no longer tells authors to call .stop() and .resume().

Measured

Hand-written source excludes tests, Markdown and the generated corpus.page copy.

Item Source Tests
61 widget-controller.js +72 / −60, plus invalidate passed through readingPaint (≈ +3 / −2) +60 / −3
63 presence.js, arrivals.js, data.js, projection-watch.js, lf-pr-brief.js: ≈ +95 / −81. About 62 lines of each side are readingPaint moving files. +35 / −1
62 presentation.js, application.js, leaf.js: +13 / −58 +2 / −166
60 thread-list.js, navigation.js, leaf.js: +18 / −17 +2 / −2
Total +204 / −219 (net −15) +99 / −172

Validation

  • test_a_returning_controller_widget_draws_again_only_a_changed_reading failed on main in both of its halves. An unchanged return redrew the widget. After a failing renderState, a return ran it again and reported the failure again. It passes here.
  • The Node test "a clock paint pauses while its owner is away and ticks again on its return" failed on main ([0] where [0, 1] was expected): with no manual resume, the returned paint never ticked. It passes here.
  • test_page_owned_registry_and_widget_use_the_captured_public_api asserted the old unconditional redraw after another widget's action. It now asserts that the unchanged return draws nothing.
  • pnpm run test:runtime passes. These browser runs pass: all of test_render_application_boundary.py, the data and projection return tests, the clock paint tests, the required-panel startup tests, the PR brief clock and remount tests, report narration, the thread and queue walk tests, and the widget, options and controls lifetime selections. test_primary_reader_revision_replaces_owner_without_losing_thread_draft fails ("The page already has a Thread presentation") as it did before this change, per Give returning data and projection watchers one rule, so a failed projection paint is reported once #2552.

Not changed

watchComparison (version.js) re-reads on every return through whileConnected. A callback that throws retires its subscription, so nothing is reported twice. Moving it onto readingPaint would need a comparison generation to key on. lf-diff's inline patch keeps the same rule in its own settled flag. Moving it onto readingPaint means exporting readingPaint to packages, which adds a public API.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 3 commits October 12, 2026 02:15
… two leftovers

A controller-driven widget now draws on return by the rule data and projection
watchers already follow (`readingPaint`): only a reading that changed while it was
away draws again, so a `renderState` that failed is reported once. Before, the
controller cleared its rendered reading on departure and redrew on every return,
reporting a failure again each time. A return to an unchanged reading still settles
its presentation ticket. Time readings in the controller's render now subscribe to
the shared clock, as module-authoring.md already said they did; a tick claims a fresh
draw through the controller's own publish, so it respects a deferral.

`clocked` now follows its owner's lifetime itself: its readings pause while the owner
is away and resume when it returns. Before, the tick dropped a departed owner's
paint for good, so lf-pr-brief stopped and resumed its clock by hand; that code is
gone, with `render.resume()`. `readingPaint` moves from arrivals.js to presence.js
beside `clocked`, which now imports `watchOwner`, so there is no import cycle.

The optional Thread panel path (`required: false`), whose only caller was a test,
is deleted with that test; every registered panel is the required kind.

The thread list's `openThreads()` returned every card with the panel open and the
open cards in page order with it shut. It is now two readings named for what they
return: `threadCards()` and `openThreadsInPageOrder()`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rts no subscription mid-connect

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 2adc952 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-a3b278001d9282912 branch October 12, 2026 09:47
max-sixty added a commit that referenced this pull request Oct 12, 2026
…rule (#2568)

The last two places that kept their own return rule now paint through
`readingPaint`, the one rule #2565 settled: on return, a paint draws
again only when its reading changed while away, or when the departure
cut a paint short. These are items 66 and 67 of the Lit survey follow-up
review, numbered in that review rather than as GitHub issues.

## Behaviour that changed

- **Item 66: a comparison watcher survives a throw.** `watchComparison`
(version.js) read on every return inside `whileConnected`'s `start`. A
callback that threw there made `watchOwner` retire the subscription for
good, so a tab's or settled ask's Δ marks stopped following the
comparison. Comparisons now carry a generation, advanced by
`announceComparison()` at each of the two places the comparison changes.
`watchComparison` keys `readingPaint` on it: each `lf-comparison` event
reads at once, and a connection reads on the following microtask,
outside the connection. A return to an unchanged comparison reads
nothing. A throw is reported once and the next comparison change reads
again. module-authoring.md "Reading version changes" says so.
- **Item 67: lf-diff's inline patch uses the shared rule.**
`readingPaint` is now exported from `widget-api.js` and documented under
"Connection lifetimes". lf-diff's inline patch paints through it, keyed
by the patch text, and its `settled` flag from #2503 is gone. No other
package or example widget keeps a copy of the rule. lf-file-editor
re-reads its file on each connection, but that is an external re-read
with no reading key, not a copy.

## Measured

Hand-written source excludes tests and Markdown.

| Item | Source | Tests |
|---|---|---|
| 66 | version.js +23 / −11 | +50 / −0 |
| 67 | widget-api.js +8 / −1, lf-diff.js +12 / −6 | 0 |
| Total | +43 / −18 | +50 / −0 |

## Validation

-
`test_a_comparison_mark_that_failed_on_return_keeps_following_the_comparison`
fails on `main`: the decision tab's mark stays empty after a later
comparison. It passes here, and checks the throw is reported once.
- These pass: all of `test_render_options_settled.py` and
`test_render_diff_controls.py`, including #2503's
`test_a_patch_that_failed_stays_failed_when_its_diff_returns`; the `diff
or tab` selection of `test_render_widgets.py` (66 tests); the margin
comparison test and two comparison-selection tests in
`test_render_anchors.py`; and `pnpm run test:runtime`.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 12, 2026
…2573)

A revision that replaces a primary Thread reader with another one no
longer throws "The page already has a Thread presentation". The thread
draft, its selection and the frozen widgets carry across to the
replacement again. This fixes review item #70:
`test_primary_reader_revision_replaces_owner_without_losing_thread_draft`
was failing on `main`.

## Cause

Bisect over `main` (781f2da..6b1210e, running only that test) names
#2503 (d57bf19) as the first bad commit; its parent bb47f5f passes.
#2503 moved `lf-conversation-workspace`'s registrations off
`connectedCallback`/`disconnectedCallback` and onto `whileConnected`.
`whileConnected`'s connect runs synchronously, but `watchOwner` decides
a departure only at the next arrival mutation batch. `patchTree` evicts
the replaced element and then inserts its replacement in the same task,
so the replacement's `start` ran while the evicted element still held
its registration. The single-holder registries (`thread/destination.js`
`register`, `thread/presentation.js` `registerPrimary`) then refused it.
`dom-move.js` appears in the stack only because it is the insertion that
connects the element. #2545, #2552 and #2565 did not cause it; #2552's
PR notes that the test already failed without it.

## Fix

This is fixed in the lifetime primitive, not in each registry. Two
changes in `arrivals.js`:

- The `offer` that `watchArrivals` returns now reads the pending
mutation records (`takeRecords`) before it decides its element. A
decision made now therefore never runs ahead of a departure already
made. `watchOwner` offers every owner as it connects, so whatever left
before has released first.
- `offerMany` now decides every departure in a batch before any arrival
in it. Each mutation record lists its added nodes before its removed
ones, so before this, an owner returning through the batch
(`old.replaceWith(returning)`) started before `old` released.

A move within one batch still keeps its resources. An element that is
removed, and then re-added after another owner connected in between, now
leaves and comes back, which is what `disconnectedCallback` did before
#2503. The `arrivals.js` header and `module-authoring.md` ("Connection
lifetimes") now state this rule. The single-holder checks in the
registries stay as they are, since they guard a real invariant: two
primary readers standing at once.

## Why CI didn't catch it

The test is in the `nightly` tier (`tests/cost_tiers.json`: it costs
more than 8 s on CI's runner). A pull request's gate adds later-tier
tests only when the change edits their own lines (`--changed-since`),
and #2503 did not edit this one. The last scheduled run started on
2026-10-11 at 10:53 UTC, before #2503 landed, so no nightly run has
executed the test since the break. The three most recent scheduled runs
(10-09, 10-10 and 10-11) were all cancelled, so the nightly tier has not
reported for three days.

## Measured (item #70)

- Hand-written source: `arrivals.js` +26 / −16. Of that, code is +15 /
−12 and the header comment is +11 / −4. The Markdown change is excluded.
- Tests: +35 / −0. That is one Node runtime test, `an owner replaced
within one batch releases before its replacement starts`, with two
cases. The case of a new owner fails on `main` with "already held". The
case of a returning owner fails the same way with only the `takeRecords`
change applied. Both pass here.

## Validation

- The failing browser test passes.
- `pnpm run test:runtime` passes (368 tests).
- 55 focused primary-reader, presentation, draft and workspace tests in
`test_render_application_boundary.py` and `test_render_threads.py` pass,
across all tiers.
- I ran 332 lifetime, return, mirror, carry, workspace, reading-region
and code-copy tests across `tests/`, in all tiers (`-k "returns or
returning or lifecycle or lifetime or disconnect or mirror or
revision_replaces or retains or carry or primary_reader or workspace or
external_link or reading_region or code_copy"`). All pass except
`test_render_anchors.py::test_code_copy_enter_leaves_nested_links_usable`,
which this change does not cause. Under `-n 4` that test fails 2 runs in
6 with `copyAtPresentation == 2`, both with `main`'s `arrivals.js` and
with this branch's.

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants