Repository navigation
Deliver a message with the unsent work it was about - #5044
Merged
Merged
Conversation
Unsent work, such as a playground's settings before the user submits them,
wakes no one, so no delivery batch carried it. A comment on the preview ("too
round") reached the agent without the radius the preview showed, and the
playground's author instructions told the agent to rebuild it from the log:
the newest tune before the comment, minus earlier undos and restatements.
Each delivered message or edit by the user now carries `unsent`: the unsent
work in force on the widgets it is about when the user wrote it
(`thread_context.unsent_at_messages`). Those are the widgets enclosing the
thread's anchor as it stood then, 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. The playground's reconstruction rule is
replaced by a pointer to the field. Whether a verb records unsent work is
read from the declaration of the document the user acted in, so a later
version redeclaring it leaves earlier messages as they were. Containment is
the live page's, as `thread_memberships` reads it.
The declaration is now `$state.unsent: true` rather than `attention: false`:
`attention` is back to `const true`, a request for the agent to act, and a
verb may not declare both. Before, one field held three meanings, and the
new delivery field would have hung off its `false`.
Behavior the tests now protect: a delivered message about a playground carries
the tune in force when it was written, across an undo before and after it, a
thread moved to another playground, an edit, a playground sent in a thread and
a later version redeclaring the verb; a message elsewhere and sent work carry
none. The eval case pastes the comment with `unsent` and page state holding
later settings; Claude Code and Codex named the comment's settings 8/8 on both
arms.
The delivery record keeps `since` 15; the protocol baseline reports no breaks.
# Conflicts: # browser/types/contract.d.ts # build/browser/protocol-baseline.json # skills/leaf/references/event-batches.md # src/leaf/delivery.py
leaf-agent
approved these changes
Nov 2, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 4, 2026
…5310) A delivery adds facts to each event it carries: what it changes, its threads, a gesture's words, the words a rewrite replaced, the work the user hadn't sent. `delivery.batch_data` worked them out on its own, so a session that missed the delivery, or compacted after it, read `leaf page state` without them: a past choice printed as option ids, a comment about a playground printed without the settings it was about (`unsent`, #5044), and a suggestion printed as an ordinary comment. Each new delivery field also reopened the question of which other places should show it. ## Decision Max chose to add a rule that settles that question, now in root `AGENTS.md` under "Validate once and share readings": each fact Leaf derives about the page is derived once; whatever a delivery tells the agent about an event, apart from what it asks of the agent at the time (`answer`, `handling`, `waiting`), `leaf page state` tells a later session about the same event, or the message as it now reads, under the same name and from the same code. What each place selects for its purpose stays as it was: the delivery's thread digests, `page state`'s paging, and the browser's served state. ## The change - **`src/leaf/event_facts.py`** (new): `EventFacts` derives `subject`, `threads`, `says`, `names`, `was`, `suggestion` and `unsent` for any events of a page's log, or messages folded from them. A folded message is read as it now reads, its `unsent` at its latest rewrite (`read_state.content_version`). Without a loadable registry it leaves out `says`, `names` and `unsent`, as the delivery did. - **`delivery.batch_data`** spreads those facts into each event, then adds `answer` and `waiting`. Its output is unchanged. - **`leaf page state`** adds them to each action in force (page and thread-frozen widgets) and to each message of a thread it reads. Messages also keep their `suggestion` flag. It hands `EventFacts` the thread memberships the served state already walked, and the threads are folded for replaced words only when a rewrite is read, which `page state` never passes. - **`thread_context.unsent_at_messages`** returns before reading the log's threads when no user message or rewrite is among its inputs, since `page state` now calls it for actions too. Whether a verb records unsent work moves onto `GestureWords.records_unsent`, shared by both callers. - **Contracts**: `event-batches.md` says `page state` prints the same fields; the `page state` help says each action and message carries what its delivery added. ## Testing - `test_a_delivered_gesture_says_what_the_user_chose_on_their_version` now also reads the choice in `page state` and expects the delivery's `subject`, `threads`, `says` and `names`; it fails without the facts. - `test_a_message_on_a_playground_carries_the_settings_it_showed` reads both of its threads with `page state` and expects the delivery's `unsent` on each message, an edited one at its rewrite; dropping the field or reading the message's first words fails it. - `test_page_state_marks_a_users_suggestion` replaces the test that pointed agents at `leaf page events` for the flag, and covers a rewrite. - `test_page_state_folds_the_log_onto_the_published_page` carries the new fields in its exact entry, and the command-help snapshot is regenerated. - Focused model tests (delivery, thread reading, interact document and layer, wait, hooks, workflows, activity, stop guard) and pre-commit pass locally. - Cost, on `leaf-dev scaling` pages: on the `widgets` page with 1024 choices in force, the facts take 12% of a profiled `leaf page state`, nearly all of it the choices' words; the delivery runs the same work it ran before. The host was at a load of 70–100 during the runs, so the wall-clock comparisons were too noisy to quote. - Two Codex (gpt-6-astra) reviews: one of the design, one of this diff. The diff review's findings on the suggestion flag and the repeated log walks are fixed here; its third finding is below. ## Left open `threads` and `unsent` read which widgets sit inside which in the live page, so a later version that moves a playground's preview out of the playground changes what an earlier message about it reads. Fixing it takes each input's revision, and rewrites carry none. The module header says so. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 newesttunebefore 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
unsenton delivered messages (src/leaf/thread_context.pyunsent_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 bybuild_threads' own rule, and the widgets sent in the thread. The walk readsInForceat 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 replacesattention: false, which had madeattentionhold three meanings, and the new delivery field would have depended on itsfalse.attentionis back toconst true, a request for the agent to act, and a verb may not declare both.skills/leaf/references/event-batches.mdlists the field. The playground's reconstruction rule inpackages/playground/instructions/author.mdbecomes a pointer to it, andpackage-data.mdandmodule-state.mdname the new declaration.Trade-offs
thread_membershipsandbatch_threadsread 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.GestureWords).build_threadsover 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_showedcovers 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-settingsnow pastes the comment withunsent, 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 withmain's alike.since15, and the protocol check reports no breaks.