Repository navigation
Redeliver a returning data subscriber only what its departure cut short - #2531
Merged
Merged
Conversation
`watchData` paused a subscription when its owner left and, on return, delivered the newest snapshot even when it was the reading already painted. A bound widget whose source failed to render (a bound lf-diff, lf-text-document, lf-visual-review) therefore failed again on each return and reported the error a second time. #2503 fixed the same symptom for lf-diff's inline patch, which is not a data delivery and keeps its own rule. Behaviour changes: - data.js: a return delivers only when the source reading changed while the owner was away, or when the departure interrupted a paint whose promise had not settled. Widgets abandon an unfinished paint when they leave, which is why the old rule redelivered at all; a finished paint, failed or not, now stands. - presence.js: `clocked(...).resume()` puts a kept painting's time readings back on the shared clock after the `stop()` its owner's departure called, so a returning subscriber's "2h ago" keeps ticking without a repaint. - lf-pr-brief (example): its clocked paint was rebuilt per connection and only painted by the data callback, so its observed age stopped ticking after a return. It now keeps one clocked paint, stopped and resumed with the owner. - lf-atlas-tree (example): a departure disposes the held reading's wait; a return now re-arms it when a newer reading is held, which redelivery used to do. - module-authoring.md states the new return rule and the stop/resume pairing. Tests: the #2503 lf-diff return test now covers the bound path as well (failed twice on main); a data.js test pins redelivery after an interrupted paint and none after a finished one; the owner-lifecycle test now expects no redelivery of an unchanged reading and a clock tick after return; the PR brief clock test covers a return. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…authors to return a deferred paint's promise Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 12, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 12, 2026
…jection paint is reported once (#2552) 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 #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 #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_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A widget bound to a data source no longer fails a second time when it leaves the page and comes back. Before this change, a bound lf-diff, lf-text-document or lf-visual-review whose source had failed to render failed again on every return and logged a second console error. This is review item #48 from the Lit survey follow-up, numbered in that review rather than as a GitHub issue.
Behaviour that changed
watchData(data.js). Previously, when a subscriber returned, it was sent the newest snapshot even when that snapshot was the one already painted. Now it is sent one only when the source reading changed while it was away, or when it left while its paint's promise was still running. The resend existed because widgets drop unfinished paints when they leave: lf-text-document and bound lf-diff both bump a rendering counter on departure. That one case is now stated exactly. A paint that finished, including one that failed, stays as it is.clocked(presence.js) gainsresume(). When a widget leaves, data.js stops its paint's clock subscription. With no repaint on return, nothing would put that subscription back, soresume()returns the kept painting's time readings to the shared clock. The next tick repaints any reading that has aged, such as "2h ago".clockedpaint on every connection, and only the data callback ever painted it. After a return, its "Observed …" age stopped updating. It now keeps one paint for its lifetime, stopped when it leaves and resumed when it returns.module-authoring.mdnow states the return rule and the stop/resume pairing forclocked. Because data.js learns that a paint is unfinished only from the promise its callback returns, the guide tells authors to return the promise of any paint that finishes later. It also says that awhileConnectedstart must restore whatever its cleanup cleared, since a return no longer repaints unchanged data. No current bound widget defers its content paint without returning that promise. lf-visual-review and lf-trace defer only layout, which their size observers schedule again when they return.Kept
lf-diff's inline-patch
settledguard from #2503 stays. It applies only to an inline patch, which is not a data delivery, so data.js never sees it. It is the same rule enforced at a second boundary, not a copy of data.js's. The other bound widgets have no local guard against the resend. The cleanup in lf-text-document and lf-diff that drops a paint on departure is what the new rule depends on. lf-trace's redraw on return is for its own closed picture.Measured
Validation
mainand passes here.test_a_returning_subscriber_is_repainted_only_where_its_departure_cut_the_paintchecks that a widget is repainted after leaving mid-paint and not after leaving with a finished paint. It fails onmain.resume()removed, the tick assertion fails.