Skip to content

Record a playground's unsent settings in the page's log, and map where widget state lives - #4845

Merged
max-sixty merged 10 commits into
mainfrom
playground-saved-choices
Oct 31, 2026
Merged

max-sixty merged 10 commits into
mainfrom
playground-saved-choices

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

A playground's settings before the user submits them lived only in the tab's sessionStorage. Another tab, another browser and the agent never saw them, so a comment on the preview reached the agent without the configuration it was about. This records them in the page's log, as a playground verb that never wakes the agent.

The change

  • tune verb (packages/playground/registry.json). It sits beside choose, has unit widget and detail {values}, and declares attention: false. choose still alone answers the playground's question.
  • $state.attention: false (src/leaf/schema.py, src/leaf/workflows.py, browser/registry.json). A verb that records what the user hasn't sent never asks for attention through its own changes. It also never counts as work the agent has in hand, so a tweak after a submission can't replace that submission as the widget's update.
  • lf-playground.js records when a gesture ends. That means a press, a committed edit, or one second without input; submitting records the settings first. Leaving or hiding the page records any pending edit, and an edit made before the page could record anything records once it can.
    • A tab adopts a tune it hasn't drawn, whether another tab's or one an undo makes current. It keeps edits it hasn't recorded, so words being typed stay put.
    • The tab store and the view's reconciliation between the tab's copy and the log are gone. Widget and view together: +123/−102, about 25 of the added lines header prose.
  • Where state goes (skills/leaf/references/module-state.md). The skill's module reference now opens with one map. It says where a widget keeps what the user makes (a declared verb), words to send (drafts), how the user looks at it in this tab (tabStore), published data and bound files, and how the widget hears of each change. browser/runtime/storage.js names the browser stores by reach and points to the map.
  • Agent instruction (packages/playground/instructions/author.md). For a comment on the preview, the configuration is the tune in force at the comment's seq. A value the comment's revision's controls can't hold showed as the control's authored value.

Trade-offs

  • Each tune carries the whole configuration, so a preset or Reset stays one gesture for Undo. The cost: when two tabs' records cross in flight, the later one sets every field. A tune per field would split those gestures, so this keeps the whole configuration. The widget header records the decision.
  • The page's z now steps back a settings change before older gestures, as an editor's undo does.
  • Closing a Firefox tab within a second of typing still loses the edit 1–2 times in 3, with or without a keepalive post. Reloads keep it on Chromium and Firefox.

Testing

  • tests/browser/widgets/test_playgrounds.py: tunes are quiet and match the values. A reload, another tab's tune, and undoing a choice all keep the right controls. An edit made while the state loads, or just before a reload, is recorded, and leaving a page with no edit records nothing, even when a recorded value is one its controls can't hold. Disabling each fix fails the new test.
  • tests/browser/widgets/test_pressed_controls.py: the sweep exempts presses that only record unsent settings from its "second press sent nothing" claim. A deliberately swallowed submit is still caught.
  • tests/model/test_workflows.py: a quiet verb asks nothing, even under work in hand. Removing either filter in workflows.py fails it.
  • evals/playground-comment-reads-its-settings: given only leaf page state, agents read the log for the comment's settings 4/4 with the instruction and 3/4 without it, on Claude Code and Codex.
  • No protocol bump. The generated types match, and the baseline reports no breaks.

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

A playground kept the settings a user hadn't submitted in the tab's
sessionStorage. Another tab, browser or device opened it at its defaults, a
reload after a submission put back the submitted values over later edits,
and the agent answering a comment on the preview couldn't know which
configuration the preview showed.

The playground now records its settings as `tune`, a user verb beside
`choose`, when a gesture ends: a press, a committed edit, or a second
without input. A tab adopts a tune it hasn't drawn (another tab's, or one
an undo makes current) and keeps the edits it hasn't recorded, so words
being typed stay put. Submitting records the settings, then `choose`, which
alone answers the obligation; undoing a choice still leaves the controls as
the user set them. The tab store and the rules that told a new choice from
one an undo revived are removed.

`$state.attention: false` is a new declaration value: a verb recording what
the user hasn't sent asks for no attention, is no update or receipt, and is
no input of work in hand (`workflows.py`). Without it, a tune after a
submission woke the agent and replaced the submission as the widget's
update.

Behavior the tests now protect: committed edits enter the log quietly; a
paused edit survives a reload; another tab's settings, not its choice,
replace the working values; undo steps the settings back a gesture. The
pressed-control sweep exempts presses whose gestures are all
`attention: false` verbs from its repeat claim, since pressing a preset
that already stands records nothing.

> _This was written by Claude Code on behalf of max-sixty_
… force at a comment

A pending pause record was cleared on disconnect and never rescheduled, so
an edit left unrecorded across a reconnection stayed unrecorded. The author
instructions now point the agent at the tune in force at the comment's seq,
past undos and restatements.

> _This was written by Claude Code on behalf of max-sixty_
The browser stores' policy in storage.js said anything two tabs must agree
about goes in the log. It now also names what the agent must read: unsent
work that changes what the page shows, such as a playground's settings,
which a comment on its preview refers to. Unsent words stay in the draft
store, since sending them is when the user says them. The module reference
tells package authors to record what the user makes, with a verb declaring
`attention: false` for work not yet sent, rather than keep it in tabStore.

No behavior changes; the kernel rebuild carries the comment's digest.
…page shows

A tab's open panel and a timeline's step also change what the page shows,
and stay in the tab. What sends a playground's settings to the log is that
the user makes them: they will submit them, Undo steps them back, and a
comment on the preview is about them. The draft store's line now covers
ink as well as words.
The draft store keeps one copy of a draft across every tab, so 'anything
two tabs must agree about goes in the log' was false. The stores reach this
tab or this browser; the log is for what another browser or the agent must
read.
# Conflicts:
#	packages/playground/widgets/lf-playground.js
The rules were spread over package-data.md (recorded verbs), module-state.md
(tabStore, bound data, bound files), module-input.md (drafts) and the runtime's
storage.js, and "working state" named both the tab store's contents and the
playground's recorded working values. module-state.md now opens with one
table: what the user makes is recorded through a declared verb, words they
write to send are drafts, how they look at the widget stays in tabStore, and
published data and bound files reach the widget through their own APIs, each
with who sees it and how the widget hears of a change. Undo tells recorded
state from tab state. The tab store's section is "State only this tab
keeps"; module-authoring.md and storage.js point to the map.

evals/playground-comment-reads-its-settings scores the playground's new
instruction: given only `leaf page state`, the candidate read the comment
against the log's settings 4/4 (Claude Code and Codex, 2 each), the base 3/4.
Given the log too, both arms passed 8/8, so the case gives only the state.
From an independent review of the branch:

- An edit made before the page's state arrived stayed unrecorded: the
  record's timer ran while `tune` was unavailable and nothing rearmed it.
  The widget now rearms after any update in which edits are pending and
  `tune` is available.
- An edit the one-second pause hadn't recorded was lost on reload. Hiding or
  leaving the page now records it. Measured with a fill-then-reload journey:
  kept on Chromium and Firefox. Closing a Firefox tab within the second still
  loses it 1 to 2 times in 3, with or without a keepalive post, so the post
  stays as it was.
- The author instruction now says a value the comment's revision's controls
  can't hold showed as that control's authored value.
- `$state.attention: false` says a change still asks for attention when it
  changes an obligation.

The widget header records why each tune carries the whole configuration:
a preset or Reset stays one gesture for Undo, and two tabs whose records
cross in flight keep the later one whole.
Review of the previous commit: leaving committed unconditionally, so a
recorded value the controls can't hold, which draws as its authored
default, was recorded as that default with no input. Leaving now records
only edits not yet recorded. The browser test reloads twice after another
tab records an out-of-range radius and checks the log still ends at it;
without the gate it ends at the default.
@max-sixty
max-sixty merged commit c3d3309 into main Oct 31, 2026
4 checks passed
@max-sixty
max-sixty deleted the playground-saved-choices branch October 31, 2026 20:18
max-sixty added a commit that referenced this pull request Nov 1, 2026
…eep presets (#4875)

The shadow-scale tool from #4478, a playground whose page draws its own
instrument and its own Save and Reset, is now a catalog example, and it
gains Flat, Soft and Deep presets drawn by the page.

- **Catalog:** `tests/fixtures/pages/page-drawn-playground.html` moves
to `examples/shadow-scale.html`, its only copy, and `docs/examples.html`
lists it as "Design tokens · Tune a shadow scale" after Panel motion.
The example still carries `actions="page"` for the corpus floor test.
Its catalog still is published to `leaf-assets`; the refresh recaptured
every preview, so the pin also moves the README's demo images.
- **Presets with no Leaf change:** `lf-playground-preset` sets only
`lf-playground-control`s, so a playground whose settings are all
contributor slices had no presets. The page can already provide them:
each chip passes a whole scale to the slice handle's `set`, the
playground records the press as one `tune` that Undo takes back whole
(#4845), Enter and Space reach it as a native button, and the page sets
`aria-pressed` on the chip whose value matches `get()`. Rejected:
letting `lf-playground-setting` carry a slice's JSON plus a hand-over
for page-drawn preset buttons, which would be a second API for what
`set` and `get` do.
- **Guidance:** five lines in
`packages/playground/instructions/author.md` say how.
- **Example writes:** the example now writes `aria-pressed` through
`keeps`, including its existing level and layer buttons, since the suite
refuses writes that change nothing and no browser test had loaded this
page before.

`test_a_page_drawn_preset_sets_its_whole_slice_as_one_gesture` applies
Deep by pointer and Flat by Enter, checks each records exactly one
`tune` and shows pressed, and that two Undos step back to Deep, then
Soft. That test, #4478's two page-actions tests, the catalog metadata
test, the corpus floor test, `check:browser` and `page check --render`
on the example pass.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
max-sixty added a commit that referenced this pull request Nov 2, 2026
A playground's settings before the user submits them are recorded in the
page's log (#4845), but they never wake the agent, so no delivery
carried them. A comment on the preview ("the corners are too round")
reached the agent without the radius the preview showed, and the
playground's author instructions told the agent to rebuild it from `leaf
page events`: the newest `tune` before the comment, minus earlier undos
and restatements. This hands the agent those settings with the message,
and gives the "records unsent work" declaration its own name.

## The change

- **`unsent` on delivered messages** (`src/leaf/thread_context.py`
`unsent_at_messages`, `src/leaf/delivery.py`). Each delivered message or
edit by the user carries the unsent work in force, when they wrote it,
on the widgets it is about. Those are the widgets enclosing the thread's
anchor as it stood then, read by `build_threads`' own rule, and the
widgets sent in the thread. The walk reads `InForce` at each input, so
an undo before the message takes a setting back and one after it
doesn't. Whether a verb records unsent work comes from the declaration
of the document the user acted in, so a later version redeclaring the
verb leaves earlier messages as they were.
- **`$state.unsent: true`** (`src/leaf/schema.py`,
`browser/registry.json`, `src/leaf/workflows.py`,
`packages/playground/registry.json`). This replaces `attention: false`,
which had made `attention` hold three meanings, and the new delivery
field would have depended on its `false`. `attention` is back to `const
true`, a request for the agent to act, and a verb may not declare both.
- **Instructions.** `skills/leaf/references/event-batches.md` lists the
field. The playground's reconstruction rule in
`packages/playground/instructions/author.md` becomes a pointer to it,
and `package-data.md` and `module-state.md` name the new declaration.

## Trade-offs

- Containment is the live page's, as `thread_memberships` and
`batch_threads` read it, not the revision each message was written on. A
later version that moves the commented passage into a different
playground before delivery would give the message that playground's
settings. Fixing it takes each input's revision and a rule for edits,
which carry none.
- A playground sent in a thread reads its declaration from the active
vocabulary, as all frozen thread markup does (`GestureWords`).
- Each input in a batch folds `build_threads` over the log up to it,
about 0.2 ms on a 400-event log.

## Testing

-
`tests/model/test_delivery.py::test_a_message_on_a_playground_carries_the_settings_it_showed`
covers an undo before and after the message, a submission (sent, so not
carried), a thread later moved to another playground, an edit, a
playground sent in a thread, a message elsewhere, and a later version
redeclaring the verb. Reverting each rule fails it.
- `evals/playground-comment-reads-its-settings` now pastes the comment
with `unsent`, while page state holds later settings. Claude Code and
Codex named the comment's settings in 8 of 8 runs, with this branch's
instructions and with `main`'s alike.
- Two Codex (gpt-6-astra) reviews: four of their five findings are fixed
here, and the containment one is the first trade-off above.
- The delivery record keeps `since` 15, and the protocol check reports
no breaks.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent pushed a commit that referenced this pull request Nov 2, 2026
Closing a Firefox tab right after typing in a playground lost the edit
in 3 of 8 closes. The playground records an unrecorded edit when the
page leaves, which in Firefox is `pagehide`, and the event post was an
ordinary request, which the browser cancels along with the document. Any
gesture still on its way when a tab closed, such as a reply sent a
moment before, could be lost the same way.

An earlier test of a `keepalive` post (#4845) set it only while the
document was hidden and concluded keepalive didn't help. Firefox fires
`pagehide` while the document still reads `visible`, so the post that
mattered never had it. One traced close: `beforeunload`, `pagehide`, the
post (document visible), `visibilitychange` to hidden, `unload`.

## The change

- **`browser/runtime/layer-client.js`, `postEvent`**: every event goes
out with `keepalive` when its body is under 60,000 bytes. A page may
keep only 64 KiB of keepalive bodies in flight, and the browser refuses
a request past that, so a longer message goes out as an ordinary
request.
- **`browser/runtime/interaction-log.js`**: the interaction log shares
that budget. Its routine uploads drop `keepalive`, since its closeout
already sends queued entries again. The closeout is one batch of up to
32,000 bytes. In Firefox it runs before the playground's edit and could
otherwise use up the room the edit needs.

## Testing

- `tests/runtime/event-post.test.mjs`: a gesture's post asks for
`keepalive`, and a body over the limit, counted in bytes rather than
characters, goes out without it. Removing `keepalive`, setting it
unconditionally, or counting characters each fails the test.
- No browser test covers the close itself. Neither engine fails it
deterministically without depending on how Playwright intercepts
requests.
- Measured with a journey that opens a second tab, types, closes the tab
and reads the edit back from the first tab, eight closes per arm:
Firefox kept 5 of 8 before and 8 of 8 after, and Chromium kept 8 of 8 in
both. Event-post round-trip medians stayed at 10–15 ms in both engines.
- `pnpm run test:runtime`, `pnpm run check:browser`, pre-commit on the
changed files, the playground's leave test, and the interaction-log
browser tests in `test_render_application_boundary.py` pass.
- Two Codex (gpt-6-astra) reviews. Their findings are fixed: the
closeout's size, the test's claim and byte counting, and two comments.
The one exception is below.

## Left open

A gesture queued behind one still in flight when the tab closes is still
never sent, because `delivery.js` sends gestures one at a time. That
takes two gestures and a close within one server round trip. Sending the
queue all at once as the page leaves would let gestures arrive out of
order.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 4, 2026
…yground restore test (#5338)

`test_complete_views_restore_native_values_in_wrapped_layouts` fills
Title, presses Bold and reloads straight away. Since #4845 the
playground saves its settings as `tune` events in the log. The Title
field's blur records `{title, tone: quiet}`, and the press then records
`{title, tone: bold}`. Delivery sends the second tune only after the
first one's answer arrives or shows up in the page's state. So a reload
inside that round trip keeps the title and loses Bold. That is the exact
failure in scheduled runs
[41432142330](https://github.com/max-sixty/leaf/actions/runs/41432142330)
(macOS, both widths) and
[41622727492](https://github.com/max-sixty/leaf/actions/runs/41622727492)
(macOS, 390). Linux passed in the same runs: its round trip is shorter.

The test now waits until the log holds the Bold tune before it reloads.
It still checks that the restored title, the checked radio and
`host.values.title` come back after the reload. #4845's intent and the
playground's behavior are unchanged.

**Verification**

- Before: a scratch copy of the test let the server admit the first tune
but held back its answer, then reloaded right after the press. The log
held only the `quiet` tune, Title was restored and Bold was unchecked,
on 3 of 3 runs.
- After: with the first event's answer delayed by 1 s, both widths pass.
Without a delay they also pass locally.

**What this leaves**

The underlying limit is in delivery, not this test. A gesture still
waiting in the queue behind an unanswered one is not sent when the page
unloads. The playground's `pagehide` handler only flushes edits that
haven't been dispatched yet (`#unsent`), not ones already queued. A
person would only lose a gesture this way by leaving within one round
trip of two quick gestures. On a local server that's milliseconds, so
this PR doesn't change delivery. Making the queue survive unload would
need ordered keepalive sends and resolving the queued events' references
to their predecessors.

Closes #5124 — automated triage

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

#4845 gave the playground a `tune` verb to record its unsent settings,
but didn't add a `tune` event to `ACTIONS_IN_FORCE`. That list is the
log the nightly journey
`test_the_render_gate_applies_every_action_in_force_a_second_time`
serves, and the test requires the log's actions to cover every verb the
registry declares, so the test has failed every scheduled run since. The
list now includes a `tune` on `ab-card` with the same settings its
`choose` sends, so the gate also re-applies the tune and checks that
nothing moves. This changes test data only; no behavior changes.

The journey fails on main with `Extra items in the right set:
('lf-playground', 'tune')` and passes with this change (`uv run pytest
tests/journeys/test_render_projection.py::test_the_render_gate_applies_every_action_in_force_a_second_time
--run-nightly`).

Closes #5132 — automated triage

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

`test_an_answered_obligations_words_are_its_widgets_semantic_state`
fails on main because its fixture still posts the events the playground
sent before #4845. That PR made a playground's controls draw the `tune`
in force rather than the latest `choose`, and the widget's own submit
records a `tune` before it sends `choose`. The test posted a bare
`choose`, so the controls stayed on Banner and the output never said
"strip". It now posts the `tune` the widget would post, then the
`choose`.

That first failure hid a second stale read. #5318 folded answered On me
cards under Done, and a Done card draws its answer in `.lf-fp-on-says >
.lf-fp-value`. The test now unfolds Done with `show_done` and reads that
element, as the neighbouring tests updated in #5318 do.

No product code changes. The behavior the test protects still holds: an
answered playground's On me card names the instruction it sent ("Build
the strip one."), not the setting its controls show afterwards. The test
failed on main with the reported `strip` assertion and passes with this
change (local run on Linux).

Closes #5168 — 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.

2 participants