Skip to content

Give returning data and projection watchers one rule, so a failed projection paint is reported once - #2552

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

max-sixty merged 3 commits into
mainfrom
agent-abb738b0fc4ec8194

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A widget fed by watchQuestions, watchReports, watchHistory or watchThreads no longer reads its projection again each time it returns to the page. Before this change, a paint that failed was reported once more on every return. #2531 had already fixed this for watchData, using its own copy of the rule. Both watchers now use one helper. This is item #55 of the Lit survey follow-up review, numbered in that review rather than as a GitHub issue.

Behaviour that changed (#55)

  • One return rule, readingPaint (arrivals.js). A paint is keyed by its reading. It draws only when the key has changed, or when the promise its last draw returned did not settle while the owner stood. That covers a departure in the middle of a paint, and a paint that settled after removal but before the departure reached the arrival batch. A finished paint stays, failed or not. The helper also pauses and resumes the paint's clock across a departure. A refresh() asked for while the owner is away now runs on the return; before, the unconditional re-read covered it, as when lf-activity's Markdown parser lands while the feed is away. watchData and watchProjection both use it, and data.js drops its delivered/painting bookkeeping.
  • What a projection reading depends on. watchProjection builds both its key and its subscriptions from one list of the three inputs it already listened to: the semantic epoch, the projection deferral, and the number of PRESENTATION announcements. The re-read on return came from Consolidate widget lifetimes and retain UI controls #1929, where it was the way to catch up on changes missed while the widget was away. No reading depends on anything outside those three inputs. A reading withheld by watchReports' readiness proof is still owed. This replaces the separate blocked flag.
  • Thread mirrors. mountThreadViews returns its reconcile promise to the watcher, so a departure that cuts a reconcile short is owed on return.
  • HeldReading takes its owner (new HeldReading(this, region, changed)) and keeps its wait for unseen growth across a departure. Five widgets disposed it on departure and relied on the unconditional re-read to re-arm it: lf-activity, the Atlas plan, worker and tree, and the conversation workspace. With only the core change, a held reading in that pattern never showed after a return. The test below failed that way before this change. Those widgets no longer dispose or re-arm it, and lf-atlas-tree's re-arm from Redeliver a returning data subscriber only what its departure cut short #2531 is gone.
  • The lf-test-worker fixture paints through its watcher's clock, not through a per-connection clocked paint that only a re-read re-armed.
  • module-authoring.md states the return rule once, under "Connection lifetimes", for data and projection subscriptions. The widget-controller-lifetime eval prompt no longer asks for a catch-up when nothing changed.

Measured

Item Hand-written source (excl. tests, Markdown, eval YAML, generated corpus copies) Tests
#55 +171 / −115 (net +56) +164 / −11 (net +153)

The source total breaks down as the runtime (+167 / −103) and the example widgets (+4 / −12). readingPaint itself is +64 / −1 in arrivals.js, including its contract comment.

Validation

  • test_a_returning_projection_subscriber_reads_again_only_where_its_departure_cut_the_paint failed on main: each of the three watchers called its failing callback twice and reported the failure twice. It passes here. It also checks that a projection paint cut short by a departure is drawn again.
  • test_a_held_reading_shows_once_unseen_after_its_owner_returns: with the core change alone and the old dispose-on-departure pattern, the held reading stayed on first. With HeldReading owning its lifetime, it shows second.
  • A Node runtime test covers readingPaint: a refusal stands, a cut-short paint is owed, and a paint that settles after removal but before departure delivery is owed. With the settle-while-detached line removed, that test fails.
  • The projection lifecycle test now expects no read on an unchanged return, and a clock tick after the return.
  • Focused browser runs pass: data and projection subscription lifecycles, the activity feed's held and print tests, the Atlas report hold, work roles, package thread mirrors, the PR brief clock, and the report narration proof. test_primary_reader_revision_replaces_owner_without_losing_thread_draft fails ("The page already has a Thread presentation") with or without this change.

Not changed

widget-controller.js (around line 254) clears renderedReading on departure, so a return re-runs renderState and the widget's subscriptions on an unchanged reading. This is a third return rule, and this PR does not test whether a renderState failure is shown again on return. Moving the controller onto readingPaint would also mean presenting its presentation ticket without a repaint, so it is left for a follow-up.

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

max-sixty and others added 3 commits October 12, 2026 01:27
…jection paint is reported once (#55)

A widget fed by watchQuestions, watchReports, watchHistory or watchThreads read
its projection again every time it returned to the page, even when nothing had
changed. A paint that failed therefore failed and was reported again on each
return. #2531 had already stopped this for watchData, with its own copy of the
rule.

Behaviour that changed:

- readingPaint (arrivals.js) is now the one home of the return rule. A paint keyed
  by its reading draws only when the key changed, or when the paint's returned
  promise did not settle while its owner stood. That covers a departure mid-paint,
  and a paint that settled after removal but before the departure was delivered.
  A finished paint stands, failed or not. It also owns the clock pause and resume
  across a departure. watchData and watchProjection both paint through it, and
  data.js loses its delivered/painting bookkeeping.
- watchProjection keys a reading by its inputs: the semantic epoch, the
  projection deferral, and the count of PRESENTATION announcements. The history
  of the re-read (#1929) shows it was there to catch up on changes missed while
  away, and no reading depends on anything else. A reading withheld by its
  readiness proof stays owed, which replaces the separate `blocked` flag.
- Package thread mirrors (mountThreadViews) return their reconcile promise to
  the watcher, so a departure that cuts one short owes it on return.
- HeldReading takes its owner and keeps its wait across a departure itself. The
  activity feed, the Atlas plan, worker and tree, and the conversation workspace
  had disposed it on departure and relied on the unconditional re-read to arm it
  again. They no longer dispose it or re-arm it.
- The lf-test-worker fixture paints through its watcher's own clock rather than
  a per-connection clocked paint that only a re-read could re-arm.
- module-authoring.md states the return rule once, under "Connection lifetimes",
  for both kinds of subscription.

Tests: a failing projection paint is reported once per watcher across a return,
and a paint cut short by a departure is drawn again. A held reading shows once
its region is unseen after a return. A runtime test covers readingPaint's rule,
including the settle-after-removal race. The projection lifecycle test now
expects no read on an unchanged return, and expects a clock tick after the return.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…'s key and subscriptions from one input list

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty max-sixty changed the title Give returning data and projection watchers one rule, so a failed projection paint is reported once (#55) Give returning data and projection watchers one rule, so a failed projection paint is reported once Oct 12, 2026
@max-sixty
max-sixty merged commit 006840e into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-abb738b0fc4ec8194 branch October 12, 2026 08:51
max-sixty added a commit that referenced this pull request Oct 12, 2026
… two leftovers (#2565)

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 #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 #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_

---------

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