Skip to content

Credit an input with the landing of a widget preparation its work began - #2391

Closed
max-sixty wants to merge 7 commits into
mainfrom
agent-a155c1464bda6744e
Closed

max-sixty wants to merge 7 commits into
mainfrom
agent-a155c1464bda6744e

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Fixes the teardown error in test_phone_diff_headers_keep_distinguishing_parent_folder_readable (added in #2368). Since about 08:00 UTC it has failed on PR test jobs, for example run 38123623356 and run 38123626725.

Cause

Nothing merged after #2368 broke it. The test is flaky under load. On the same base (f89886583) it errored in two runs and passed in a third (38123586759).

When a tap opens a closed lf-diff file, the file's lines load asynchronously. The toggle handler calls loadEntry, which imports the Markdown grammar and runs Shiki rendering. lf-diff declares that work through present. The shift watch ended a gesture's credit when lfRenderingSettled() read true, and by its own contract (runtime/rendering.js) that reading cannot see work held in a promise. On a loaded runner the loop settled before the lines arrived, so the 49 px push on the next file header was judged as moving "without input". The product behaved correctly: the files below moved because the user opened the one above them.

Holding /vendor/syntax/markdown.js with page.route reproduces the failure every time, with the same (0, 49)px report as CI.

Fix

An input owns the landing of a widget preparation its own work began, and nothing while the preparation waits. Ownership comes from provenance, not from timing or location.

  • Runtime: attachWidgetPresentation (semantic-state.js), the one door for widget preparation regions, announces each preparation to observers. It sends begin synchronously in the callback that declared it, and settle when its completion settles, in the task that committed it. One frozen identity spans both, across the widget's native awaits. leaf.js publishes the observer on the validation seam as lfObserveWidgetPreparations, beside lfObserveQueuedWork.

  • Input provenance (input_work_watch.js): this extends the native activation seam that already tied a click to the <details> it closes, so it now covers opening too. A summary activation that opens its details records the activating input. The toggle the browser later dispatches for that opening, as a separate task, runs its listeners under that input, unless the click was cancelled. Two kinds of click count:

    • the input's own trusted click, from a mouse or the keyboard;
    • a click the input's work dispatches. Leaf's held-word release dispatches the summary's click on pointerup, which is how a tap or mouse press opens a diff file here.

    A details opened by a script, or clicked by a timer with no input on the stack, opens for no input.

    The browser coalesces flips into one toggle, and the first trusted toggle after an activation settles that activation, whatever state it announces. Its listeners answer to the input only for an opening the activation didn't cancel. Any other toggle expires the record, for example when a click listener opens the details and the native activation shuts it again. The watch listens for toggles on each recorded details itself, so expiry doesn't depend on the page having a listener.

  • Watch (shift_watch.js): when a preparation begins, the watch reads lfInputWork.current(). If an input is running, the preparation's identity carries it to the settlement. The watch then opens a rendering for that input from that task until the loop settles again. Otherwise the landing is judged passive. The gesture's own rendering still ends on lfRenderingSettled.

Three earlier revisions guessed the cause, and review caught each one: page-wide readiness, overlapping renderings, and containment of the input's target in the widget. Their code is gone.

Tests

  • test_an_input_owns_the_landing_of_a_widget_preparation_it_began: a control moved while the preparation waits is reported, the landing's push is the press's, and a move after the landing is reported.
  • test_a_preparation_no_input_began_lands_passive: a response the page requested before the press opens a diff file while the press's counted work runs, and the landing must be reported. It has two arms:
    • elsewhere: the press lands outside the diff. The overlap revision misses this one.
    • in the same widget: the press lands on the diff's filter field. The containment revision misses this one.
  • test_an_activation_that_opens_nothing_leaves_a_later_open_passive: Enter on a header either has its click cancelled, or has the click's listener open the file and the activation shut it again. A later scripted opening must land passive in both arms. The closed again arm fails on 9be86e2.

I ran:

  • both tests
  • Codex's three scratch reproductions
  • the phone tap with the grammar held, which goes through held-word's pointerup click
  • tests/test_render_shift_watch.py and tests/test_render_words_watch.py, whole files, since both watches changed
  • tests/test_render_diff_controls.py
  • the two other tests that expect passive findings, test_a_comment_box_on_words_in_a_scroller_stands_without_scroll_timelines and test_a_fold_at_the_foot_admits_no_change_above_it
  • pnpm run test:runtime: 335 passed

Main already carries this PR's first version, through #2385: there, a gesture keeps its credit while any part of the page is still unpresented. That version hides unrelated movement while any widget preparation is pending, as leaf-agent's review showed. This PR replaces it: the merge with main keeps the provenance-based watch and its tests, and drops the page-wide presented condition and its test.

It also carries #2393's one-line fix for main's vulture failure (leaf_dev.suite_profile's unused nextitem hook argument), so its lint can pass before #2393 lands.

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

test_phone_diff_headers_keep_distinguishing_parent_folder_readable failed at
teardown on loaded CI runners: the second lf-diff file header "moved without
input by (0, 49)px" after the tap that opened the first file. Opening a closed
file loads its evidence in a promise (the Markdown grammar and Shiki
rendering) that lf-diff declares through `present`, so the page's
presentation proof stays pending until the lines land. The shift watch ended
a gesture's ownership on `lfRenderingSettled` alone, which by its contract
(runtime/rendering.js) cannot see promise-held work. On a slow machine the
loop settled before the file's lines arrived, so their growth read as
passive. The product behaved correctly: the files below moved because the
user opened the one above them.

The watch now ends a gesture's rendering once the page has also presented
its current publication (`lfReadiness(null, "presented")`), widget
preparations included, which is the declared completion `pageReadiness`
already states. Deferred arrivals stay outside that credit, so a late
arrival still fails as passive.

New test: test_an_input_owns_a_widget_preparation_it_began_until_presented
holds the Markdown grammar with page.route, so the loop settles while the
preparation is pending, and checks that the press owns the growth and that
a passive move after presentation still fails. With the old reading it
fails with the same 49 px report the CI runs showed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent added a commit that referenced this pull request Oct 11, 2026
The restored-surface browser test's contained cases opened an isolated
`lf-sample` child URL in a new top-level tab and waited for it to
present. That child needs its host's private port, so the detached tab
cannot start. The test now primes saved auxiliary chrome on the host,
waits for the contained child to present, and checks that the host
restores its panel while the isolated child does not inherit it. The
standalone cases still measure their original first-paint geometry.

The formerly failing contained cases and the standalone controls passed
in the pinned full CI run. Lint, build, and review passed. That run's
only red result was a separate 49px diff-header shift in a newly added
test; #2391 addresses the shift watcher's completion boundary. This PR
does not change diff rendering or the shift watcher.

---------

Co-authored-by: leaf-agent <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new completion condition masks unrelated layout shifts while a widget preparation is pending.

Comment thread tests/shift_watch.js Resolved
…readiness

The previous commit kept a gesture's shift credit open until the page's
`presented` readiness stage, so while any widget preparation was pending the
gesture owned every movement on the page. Review showed the cost: with the
diff's Markdown grammar held, moving an unrelated control 40 px went
unreported.

The runtime now publishes each widget preparation's lifecycle on its
validation seam (`lfObserveWidgetPreparations`, owned by
`attachWidgetPresentation` in semantic-state.js): "begin" when a widget
declares it and "settle" in the task that settles its completion. The shift
watch records a preparation declared while an input's rendering (or an
earlier landing's) runs. When that preparation settles, the watch opens a
rendering for the same input that runs until the loop settles again, as the
input's own rendering does. A preparation's wait owns nothing, and the
gesture's own rendering again ends on `lfRenderingSettled`.

test_an_input_owns_the_landing_of_a_widget_preparation_it_began now holds
the grammar and checks three things. A control moved while the preparation
waits is reported (the reviewer's case, which the page-wide version
missed). The landing's push on the files and control after it is the
press's. A move after the landing is reported. With landings uncredited it
fails at the landing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty max-sixty changed the title Hold a gesture's shift credit until its widget preparation presents Credit an input with the landing of a widget preparation it began Oct 11, 2026
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
Review of 3106d41 found the credit still too broad. A preparation took as
its owner whichever input's rendering happened to be running, so a passive
timer that opened a diff file during an unrelated button's counted work gave
that file's landing to the button. Its 49 px push on a later control then
went unreported.

The runtime's preparation identity now names the declaring widget's element
(`owner`). Every input rendering the shift watch opens records the node it
was aimed at: the pointer or key event's composed target, or the typing
field. A preparation belongs to an input only if that target lies inside
the declaring widget in the rendered tree and the input's rendering, or a
landing it owns, is still running. A preparation started by a timer, by
news, or by input aimed at another widget lands passive.

New test: test_a_preparation_no_input_aimed_at_lands_passive opens a diff
file from a held response the page requested before an unrelated press,
while the press's counted work runs. The landing must be reported. With the
overlap-only watch from 3106d41 it is not.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent pushed a commit that referenced this pull request Oct 11, 2026
The hosted agent could describe a thread as collapsed without changing
it: its website harness disabled native plugins and skill discovery, so
it had no ordinary Leaf workflow to follow. Install the complete
prepared Leaf plugin through Codex's native marketplace and let hosted
threads use normal skill discovery and the shared App Server
instructions. Keep only the website's page scope and harness ownership
in its additional instructions; restrictive configuration belongs solely
to the separate title-generation task.

Copy the complete prepared payload into the container, excluding
generated Python environments, and redeploy when its hooks or manifests
change. Website verification and evals share the native installer. The
thread reference now distinguishes omitted model context from an actual
summary event that folds messages in the browser.

Validated with real Codex App Server and queue journeys, the website
adapter journey, and native-plugin replays on both the host and
container-pinned Codex. The summary replay folded 13 originals and
verified reveal/refold in Chrome. Focused website, CLI admission, thread
rendering, title-generation, native eval-install tests, and all 75
Worker tests pass. Hosted latency will be measured against the deployed
release after merge.

Includes the completed shift-checker repair from #2391 after the broad
CI suite exposed its delayed diff-disclosure failure: gesture ownership
now includes the widget preparation the page declares pending. A
held-grammar regression verifies both the delayed result and continued
rejection of passive movement after presentation.

> _This was written by Codex on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…d it

Containment still guessed the cause. A passive response opened a diff file
while a click on the diff's own filter field ran, and because that click was
aimed inside the widget it received the file's landing. Its 49 px push on a
later control went unreported.

A preparation now belongs to an input only by provenance. The shift watch
reads `lfInputWork.current()` as the widget declares the preparation and
carries that input to the landing through the preparation's identity, which
spans lf-diff's native awaits. A timer, news, or script with no input on
the stack leaves the landing passive. Containment, the target recorded on
each rendering, and the runtime identity's `owner` field are gone.

`input_work_watch.js` makes the opening of a <details> explicit by
extending its native activation seam. A summary activation that opens its
details records the activating input, and the toggle the browser later
dispatches for that opening runs its listeners under that input (unless the
click was cancelled). That covers the input's own trusted click (keyboard,
mouse) and a click its work dispatches. Leaf's held-word release on
pointerup dispatches the summary's click, so the pointerup owns the opening.
A script-opened details, or one clicked by a passive timer, opens for no
input.

test_a_preparation_no_input_began_lands_passive gains the same-widget arm
(the click lands on the diff's filter field). The containment watch
(0eb1e1d) fails it. The landing-owned test, the elsewhere arm, the phone
tap with the grammar held, and Codex's scratch reproductions all pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty max-sixty changed the title Credit an input with the landing of a widget preparation it began Credit an input with the landing of a widget preparation its work began Oct 11, 2026
max-sixty and others added 2 commits October 11, 2026 04:12
# Conflicts:
#	tests/shift_watch.js
#	tests/test_render_shift_watch.py
Main's vulture hook, which arrived beside #2345, flags it; pluggy passes a hook
implementation only the arguments it names.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
… says

The input-work watch consumed a recorded summary activation only on a
toggle announcing "open". When Enter's click listener opened a file and its
native activation then shut it, the one coalesced toggle announced "closed"
and left the activation recorded. A script opening the file later
inherited the keydown as its cause, so that file's landing moved a control
49 px with no report.

The first trusted toggle after an activation now settles it, open or
closed. Its listeners answer to the input only for an opening the
activation did not cancel. Any other toggle expires the record. The watch
listens for toggles on each recorded details itself, so expiry no longer
depends on the page having a toggle listener.

New test: test_an_activation_that_opens_nothing_leaves_a_later_open_passive,
with a cancelled arm and a closed-again arm, requires a later scripted
opening to land passive. The closed-again arm fails on 9be86e2.

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