Skip to content

Give the runtime's state, delivery and traffic facts one owner each - #2332

Merged
max-sixty merged 20 commits into
mainfrom
code-quality-runtime-state
Oct 11, 2026
Merged

max-sixty merged 20 commits into
mainfrom
code-quality-runtime-state

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Small cleanups from the code-quality survey of the browser runtime's state, delivery and traffic code. Each removes a second writer, reader or check of something the runtime already states once.

State and delivery

  • data-lf-traffic's pending has one writer: traffic.js watches the published effective.sending from mountApplication, painting only when the attempts change. afterEnqueue loses the presentation promise no caller read. pending now clears with the publication that accepts or refuses an attempt, slightly before the drain finishes settling it.
  • The application publisher reads its own receipts when naming a reply's parent or an undo's target; one admittedId helper states that rule for derive, nameParent and nameUndo.
  • runtime.undoing and runtime.restoringState go. The pending ledger already covers an undo in flight, and a gesture that leaves the ledger on accept now repaints keys on that edge. Nothing inside paintReading's scope plays motion any more, so Expand and contain the interaction gallery #354's "a refusal's restore does not animate" was already lost; whether it should animate stays open.
  • delivery.js classifies an /api/event answer once (readEventAnswer) for both senders, and its four retry tails are one retry().
  • state-feed.js releases its read slot in one place and names the quiet-feed guard; the reading's own completions keep their narrower guards.
  • The 2-second tick no longer retries a drag-deferred projection; the drag's release already does, and onDeferredReady presents and releases directly, including when the release lands during a state application (the pass queues behind it).
  • Redundant checks in the state read path go: a duplicate Leaf-View-Revision header, guards on a Response an awaited fetch always returns, an overtaken check canAdopt repeats, and questions defaults in queues.js.

Requests

  • layer-client.js has one JSON request primitive, requestJson, used by the file API, deferred data values, media upload and samples. Behaviour changes: sample allocation and release are now layer-admitted (a stale-layer allocation reloads instead of failing as "The sample document did not start Leaf", and a refused key there is observed); a non-JSON body fails as <what>: HTTP <status> rather than a SyntaxError; upload and deferred-value fallbacks read "image upload: HTTP n" and "deferred value: HTTP n", and a deferred value refused for another layer says "Leaf's layer changed while requesting deferred value".
  • storage.js reads the served delivery script once (DELIVERY, WEBSITE_DELIVERY, layerRoot), replacing four selectors and two derivations of the layer root. The script[data-lf-entry] seam harnesses use is unchanged.

Presentation

  • other_leaves drops closed neighbours, so they stop travelling in /api/state and the Leaves drawer no longer filters them. The Python neighbour fixture becomes a waiting page.
  • One phrase table words every activity count; a Leaves row's hover no longer repeats the queued and pending counts its line already says.
  • Widget Questions are filtered once, and questionItem picks its subject and ends in one switch.
  • The window resize handler stops running pageShifted a second time; its synchronous layout pass stays and is documented.

API surface

  • Thirteen re-exports only the render gate's probes and tests read move from widget-api.js to check-api.js, which every probe may now import; application.js's shallowSigs trampoline goes.

Not done: the probes' JSON-body fallback for a probe without Leaf-Layer stays. live_shell.py says a static host may serve the derived tree, and test_a_failed_bootstrap_hears_a_static_registry_generation holds that a headerless static host can supervise startup, so removing it would drop that support.

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

max-sixty and others added 17 commits October 10, 2026 17:19
…ead promise

startPost returned {answer, presentation}, but every caller read only the
answer, so afterEnqueue's whenDocumentPresented() promise went nowhere. It now
returns void and startPost returns the answer.

The `pending` field of data-lf-traffic had two writers, afterEnqueue and the
delivery drain, both writing the published effective.sending. traffic.js now
watches that selection from mountApplication, painting only when the attempts
change and nothing before the first send. Behaviour change: `pending` clears
with the publication that accepts or refuses an attempt, slightly before the
drain finishes settling it, rather than after.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ture's target

nameParent and nameUndo took the receipts as an argument, which delivery
fetched from the same publisher through a currentReceipts callback that
application.js threaded in. They now read the publisher themselves, and one
admittedId helper states the rule ("the ledger entry's admitted id while it
stands, its receipt's once released") that derive's undo projection,
nameParent and nameUndo each wrote out. No behaviour change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…light

withdraw() raised runtime.undoing around its post, and unaccountedGesture read
it beside hasPending(). The post enqueues the undo synchronously and the entry
stays in the ledger at least until its answer, so hasPending() already covers
that window; the flag only held z back for a few microtasks after the undo was
accepted and presented. Its two paintKeys calls go too: afterEnqueue paints on
enqueue, and a render probe holding an undo's POST while a read presented it
showed z return when the POST answered without the trailing paint.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
page-geometry.js's resize door already answers every window resize with
invalidate() and pageShifted(); chrome-layout's own handler ran pageShifted
again on the same event, before the body observer's repaint frame ran it a
third time. The handler keeps its synchronous edge, modality and layout
restatement, now documented in the module header, because moving it to the
frame would let an edge or a beside surface lag a live window drag by one
frame. The body observer's layoutChanged flag, which was exactly
widthChanged || chromeMoved, goes. No behaviour change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
questions/view.js filtered to widget Questions before calling questionHolding,
which filters the same predicate itself for its unfiltered callers, and the
annotation inventory filtered before questionPlace, which already gives a
non-widget Question no node. queues.js's questionItem chose its subject and its
`ends` from the source kind in two parallel ternaries; one switch now returns
both. No behaviour change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
other_leaves documented "live neighboring pages" but returned every running
server's row, closed ones included, and the Leaves drawer filtered them out
itself. The rule now lives in other_leaves, so closed rows stop travelling in
/api/state, stop feeding presence_fingerprint and activityTransitionAt, and
live-leaves.js draws the list as given. Behaviour change: state.others no
longer carries closed pages. The Python neighbour fixture becomes a waiting
page, and the drawer tests wait for a closed page's row to leave the list.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
banner.js's activityFacts and live-leaves.js's activityAccount each wrote the
queued and pending phrases, and a neighbour row's hover joined the row line,
which already ends with them, to the account, which said them again. One phrase
table in banner.js now words every count: `waiting` keeps the queued and
pending ones for the line and the banner, and a new `owed` carries the rest for
the row's hover. Behaviour change: the hover no longer repeats the queued and
pending counts; every phrase reads as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The served runtime script was selected four ways for four facts: layer-client
read the layer, release and probe, banner-status-view tested for a release to
mean "the website", storage.js read the share address, and context.js and
version.js each derived the layer root from the probe, one by URL resolution
and one by regex. storage.js, which imports nothing, now reads the script once
and exports DELIVERY, WEBSITE_DELIVERY and layerRoot(doc); every reader uses
them, and version.js's artifactRoot is layerRoot. The `script[data-lf-entry]`
seam leaf.js, sample.js and outside harnesses use is unchanged. No behaviour
change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
file-api, data.js's deferred values, uploadMedia and sample.js each wrote
"fetch with layerHeaders, admit, parse, throw the server's error" differently.
requestJson(url, init, what) now does it once, with sample.js's tested error
shape: the JSON is read off the text, and a failure throws the server's
`error` or "<what>: HTTP <status>" carrying the status, raw body and the
answer's fields. A refused admission throws LayerRefused, which each caller
maps to its own contract.

Behaviour changes: sample allocation and release are now layer-admitted, so a
stale-layer allocation reloads through the delivery probe instead of failing
as "The sample document did not start Leaf", and their responses report a
refused key and session activation like every other page call. A non-JSON
error body from the file API fails as its status rather than a SyntaxError.
The upload and deferred-value fallback messages read "image upload: HTTP n"
and "deferred value: HTTP n".

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
deliver() and deliverBookkeeping() each decided whether an answer accepted the
event, refused it finally, or said too little, and each wrapped applying its
state in the same catch. readEventAnswer and applyAnswerState now do that for
both; deliver() keeps its receipt match and attempt check on top, and its four
"notice once, pause, try again" tails are one local retry(). No behaviour
change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
readAndPresent and ask() each released the read slot and started the queued
trailing read with the same five lines; releaseSlot() now does it for both. The
news look's "nothing read or applying" guard, checked before and again after
presenting, is feedQuiet(). The reading completions keep their narrower guards,
which ignore a read still in flight so it cannot hold a return open, and the
feedQuiet comment says so. No behaviour change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
paintReading raised the flag while a refused projection entry stood, and
motion() returned null under it, so a restore after a refusal would not
animate (#354). Since widget rendering moved into its own presenters, nothing
inside paintReading's scope calls motion(): the board's FLIP, suggestion folds
and thread folds all run in other presentation regions. The guarantee was
already lost; this removes the global that implied it. No behaviour change.
Whether a refusal's restore should animate is left as an open product question.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
readState set Leaf-View-Revision itself from the same runtime.currentRevision
layerHeaders already sends; it guarded a Response an awaited fetch always
returns; state-application checked `overtaken` immediately before canAdopt,
whose first test is the same; and selectQueues/selectDone defaulted a
`questions` their one caller always passes. No behaviour change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Only a held drag defers the projection, and its release already calls
onDeferredReady. The 2-second tick also retried it, re-claiming every document
region each tick while the drag stayed held, only for presentCurrent to defer
again. The tick retry goes, and with it state-feed's projectionDeferred,
retryProjection, releasePending and notifyDataSubscribers dependencies;
onDeferredReady presents the held reading and releases pending entries
directly, with invalidateDom queuing the pass behind a state application as
retryProjection did. No behaviour change beyond the idle passes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
widget-api.js is the documented behavior-module API, yet thirteen of its
re-exports were read only by the render gate's probes and the browser tests:
ADDRESSABLE, USER_VIEW_RESTORE_CASES, quoteFrom, readingRegions,
renderedParent, shallowSigs, shownBand, shownBox, shownRegionBounds, uiInside,
upFrom and the two verbatim identity maps. check-api.js, the diagnostic entry
layer.py already refuses to packages, now carries them; the probes and tests
import them from there. TEXT_BOX stays, since module-authoring.md documents it.

check-api takes shallowSigs from its owner, projection/presentation.js, so
application.js's shallowSigs trampoline goes. ESLint let three named probes use
check-api.js; every render-check probe may now, which also retires the
widgets.js-only rule that the later block already overrode. No behaviour
change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/assets/runtime/sample.js
…n-JSON answer as its status

Review follow-ups. With runtime.undoing gone, an undo a read presented
before its POST answered leaves the ledger on accept, and if the answer's own
state is overtaken nothing repaints z; settlementChanged now repaints keys on
that edge as accountPending does for an entry leaving on presentation.
requestJson now fails an OK response whose body is not JSON as
"<what>: HTTP <status>" too, and copies only `current` from an error answer
rather than every field, so a server field cannot replace the Error's own.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
# Conflicts:
#	skills/leaf/scripts/leaf/render-checks/widgets.js
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
# Conflicts:
#	skills/leaf/assets/runtime/widget-api.js
leaf-agent
leaf-agent previously approved these changes Oct 11, 2026
# Conflicts:
#	skills/leaf/assets/runtime/banner.js
#	skills/leaf/assets/runtime/delivery.js
#	skills/leaf/assets/runtime/state-feed.js
@max-sixty
max-sixty merged commit ccf27b4 into main Oct 11, 2026
6 checks passed
@max-sixty
max-sixty deleted the code-quality-runtime-state branch October 11, 2026 06:28
max-sixty added a commit that referenced this pull request Oct 12, 2026
…, and correct the claims the code contradicts (#2612)

`module-authoring.md` is the package author's reference for the helpers
`widget-api.js` exports. #2538 documented every authoring export, adding
each to the section that owned its topic, so the reference had grown
piecemeal. It now follows the task a package author is doing rather than
`widget-api.js`'s order, which groups exports by owning file and
scatters one task across the list. Each helper is documented once, with
its signature and return value where it was only named before, and other
sections point at it by name. Mechanism a package author doesn't act on
is cut. The file goes from 1657 to about 1770 lines.

Every behavioral claim was checked against the runtime, and a second
pass tried to refute about 110 of them. Claims the code contradicted are
corrected, among them:

- `readingRegion(id)` was documented but is not exported.
- `motion()` returns null only under reduced motion or before
presentation; the restored-state case went in #2332.
- `quietWord`: Leaf writes quiet words on elements it marks rewritten,
changed by the user, or reported. `x-paints` went in #2555.
- `renderState` runs only while the widget has a subscriber, and a
throwing `renderState` or subscriber replaces the widget with its
fail-soft box.
- Only subscriptions built on the owner lifetime pause while the owner
is away; `watchDraft`, `onUserInput`, `watchReadingRegionTransitions`,
`claimTraversals` and `boundFile.watch` do not.
- `afterScript` coalesces by function identity, so a new arrow each call
runs each time.
- `watchDraft` takes `{input}`, which the restructure first dropped: it
hands the user's caret to the replacement box across a live revision.
Its callback also fires with `null` when the box's own send goes.
- `threadActions.open` tries the registered primary reader, then the
open Threads panel, then inline, then Threads.
- `reach` is read from a row only; `readWork().done` is a count;
`compareImages` also returns `width` and `height`; `alignedNodes`
renders `same` runs as spans; the contribution kind is `ask`.

`tabStore` has its own section, "Tab-local working state", and "Sticky
headers" is its own section, which the glossary now cites.
`assets/AGENTS.md` cites "Retained nodes" for the placement guarantees.
`motion.js`'s header loses the same stale restored-state clause.

`tests/runtime/widget-api.test.mjs` let `readingRegion(id)` through:
when a following code span opened with a brace, it read the call as a
method an example defines. A method head must now sit on one line; the
test fails on the old reference and passes on the new one.

Tests: `node --test tests/runtime/widget-api.test.mjs` and `pnpm run
test:runtime` pass; pre-commit passes.

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