Skip to content

Derive each event fact once, for the delivery and page state alike - #5310

Merged
max-sixty merged 4 commits into
mainfrom
playground-saved-choices
Nov 4, 2026
Merged

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

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

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

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
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
max-sixty marked this pull request as ready for review November 4, 2026 08:26
@max-sixty
max-sixty merged commit 69da5ef into main Nov 4, 2026
5 checks passed
@max-sixty
max-sixty deleted the playground-saved-choices branch November 4, 2026 08:36
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