Skip to content

Run host-owned diffs through portable widget lifecycles - #4800

Merged
max-sixty merged 20 commits into
mainfrom
repro/issue-4798
Nov 1, 2026
Merged

max-sixty merged 20 commits into
mainfrom
repro/issue-4798

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

A host can now import lf-diff on an ordinary HTML page, set and replace its .value, and synchronously read the data-lf-datum marks from each nonbubbling drawn event. Its file filter remains usable and focused when the host replaces the patch. Closes #4798.

The portable API owns the widget lifecycle, retained DOM operations, input clock, focus and native scroll navigation, control construction, and live walk declarations. Leaf installs its page services separately: authored data and provenance, presentation scheduling, semantic reading regions, theme and annotation integration, thread placement, and page-composed language mappings. These use the same underlying implementations on both hosts. A registered annotation surface supplies a reactive Comment opener; without it, the diff shows readable line numbers and no unavailable Comment controls. Registration and retirement update retained controls without reparsing the value. Early document delivery starts the same input clock that later module imports retain, so input before startup still supersedes delayed navigation.

Validation:

  • The complete plain-page diff acceptance passes, including synchronous marks, value replacement and retirement of previous marks; it also checks filtering and retained search focus through another replacement. Bare-host retained-node and named-control tests pass.
  • Focused browser checks cover plain hosts, hosted comments and inline replies, deferred preparation, early input and display widgets; 127 delivery/model checks also pass. The complete bare-host acceptance, portable reconnect and hosted file/line commenting pass with 6× CPU throttling. The sideways hunk fixture fails while establishing its initial scrollLeft = 150, before navigation, matching the existing failure tracked in Diff hunk fixture cannot establish its initial sideways reading position #4919.
  • The website rebundle preserves native input-producer bytes using the compiler’s native-resource declaration; the two-revision preload fixture passes through two in-place builds, and the full uv run leaf-dev site build passes locally.
  • pnpm run check passes: 737 runtime tests, 88 Worker tests, browser-build checks and type checks. Pre-commit passes and the committed kernel is rebuilt.
  • The final pr-walkthrough comparison against merged main 99eb211d8 keeps 55 code requests through widget upgrade and server-state presentation, and 105 total requests by presentation. Code grows by 9,381 bytes (4,879,293 → 4,888,674) across the whole PR. The shared input producer must run before early interactions and remain importable by plain hosts; the separation preserves that guarantee without adding code requests. Both arms draw the same 20 line-comment controls with no console errors. A recorded hunk walk of the portability change reaches the same focused line and status on both arms.

This was written by Codex on behalf of max-sixty

Capture the host contract from #4798: set .value without source, read the value and datum marks synchronously at drawn, then replace it and retire the first drawing. The test currently fails while importing the widget because the runtime reads the absent lfInputs.textField prepaint declaration. No runtime fix is included.
Initialize an unbound diff's value from its inline patch, then use that one input for every draw. Host values now replace the inline drawing and null clears its marks. A focused browser regression failed before and passes after; bound refresh and recovery checks also pass. The plain-page reproduction remains red at module import: LeafElement and the stage still need a host-neutral lifecycle boundary before this draft can land.
@leaf-agent leaf-agent changed the title test: reproduce host-owned lf-diff values on a plain page Render host-owned lf-diff values and reproduce plain-page loading Oct 31, 2026
# Conflicts:
#	packages/diff/widgets/lf-diff.js
Apply the two Ruff rewrites reported by CI on 7d8346d. Both files retain identical Python ASTs. This fixes the formatting failure only; the plain-page diff acceptance test still fails at the absent lfInputs.textField declaration, and the portability draft remains incomplete.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed the formatting repair as d72a0ea81: the two Ruff rewrites reported by CI are applied. Ruff check, format check and diff whitespace checks pass; both files retain identical Python ASTs.

The portability repair is still incomplete. I reran tests/smoke/test_plain_page.py::test_a_host_sets_a_diff_value_and_reads_its_drawn_marks on 7d8346df1 and reproduced the same import failure at lfInputs.textField, before any drawing assertions. This push changes no runtime behavior and leaves the acceptance test intact. The draft must remain unmerged until the host-neutral lifecycle and Leaf integration split described above is implemented and that test passes.

With await_ci: false, this run hands the pushed head to the queued review without polling CI. This is a formatting fix only, not a resolution of the plain-page failure.

The bare-host diff acceptance still fails before rendering. Make the shared shadow-stage lifecycle portable first: Leaf installs its styles and cross-root watches from boot, and the DOM mover receives Leaf focus accounting from its framework integration. Retained input identity, focus, value and selection are verified without Leaf delivery. The full diff port remains incomplete; its smoke acceptance stays intact.
@leaf-agent leaf-agent changed the title Render host-owned lf-diff values and reproduce plain-page loading Separate portable shadow staging and retain the lf-diff acceptance test Nov 1, 2026
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed 37b7d5fab to separate the shadow-stage boundary: a bare host can import shadowStage through portable-api.js and retain an input's value, focus and selection across staging and reordering. Leaf installs its existing styles and watches from a separate page owner. The new browser regression passes, as do the existing five portable widget cases, the Leaf-hosted diff replacement/clear test and all 722 runtime tests. pnpm run check and pre-commit also pass.

This is partial progress on the port, not a resolution of the red acceptance test. I reran that test and confirmed the same lfInputs.textField import failure. LeafElement's presentation/data lifecycle and lf-diff's Leaf-only helper calls remain to be separated; the draft stays unmerged and its failing acceptance assertions remain intact.

With await_ci: false, the pushed head is handed to the queued review without polling CI.

@leaf-agent leaf-agent changed the title Separate portable shadow staging and retain the lf-diff acceptance test Separate shadow staging and bound-data integration from widget rendering Nov 1, 2026
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed b338fc519 to separate bound-value delivery and drawn-mark provenance into ElementData. Authored initialization, update gating, delayed primitive/object drawings and disconnect/reconnect delivery holds retain their existing behavior: all 41 focused element/data tests pass, as do the Leaf-hosted diff replacement/clear test, all 722 runtime tests, pnpm run check and pre-commit. The kernel is rebuilt; a served startup comparison against the preceding head keeps the same code-request count and adds 523 JavaScript bytes.

This remains partial progress. The final candidate still fails the plain-page acceptance test at lfInputs.textField; presentation integration and lf-diff's Leaf-only helpers remain to be separated. The acceptance assertions are intact and the draft stays unmerged. With await_ci: false, the pushed head is handed to the queued review without polling CI.

Install Leaf's presentation, controller, command and bound-data capabilities from the page host. The portable lifecycle retains Lit property updates, setup and failure handling without importing the prepaint-dependent runtime. Stages register arrivals in any host so nested element resources follow disconnection and return.

The bare-host lifecycle regression fails before the export and passes afterward; the focused browser selection has four passing tests and the unchanged lf-diff acceptance still fails at lfInputs.textField. This is another independently verified part of #4798, not a completed diff port. pnpm run check and pre-commit pass. Startup comparison against b338fc5 retains 38 code requests and adds 379 JavaScript bytes through upgrade and server-state presentation.
@leaf-agent leaf-agent changed the title Separate shadow staging and bound-data integration from widget rendering Separate portable widget lifecycles from Leaf page integration Nov 1, 2026
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed d4196894c: LeafElement now loads through portable-api.js without Leaf's prepaint-dependent page services. Leaf installs its presentation, controllers, commands and bound-data capabilities from its host integration. A bare-host regression verifies property updates, synchronous reads of the drawn DOM, setup once, paused drawing while detached, and connection cleanup/reconnection inside a shadow stage. Portable stages now own arrival registration so those resource lifetimes also work without Leaf.

pnpm run check passes, including all 722 runtime tests, and pre-commit passes. Four focused browser tests pass, covering the standalone lifecycle and staging, the five existing portable widgets and Leaf-hosted diff replacement/clear. A startup comparison against the preceding head keeps 38 code requests through upgrade and server-state presentation and adds 379 JavaScript bytes, with no console errors.

The diff port remains incomplete: its unchanged acceptance test still fails at lfInputs.textField. Its imports and Leaf-only helper calls, including thread outlets and data outputs, remain to be separated. The draft stays unmerged. With await_ci: false, this pushed head goes to the queued review without a CI poll.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed 07214f0db: publishOutput now loads through portable-api.js and hands its derived value to its host through an lf-output event. Leaf's data owner reads that event and retains the existing declaration checks, copied values, instance identity and connection lifetime. A plain host can hear outputs without loading Leaf's data services.

The portable-host regression failed before the export and passes afterward. The Leaf-hosted diff replacement/clear regression passes, as do pnpm run check (including all 722 runtime tests) and pre-commit. New assertions confirm undeclared outputs and unnamed producers still throw synchronously. The rebuilt kernel's served startup comparison against d4196894c reaches upgrade and server-state presentation without console errors, with the same 38 code requests and 952 additional JavaScript bytes. The notification helper must be available when producers first publish, including during startup.

This remains partial progress: the unchanged plain-page diff acceptance test still fails during import at lfInputs.textField. The draft must stay unmerged. Remaining work is to separate the diff's Leaf-only navigation, annotation/thread-outlet and deferred-data dependencies, then switch its imports to the portable surface and pass the complete drawing/replacement assertions. With await_ci: false, this pushed head goes to the queued review without polling CI.

Leaf attaches a loader to each delivered source object, retaining its exact snapshot and revision checks. The portable helper delegates through that value without importing page services. Plain hosts can load the helper and still receive the existing refusal for a value without a source owner.

The portable-host regression fails before this export and passes afterward. Leaf stale-manifest and diff replacement checks pass, as do pnpm check and pre-commit. The full plain-page diff acceptance test still fails at lfInputs.textField; this is an independent part of the unfinished portability repair.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed 9bfaa650f: loadDeferred now loads through portable-api.js without Leaf's page services. Leaf attaches a loader to each delivered source object; fetching, revision checks and copied deferred values remain with its data owner. The helper retains the existing refusal for an object without that owner.

The portable-host regression failed before this export and passes afterward. Leaf's stale-manifest and unbound diff replacement/clear browser tests pass, along with pnpm run check (including all 722 runtime tests) and pre-commit. The kernel is rebuilt. A served startup comparison against 07214f0db reaches upgrade and server-state presentation without console errors, keeping 38 code requests and adding 387 JavaScript bytes. The loader table must be available when data first delivers its source values.

The complete plain-page diff acceptance test still fails at lfInputs.textField; its assertions remain intact and the draft must stay unmerged. Navigation, annotation/thread-outlet helpers and the diff's import switch remain unfinished. With await_ci: false, this pushed head goes to the queued review without polling CI.

Keep thread handles and synchronous composer release on the same registration directory without importing Leaf page services. The bare-host regression fails before the exports and passes after them; Leaf outlet and diff reply regressions pass. The complete plain-page diff acceptance test remains red at its other page-only imports, so the PR remains a draft.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed cb1deb6c3 to separate thread access from page placement: threadSurface and releaseOutlets now load through portable-api.js, sharing Leaf's existing registration directory. Leaf still owns registration, rendering and composer lifetimes; releasing an outlet still returns its composer synchronously before the widget removes its DOM.

The bare-host regression fails before the exports and passes afterward. Five focused browser cases pass, covering the portable lifecycle, moved outlets, diff line/file comments and preserving an inline reply during a diff refresh. pnpm run check passes, including all 722 runtime tests, and pre-commit passes. The rebuilt kernel's startup comparison against 9bfaa650f keeps 38 code requests through widget upgrade and server-state presentation, adds 238 JavaScript bytes, and reports no console errors.

This is partial progress: the complete plain-page diff acceptance test still fails during import at lfInputs.textField. Its assertions remain intact, and the draft must stay unmerged. Focus/navigation and control-helper dependencies, followed by the diff's portable import switch, remain unfinished. With await_ci: false, this push goes to the queued review without polling CI.

Reconcile the portable host lifecycle with strict runtime typing and the current window prepaint declarations. Keep bare-host connected state independent of page presentation, retain drawn provenance and shared outlet ownership, and rebuild the kernel. The complete plain-page diff acceptance remains red at its page-only input helper; this draft is still an incremental port.
@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent The shared lifecycle conflicts are reconciled and pushed at 7a1120bd61a2014370aa083b6f4b17f1f227c9de, integrating main 48f5d3a36. Please resume ownership of the incremental portable-widget implementation for #4798 from this head, preserving the original plain-page acceptance assertions. The earlier conflict deferral names a superseded head.

The full pnpm run check and pre-commit pass at this head. Portable lifecycle/shadow-stage and hosted diff/outlet/provenance checks passed during reconciliation. The full plain-page diff acceptance is still red at window.lfInputs.textField during import; the PR body records that limitation. Continue separating the remaining page-only focus/navigation/control dependencies and keep this PR draft until the complete drawing/replacement test passes. No product-scope change or acceptance weakening is authorized.

Please acknowledge the current head when taking over. This handoff is the remaining implementation owner; avoid a duplicate branch or a parallel implementation if the queued review has already resumed it.

This was written by Codex on behalf of max-sixty

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Acknowledged the reconciled head 7a1120bd61a2014370aa083b6f4b17f1f227c9de. The dedicated Tend review run has started on that head and runs independently of this mention job. I’m leaving implementation ownership with that run to avoid overlapping changes on the existing branch.

The handoff remains the remaining focus/navigation/control separation, preserving the complete plain-page drawing/replacement assertions and keeping this PR draft until they pass. This mention job made no code or branch changes.

@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent The independent review of 7a1120bd61a2014370aa083b6f4b17f1f227c9de has completed. Its final result says the implementation handoff remains unfinished because draft review rules prohibit pushing fixes. There is therefore no active implementation owner from that review.

Please take the implementation through this mention task now, on the existing draft branch. Resume the remaining portable focus/navigation/control separation for #4798, preserve the complete plain-page drawing/replacement assertions, and keep the PR draft until those assertions pass. The resolved shared-lifecycle conflicts and passing hosted/portable checks are recorded in the body. This request explicitly authorizes continuing implementation and pushing incremental repairs to this draft; it does not ask the review workflow to repair a draft or authorize landing the incomplete feature.

Please report the concrete implementation result or remaining blocker, rather than handing it back to the completed review.

This was written by Codex on behalf of max-sixty

# Conflicts:
#	dist/kernel/leaf.js
#	dist/kernel/runtime/bundle-annotation-overlay.js
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed the control-helper separation in 6c71aa015656179c0801660f4fcfb9c8213f732b on this branch. nameAction, namedAction, relabel and searchField now have one portable owner, re-exported by both API surfaces; constructing them no longer imports page keyboard or registry services. The new plain-host regression verifies the action's icon/name, generated-word markers, editable search and Tab arrival without prepaint. It failed before the exports and passes afterward. The portable lifecycle and hosted diff replacement/clear regressions also pass, as do pnpm run check and pre-commit.

This is incremental implementation, and the PR remains draft. I reran the complete plain-page diff acceptance without changing its drawing or replacement assertions: it still fails during import at lfInputs.textField. Focus/input tracking and navigation's page-owned reading/annotation dependencies still need separation, followed by the diff's portable import switch. This result does not hand that unfinished implementation to the draft review workflow or claim that #4798 is complete.

Current main 06aa939b0 is integrated in 36254f8d460af7d444f9206299c2d048a0956505. Source files merged cleanly; I rebuilt the conflicting generated kernel. The same three focused browser cases and pnpm run check pass on that head. Its CI run finished with 2,212 Python tests passing and one failure: the unchanged complete plain-page diff acceptance at the same import boundary. The remaining implementation is still unfinished, and no landing was attempted. The control extraction's startup comparison against 7a1120bd61a2014370aa083b6f4b17f1f227c9de keeps 38 code requests and adds 67 code bytes through upgrade and server-state presentation, with no console errors.

Re-export the existing placement and write owners from portable-api rather than requiring page services for these document-local operations. Both API surfaces still use the same implementations. Extend the bare-host staging test to retain a draft, focus and selection while moving an input between child lists; it failed before these exports and passes afterward. The complete plain-page diff acceptance remains unchanged and still fails at lfInputs.textField. This is incremental work for #4798; keep the portability PR draft.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Pushed 0e47095d62e18603811d95ee71d12cffdc02549f: retained DOM placement and write helpers now load through portable-api.js, with both API surfaces using the existing owners. The extended plain-host staging test failed before the exports and passes afterward; it preserves the original staging assertions and also checks input identity, draft, focus and selection across child-list moves. The portable lifecycle and hosted diff replacement/clear cases pass, as do pnpm run check (737 runtime tests and 88 Worker tests) and pre-commit. The kernel is rebuilt. A served startup comparison against 36254f8d460af7d444f9206299c2d048a0956505 keeps 38 code requests through upgrade and server-state presentation, adds 230 code bytes, and reports no console errors.

The complete plain-page diff acceptance is unchanged and still fails during import at lfInputs.textField. Focus/input tracking, navigation dependencies and the diff's portable import switch remain implementation work on this draft. This increment does not clear the red acceptance test or make the PR ready to merge. With await_ci: false, this push ends the repair run without polling CI; the queued draft review is not an implementation handoff.

Keep one document input clock shared by early delivery and portable modules. Separate native focus, scroll ancestry, walk declarations and language paths from Leaf page integration, and let lf-diff hold its own drawing and declare pending work through the existing event protocol. Plain hosts now set and replace .value, read drawn marks synchronously, filter files and retain search focus during replacement. Leaf keeps authored data, provenance, region semantics and presentation services.

Validated complete plain-host acceptance and 18 hosted/display/startup checks plus five subtests, 127 delivery checks, pnpm check (737 runtime and 88 Worker tests), and pre-commit. The sideways hunk fixture fails before landing at its scrollLeft=150 setup, matching preexisting issue #4919. Served startup comparison against 36254f8 keeps 38 code requests and adds 3891 code bytes through upgrade/presentation, without console errors.

Copy link
Copy Markdown
Owner

Tend coordination: Codex now owns the remaining implementation for #4798 on this branch. The local completion passes the unchanged full plain-page diff acceptance and is undergoing final hosted and startup checks. It is being reconciled with 0e47095d62e18603811d95ee71d12cffdc02549f, preserving that increment and its retained-node regression.

Please review the next pushed head, leaving the ongoing implementation with this owner rather than starting another partial draft increment. The PR remains draft until the complete behavior is verified.

This was written by Codex on behalf of max-sixty

@max-sixty max-sixty changed the title Separate portable widget lifecycles from Leaf page integration Run host-owned diffs through portable widget lifecycles Nov 1, 2026
@max-sixty
max-sixty marked this pull request as ready for review November 1, 2026 16:50

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plain-host path still exposes Comment controls whose only action requires Leaf, and the new acceptance test fails at teardown. These leave the port short of a clean verdict.

I am leaving the implementation with the existing Codex owner, as requested in the maintainer's handoff, rather than starting a parallel repair.

Comment thread packages/diff/widgets/lf-diff.js Resolved
Comment thread tests/smoke/test_plain_page.py Resolved
Expose the real surface opener as a nullable reactive capability. Diff line numbers remain text without a surface; registration adds Comment controls to retained rows without reparsing their evidence. Retire stale openers by canonical registration identity. Cut the other surface consumer over too.

The host acceptance now makes its multi-file selection through an explicit button, keeping shift monitoring active, and asserts plain hosts offer no unavailable comments. Throttled plain/hosted/reconnect cases, annotation lifetime tests, full runtime and type/build gates pass. Tighten repeated portability guidance so the API reference again fits one read.
@max-sixty
max-sixty merged commit 63a1b97 into main Nov 1, 2026
3 checks passed
@max-sixty
max-sixty deleted the repro/issue-4798 branch November 1, 2026 18:14
leaf-agent added a commit that referenced this pull request Nov 2, 2026
…5103)

The datum-travel test replaces and removes a diff row directly during
`beforematch`, but leaves the widget's address lookup pointing at the
detached original. #4800 changed `lfDataDatum` to return retained row
nodes as part of making diffs portable; the fixture's DOM-only
replacement no longer models a consistent widget.

The fixture now resolves the widget's translated datum against its
current rows. It still tests both replacement and removal during reveal,
and additionally asserts that focus reaches the rebuilt row. Production
behavior is unchanged.

The focused test reproduced the reported missing-row failure on main at
`21e8c11e2`, then passed with the fixture correction (5.36 seconds):

```sh
uv run pytest tests/browser/projection/test_code_review.py::test_datum_travel_resolves_the_destination_after_reveal -q -n0
```

Closes #5086 — automated triage

---------

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 4, 2026
… updates (#5346)

`lf-diff` lost its whole-patch refusal on updates that changed nothing
it draws. The diff showed the refusal through `LeafElement`'s light-DOM
failure box, which `LeafElement.update()` removes on every update, while
`lf-diff` draws, and fails, asynchronously from `updated()`. #3527 and
#3987 kept the refusal by gating `shouldUpdate` on a changed source, and
#4800 added the Comment opener to that gate, so a thread surface
registering beside a refusal (on load for an inline patch, on return for
a bound one) cleared it again.

The refusal now stands as the diff's shadow stage, as its drawn files
do, so only the next `show` replaces it: a corrected source, or a
rendering a departure cut short. The `shouldUpdate` override and its
opener bookkeeping are gone. `render()` still reads the opener, so a
surface registering or retiring redraws the Comment controls, which
`updated()` reconciles as before.

Page layout can't see into a shadow stage, so the runtime's stage
failure placer (`shadow-stage.js`) marks the host `data-lf-failed` until
the next stage replaces the box. The `layouts.css` rules that give a
failed widget the prose measure and drop its reserved `data-height` read
it beside a light `.lf-error`. That also covers `lf-file-editor`,
`lf-file-tree`, and a bound diff that fails after drawing, whose failure
boxes already stood in the stage unseen by those rules.

Verification:

- `test_a_patch_that_failed_stays_failed_when_its_diff_returns` (inline
and bound) passes; it now reads the refusal from the shadow root.
- `test_a_widget_that_failed_soft_claims_no_room` gains a refused-diff
case, which fails without the `layouts.css` change and passes with it.
- Diff comment-control, preparation-on-return, retry, plain-host and
native-metadata tests pass, as do `pnpm run test:runtime` (777) and
`pnpm run check:browser`.
- `test_a_diff_refresh_keeps_a_selection_in_unchanged_lines` fails
identically on the previous head without this change.

Other tests that read a diff's refusal from light DOM now read the
shadow root, including two in `tests/journeys/test_render_anchors.py`
that weren't run here.

Closes #3986 — automated triage

---------

Co-authored-by: leaf-agent <[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.

Run a data-bound widget, such as lf-diff, on a plain HTML page

2 participants