Repository navigation
Ask the log which drafts were sent, and save leaf.page's drafts when a container stops - #6213
Merged
Merged
Conversation
The drafts store kept the last 64 admitted attempts beside the drafts, a bounded copy of what the log already records, so sent words could come back as a draft when a tab's late write waited out 64 later sends, or when the server stopped between admitting a send and settling its draft. The store now asks the log: a generation whose attempt the log admitted is settled. The first reading or write after a send drops it and moves the drafts version, so every tab hears it at its next look, and a late write of it settles it. Admission no longer touches the drafts store (`settle_sent` is gone), so no stop between the two can leave sent words standing. `event_log.admitted_attempts` keeps each page's admitted attempts in the server process and reads only what the log gained since the last question, through the place-in-log reader `follow_events` now shares (`_Tail`): about 20 µs a question on any log, where parsing `leaf-dev bench`'s largest log takes 54 ms. The browser no longer asks the log too (`attemptAccepted`, which walked every event of the session on each draft lookup): the server's drafts never hold a sent generation. The drafts record drops `sent`, so its format moves to the current protocol, 46. Behavior changes: a late write of sent words, or a store left holding them by a stopped server, settles them however many sends came between. Tests: `test_the_log_settles_every_generation_it_admitted` replaces the 64-send test and fails on the previous store; `test_admitting_a_send_settles_the_generation_it_carries` now also checks that the news version moves.
Drafts change no page reading, so a commit published them only beside a change of its own: a visitor's words typed since their last send were lost when the container slept after ten idle minutes with no tab left to give them back, and a tab opened while it slept showed the drafts as of that send. A container now publishes each page whose drafts moved since its last publication as it stops (`storage.save_drafts`, from the stop handler, once serving has ended), so the next container restores them and the saved answers show them. The handler closes the listening socket first, so a request arriving during the save is refused at once, as after the process ends, rather than waiting on a listener nothing serves. Each publication records the drafts version it carried (`website-publication`, now at format 46), so a stop publishes only pages whose drafts moved; a page restored with drafts and not published since is published again, which costs only the stop. Commits keep publishing on their reading alone, so a draft written during an agent turn adds no publication to each tool call's transaction. Behavior change: drafts survive a container's sleep or replacement; a container lost without a stop, or a page store unreachable at the stop, loses the words typed since the last save. Test: `test_a_stopping_container_saves_the_drafts_typed_since_the_last_commit`.
leaf-agent
approved these changes
Nov 16, 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 review of how Leaf keeps drafts since #6124. The model stays: drafts live on the page's server outside the log, and tabs hear them through the news look. Two places where the drafts store kept a weaker copy of something another part knew change.
event_log.admitted_attempts, an index each server process keeps over the append-only log, about 20 µs a question on any log. The first reading or write after a send settles its draft and moves the drafts version, so admission no longer touches the store, and sent words can't come back however many sends came between or wherever the server stopped. The browser stops walking every event of the session on each draft lookup.To weigh: a
/api/newsor/api/draftsread now writesdrafts.jsononce after a send. The drafts and website-publication records move to format 46. A Cancel in one tab can still be undone by another tab's closing write that lands after it, left as too narrow for a mechanism.Max asked for the review. Codex reviewed twice; its two findings are fixed. Tests:
tests/process/test_drafts.pyandtests/process/website_server/test_saved_records.pygain a case each, failing before; the drafts browser tests pass.