Skip to content

Consolidate widget lifetimes and retain UI controls - #1929

Merged
max-sixty merged 3 commits into
mainfrom
codex/simplify-ui-ownership
Oct 6, 2026
Merged

max-sixty merged 3 commits into
mainfrom
codex/simplify-ui-ownership

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Widget subscriptions and generated controls had overlapping owners. Removal could leave queued callbacks running, and targeting rebuilt a focused field during unrelated preview updates. This change gives subscriptions one owner lifetime and retains editable controls across repaint.

  • Share owner lifetime between widget controllers, data subscriptions, and projection readers. Pause on departure, catch up on return, retain subscriptions across moves within one mutation batch, and permanently cancel queued work on explicit stop. Cut bundled consumers over to that contract. Initialize each physical node independently of copied upgrade marks, so cloned data widgets start their own subscriptions.
  • Paint option controls directly through their controller, removing three reactive lifecycles and the child-update barrier. Keep authored option nodes, keyboard routes, selection, Done, refusal, and undo behavior.
  • Retain targeting fields and select options by identity, preserve unfinished name drafts, and normalize names at submission. Focus initialized fields through the existing user-intent guard.
  • Reuse child reconciliation for repeated rows, render media directly into the native dialog, and reconnect chart resize observation.

Validation: 30 focused browser tests and 226 runtime tests passed before integration, plus independent browser review and desktop/phone appearance comparisons. Focused checks were repeated after integrating main; the asynchronous source-provenance regression and a base/candidate clone-initialization probe cover the initialization repair. Startup comparisons retain the same request counts. The package-author reference and its base/candidate lifecycle evaluation cover the new subscription contract.

This was written by Codex on behalf of max-sixty

leaf-agent
leaf-agent previously approved these changes Oct 6, 2026
The shared subscription lifetime registers data consumers once per element.
A shallow clone copies data-lf-done but has no subscriptions of its own, so
using that painted mark as the initialization guard prevented cloned text
documents from rendering their first data snapshot.

Keep initialization with the actual node in a WeakSet. Reconnecting retains
the original lifetime; a clone starts its own regardless of copied marks.
The existing asynchronous source-provenance browser case now completes, and
a base/candidate probe also verifies removing the mark cannot reinitialize
an already initialized node.
@max-sixty
max-sixty merged commit 837abec into main Oct 6, 2026
4 checks passed
@max-sixty
max-sixty deleted the codex/simplify-ui-ownership branch October 6, 2026 22:00
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]>
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