Repository navigation
Derive each event fact once, for the delivery and page state alike - #5310
Merged
Merged
Conversation
Since #5044 a message about a playground reaches the agent with the settings the preview showed (`unsent`), but only in its delivery. A session that compacted, or took the page over, reads the thread with `leaf page state <page> <message>`, which printed each message without them, so it could no longer tell which settings a comment was about. Each message in that reading now carries the same `unsent`, from the same function the delivery calls (`unsent_at_messages`). An edited message reads what stood at its latest edit, which is what the delivery of that edit carried. Whether a verb records unsent work moves onto `GestureWords.records_unsent`, so the two callers share it rather than each building the predicate. Behavior the tests now protect: `test_a_message_on_a_playground_carries_the_settings_it_showed` reads both threads with `page state` and expects the delivery's `unsent` on each message, the edited one at its edit. Dropping the field, or reading an edited message at its first words, fails it.
# Conflicts: # src/leaf/agent_state.py
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. `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, and a suggestion printed as an ordinary comment. Each new delivery field reopened the question of which other places should show it. `event_facts.EventFacts` now derives them, and both places call it. The delivery adds them to each event as before. `page state` adds them to each action in force and to each message of a thread it reads, as the message now reads, its `unsent` taken at its latest rewrite. A message also keeps its `suggestion` flag. What a delivery asks of the agent at the time (`answer`, `handling`, `waiting`) stays the delivery's own. Root `AGENTS.md` states the rule under "Validate once and share readings", and `event-batches.md` says `page state` prints the same fields. `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. Behavior the tests now protect: a choice in force reads in `page state` with the subject, threads, words and names its delivery gave it (`test_a_delivered_gesture_says_what_the_user_chose_on_their_version`, which fails without the facts), the page state test's exact entry carries them, and a suggestion reads as one in its thread, after a rewrite too (`test_page_state_marks_a_users_suggestion`, which replaces the test that pointed agents at `leaf page events` for the flag).
max-sixty
marked this pull request as draft
November 4, 2026 07:22
`leaf page state` builds the served state, which already walks the log for every event's threads, then had `EventFacts` walk it again, and fold every thread for the words rewrites replaced although it never passes a rewrite. It now hands the served memberships over, and the fold runs only for a rewrite. On a generated page with 1024 choices in force, the facts went from 20% of a profiled `page state` to 12%, nearly all of it the choices' words.
max-sixty
marked this pull request as ready for review
November 4, 2026 08:26
leaf-agent
approved these changes
Nov 4, 2026
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 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_dataworked them out on its own, so a session that missed the delivery, or compacted after it, readleaf page statewithout 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.mdunder "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 statetells 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):EventFactsderivessubject,threads,says,names,was,suggestionandunsentfor any events of a page's log, or messages folded from them. A folded message is read as it now reads, itsunsentat its latest rewrite (read_state.content_version). Without a loadable registry it leaves outsays,namesandunsent, as the delivery did.delivery.batch_dataspreads those facts into each event, then addsanswerandwaiting. Its output is unchanged.leaf page stateadds them to each action in force (page and thread-frozen widgets) and to each message of a thread it reads. Messages also keep theirsuggestionflag. It handsEventFactsthe thread memberships the served state already walked, and the threads are folded for replaced words only when a rewrite is read, whichpage statenever passes.thread_context.unsent_at_messagesreturns before reading the log's threads when no user message or rewrite is among its inputs, sincepage statenow calls it for actions too. Whether a verb records unsent work moves ontoGestureWords.records_unsent, shared by both callers.event-batches.mdsayspage stateprints the same fields; thepage statehelp says each action and message carries what its delivery added.Testing
test_a_delivered_gesture_says_what_the_user_chose_on_their_versionnow also reads the choice inpage stateand expects the delivery'ssubject,threads,saysandnames; it fails without the facts.test_a_message_on_a_playground_carries_the_settings_it_showedreads both of its threads withpage stateand expects the delivery'sunsenton 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_suggestionreplaces the test that pointed agents atleaf page eventsfor the flag, and covers a rewrite.test_page_state_folds_the_log_onto_the_published_pagecarries the new fields in its exact entry, and the command-help snapshot is regenerated.leaf-dev scalingpages: on thewidgetspage with 1024 choices in force, the facts take 12% of a profiledleaf 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.Left open
threadsandunsentread 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.